You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/03/01 05:07:36 UTC

[incubator-nlpcraft] branch NLPCRAFT-206 updated: WIP.

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 bdf6918  WIP.
bdf6918 is described below

commit bdf69182fea52c59c7534b3c6afaf7f9c80b45b6
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Sun Feb 28 21:07:25 2021 -0800

    WIP.
---
 .../apache/nlpcraft/common/debug/NCLogHolder.scala  |  6 +++---
 ...ompiler.scala => NCIntentDslBaselCompiler.scala} |  2 +-
 .../intent/impl/ver2/NCIntentDslCompiler.scala      | 10 +++++++---
 .../ver2/NCIntentDslFragmentCache.scala}            | 18 ++++++------------
 .../ver2/{NCDslTerm.scala => NCDslFragment.scala}   | 21 +++++++++++----------
 .../model/intent/utils/ver2/NCDslIntent.scala       | 15 +++++++++++----
 .../model/intent/utils/ver2/NCDslTerm.scala         | 15 ++++++++++++---
 7 files changed, 51 insertions(+), 36 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/debug/NCLogHolder.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/debug/NCLogHolder.scala
index b8cb4f8..e57fecf 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/debug/NCLogHolder.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/debug/NCLogHolder.scala
@@ -49,7 +49,7 @@ class NCLogHolder extends Serializable {
         groups: util.List[String]
     )
     
