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

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


The following commit(s) were added to refs/heads/NLPCRAFT-513 by this push:
     new d6e2716  Examples fixes.
d6e2716 is described below

commit d6e2716010ba924c1df9ea33b4f4d36d392c0951
Author: Sergey Kamov <[email protected]>
AuthorDate: Sun Jan 22 00:47:17 2023 +0400

    Examples fixes.
---
 examples/calculator.html      |  12 ++---
 examples/light_switch.html    |  14 ++---
 examples/light_switch_fr.html |  25 ++++-----
 examples/light_switch_ru.html |  23 ++++----
 examples/pizzeria.html        | 119 +++++++++++++++++++-----------------------
 examples/time.html            |   8 +--
 6 files changed, 96 insertions(+), 105 deletions(-)

diff --git a/examples/calculator.html b/examples/calculator.html
index e62ade9..3e51d55 100644
--- a/examples/calculator.html
+++ b/examples/calculator.html
@@ -43,7 +43,7 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
                 name := "NLPCraft Calculator Example",
@@ -51,7 +51,7 @@ fa_icon: fa-cube
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % 
"nlpcraft-stanford" % "1.0.0",
                 libraryDependencies += "edu.stanford.nlp" % "stanford-corenlp" 
% "4.5.1",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
         <p><b>NOTE: </b>use the latest versions of Scala, ScalaTest and 
StanfordNLP library.</p>
@@ -87,9 +87,9 @@ fa_icon: fa-cube
             import edu.stanford.nlp.pipeline.StanfordCoreNLP
             import org.apache.nlpcraft.*
             import org.apache.nlpcraft.annotations.*
-            import org.apache.nlpcraft.nlp.entity.parser.stanford.*
             import org.apache.nlpcraft.nlp.parsers.*
-            import 
org.apache.nlpcraft.nlp.token.parser.stanford.NCStanfordNLPTokenParser
+            import org.apache.nlpcraft.nlp.stanford.*
+
             import java.util.Properties
 
             object CalculatorModel:
@@ -125,7 +125,7 @@ fa_icon: fa-cube
                 @NCIntent(
                     "intent=calc options={ 'ordered': true }" +
                     "   term(x)={# == 'stanford:number'}" +
-                    "   term(op)={has(list('+', '-', '*', '/'), 
meta_ent('nlp:token:text')) == true}" +
+                    "   term(op)={has(list('+', '-', '*', '/'), 
meta_ent('nlp:entity:text')) == true}" +
                     "   term(y)={# == 'stanford:number'}"
                 )
                 def onMatch(
@@ -139,7 +139,7 @@ fa_icon: fa-cube
 
                 @NCIntent(
                     "intent=calcMem options={ 'ordered': true }" +
-                    "   term(op)={has(list('+', '-', '*', '/'), 
meta_ent('nlp:token:text')) == true}" +
+                    "   term(op)={has(list('+', '-', '*', '/'), 
meta_ent('nlp:entity:text')) == true}" +
                     "   term(y)={# == 'stanford:number'}"
                 )
                 def onMatchMem(
diff --git a/examples/light_switch.html b/examples/light_switch.html
index 1101491..c3c79ec 100644
--- a/examples/light_switch.html
+++ b/examples/light_switch.html
@@ -45,13 +45,13 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
                 name := "NLPCraft LightSwitch Example",
                 version := "{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
         <p><b>NOTE: </b>use the latest versions of Scala and ScalaTest.</p>
@@ -83,7 +83,7 @@ fa_icon: fa-cube
         <p>
             We are going to start with declaring the static part of our model 
using YAML which we will later load
             in our Scala-based model implementation.
-            Open <code>src/main/resources/<b>light_switch.yaml</b></code>
+            Open <code>src/main/resources/<b>lightswitch_model.yaml</b></code>
             file and replace its content with the following YAML:
         </p>
         <pre class="brush: js, highlight: [1, 10, 17, 25]">
@@ -96,14 +96,14 @@ fa_icon: fa-cube
               "&lt;LIGHT&gt;" : "{all|_} 
{it|them|light|illumination|lamp|lamplight}"
 
             elements:
-              - id: "ls:loc"
+              - type: "ls:loc"
                 description: "Location of lights."
                 synonyms:
                   - "&lt;ENTIRE_OPT&gt; &lt;FLOOR_OPT&gt; 
{kitchen|library|closet|garage|office|playroom|{dinning|laundry|play} 
&lt;TYPE&gt;}"
                   - "&lt;ENTIRE_OPT&gt; &lt;FLOOR_OPT&gt; 
{master|kid|children|child|guest|_} {bedroom|bathroom|washroom|storage} 
{&lt;TYPE&gt;|_}"
                   - "&lt;ENTIRE_OPT&gt; {house|home|building|{1st|first} 
floor|{2nd|second} floor}"
 
