简体   繁体   English

将自然语言逻辑条件转换为Java代码

[英]Converting Natural language logical condition into a Java code

How do I go about translating a Natural language logical condition into its Java code counterpart? 我该如何将自然语言逻辑条件转换为其Java代码对应物?

Say I have this condition 说我有这种情况

(Color Equals Blue) AND (Name Contains Smith)

What can be done to translate this to a Java level code, which might look like 如何将其转换为Java级别的代码,可能看起来像

(Color.equals("Blue") && (Name.contains("Smith")))

I could not come up with any definitive approach to achieve the desired outcome, so here I am asking this question. 我无法想出任何确定的方法来达到预期的结果,所以在这里我要问这个问题。 Also, please let me know that reason before down-voting. 另外,请在拒绝投票之前让我知道该原因。

I would try a dsl that parses the syntax you specified (Color Equals Blue) AND (Name Contains Smith) into java code. 我会尝试将您指定的语法(Color Equals Blue) AND (Name Contains Smith)解析为Java代码的dsl。 Make sure you understand the grammar for this syntax very well though before you start translating it into your parser grammar. 在开始将其转换为解析器语法之前,请确保对本语法的语法非常了解。 A language specification link would help a lot. 语言规范链接会有所帮助。 In the past I used ANTLR and it was really easy to generate JAVA code once i had the syntax tree from the output string. 过去,我使用ANTLR,一旦我从输出字符串中获得了语法树,就很容易生成JAVA代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM