This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-520
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-520 by this push:
new a4e62f9c WIP
a4e62f9c is described below
commit a4e62f9c2cc22ed4fca6a4b5f8e2109905ad7544
Author: Aaron Radzinski <[email protected]>
AuthorDate: Fri Jan 13 15:23:49 2023 -0800
WIP
---
.../nlpcraft/examples/time/CalculatorModel.scala | 2 +-
.../nlpcraft/examples/pizzeria/PizzeriaModel.scala | 3 +-
.../apache/nlpcraft/examples/time/TimeModel.scala | 5 +-
.../examples/time/utils/keycdn/GeoManager.scala | 6 +--
.../stanford/NCStanfordNLPEntityParser.scala | 7 +--
.../nlpcraft/nlp/parsers/NCSemanticElement.scala | 2 +-
.../nlp/parsers/NCSemanticEntityParser.scala | 53 +++++++++-------------
7 files changed, 36 insertions(+), 42 deletions(-)
diff --git
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
index 2725b49b..8572e02e 100644
---
a/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
+++
b/nlpcraft-examples/calculator/src/main/scala/org/apache/nlpcraft/examples/time/CalculatorModel.scala
@@ -49,7 +49,7 @@ import CalculatorModel.*
/**
*
*/
-class CalculatorModel extends NCModel(NCModelConfig("nlpcraft.calculator.ex",
"Calculator Example Model", "1.0"), PIPELINE) :
+class CalculatorModel extends NCModel(NCModelConfig("nlpcraft.calculator.ex",
"Calculator Example Model", "1.0"), PIPELINE):
private var mem: Option[Int] = None
private def calc(x: Int, op: String, y: Int): NCResult =
diff --git
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
index 82560df7..4539174e 100644
---
a/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
+++
b/nlpcraft-examples/pizzeria/src/main/scala/org/apache/nlpcraft/examples/pizzeria/PizzeriaModel.scala
@@ -85,8 +85,7 @@ object PizzeriaModel extends LazyLogging:
private def doShowMenuResult(): NCResult =
mkResult(
- "There are accessible for order: margherita, carbonara and
marinara. Sizes: large, medium or small. " +
- "Also there are tea, coffee and cola."
+ "There are accessible for order: margherita, carbonara and
marinara. Sizes: large, medium or small. Also there are tea, coffee and cola."
)
private def doShowMenu(state: State): Result = doShowMenuResult() -> state
diff --git
a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
index bf225828..c348a6b8 100644
---
a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
+++
b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.scala
@@ -30,6 +30,9 @@ import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle.MEDIUM
import java.time.*
+/**
+ * Time answering model.
+ */
@NCIntent("fragment=city term(city)~{# == 'opennlp:location'}")
@NCIntent("intent=intent2 term~{# == 'x:time'} fragment(city)")
@NCIntent("intent=intent1 term={# == 'x:time'}")
@@ -89,7 +92,7 @@ class TimeModel extends NCModel(
// We don't have timezone mapping for parsed GEO location.
// Instead of defaulting to a local time - we reject with a specific
error message for cleaner UX.
- val (city, data) =
citiesData.find(_._1.name.equalsIgnoreCase(cityName)).getOrElse(throw new
NCRejection(String.format("No timezone mapping for %s.", cityName)))
+ val (city, data) =
citiesData.find(_._1.name.equalsIgnoreCase(cityName)).getOrElse(throw new
NCRejection(s"No timezone mapping for $cityName."))
mkResult(city.name, city.country, data.timezone, data.latitude,
data.longitude)
diff --git
a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/utils/keycdn/GeoManager.scala
b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/utils/keycdn/GeoManager.scala
index 49a5e12c..a51eac73 100644
---
a/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/utils/keycdn/GeoManager.scala
+++
b/nlpcraft-examples/time/src/main/scala/org/apache/nlpcraft/examples/time/utils/keycdn/GeoManager.scala
@@ -50,16 +50,16 @@ object GeoManager:
externalIp match
case Some(_) => // No-op.
case None =>
- try externalIp = Some(getExternalIp)
+ try externalIp = Option(getExternalIp)
catch
case _: IOException => // No-op.
externalIp match
case Some(ip) =>
cache.get(ip) match
- case Some(geo) => Some(geo)
+ case Some(geo) => Option(geo)
case None =>
- val conn = new URL(URL +
ip).openConnection.asInstanceOf[HttpURLConnection]
+ val conn = new
URL(s"$URL$ip").openConnection.asInstanceOf[HttpURLConnection]
// This service requires "User-Agent" property
with its own format.
conn.setRequestProperty("User-Agent",
"keycdn-tools:https://nlpcraft.apache.org")
diff --git
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
index 5939390d..c34c433b 100644
---
a/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
+++
b/nlpcraft-stanford/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/stanford/NCStanfordNLPEntityParser.scala
@@ -25,15 +25,16 @@ import scala.collection.mutable
import scala.jdk.CollectionConverters.*
/**
- * [[https://nlp.stanford.edu/ Stanford NLP]] based language independent
[[NCEntityParser entity parser]] configured by
- * given [[StanfordCoreNLP]] pipeline instance.
+ * [[https://nlp.stanford.edu/ Stanford NLP]] based language independent
[[NCEntityParser entity parser]] configured by
+ * given [[StanfordCoreNLP]] pipeline instance.
*
* This parser prepares [[NCEntity]] instances which are detected by prepared
[[StanfordCoreNLP]] pipeline.
* These entities are created with ID `stanford:modelName`, where `modelName`
is model configured in [[StanfordCoreNLP pipeline]].
* Also this parser copies optional `nne` string and `confidence` double
[[NCPropertyMap metadata]] properties to the
* created entities extracted from [[StanfordCoreNLP]] annotations.
- * **NOTE:** that parser can produce different types of [[NCEntity]]
instances and each input [[NCToken]] can be included into several output
[[NCEntity]] instances.
+ * **NOTE:** this parser can produce different types of [[NCEntity]]
instances and each input [[NCToken]] can be included
+ * into several output [[NCEntity]] instances.
*
* @param stanford Configured [[StanfordCoreNLP]] pipeline instance.
* @param supported Supported [[StanfordCoreNLP]] model names. Only supported
models will be used for [[NCEntity]] instances generation.
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticElement.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticElement.scala
index 85dece07..134a3514 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticElement.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticElement.scala
@@ -20,7 +20,7 @@ package org.apache.nlpcraft.nlp.parsers
import org.apache.nlpcraft.nlp.stemmer.NCStemmer
import org.apache.nlpcraft.*
/**
- * This trait defines a named [[NCEntity entity]] that is used by
[[NCSemanticEntityParser]].
+ * This trait defines a named [[NCEntity entity]] that is used by
[[NCSemanticEntityParser]].
*
* THe main purpose of this trait is to provide a set of synonyms by which
this named entity can be matched
* in the input text. Each synonym consists of one or more individual words.
Synonym matching is performed on the
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticEntityParser.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticEntityParser.scala
index ea40ca8b..86d22c07 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticEntityParser.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCSemanticEntityParser.scala
@@ -123,17 +123,15 @@ private object NCSemanticEntityParser:
import NCSemanticEntityParser.*
/**
- * **Semantic** [[NCEntityParser entity parser]] implementation.
+ * Semantic entity parser implementation.
*
- * This synonyms based parser provides simple but very powerful way to find
domain specific data in the input text.
- * It is configured via [[NCSemanticElement]] list which represents
[[NCEntity name entities]] that
- * can be produced by this parser.
+ * This synonyms based parser provides simple yet powerful way to find domain
specific data in the input text.
+ * It is configured via [[NCSemanticElement]] list which represents all
possible [[NCEntity named entities]] that
+ * this parser can detect.
*
- * [[NCSemanticElement Semantic elements]] can be configured via YAML or
JSON files in special format or
- * passed in this parser as programmatically prepared list.
- *
- * [[NCSemanticElement Semantic elements]] contain set of synonyms which can
use special
- * [[https://nlpcraft.apache.org/built-in-entity-parser.html#macros macros]].
+ * [[NCSemanticElement Semantic elements]] can be configured via YAML or JSON
files in special format or
+ * passed in this parser as programmatically prepared list.
[[NCSemanticElement Semantic elements]] contain set of
+ * synonyms which can use special
[[https://nlpcraft.apache.org/built-in-entity-parser.html#macros macros]].
* These macros also can be provided via YAML and JSON files or passed
directly in case of programmatically prepared
* [[NCSemanticElement]] list.
*
@@ -150,25 +148,18 @@ import NCSemanticEntityParser.*
* - "{<CUR>|_} <TIME>"
* - "what <TIME> {is it now|now|is it|_}"
* </pre>
- * So **x:time** element can be detected by huge bunch of synonyms like *day
time*,
- * *local day time*, *time of day*, *local time of day*, *what hour is it*
etc.
- * Note that these synonyms are configured in easy to extend and support way,
very compactly.
- *
- * See detailed description on the website
[[https://nlpcraft.apache.org/built-in-entity-parser.html#parser-semantic
Semantic Parser]].
- * Also look at the
[[https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples
examples section]].
- *
- * **NOTE:** [[NCSemanticElement]] synonyms, **stemmer** and **parser**
parameters must be configured for the same language.
- * `stemmer` implementation language should be corresponded with other
components of [[NCPipeline]], but
- * required `stemmer` implementation is independent from other components'
stemmers.
- *
- * **NOTE:** that parser can produce different types of [[NCEntity]]
instances and each input [[NCToken]] can be included into several output
[[NCEntity]] instances.
+ * Given this simple definition the **x:time** element can be detected by a
large number of synonyms like *day time*,
+ * *local day time*, *time of day*, *local time of day*, *what hour is it*,
etc.
*
- * There are several constructors with different set of parameters.
- * - **stemmer** [[NCStemmer]] implementation which used for matching tokens
and given [[NCSemanticElement]] synonyms.
- * - **parser** [[NCTokenParser]] implementation which used for given
[[NCSemanticElement]] synonyms tokenization. It should be same implementation
as used in [[NCPipeline.getTokenParser]].
- * - **macros** Macros map which are used for extracting
[[NCSemanticElement]] synonyms defined via **macros**. Empty by default. Look
more at the website
[[https://nlpcraft.apache.org/built-in-entity-parser.html#macros Macros]].
- * - **elements** Programmatically prepared [[NCSemanticElement]] instances.
- * - **mdlRes** Relative path, absolute path, classpath resource or URL to
YAML or JSON semantic model which contains [[NCSemanticElement]] definitions.
+ * @param stemmer [[NCStemmer]] implementation which used to match tokens and
given [[NCSemanticElement]] synonyms.
+ * @param parser [[NCTokenParser]] implementation which will be used for
[[NCSemanticElement]] synonyms tokenization.
+ * It should be same implementation as used in
[[NCPipeline.getTokenParser]].
+ * @param macros Macros map which are used for extracting
[[NCSemanticElement]] synonyms defined via **macros**.
+ * More information at
[[https://nlpcraft.apache.org/built-in-entity-parser.html#macros]].
+ * @param elements Programmatically prepared [[NCSemanticElement]] instances.
Note that either the model or elements
+ * must be supplied at least.
+ * @param mdlResOpt Optional relative path, absolute path, classpath resource
or URL to YAML or JSON semantic model
+ * which contains [[NCSemanticElement]] definitions. Note that either the
model or elements must be supplied at least.
*
* @see [[NCSemanticElement]]
*/
@@ -182,10 +173,10 @@ class NCSemanticEntityParser private (
require(stemmer != null, "Stemmer cannot be null.")
require(parser != null, "Token parser cannot be null.")
require(macros != null, "Macros cannot be null.")
- require(elements != null && elements.nonEmpty || mdlResOpt.isDefined,
"Elements cannot be null or empty or model resource cannot be empty.")
+ require(elements != null && elements.nonEmpty || mdlResOpt.isDefined,
"Either elements or external YAML/JSON model must be supplied.")
/**
- * Creates [[NCSemanticEntityParser]] instance.
+ * Creates [[NCSemanticEntityParser]] instance with given parameters.
*
* @param stemmer [[NCStemmer]] implementation for synonyms language.
* @param parser [[NCTokenParser]] implementation.
@@ -197,7 +188,7 @@ class NCSemanticEntityParser private (
/**
*
- * Creates [[NCSemanticEntityParser]] instance.
+ * Creates [[NCSemanticEntityParser]] instance with given parameters.
*
* @param stemmer [[NCStemmer]] implementation for synonyms language.
* @param parser [[NCTokenParser]] implementation.
@@ -208,7 +199,7 @@ class NCSemanticEntityParser private (
/**
*
- * Creates [[NCSemanticEntityParser]] instance.
+ * Creates [[NCSemanticEntityParser]] instance with given parameters.
*
* @param stemmer [[NCStemmer]] implementation for synonyms language.
* @param parser [[NCTokenParser]] implementation.