-              - id: "ls:on"
+              - type: "ls:on"
                 groups:
                   - "act"
                 description: "Light switch ON action."
@@ -111,7 +111,7 @@ fa_icon: fa-cube
                   - "&lt;ACTION&gt; {on|up|_} &lt;LIGHT&gt; {on|up|_}"
                   - "&lt;LIGHT&gt; {on|up}"
 
-              - id: "ls:off"
+              - type: "ls:off"
                 groups:
                   - "act"
                 description: "Light switch OFF action."
@@ -167,7 +167,7 @@ fa_icon: fa-cube
                     @NCIntentTerm("act") actEnt: NCEntity,
                     @NCIntentTerm("loc") locEnts: List[NCEntity]
                 ): NCResult =
-                    val status = if actEnt.getId == "ls:on" then "on" else 
"off"
+                    val status = if actEnt.getType == "ls:on" then "on" else 
"off"
                     val locations = if locEnts.isEmpty then "entire house" 
else locEnts.map(_.mkText).mkString(", ")
 
                     // Add HomeKit, Arduino or other integration here.=
diff --git a/examples/light_switch_fr.html b/examples/light_switch_fr.html
index b370574..2b163c9 100644
--- a/examples/light_switch_fr.html
+++ b/examples/light_switch_fr.html
@@ -45,16 +45,16 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7, 8, 9, 10]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
                 name := "NLPCraft LightSwitch FR Example",
                 version := "{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
                 libraryDependencies += "org.apache.lucene" % 
"lucene-analyzers-common" % "8.11.2",
-                libraryDependencies += "org.languagetool" % 
"languagetool-core" % "5.9",
-                libraryDependencies += "org.languagetool" % "language-fr" % 
"5.9",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.languagetool" % 
"languagetool-core" % "6.0",
+                libraryDependencies += "org.languagetool" % "language-fr" % 
"6.0",
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
 
@@ -134,14 +134,14 @@ fa_icon: fa-cube
               "&lt;LIGHT&gt;" : "{tout|_} 
{cela|lumière|éclairage|illumination|lampe}"
 
             elements:
-              - id: "ls:loc"
+              - type: "ls:loc"
                 description: "Location of lights."
                 synonyms:
                   - "&lt;ENTIRE_OPT&gt; &lt;FLOOR_OPT&gt; 
{cuisine|bibliothèque|placard|garage|bureau|salle de jeux|{salle à 
manger|buanderie|jeu} &lt;TYPE&gt;}"
                   - "&lt;ENTIRE_OPT&gt; &lt;FLOOR_OPT&gt; 
{maître|gamin|bébé|enfant|hôte|client|_} {coucher|bains|toilette|rangement} 
{&lt;TYPE&gt;|_}"
                   - "&lt;ENTIRE_OPT&gt; {maison|foyer|bâtiment|{1er|premier} 
étage|chaussée|{2ème|deuxième} étage}"
 
-              - id: "ls:on"
+              - type: "ls:on"
                 groups:
                   - "act"
                 description: "Light switch ON action."
@@ -149,7 +149,7 @@ fa_icon: fa-cube
                   - "{&lt;ACTION&gt;|_} &lt;LIGHT&gt;"
                   - "{&lt;LIGHT&gt;|_} &lt;ACTION&gt;"
 
