我正在为项目使用json-logic库。 我想使用python将用户输入字符串转换为json-logic格式。
用户输入字符串:
intent == serviceRequest and entities.entity== charges and entities.value ==getRoamingCharges or entities.entity==plans and entities.value ==data plans
必需的json格式:
{"and":[
{"==" :[{"var":"intent"},'serviceRequest']},
{"or":[
{"and":[{"some" : [ {"var":"entities"}, {"==":[{"var":"entity"}, "charges"]} ]},
{"some" : [ {"var":"entities"}, {"==":[{"var":"value"}, "getRoamingCharges"]} ]}]
},{"and":[
{"some" : [ {"var":"entities"}, {"==":[{"var":"entity"}, "plans"]} ]},
{"some" : [ {"var":"entities"}, {"==":[{"var":"value"}, "data plans"]} ]}
]}]} ]}
用户输入字符串逻辑(和或运算符)将始终是dynamic。 谁可以帮我这个事。 我尝试使用pyparsing库执行此操作,但无法将字符串解析为所需的json格式。 谢谢