This is an automated email from the ASF dual-hosted git repository.
sergeykamov 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 b1b0fb4a WIP.
b1b0fb4a is described below
commit b1b0fb4a096592e204fb8e77abd6ddf66fa6f4ff
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Dec 14 19:29:09 2022 +0400
WIP.
---
.../entity/parser/NCFrSemanticEntityParser.scala | 2 +-
.../entity/parser/NCRuSemanticEntityParser.scala | 2 +-
.../nlp/enrichers/NCOpenNLPTokenEnricher.scala | 4 ++--
.../nlp/parsers/NCOpenNLPEntityParser.scala | 2 +-
.../nlp/parsers/NCSemanticEntityParser.scala | 24 ++++++++++++----------
5 files changed, 18 insertions(+), 16 deletions(-)
diff --git
a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCFrSemanticEntityParser.scala
b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCFrSemanticEntityParser.scala
index 1d69818c..e119a08a 100644
---
a/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCFrSemanticEntityParser.scala
+++
b/nlpcraft-examples/lightswitch-fr/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCFrSemanticEntityParser.scala
@@ -33,5 +33,5 @@ class NCFrSemanticEntityParser(src: String) extends
NCSemanticEntityParser(
override def stem(word: String): String = stemmer.synchronized {
stemmer.stem(word.toLowerCase).toString }
,
new NCFrTokenParser(),
- mdlSrcOpt = src.?
+ mdlResOpt = src.?
)
diff --git
a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCRuSemanticEntityParser.scala
b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCRuSemanticEntityParser.scala
index 3685eda6..cafeef39 100644
---
a/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCRuSemanticEntityParser.scala
+++
b/nlpcraft-examples/lightswitch-ru/src/main/scala/org/apache/nlpcraft/examples/lightswitch/nlp/entity/parser/NCRuSemanticEntityParser.scala
@@ -33,5 +33,5 @@ class NCRuSemanticEntityParser(src: String) extends
NCSemanticEntityParser(
override def stem(word: String): String = stemmer.synchronized {
stemmer.stem(word.toLowerCase).toString }
,
new NCRuTokenParser(),
- mdlSrcOpt = src.?
+ mdlResOpt = src.?
)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCOpenNLPTokenEnricher.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCOpenNLPTokenEnricher.scala
index 4178d2ca..4b66c396 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCOpenNLPTokenEnricher.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCOpenNLPTokenEnricher.scala
@@ -39,10 +39,10 @@ import scala.concurrent.ExecutionContext
*
* @param posMdlRes Relative path, absolute path or URL to
*
[[https://opennlp.apache.org/docs/2.0.0/apidocs/opennlp-tools/opennlp/tools/postag/POSTaggerME.html
POSTaggerME]] model.
- * Can be `null` if **part-of-speech** model shouldn't be configured,
so `pos` property will not be passed.
+ * Can be `null` if **part-of-speech** model is not configured, so
`pos` property will not be passed.
* @param lemmaDicRes Relative path, absolute path or URL to
*
[[https://opennlp.apache.org/docs/2.0.0/apidocs/opennlp-tools/opennlp/tools/lemmatizer/DictionaryLemmatizer.html
DictionaryLemmatizer]] model.
- * Can be `null` if **lemmatizer** model shouldn't be configured, so
`lemma` property will not be passed.
+ * Can be `null` if **lemmatizer** model is not configured, so
`lemma` property will not be passed.
*/
class NCOpenNLPTokenEnricher(posMdlRes: String = null, lemmaDicRes: String =
null) extends NCTokenEnricher with LazyLogging:
require(posMdlRes != null || lemmaDicRes != null, "At least one model must
be defined")
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCOpenNLPEntityParser.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCOpenNLPEntityParser.scala
index 31c84450..d29e2daa 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCOpenNLPEntityParser.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/parsers/NCOpenNLPEntityParser.scala
@@ -62,7 +62,7 @@ object NCOpenNLPEntityParser:
* @param findersMdlsRes Paths to
[[https://opennlp.apache.org/docs/2.0.0/apidocs/opennlp-tools/opennlp/tools/namefind/TokenNameFinderModel.html
models]].
*/
class NCOpenNLPEntityParser(findersMdlsRes: List[String]) extends
NCEntityParser with LazyLogging:
- require(findersMdlsRes != null, "Models sources cannot be null.")
+ require(findersMdlsRes != null && findersMdlsRes.nonEmpty, "Models paths
cannot be null or empty.")
private var finders: Seq[NameFinderME] = _
private case class Holder(start: Int, end: Int, name: String, probability:
Double)
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 fd6e6ba3..8de55ac1 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
@@ -82,14 +82,14 @@ object NCSemanticEntityParser:
*
* @param stemmer [[NCStemmer]] implementation for synonyms language.
* @param parser [[NCTokenParser]] implementation.
- * @param mdlSrc Classpath resource, file path or URL for YAML or JSON
semantic model definition file.
+ * @param mdlRes Classpath resource, file path or URL for YAML or JSON
semantic model definition file.
*/
- def apply(stemmer: NCStemmer, parser: NCTokenParser, mdlSrc: String):
NCSemanticEntityParser =
+ def apply(stemmer: NCStemmer, parser: NCTokenParser, mdlRes: String):
NCSemanticEntityParser =
require(stemmer != null, "Stemmer cannot be null.")
require(parser != null, "Parser cannot be null.")
- require(mdlSrc != null, "Model source cannot be null.")
+ require(mdlRes != null, "Model path cannot be null.")
- new NCSemanticEntityParser(stemmer, parser, mdlSrcOpt = mdlSrc.?)
+ new NCSemanticEntityParser(stemmer, parser, mdlResOpt = mdlRes.?)
/**
* @param baseTokens Tokens.
@@ -182,28 +182,30 @@ import
org.apache.nlpcraft.nlp.parsers.NCSemanticEntityParser.*
*
* See detailed description on the website
[[https://nlpcraft.apache.org/built-in-entity-parser.html#parser-semantic
Semantic Parser]].
*
+ * **NOTE:** [[NCSemanticElement]] synonyms, **stemmer** and **parser**
parameters must be configured for the same language.
+ *
* @see [[NCSemanticElement]]
* @param stemmer [[NCStemmer]] implementation for synonyms language.
* @param parser [[NCTokenParser]] implementation.
* @param macros Macros map. Empty by default.
* @param elements [[NCSemanticElement]] list.
- * @param mdlSrcOpt Optional classpath resource, file path or URL for YAML or
JSON semantic model definition file.
+ * @param mdlResOpt Optional classpath resource, file path or URL for YAML or
JSON semantic model definition file.
*/
class NCSemanticEntityParser(
stemmer: NCStemmer,
parser: NCTokenParser,
macros: Map[String, String] = Map.empty,
elements: List[NCSemanticElement] = List.empty,
- mdlSrcOpt: Option[String] = None
+ mdlResOpt: Option[String] = None
) extends NCEntityParser with LazyLogging:
require(stemmer != null)
require(parser != null)
require(macros != null)
- require(elements != null && elements.nonEmpty || mdlSrcOpt.isDefined)
+ require(elements != null && elements.nonEmpty || mdlResOpt.isDefined)
private lazy val scrType =
- require(mdlSrcOpt.isDefined)
- NCSemanticSourceType.detect(mdlSrcOpt.get)
+ require(mdlResOpt.isDefined)
+ NCSemanticSourceType.detect(mdlResOpt.get)
private var synsHolder: NCSemanticSynonymsHolder = _
private var elemsMap: Map[String, NCSemanticElement] = _
@@ -217,10 +219,10 @@ class NCSemanticEntityParser(
val (macros, elements, elemsMap) =
def toMap(elems: Seq[NCSemanticElement]): Map[String,
NCSemanticElement] = elems.map(p => p.getId -> p).toMap
- mdlSrcOpt match
+ mdlResOpt match
case Some(mdlSrc) =>
val src = NCSemanticSourceReader.read(new
BufferedInputStream(NCUtils.getStream(mdlSrc)), scrType)
- logger.trace(s"Loaded resource: $mdlSrcOpt")
+ logger.trace(s"Loaded resource: $mdlResOpt")
(src.macros, src.elements, toMap(src.elements))
case None => (this.macros, this.elements, toMap(this.elements))