123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182(*
* This file is part of the Watson Conversation Service OCaml API project.
*
* Copyright 2016-2017 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*)(** Spel data structure constructors *)openSpel_topenWcs_topenSpel_util(** {6 parsers} *)letof_strings=Spel_parse.expr_from_stringsletof_texts=Spel_parse.quoted_expr_from_strings(** {6 printers} *)letto_string=Spel_print.to_stringletto_text=Spel_print.to_text(** {6 from OCaml types} *)letentityentity_def?value()=beginmatchvaluewith|None->mk_expr(E_entity(entity_def.e_def_entity,None))|Somevalue_def->letvalue=value_def.e_val_valueinifList.memvalue(List.map(funev->ev.e_val_value)entity_def.e_def_values)thenmk_expr(E_entity(entity_def.e_def_entity,Somevalue))elseLog.error"Spel builder"None("Undefined entity: "^value)endletintentintent_def=mk_expr(E_intentintent_def.i_def_intent)letboolb=mk_expr(E_lit(L_booleanb))letintn=mk_expr(E_lit(L_intn))letstrings=mk_expr(E_lit(L_strings))(** {6 expression constructors} *)letpropex=mk_expr(E_prop(e,x))letprop_catchex=mk_expr(E_prop_catch(e,x))letgete1e2=mk_expr(E_get(e1,e2))letlistl=mk_expr(E_listl)letnew_arraytl1l2=mk_expr(E_new_array(t,l1,l2))letnew_tl=mk_expr(E_new(t,l))letcalleml=mk_expr(E_call(e,m,l))letcall_catcheml=mk_expr(E_call_catch(e,m,l))letopopl=mk_expr(E_op(op,l))leteqe1e2=opOp_eq[e1;e2;]letnee1e2=opOp_ne[e1;e2;]letlte1e2=opOp_lt[e1;e2;]letgte1e2=opOp_gt[e1;e2;]letgee1e2=opOp_ge[e1;e2;]letnote=opOp_not[e;]letand_e1e2=opOp_and[e1;e2;]letor_e1e2=opOp_or[e1;e2;]letpluse1e2=opOp_plus[e1;e2;]letminuse1e2=opOp_minus[e1;e2;]letuminuse=opOp_uminus[e;]letmulte1e2=opOp_mult[e1;e2;]letdive1e2=opOp_div[e1;e2;]letmod_e1e2=opOp_mod[e1;e2;]letconcatl=opOp_concatlletto_stringe=opOp_toString[e;]letconditionale1e2e3=mk_expr(E_conditional(e1,e2,e3))letidentv=mk_expr(E_identv)(** {6 other constructors} *)letanything_else=mk_exprE_anything_elseletcontext=mk_exprE_contextletconversation_start=mk_exprE_conversation_startletentitites=mk_exprE_entitiesletinput=mk_exprE_inputletintents=mk_exprE_intentsletoutput=mk_exprE_outputletvariablev=mk_expr(E_variable(v,None))(** {6 Spel checker *)letspel_checks=lete=of_stringsinSpel_print.to_stringe