-              - id: "ls:off"
+              - type: "ls:off"
                 groups:
                   - "act"
                 description: "Light switch OFF action."
@@ -212,7 +212,7 @@ fa_icon: fa-cube
                     @NCIntentTerm("act") actEnt: NCEntity,
                     @NCIntentTerm("loc") locEnts: List[NCEntity]
                 ): NCResult =
-                    val action = if actEnt.getId == "ls:on" then "allumer" 
else "éteindre"
+                    val action = if actEnt.getType == "ls:on" then "allumer" 
else "éteindre"
                     val locations = if locEnts.isEmpty then "toute la maison" 
else locEnts.map(_.mkText).mkString(", ")
 
                     // Add HomeKit, Arduino or other integration here.
@@ -395,22 +395,23 @@ fa_icon: fa-cube
         <pre class="brush: scala, highlight: [8, 12]">
             package demo.nlp.entity.parser
 
-            import opennlp.tools.stemmer.snowball.SnowballStemmer
             import demo.nlp.token.parser.NCFrTokenParser
+            import opennlp.tools.stemmer.snowball.SnowballStemmer
             import org.apache.nlpcraft.nlp.parsers.*
+            import org.apache.nlpcraft.nlp.stemmer.NCStemmer
 
             class NCFrSemanticEntityParser(src: String) extends 
NCSemanticEntityParser(
-                new NCSemanticStemmer:
+                new NCStemmer:
                     private val stemmer = new 
SnowballStemmer(SnowballStemmer.ALGORITHM.FRENCH)
                     override def stem(txt: String): String = 
stemmer.synchronized { stemmer.stem(txt.toLowerCase).toString }
                 ,
                 new NCFrTokenParser(),
-                mdlSrcOpt = Option(src)
+                src
             )
         </pre>
         <ul>
             <li>
-                <code>NCFrSemanticEntityParser</code> extends 
<code>NCSemanticEntityParser</code>.
+                <code>NCFrSemanticEntityParser</code> extends {% scaladoc 
nlp/parsers/NCSemanticEntityParser NCSemanticEntityParser %}.
                 It uses stemmer implementation from <a 
href="https://opennlp.apache.org/";>Apache OpenNLP</a> project.
             </li>
         </ul>
diff --git a/examples/light_switch_ru.html b/examples/light_switch_ru.html
index a29a79b..92a5cd2 100644
--- a/examples/light_switch_ru.html
+++ b/examples/light_switch_ru.html
@@ -45,16 +45,16 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7, 8, 9, 10]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
                 name := "NLPCraft LightSwitch RU Example",
                 version := "{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
                 libraryDependencies += "org.apache.lucene" % 
"lucene-analyzers-common" % "8.11.2",
-                libraryDependencies += "org.languagetool" % 
"languagetool-core" % "5.9",
-                libraryDependencies += "org.languagetool" % "language-ru" % 
"5.9",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.languagetool" % 
"languagetool-core" % "6.0",
+                libraryDependencies += "org.languagetool" % "language-ru" % 
"6.0",
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
 
@@ -132,12 +132,12 @@ fa_icon: fa-cube
               "&lt;LIGHT_OPT&gt;" : 
"{это|лампа|бра|люстра|светильник|лампочка|лампа|освещение|свет|электричество|электрика|_}"
 
             elements:
-              - id: "ls:loc"
+              - type: "ls:loc"
                 description: "Location of lights."
                 synonyms:
                   - "&lt;ENTIRE_OPT&gt; 
{здание|помещение|дом|кухня|детская|кабинет|гостиная|спальня|ванная|туалет|{большая|обеденная|ванная|детская|туалетная}
 комната}"
 
-              - id: "ls:on"
+              - type: "ls:on"
                 groups:
                   - "act"
                 description: "Light switch ON action."
@@ -145,7 +145,7 @@ fa_icon: fa-cube
                   - "&lt;LIGHT_OPT&gt; &lt;ENTIRE_OPT&gt; &lt;TURN_ON&gt;"
                   - "&lt;TURN_ON&gt; &lt;ENTIRE_OPT&gt; &lt;LIGHT_OPT&gt;"
 
