This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-206
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-206 by this push:
     new 33ee086  WIP.
33ee086 is described below

commit 33ee08614186c5893fe03d5e350bf821851ec713
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Fri Feb 26 20:10:41 2021 -0800

    WIP.
---
 .../model/intent/impl/antlr4/NCIntentDsl.g4        | 151 +++++++++++++++++++--
 .../model/intent/impl/ver2/NCBaseDslCompiler.scala |   5 +-
 .../model/intent/dsl/NCIntentDslCompilerSpec.scala |  20 +--
 3 files changed, 152 insertions(+), 24 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
index ed40c96..b051044 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
@@ -23,12 +23,12 @@ dslItems
     : dslItem
     | dslItems dslItem
     ;
-dslItem: intent | pred;
-pred: predId terms;
-predId: 'predicate' ASSIGN ID;
-predRef: 'predicate' LPAR ID RPAR;
+dslItem: intent | frag;
+frag: fragId terms;
+fragId: FRAG ASSIGN id;
+fragRef: FRAG LPAR id RPAR;
 intent: intentId orderedDecl? flowDecl? metaDecl? terms;
-intentId: 'intent' ASSIGN ID;
+intentId: 'intent' ASSIGN id;
 orderedDecl: 'ordered' ASSIGN BOOL;
 mtdDecl: DIV mtdRef DIV;
 flowDecl: 'flow' ASSIGN (qstring | mtdDecl);
@@ -53,18 +53,18 @@ jsonArr
 terms
     : termItem
     | terms termItem;
-termItem: term | predRef;
+termItem: term | fragRef;
 termEq
     : ASSIGN // Do not use conversation.
     | TILDA // Use conversation.
     ;
 term: 'term' termId? termEq ((LBRACE expr RBRACE) | mtdDecl) minMax?;
-mtdRef: javaFqn? POUND ID;
+mtdRef: javaFqn? POUND id;
 javaFqn
-    : ID
-    | javaFqn DOT ID
+    : id
+    | javaFqn DOT id
     ;
-termId: LPAR ID RPAR;
+termId: LPAR id RPAR;
 expr
     // NOTE: order of productions defines precedence.
     : op=(MINUS | NOT) expr # unaryExpr
@@ -75,7 +75,7 @@ expr
     | expr op=(EQ | NEQ) expr # eqExpr
     | expr op=(AND | OR) expr # logExpr
     | atom # atomExpr
-    | ID LPAR paramList? RPAR # callExpr
+    | FUN_NAME LPAR paramList? RPAR # callExpr
     ;
 paramList
     : expr
@@ -101,8 +101,137 @@ minMaxShortcut
     | MULT
     ;
 minMaxRange: LBR INT COMMA INT RBR;
+id: ID | FUN_NAME;
 
 // Lexer.
+FUN_NAME
+    : 'meta_token'
+    | 'meta_model'
+    | 'meta_intent'
+    | 'meta_req'
+    | 'meta_user'
+    | 'meta_company'
+    | 'meta_sys'
+    | 'meta_conv'
+    | 'json'
+    | 'if'
+    | 'id'
+    | 'ancestors'
+    | 'parent'
+    | 'groups'
+    | 'value'
+    | 'aliases'
+    | 'start_idx'
+    | 'end_idx'
+    | 'req_id'
+    | 'req_normtext'
+    | 'req_tstamp'
+    | 'req_addr'
+    | 'req_agent'
+    | 'user_id'
+    | 'user_fname'
+    | 'user_lname'
+    | 'user_email'
+    | 'user_admin'
+    | 'user_signup_tstamp'
+    | 'comp_id'
+    | 'comp_name'
+    | 'comp_website'
+    | 'comp_country'
+    | 'comp_region'
+    | 'comp_city'
+    | 'comp_addr'
+    | 'comp_postcode'
+    | 'trim'
+    | 'strip'
+    | 'uppercase'
+    | 'lowercase'
+    | 'is_alpha'
+    | 'is_alphanum'
+    | 'is_whitespace'
+    | 'is_num'
+    | 'is_numspace'
+    | 'is_alphaspace'
+    | 'is_alphanumspace'
+    | 'substring'
+    | 'charAt'
+    | 'regex'
+    | 'soundex'
+    | 'split'
+    | 'split_trim'
+    | 'replace'
+    | 'abs'
+    | 'ceil'
+    | 'floor'
+    | 'rint'
+    | 'round'
+    | 'signum'
+    | 'sqrt'
+    | 'cbrt'
+    | 'pi'
+    | 'euler'
+    | 'acos'
+    | 'asin'
+    | 'atan'
+    | 'cos'
+    | 'sin'
+    | 'tan'
+    | 'cosh'
+    | 'sinh'
+    | 'tanh'
+    | 'atn2'
+    | 'degrees'
+    | 'radians'
+    | 'exp'
+    | 'expm1'
+    | 'hypot'
+    | 'log'
+    | 'log10'
+    | 'log1p'
+    | 'pow'
+    | 'rand'
+    | 'square'
+    | 'list'
+    | 'map'
+    | 'get'
+    | 'index'
+    | 'has'
+    | 'tail'
+    | 'add'
+    | 'remove'
+    | 'first'
+    | 'last'
+    | 'keys'
+    | 'values'
+    | 'length'
+    | 'count'
+    | 'take'
+    | 'drop'
+    | 'size'
+    | 'reverse'
+    | 'is_empty'
+    | 'non_empty'
+    | 'to_string'
+    | 'avg'
+    | 'max'
+    | 'min'
+    | 'stdev'
+    | 'sum'
+    | 'year'
+    | 'month'
+    | 'day_of_month'
+    | 'day_of_week'
+    | 'day_of_year'
+    | 'hour'
+    | 'minute'
+    | 'sec'
+    | 'week_of_month'
+    | 'week_of_year'
+    | 'quarter'
+    | 'msec'
+    | 'now'
+    ;
+FRAG: 'fragment'; // To resolve ambiguity with ANTLR4 keyword.
 SQSTRING: SQUOTE ((~'\'') | ('\\''\''))* SQUOTE; // Allow for \' (escaped 