-    case class UserJson(
+    case class UserJson( // TODO: add metadata
         id: Long,
         firstName: String,
         lastName: String,
@@ -57,10 +57,10 @@ class NCLogHolder extends Serializable {
         avatarUrl: String,
         isAdmin: Boolean,
         signupTimestamp: Long,
-        meta: JavaMeta
+        meta: JavaMeta // TODO: remove.
     )
     
-    case class CompanyJson(
+    case class CompanyJson( // TODO: add metadata
         id: Long,
         name: String,
         website: String,
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/NCIntentDslBaselCompiler.scala
similarity index 99%
rename from nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
rename to nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslBaselCompiler.scala
index b2c0b64..2929b07 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/NCIntentDslBaselCompiler.scala
@@ -30,7 +30,7 @@ import java.util.{Collections, ArrayList ⇒ JArrayList, HashMap ⇒ JHashMap}
 import scala.collection.mutable
 
 //noinspection DuplicatedCode
-trait NCBaseDslCompiler {
+trait NCIntentDslBaselCompiler {
     def syntaxError(errMsg: String, srcName: String, line: Int, pos: Int): NCE
     def runtimeError(errMsg: String, srcName: String, line: Int, pos: Int, cause: Exception = null): NCE
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
index 989963d..ed16c1d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
@@ -40,7 +40,7 @@ object NCIntentDslCompiler extends LazyLogging {
      * @param dsl
      * @param mdlId
      */
-    class FiniteStateMachine(dsl: String, mdlId: String) extends NCIntentDslBaseListener with NCBaseDslCompiler {
+    class FiniteStateMachine(dsl: String, mdlId: String) extends NCIntentDslBaseListener with NCIntentDslBaselCompiler {
         // Intent components.
         private var id: String = _
         private var ordered: Boolean = false
@@ -204,7 +204,7 @@ object NCIntentDslCompiler extends LazyLogging {
             require(id != null)
             require(terms.nonEmpty)
 
-            NCDslIntent(dsl, id, ordered, if (meta == null) Map.empty else meta, flowRegex, terms.toArray)
+            NCDslIntent(dsl, id, ordered, if (meta == null) Map.empty else meta, flowRegex, terms.toList)
         }
         
         override def syntaxError(errMsg: String, srcName: String, line: Int, pos: Int): NCE =
@@ -262,8 +262,12 @@ object NCIntentDslCompiler extends LazyLogging {
         val posPtr = dash.substring(0, pos) + r("^") + y(dash.substring(pos + 1))
         val dslPtr = dslLine.substring(0, pos) + r(dslLine.charAt(pos)) + y(dslLine.substring(pos + 1))
         val src = if (srcName == "<unknown>") "<inline>"else srcName
+        val aMsg = U.decapitalize(msg) match {
+            case s: String if s.last == '.' ⇒ s
+            case s: String ⇒ s + '.'
+        }
         
-        s"Intent DSL $kind error in '$src' at line $line:${charPos + 1} - ${U.decapitalize(msg)}\n" +
+        s"Intent DSL $kind error in '$src' at line $line:${charPos + 1} - $aMsg\n" +
         s"  |-- ${c("Model:")}    $mdlId\n" +
         s"  |-- ${c("Line:")}     $dslPtr\n" +
         s"  +-- ${c("Position:")} $posPtr"
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslFragmentCache.scala
similarity index 72%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslFragmentCache.scala
index 3a7fa2a..7c72683 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslFragmentCache.scala
@@ -15,17 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft.model.intent.utils.ver2
-
-import org.apache.nlpcraft.model.NCToken
+package org.apache.nlpcraft.model.intent.impl.ver2
 
 /**
- * DSL term.
- */
-case class NCDslTerm(
-    id: String,
-    pred: (NCToken, NCDslTermContext) ⇒ (Boolean/*Predicate.*/, Boolean/*Whether or not token was used.*/),
-    min: Int,
-    max: Int,
-    conv: Boolean
-)
+  * Global intent DSL fragment cache.
+  */
+object NCIntentDslFragmentCache {
+
+}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslFragment.scala
similarity index 77%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslFragment.scala
index 3a7fa2a..beb1e74 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslFragment.scala
@@ -17,15 +17,16 @@
 
 package org.apache.nlpcraft.model.intent.utils.ver2
 
-import org.apache.nlpcraft.model.NCToken
-
 /**
- * DSL term.
- */
-case class NCDslTerm(
+  * DSL fragment.
+  *
+  * @param id ID of this fragment (must be unique within a model).
+  * @param terms List of terms this fragment defines.
+  */
+case class NCDslFragment(
     id: String,
-    pred: (NCToken, NCDslTermContext) ⇒ (Boolean/*Predicate.*/, Boolean/*Whether or not token was used.*/),
-    min: Int,
-    max: Int,
-    conv: Boolean
-)
+    terms: List[NCDslTerm]
+) {
+    require(id != null)
+    require(terms.nonEmpty)
+}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
index 512d5fc..2582f3e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
@@ -17,18 +17,25 @@
 
 package org.apache.nlpcraft.model.intent.utils.ver2
 
-import java.util.regex.{Pattern, PatternSyntaxException}
+import java.util.regex.Pattern
 
 /**
  * DSL intent.
- */
+  *
+  * @param dsl Original DSL of this intent.
+  * @param id
+  * @param ordered
+  * @param meta
+  * @param flow
+  * @param terms
+  */
 case class NCDslIntent(
-    orig: String,
+    dsl: String,
     id: String,
     ordered: Boolean,
     meta: Map[String, Any],
     flow: Option[String],
-    terms: Array[NCDslTerm]
+    terms: List[NCDslTerm]
 ) {
     require(id != null)
     require(terms.nonEmpty)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
index 3a7fa2a..81df585 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
@@ -21,11 +21,20 @@ import org.apache.nlpcraft.model.NCToken
 
 /**
  * DSL term.
- */
+  *
+  * @param id Optional ID of this term.
+  * @param pred
+  * @param min
+  * @param max
+  * @param conv
+  */
 case class NCDslTerm(
-    id: String,
+    id: String, // Could be null.
     pred: (NCToken, NCDslTermContext) ⇒ (Boolean/*Predicate.*/, Boolean/*Whether or not token was used.*/),
     min: Int,
     max: Int,
     conv: Boolean
-)
+) {
+    require(pred != null)
+    require(min >= 0 && max >= min)
+}