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

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


The following commit(s) were added to refs/heads/NLPCRAFT-483 by this push:
     new 23c18b7  Minor fixes.
23c18b7 is described below

commit 23c18b7528de26d7f0dbfc1868fb639920caebd2
Author: Sergey Kamov <skhdlem...@gmail.com>
AuthorDate: Sat Feb 26 12:19:34 2022 +0300

    Minor fixes.
---
 .../examples/lightswitch/LightSwitchRuModel.scala  | 10 +++++-
 .../examples/lightswitch/NCRuPipeline.scala        | 37 ----------------------
 .../nlp/token/parser/NCRuTokenParser.scala         | 31 ++++++++----------
 3 files changed, 23 insertions(+), 55 deletions(-)

diff --git 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
 
b/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
index 802934c..822e98c 100644
--- 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
+++ 
b/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchRuModel.scala
@@ -19,12 +19,17 @@ package org.apache.nlpcraft.examples.lightswitch
 
 import org.apache.nlpcraft.*
 import 
org.apache.nlpcraft.examples.lightswitch.nlp.entity.parser.semantic.NCRuSemanticEntityParser
+import 
org.apache.nlpcraft.examples.lightswitch.nlp.token.enricher.NCRuStopWordsTokenEnricher
+import 
org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCRuTokenParser
 import org.apache.nlpcraft.nlp.entity.parser.nlp.NCNLPEntityParser
 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.token.enricher.en.NCStopWordsTokenEnricher
 import org.apache.nlpcraft.nlp.token.parser.opennlp.NCOpenNLPTokenParser
 
+import java.util
+import scala.jdk.CollectionConverters.*
+
 /**
   * This example provides very simple implementation for NLI-powered light 
switch.
   * You can say something like this:
@@ -40,7 +45,10 @@ import 
org.apache.nlpcraft.nlp.token.parser.opennlp.NCOpenNLPTokenParser
 
 class LightSwitchRuModel extends NCModelAdapter(
     new NCModelConfig("nlpcraft.lightswitch.ru.ex", "LightSwitch Example Model 
RU", "1.0"),
-    new NCRuPipeline(new NCRuSemanticEntityParser("lightswitch_model_ru.yaml"))
+    new NCModelPipeline:
+        override val getTokenParser: NCTokenParser = new NCRuTokenParser()
+        override val getTokenEnrichers: util.List[NCTokenEnricher] = Seq(new 
NCRuStopWordsTokenEnricher()).asJava
+        override val getEntityParsers: util.List[NCEntityParser] = Seq(new 
NCRuSemanticEntityParser("lightswitch_model_ru.yaml")).asJava
 ):
     /**
       * Intent and its on-match callback.
diff --git 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/NCRuPipeline.scala
 
b/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/NCRuPipeline.scala
deleted file mode 100644
index 3fe37d1..0000000
--- 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/NCRuPipeline.scala
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.examples.lightswitch
-
-import org.apache.nlpcraft.*
-import 
org.apache.nlpcraft.examples.lightswitch.nlp.token.enricher.NCRuStopWordsTokenEnricher
-import 
org.apache.nlpcraft.examples.lightswitch.nlp.token.parser.NCRuTokenParser
-import org.apache.nlpcraft.internal.util.NCResourceReader
-import org.apache.nlpcraft.nlp.token.enricher.en.*
-import org.apache.nlpcraft.nlp.token.parser.opennlp.NCOpenNLPTokenParser
-
-import java.util
-import java.util.*
-import scala.jdk.CollectionConverters.*
-
-/**
-  * Default RU implementation based on Open Nlp token parser, and stopword 
token enricher.
-  * Also at least one entity parser must be defined. */
-class NCRuPipeline(parser: NCEntityParser) extends NCModelPipeline:
-    override val getTokenParser: NCTokenParser = new NCRuTokenParser()
-    override val getEntityParsers: util.List[NCEntityParser] = 
Seq(parser).asJava
-    override val getTokenEnrichers: util.List[NCTokenEnricher] = Seq(new 
NCRuStopWordsTokenEnricher()).asJava
diff --git 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCRuTokenParser.scala
 
b/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCRuTokenParser.scala
index feca7fc..73e4b33 100644
--- 
a/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCRuTokenParser.scala
+++ 
b/nlpcraft-examples/lightswitch-ru/src/main/java/org/apache/nlpcraft/examples/lightswitch/nlp/token/parser/NCRuTokenParser.scala
@@ -55,22 +55,19 @@ class NCRuTokenParser extends NCTokenParser:
         spans.zip(tags).zipWithIndex.map { case ((span, tag), idx) =>
             val readings = tag.getReadings.asScala
 
-            val (lemma, pos) =
-                readings.size match
-                    // No data. Lemma is word as is, POS is undefined.
-                    case 0 => (span.word, "")
-                    // Takes first. Other variants ignored.
-                    case _ =>
-                        val aTok: AnalyzedToken = readings.head
-                        (nvl(aTok.getLemma, span.word), nvl(aTok.getPOSTag, 
""))
+            val (lemma, pos) = readings.size match
+                // No data. Lemma is word as is, POS is undefined.
+                case 0 => (span.word, "")
+                // Takes first. Other variants ignored.
+                case _ =>
+                    val aTok: AnalyzedToken = readings.head
+                    (nvl(aTok.getLemma, span.word), nvl(aTok.getPOSTag, ""))
 
-            val tok: NCToken =
-                new NCPropertyMapAdapter with NCToken:
-                    override val getText: String = span.word
-                    override val getIndex: Int = idx
-                    override val getStartCharIndex: Int = span.start
-                    override val getEndCharIndex: Int = span.end
-                    override val getLemma: String = lemma
-                    override val getPos: String = pos
-            tok
+            new NCPropertyMapAdapter with NCToken:
+                override val getText: String = span.word
+                override val getIndex: Int = idx
+                override val getStartCharIndex: Int = span.start
+                override val getEndCharIndex: Int = span.end
+                override val getLemma: String = lemma
+                override val getPos: String = pos
         }.asJava
\ No newline at end of file

Reply via email to