single quote) in the string.
 DQSTRING: DQUOTE ((~'"') | ('\\''"'))* DQUOTE; // Allow for \" (escape double 
quote) in the string.
 BOOL: 'true' | 'false';
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
index eb0a48e..d15c241 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
@@ -643,7 +643,7 @@ trait NCBaseDslCompiler {
             case "is_alphaspace" ⇒ doIsAlphaSpace()
             case "is_alphanumspace" ⇒ doIsAlphaNumSpace()
             case "substring" ⇒
-            case "index" ⇒
+            case "charAt" ⇒
             case "regex" ⇒
             case "soundex" ⇒
             case "split" ⇒ doSplit()
@@ -696,7 +696,6 @@ trait NCBaseDslCompiler {
             case "last" ⇒
             case "keys" ⇒
             case "values" ⇒
-            case "length" ⇒
             case "count" ⇒
             case "take" ⇒
             case "drop" ⇒
@@ -721,7 +720,7 @@ trait NCBaseDslCompiler {
             case "day_of_week" ⇒ doDayOfWeek()
             case "day_of_year" ⇒ doDayOfYear()
             case "hour" ⇒
-            case "min" ⇒
+            case "minute" ⇒
             case "sec" ⇒
             case "week_of_month" ⇒
             case "week_of_year" ⇒
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/NCIntentDslCompilerSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/NCIntentDslCompilerSpec.scala
index 9f8b66e..331a491 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/NCIntentDslCompilerSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/NCIntentDslCompilerSpec.scala
@@ -60,16 +60,16 @@ class NCIntentDslCompilerSpec {
         checkOk(
             """
               |intent=i1
-              |flow="a[^0-9]b"
-              |meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
-              |term(t1)={2 == 2 && size(id()) != -25}
+              |     flow="a[^0-9]b"
+              |     meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
+              |     term(t1)={2 == 2 && size(id()) != -25}
               |""".stripMargin
         )
         checkOk(
             """
               |intent=i1
-              |flow="a[^0-9]b"
-              |term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 3]}}"), 
map("موسكو\"", 'v1\'v1', "k2", "v2"))}
+              |     flow="a[^0-9]b"
+              |     term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 
3]}}"), map("موسكو\"", 'v1\'v1', "k2", "v2"))}
               |""".stripMargin
         )
     }
@@ -80,16 +80,16 @@ class NCIntentDslCompilerSpec {
         checkError(
             """
               |intent=i1
-              |flow="a[^0-9]b"
-              |meta={{'a': true, 'b': {'arr': [1, 2, 3]}}
-              |term(t1)={2 == 2 && size(id()) != -25}
+              |     flow="a[^0-9]b"
+              |     meta={{'a': true, 'b': {'arr': [1, 2, 3]}}
+              |     term(t1)={2 == 2 && size(id()) != -25}
               |""".stripMargin
         )
         checkError(
             """
               |intent=i1
-              |flow="a[^0-9]b"
-              |term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 3]}}"), 
map("k1\"", 'v1\'v1', "k2", "v2"))}[1:2]
+              |     flow="a[^0-9]b"
+              |     term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 
3]}}"), map("k1\"", 'v1\'v1', "k2", "v2"))}[1:2]
               |""".stripMargin
         )
     }

Reply via email to