-              - id: "ls:off"
+              - type: "ls:off"
                 groups:
                   - "act"
                 description: "Light switch OFF action."
@@ -209,7 +209,7 @@ fa_icon: fa-cube
                     @NCIntentTerm("act") actEnt: NCEntity,
                     @NCIntentTerm("loc") locEnts: List[NCEntity]
                 ): NCResult =
-                    val action = if actEnt.getId == "ls:on" then "включить" 
else "выключить"
+                    val action = if actEnt.getType == "ls:on" then "включить" 
else "выключить"
                     val locations = if locEnts.isEmpty then "весь дом" else 
locEnts.map(_.mkText).mkString(", ")
 
                     // Add HomeKit, Arduino or other integration here.
@@ -400,20 +400,21 @@ fa_icon: fa-cube
             import opennlp.tools.stemmer.snowball.SnowballStemmer
             import demo.nlp.token.parser.NCRuTokenParser
             import org.apache.nlpcraft.nlp.parsers.*
+            import org.apache.nlpcraft.nlp.stemmer.NCStemmer
 
             class NCRuSemanticEntityParser(src: String) extends 
NCSemanticEntityParser(
-                new NCSemanticStemmer:
+                new NCStemmer:
                     private val stemmer = new 
SnowballStemmer(SnowballStemmer.ALGORITHM.RUSSIAN)
                     override def stem(txt: String): String = 
stemmer.synchronized { stemmer.stem(txt.toLowerCase).toString }
                 ,
                 new NCRuTokenParser(),
-                mdlSrcOpt = Option(src)
+                src
             )
         </pre>
 
         <ul>
             <li>
-                <code>NCRuSemanticEntityParser</code> extends 
<code>NCSemanticEntityParser</code>.
+                <code>NCRuSemanticEntityParser</code> extends {% scaladoc 
nlp/parsers/NCSemanticEntityParser NCSemanticEntityParser %}.
                 It uses stemmer implementation from <a 
href="https://opennlp.apache.org/";>Apache OpenNLP</a> project.
             </li>
         </ul>        
diff --git a/examples/pizzeria.html b/examples/pizzeria.html
index 088b13e..e8e9062 100644
--- a/examples/pizzeria.html
+++ b/examples/pizzeria.html
@@ -43,15 +43,15 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
-                name := "NLPCraft Calculator Example",
+                name := "NLPCraft Pizzeria Example",
                 version := "{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % 
"nlpcraft-stanford" % "1.0.0",
                 libraryDependencies += "edu.stanford.nlp" % "stanford-corenlp" 
% "4.5.1",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
         <p><b>NOTE: </b>use the latest versions of Scala, ScalaTest and 
StanfordNLP library.</p>
@@ -97,56 +97,56 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [2, 9, 16, 23, 29, 35, 40, 46, 51]">
              elements:
-              - id: "ord:pizza"
+              - type: "ord:pizza"
                 description: "Kinds of pizza."
                 values:
                   "margherita": [ ]
                   "carbonara": [ ]
                   "marinara": [ ]
 
