This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-477
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-477 by this push:
new 4ab7ee7 WIP.
4ab7ee7 is described below
commit 4ab7ee74d116edbdd1ece4b48fa5aff5cbbd4f4b
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Feb 17 23:24:55 2022 +0300
WIP.
---
.../internal/impl/NCModelPipelineProcessor.scala | 5 +-
.../internal/intent/matcher/NCIntentSolver.scala | 2 +-
.../internal/impl/NCModelClientImplSpec.scala | 63 ++++++++++++++++++++++
.../{ => impl}/NCModelPipelineProcessorSpec.scala | 2 +-
4 files changed, 67 insertions(+), 5 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessor.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessor.scala
index b1054ef..460a45d 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessor.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessor.scala
@@ -46,7 +46,7 @@ class NCModelPipelineProcessor(mdl: NCModel) extends
LazyLogging:
require(mdl != null)
require(mdl.getPipeline.getTokenParser != null)
require(mdl.getPipeline.getEntityParsers != null)
- require(mdl.getPipeline.getEntityParsers.size() > 0)
+ require(!mdl.getPipeline.getEntityParsers.isEmpty)
private val pipeline = mdl.getPipeline
private val pool = new java.util.concurrent.ForkJoinPool()
@@ -83,13 +83,12 @@ class NCModelPipelineProcessor(mdl: NCModel) extends
LazyLogging:
val allEnts = h.variants.flatMap(_.getEntities.asScala)
val conv =
- new NCConversation {
+ new NCConversation:
override val getSession: NCPropertyMap = convHldr.getUserData
override val getStm: JList[NCEntity] = convHldr.getEntities
override val getDialogFlow: JList[NCDialogFlowItem] =
dialogMgr.getDialogFlow(userId).asJava
override def clearStm(filter: Predicate[NCEntity]): Unit =
convHldr.clearEntities(filter)
override def clearDialog(filter: Predicate[String]): Unit =
dialogMgr.clearForPredicate(userId, (s: String) => filter.test(s))
- }
val ctx = new NCContext:
override def isOwnerOf(ent: NCEntity): Boolean =
allEnts.contains(ent)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolver.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolver.scala
index 5e7fcca..734fe40 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolver.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/matcher/NCIntentSolver.scala
@@ -649,7 +649,7 @@ case class NCIntentSolver(dialog: NCDialogFlowManager,
intents: Map[NCIDLIntent,
def solve(in: NCIntentSolverInput): NCResult =
var res: NCResult = null
- while (res != null)
+ while (res == null)
solveIteration(in) match
case Some(iterRes) => res = iterRes
case None => // No-op.
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientImplSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientImplSpec.scala
new file mode 100644
index 0000000..36fc302
--- /dev/null
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelClientImplSpec.scala
@@ -0,0 +1,63 @@
+/*
+ * 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.impl
+
+import org.apache.nlpcraft.*
+import
org.apache.nlpcraft.internal.impl.scan.NCTestModelScala.NCTestModelScalaObj
+import org.apache.nlpcraft.nlp.entity.parser.semantic.NCSemanticEntityParser
+import
org.apache.nlpcraft.nlp.entity.parser.semantic.impl.en.NCEnSemanticPorterStemmer
+import org.apache.nlpcraft.nlp.util.NCTestModelAdapter
+import org.apache.nlpcraft.nlp.util.opennlp.*
+import org.junit.jupiter.api.Test
+
+import scala.jdk.CollectionConverters.*
+
+class NCModelClientImplSpec:
+ /**
+ *
+ */
+ @Test
+ def test(): Unit =
+ val mdl =
+ new NCTestModelAdapter():
+ @NCIntent("intent=ls term(act)={has(ent_groups, 'act')}
term(loc)={# == 'ls:loc'}*")
+ def onMatch(@NCIntentTerm("act") act: NCEntity,
@NCIntentTerm("loc") locs: Seq[NCEntity]): NCResult =
+ val ncRes = new NCResult()
+ ncRes.setType(NCResultType.ASK_RESULT)
+ ncRes.setBody(if locs.isEmpty then "entire house" else
locs.map(_.mkText()).mkString(","))
+
+ ncRes
+
+ mdl.getPipeline.getEntityParsers.add(
+ new NCSemanticEntityParser(
+ new NCEnSemanticPorterStemmer,
+ EN_PIPELINE.getTokenParser,
+ "models/lightswitch_model.yaml"
+ )
+ )
+
+ val client = new NCModelClientImpl(mdl)
+
+ val res = client.askSync("What are the least performing categories for
the last quarter?", null, "userId")
+
+ println(res)
+ println(res.getIntentId)
+ println(res.getBody)
+
+
+
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/NCModelPipelineProcessorSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessorSpec.scala
similarity index 98%
rename from
nlpcraft/src/test/scala/org/apache/nlpcraft/internal/NCModelPipelineProcessorSpec.scala
rename to
nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessorSpec.scala
index 0a88fd4..c9eb33c 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/NCModelPipelineProcessorSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/NCModelPipelineProcessorSpec.scala
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.internal
+package org.apache.nlpcraft.internal.impl
import org.apache.nlpcraft.*
import org.apache.nlpcraft.internal.impl.NCModelPipelineProcessor