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

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


The following commit(s) were added to refs/heads/NLPCRAFT-474 by this push:
     new 210512c  WIP
210512c is described below

commit 210512c5b5d489612168b94e9effdf59b8b6fd5e
Author: Aaron Radzinski <aradzin...@datalingvo.com>
AuthorDate: Sat Jan 22 18:22:03 2022 -0800

    WIP
---
 .../intent/compiler/NCIDLCompilerGlobal.scala      | 83 ++++++++++++++++++++++
 .../internal/intent/compiler/NCIDLFragment.scala   | 30 ++++++++
 .../internal/intent/compiler/antlr4/NCIDL.g4       |  3 +-
 3 files changed, 115 insertions(+), 1 deletion(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompilerGlobal.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompilerGlobal.scala
new file mode 100644
index 0000000..2191172
--- /dev/null
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompilerGlobal.scala
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.internal.intent.compiler
+
+import scala.collection.concurrent.TrieMap
+import scala.collection.mutable
+
+/**
+  * Global IDL compiler state.
+  */
+object NCIDLCompilerGlobal:
+    private final val fragCache = TrieMap.empty[String /* Model ID. */ , 
mutable.Map[String, NCIDLFragment]]
+    private final val importCache = mutable.HashSet.empty[String]
+
+    /**
+      *
+      */
+    def clearAllCaches(): Unit =
+        fragCache.clear()
+        clearImportCache()
+
+    /**
+      *
+      */
+    private def clearImportCache(): Unit = importCache.synchronized { 
importCache.clear() }
+
+    /**
+      *
+      * @param mdlId
+      */
+    def clearCache(mdlId: String): Unit = fragCache += mdlId -> 
mutable.HashMap.empty[String, NCIDLFragment]
+
+    /**
+      *
+      * @param imp
+      */
+    def addImport(imp: String): Unit = importCache.synchronized { importCache 
+= imp }
+
+    /**
+      *
+      * @param imp
+      * @return
+      */
+    def hasImport(imp: String): Boolean = importCache.synchronized { 
importCache.contains(imp) }
+
+    /**
+      *
+      * @param mdlId
+      * @param frag
+      */
+    def addFragment(mdlId: String, frag: NCIDLFragment): Unit =
+        fragCache.getOrElse(mdlId, {
+            val m = mutable.HashMap.empty[String, NCIDLFragment]
+
+            fragCache += mdlId -> m
+
+            m
+        }) += (frag.id -> frag)
+
+    /**
+      *
+      * @param mdlId
+      * @param fragId
+      * @return
+      */
+    def getFragment(mdlId: String, fragId: String): Option[NCIDLFragment] =
+        fragCache.get(mdlId).flatMap(_.get(fragId))
+
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragment.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragment.scala
new file mode 100644
index 0000000..83b1b87
--- /dev/null
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragment.scala
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.internal.intent.compiler
+
+import org.apache.nlpcraft.internal.intent.*
+
+/**
+  * IDL fragment.
+  *
+  * @param id ID of this fragment (must be unique within a model).
+  * @param terms List of terms this fragment defines.
+  */
+case class NCIDLFragment(id: String, terms: List[NCIDLTerm]):
+    require(id != null)
+    require(terms.nonEmpty)
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/antlr4/NCIDL.g4
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/antlr4/NCIDL.g4
index d47699c..090a338 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/antlr4/NCIDL.g4
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/antlr4/NCIDL.g4
@@ -146,10 +146,11 @@ FUN_NAME
     | 'if'
     | 'ent_id'
     | 'ent_index'
+    | 'ent_text'
     | 'ent_groups'
     | 'ent_count'
     | 'req_id'
-    | 'req_normtext'
+    | 'req_text'
     | 'req_tstamp'
     | 'user_id'
     | 'trim'

Reply via email to