站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss RULES 3.0.6 API 英文版文档

NLExpressionCompiler - JBoss RULES 3.0.6 API 英文版文档


org.drools.lang.dsl.template
Class NLExpressionCompiler

java.lang.Object
  extended by org.drools.lang.dsl.template.NLExpressionCompiler

public class NLExpressionCompiler
extends java.lang.Object

This is the utility class for compiling pseudo natural/DSL expression into the target language, via the supplied mappings. This version works off "string templates" rather then infix operators. Note that this is not particularly efficient for large grammars - IN THEORY ! However, I have tested it with grammars of 200 000 terms, and it took less then a second per expression, so its no slouch. This could be a problem for bulk compiling of large pkgs with thousands of conditions. In general, grammars of < 1000 items should be fine. The cost is a parse time cost for Drools, which can be done incrementally in a suitable environment ideally anyway. It will go through each item in the grammar, trying to apply it regardless of if it is needed. This may be improved by some early regex scanning, but most likely this will not really save much.


Constructor Summary
NLExpressionCompiler(NLGrammar grammar)
           
 
Method Summary
 java.lang.String compile(java.lang.String expression, java.lang.String scope)
          This will iterate through the grammar, trying to match any grammar templates with the expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NLExpressionCompiler

public NLExpressionCompiler(NLGrammar grammar)
Method Detail

compile

public java.lang.String compile(java.lang.String expression,
                                java.lang.String scope)
This will iterate through the grammar, trying to match any grammar templates with the expression. When it can, it will pull the values out of the expression, put them in the target string, and then swap it out with the original, and then move on to the next item from the grammar/dictionary. scope is to indicate if it is expanding condition or consequence. (null will only expand globals).