-              - id: "ord:pizza:size"
+              - type: "ord:pizza:size"
                 description: "Size of pizza."
                 values:
                   "small": [ "{small|smallest|min|minimal|tiny} 
{size|piece|_}" ]
                   "medium": [ "{medium|intermediate|normal|regular} 
{size|piece|_}" ]
                   "large": [ "{big|biggest|large|max|maximum|huge|enormous} 
{size|piece|_}" ]
 
-              - id: "ord:drink"
+              - type: "ord:drink"
                 description: "Kinds of drinks."
                 values:
                   "tea": [ ]
                   "coffee": [ ]
                   "cola": [ "{pepsi|sprite|dr. pepper|dr 
pepper|fanta|soda|cola|coca cola|cocacola|coca-cola}" ]
 
-              - id: "ord:yes"
+              - type: "ord:yes"
                 description: "Confirmation (yes)."
                 synonyms:
                   - 
"{yes|yeah|right|fine|nice|excellent|good|correct|sure|ok|exact|exactly|agree}"
                   - "{you are|_} {correct|right}"
 
-              - id: "ord:no"
+              - type: "ord:no"
                 description: "Confirmation (no)."
                 synonyms:
                   - "{no|nope|incorrect|wrong}"
                   - "{you are|_} {not|are not|aren't} {correct|right}"
 
-              - id: "ord:stop"
+              - type: "ord:stop"
                 description: "Stop and cancel all."
                 synonyms:
                   - "{stop|cancel|clear|interrupt|quit|close} 
{it|all|everything|_}"
 
-              - id: "ord:status"
+              - type: "ord:status"
                 description: "Order status information."
                 synonyms:
                   - "{present|current|_} {order|_} 
{status|state|info|information}"
                   - "what {already|_} ordered"
 
-              - id: "ord:finish"
+              - type: "ord:finish"
                 description: "The order is over."
                 synonyms:
                   - "{i|everything|order|_} {be|_} 
{finish|ready|done|over|confirmed}"
 
-              - id: "ord:menu"
+              - type: "ord:menu"
                 description: "Order menu."
                 synonyms:
                   - "{menu|carte|card}"
@@ -156,7 +156,7 @@ fa_icon: fa-cube
 
         <ul>
             <li>
-                <code>Lines 1, 9, 16</code> define order elements which 
present parts of order.
+                <code>Lines 2, 9, 16</code> define order elements which 
present parts of order.
             </li>
             <li>
                 <code>Lines 35, 40, 46, 51</code> define command elements 
which are used to control order state.
@@ -240,7 +240,7 @@ fa_icon: fa-cube
                 def fixPizzaWithoutSize(size: String): Boolean =
                     findPizzaWithoutSize match
                         case Some(p) =&gt;
-                            p.size = size.?
+                            p.size = Option(size)
                             true
                         case None =&gt; false
 
@@ -426,7 +426,7 @@ fa_icon: fa-cube
                         case DIALOG_CONFIRM => askConfirm(o)
                         // Changes state.
                         case DIALOG_SHOULD_CANCEL => doShowStatus(o, 
DIALOG_EMPTY)
-                         // Keeps same state.
+                        // Keeps same state.
                         case DIALOG_EMPTY | DIALOG_IS_READY | DIALOG_SPECIFY 
=> doShowStatus(o, o.getState)
                 )
 
@@ -469,8 +469,8 @@ fa_icon: fa-cube
                         // If order in progress and has pizza with unknown 
size, it doesn't depend on dialog state.
                         o =>
                             if !o.isEmpty && 
o.fixPizzaWithoutSize(extractPizzaSize(size))
-                                then askIsReadyOrAskSpecify(o)
-                                else throw UNEXPECTED_REQUEST
+                            then askIsReadyOrAskSpecify(o)
+                            else throw UNEXPECTED_REQUEST
                     )
 
                 override def onRejection(
@@ -546,7 +546,7 @@ fa_icon: fa-cube
 
             class PizzeriaOrderValidator extends NCEntityValidator:
                 override def validate(req: NCRequest, cfg: NCModelConfig, 
ents: List[NCEntity]): Unit =
-                    def count(id: String): Int = ents.count(_.getId == id)
+                    def count(typ: String): Int = ents.count(_.getType == typ)
 
                     val cntPizza = count("ord:pizza")
                     val cntDrink = count("ord:drink")
@@ -554,11 +554,8 @@ fa_icon: fa-cube
                     val cntSize = count("ord:pizza:size")
 
                     // Single size - it is order specification request.
-                    if cntSize != 1 && cntSize > cntPizza then
-                        throw new NCRejection("There are unrecognized pizza 
sizes in the request, maybe because some misprints.")
-
-                    if cntNums > cntPizza + cntDrink then
-                        throw new NCRejection("There are many unrecognized 
numerics in the request, maybe because some misprints.")
+                    if (cntSize != 1 && cntSize > cntPizza) || cntNums > 
cntPizza + cntDrink then
+                        throw new NCRejection("Invalid pizza request.")
         </pre>
 
         <p>
@@ -569,49 +566,48 @@ fa_icon: fa-cube
         <p>
             Open 
<code>src/main/scala/demo/components/<b>PizzeriaOrderMapper.scala</b></code> 
file and replace its content with the following code:
         </p>
-        <pre class="brush: scala, highlight: [11, 25, 30, 61]">
+        <pre class="brush: scala, highlight: [11, 26, 30, 60]">
             package demo.components
 
             import org.apache.nlpcraft.*
             import com.typesafe.scalalogging.LazyLogging
             import org.apache.nlpcraft.NCResultType.ASK_DIALOG
+
             import scala.collection.*
 
-            case class PizzeriaOrderMapperDesc(elementId: String, 
propertyName: String)
+            case class PizzeriaOrderMapperDesc(elementType: String, 
propertyName: String)
 
-            object PizzeriaOrderMapper:
+            private object PizzeriaOrderMapper:
                 extension(entity: NCEntity)
-                    def position: Double =
+                    private def position: Double =
                         val toks = entity.getTokens
                         (toks.head.getIndex + toks.last.getIndex) / 2.0
-                    def tokens: List[NCToken] = entity.getTokens
+                    private def tokens: List[NCToken] = entity.getTokens
 
                 private def str(es: Iterable[NCEntity]): String =
-                    es.map(e => 
s"id=${e.getId}(${e.tokens.map(_.getIndex).mkString("[", ",", "]")})").
-                        mkString("{", ", ", "}")
+                    es.map(e => 
s"type=${e.getType}(${e.tokens.map(_.getIndex).mkString("[", ",", 
"]")})").mkString("{", ", ", "}")
+
+                def apply(extra: PizzeriaOrderMapperDesc, descr: 
PizzeriaOrderMapperDesc*): PizzeriaOrderMapper = new PizzeriaOrderMapper(extra, 
descr)
 
-                def apply(extra: PizzeriaOrderMapperDesc, dests: 
PizzeriaOrderMapperDesc*): PizzeriaOrderMapper =
-                    new PizzeriaOrderMapper(extra, dests)
 
             import PizzeriaOrderMapper.*
 
             case class PizzeriaOrderMapper(
                 extra: PizzeriaOrderMapperDesc,
-                dests: Seq[PizzeriaOrderMapperDesc]
+                descr: Seq[PizzeriaOrderMapperDesc]
             ) extends NCEntityMapper with LazyLogging:
                 override def map(req: NCRequest, cfg: NCModelConfig, ents: 
List[NCEntity]): List[NCEntity] =
                     def map(destEnt: NCEntity, destProp: String, extraEnt: 
NCEntity): NCEntity =
                         new NCPropertyMapAdapter with NCEntity:
                             destEnt.keysSet.foreach(k => put(k, destEnt(k)))
                             put[String](destProp, 
extraEnt[String](extra.propertyName).toLowerCase)
-                            override val getTokens: List[NCToken] =
-                                (destEnt.tokens ++ 
extraEnt.tokens).sortBy(_.getIndex)
+                            override val getTokens: List[NCToken] = 
(destEnt.tokens ++ extraEnt.tokens).sortBy(_.getIndex)
                             override val getRequestId: String = 
req.getRequestId
-                            override val getId: String = destEnt.getId
+                            override val getType: String = destEnt.getType
 
-                    val destsMap = dests.map(p => p.elementId -> p).toMap
-                    val destEnts = mutable.HashSet.empty ++ ents.filter(e => 
destsMap.contains(e.getId))
-                    val extraEnts = ents.filter(_.getId == extra.elementId)
+                    val descrMap = descr.map(p => p.elementType -> p).toMap
+                    val destEnts = mutable.HashSet.empty ++ ents.filter(e => 
descrMap.contains(e.getType))
+                    val extraEnts = ents.filter(_.getType == extra.elementType)
 
                     if destEnts.nonEmpty && extraEnts.nonEmpty && 
destEnts.size >= extraEnts.size then
                         val used = (destEnts ++ extraEnts).toSet
@@ -623,7 +619,7 @@ fa_icon: fa-cube
                             dest2Extra += destEnt -> extraEnt
 
                         val unrelated = ents.filter(e => !used.contains(e))
-                        val artificial = for ((m, e) <- dest2Extra) yield 
map(m, destsMap(m.getId).propertyName, e)
+                        val artificial = for ((m, e) <- dest2Extra) yield 
map(m, descrMap(m.getType).propertyName, e)
                         val unused = destEnts
 
                         val res = (unrelated ++ artificial ++ 
unused).sortBy(_.tokens.head.getIndex)
@@ -644,7 +640,7 @@ fa_icon: fa-cube
                 helper methods.
             </li>
             <li>
-                <code>Line 25</code> defines <code>PizzeriaOrderMapper</code> 
model which implements {% scaladoc NCEntityMapper NCEntityMapper %}.
+                <code>Line 26</code> defines <code>PizzeriaOrderMapper</code> 
model which implements {% scaladoc NCEntityMapper NCEntityMapper %}.
             </li>
             <li>
                 <code>Line 30</code> defines helper method
@@ -654,7 +650,7 @@ fa_icon: fa-cube
                 returns new entities instances instead of passed into the 
method.
             </li>
             <li>
-                <code>Line 61</code> defines <code>PizzeriaOrderMapper</code> 
result.
+                <code>Line 60</code> defines <code>PizzeriaOrderMapper</code> 
result.
                 These entities will be processed further instead of passed 
into this component method.
             </li>
         </ul>
@@ -662,17 +658,17 @@ fa_icon: fa-cube
         <p>
             Open 
<code>src/main/scala/demo/components/<b>PizzeriaModelPipeline.scala</b></code> 
file and replace its content with the following code:
         </p>
-        <pre class="brush: scala, highlight: [14, 31, 37, 43]">
+        <pre class="brush: scala, highlight: [14, 27, 28, 32, 36]">
             package demo.components
 
             import edu.stanford.nlp.pipeline.StanfordCoreNLP
-            import opennlp.tools.stemmer.PorterStemmer
             import org.apache.nlpcraft.nlp.parsers.*
-            import 
org.apache.nlpcraft.nlp.entity.parser.stanford.NCStanfordNLPEntityParser
-            import 
org.apache.nlpcraft.nlp.token.parser.stanford.NCStanfordNLPTokenParser
             import org.apache.nlpcraft.*
+            import org.apache.nlpcraft.nlp.stemmer.*
             import org.apache.nlpcraft.nlp.enrichers.NCEnStopWordsTokenEnricher
-            import org.apache.nlpcraft.nlp.parsers.{NCSemanticEntityParser, 
NCSemanticStemmer}
+            import org.apache.nlpcraft.nlp.parsers.NCSemanticEntityParser
+            import org.apache.nlpcraft.nlp.stanford.*
+
             import java.util.Properties
 
             object PizzeriaModelPipeline:
@@ -682,28 +678,21 @@ fa_icon: fa-cube
                         props.setProperty("annotators", "tokenize, ssplit, 
pos, lemma, ner")
                         new StanfordCoreNLP(props)
                     val tokParser = new NCStanfordNLPTokenParser(stanford)
-                    val stemmer = new NCSemanticStemmer():
-                        private val ps = new PorterStemmer
-                        override def stem(txt: String): String = 
ps.synchronized { ps.stem(txt) }
 
-                    import PizzeriaOrderMapperDesc as D
+                    import demo.components.PizzeriaOrderMapperDesc as D
 
                     new NCPipelineBuilder().
                         withTokenParser(tokParser).
                         withTokenEnricher(new NCEnStopWordsTokenEnricher()).
                         withEntityParser(new 
NCStanfordNLPEntityParser(stanford, Set("number"))).
-                        withEntityParser(NCSemanticEntityParser(stemmer, 
tokParser, "pizzeria_model.yaml")).
-                        withEntityMapper(
-                            PizzeriaOrderMapper(
-                                extra = D("ord:pizza:size", 
"ord:pizza:size:value"),
-                                dests = D("ord:pizza", "ord:pizza:size")
-                            )
+                        withEntityParser(new NCSemanticEntityParser(new 
NCEnStemmer, tokParser, "pizzeria_model.yaml")).
+                        withEntityMapper(PizzeriaOrderMapper(
+                            extra = D("ord:pizza:size", 
"ord:pizza:size:value"),
+                            descr = D("ord:pizza", "ord:pizza:size"))
                         ).
-                        withEntityMapper(
-                            PizzeriaOrderMapper(
-                                extra = D("stanford:number", 
"stanford:number:nne"),
-                                dests = D("ord:pizza", "ord:pizza:qty"), 
D("ord:drink", "ord:drink:qty")
-                            )
+                        withEntityMapper(PizzeriaOrderMapper(
+                            extra = D("stanford:number", 
"stanford:number:nne"),
+                            descr = D("ord:pizza", "ord:pizza:qty"), 
D("ord:drink", "ord:drink:qty"))
                         ).
                         withEntityValidator(new PizzeriaOrderValidator()).
                         build
@@ -716,16 +705,16 @@ fa_icon: fa-cube
                 <code>Line 14</code> defines the pipeline.
             </li>
             <li>
-                <code>Line 30</code> declares {% scaladoc 
nlp/parsers/NCSemanticEntityParser NCSemanticEntityParser %}
+                <code>Line 27</code> declares {% scaladoc 
nlp/parsers/NCSemanticEntityParser NCSemanticEntityParser %}
                 which is based on YAM model definition 
<code>pizzeria_model.yaml</code>.
             </li>
             <li>
-                <code>Lines 31 and 37</code> define entity mappers 
<code>PizzeriaOrderMapper</code> instances which
+                <code>Lines 28 and 32</code> define entity mappers 
<code>PizzeriaOrderMapper</code> instances which
                 map <code>ord:pizza</code> elements with theirs sizes from 
<code>ord:pizza:size</code> and
                 quantities from <code>stanford:number</code>.
             </li>
             <li>
-                <code>Line 43</code> defines 
<code>PizzeriaOrderValidator</code> class described above.
+                <code>Line 36</code> defines 
<code>PizzeriaOrderValidator</code> class described above.
             </li>
         </ul>
 
diff --git a/examples/time.html b/examples/time.html
index 39a7bd4..d2c2fed 100644
--- a/examples/time.html
+++ b/examples/time.html
@@ -43,13 +43,13 @@ fa_icon: fa-cube
         </p>
         <pre class="brush: js, highlight: [7]">
             ThisBuild / version := "0.1.0-SNAPSHOT"
-            ThisBuild / scalaVersion := "3.1.3"
+            ThisBuild / scalaVersion := "3.2.2"
             lazy val root = (project in file("."))
               .settings(
-                name := "NLPCraft Calculator Example",
+                name := "NLPCraft Time Example",
                 version := "{{site.latest_version}}",
                 libraryDependencies += "org.apache.nlpcraft" % "nlpcraft" % 
"{{site.latest_version}}",
-                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.14" % "test"
+                libraryDependencies += "org.scalatest" %% "scalatest" % 
"3.2.15" % "test"
               )
         </pre>
         <p><b>NOTE: </b>use the latest versions of Scala and ScalaTest.</p>
@@ -96,7 +96,7 @@ fa_icon: fa-cube
               "&lt;CUR&gt;": "{current|present|now|local}"
               "&lt;TIME&gt;": "{time &lt;OF&gt; day|day 
time|date|time|moment|datetime|hour|o'clock|clock|date time|date and time|time 
and date}"
             elements:
-              - id: "x:time"
+              - type: "x:time"
                 description: "Date and/or time token indicator."
                 synonyms:
                   - "{&lt;CUR&gt;|_} &lt;TIME&gt;"

Reply via email to