You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2022/12/03 03:07:19 UTC

[incubator-nlpcraft] branch master updated: WIP Scaladoc.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new b0fb66b7 WIP Scaladoc.
b0fb66b7 is described below

commit b0fb66b77094ec1f9342197236f5b071ab241f79
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Dec 2 19:07:14 2022 -0800

    WIP Scaladoc.
---
 .../main/scala/org/apache/nlpcraft/NCModel.scala   |   2 -
 .../scala/org/apache/nlpcraft/NCModelConfig.scala  |   2 +
 .../org/apache/nlpcraft/NCPipelineBuilder.scala    | 164 +++++++++++++--------
 .../nlp/parsers/NCSemanticEntityParser.scala       |   3 +-
 4 files changed, 110 insertions(+), 61 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
index b45735be..028555d5 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModel.scala
@@ -32,10 +32,8 @@ package org.apache.nlpcraft
   * some aspects of your data models - your entire model and all of its components are part of your project's
   * source code.
   *
-  * Note that in most cases, one would use a convenient [[NCModelAdapter]] adapter to implement this interface.
   *
   * @see [[NCModelClient]]
-  * @see [[NCModelAdapter]]
   * @see [[NCModelConfig]]
   * @see [[NCPipeline]]
   */
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
index e6eecb50..55ec4d7e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.scala
@@ -81,6 +81,8 @@ import org.apache.nlpcraft.NCModelConfig.*
 
 /**
   * Model configuration container.
+  *
+  * @see [[NCModel.getConfig]]
   */
 trait NCModelConfig extends NCPropertyMap:
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCPipelineBuilder.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCPipelineBuilder.scala
index d15ba80f..3183875f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCPipelineBuilder.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCPipelineBuilder.scala
@@ -24,6 +24,9 @@ import org.apache.nlpcraft.nlp.enrichers.*
 
 import java.util.Objects
 
+/**
+  * Convenient builder for [[NCPipeline]] instance.
+  */
 class NCPipelineBuilder:
     import scala.collection.mutable.ArrayBuffer as Buf
 
@@ -34,11 +37,8 @@ class NCPipelineBuilder:
     private val tokVals: Buf[NCTokenValidator] = Buf.empty
     private val entVals: Buf[NCEntityValidator] = Buf.empty
     private val entMappers: Buf[NCEntityMapper] = Buf.empty
-    private var varFilters: Buf[NCVariantFilter] = Buf.empty
+    private val varFilters: Buf[NCVariantFilter] = Buf.empty
 
-    /**
-      *
-      * @return */
     private def mkEnStemmer: NCSemanticStemmer =
         new NCSemanticStemmer:
             final private val ps: PorterStemmer = new PorterStemmer
@@ -48,128 +48,173 @@ class NCPipelineBuilder:
         new NCOpenNLPTokenParser(NCResourceReader.getPath("opennlp/en-token.bin"))
 
     /**
-      * @param tokEnrichers
-      * @return This instance for call chaining. */
+      * Adds given token enrichers to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param tokEnrichers Token enrichers to add this pipeline builder.
+      */
     def withTokenEnrichers(tokEnrichers: List[NCTokenEnricher]): NCPipelineBuilder =
         require(tokEnrichers != null, "List of token enrichers cannot be null.")
-        tokEnrichers.foreach((p: NCTokenEnricher) => require(p != null, "Token enricher cannot be null."))
-        this.tokEnrichers ++= tokEnrichers
+        tokEnrichers.foreach(withTokenEnricher)
         this
 
     /**
-      * @param tokEnricher
-      * @return This instance for call chaining. */
+      * Adds given token enricher to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param tokEnricher Token enricher to add this pipeline builder.
+      */
     def withTokenEnricher(tokEnricher: NCTokenEnricher): NCPipelineBuilder =
         require(tokEnricher != null, "Token enricher cannot be null.")
         this.tokEnrichers += tokEnricher
         this
 
     /**
-      * @param entEnrichers
-      * @return This instance for call chaining. */
+      * Adds given entity enrichers to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entEnrichers Entity enrichers to add this pipeline builder.
+      */
     def withEntityEnrichers(entEnrichers: List[NCEntityEnricher]): NCPipelineBuilder =
         require(entEnrichers != null, "List of entity enrichers cannot be null.")
-        entEnrichers.foreach((p: NCEntityEnricher) => require(p != null, "Entity enrichers cannot be null."))
-        this.entEnrichers ++= entEnrichers
+        entEnrichers.foreach(withEntityEnricher)
         this
 
     /**
-      * @param entEnricher
-      * @return This instance for call chaining. */
+      * Adds given entity enricher to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entEnricher Entity enricher to add this pipeline builder.
+      */
     def withEntityEnricher(entEnricher: NCEntityEnricher): NCPipelineBuilder = 
         require(entEnricher != null, "Entity enricher cannot be null.")
         this.entEnrichers += entEnricher
         this
 
     /**
-      * @param entParsers
-      * @return This instance for call chaining. */
+      * Adds given entity parsers to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entParsers Entity parsers to add this pipeline builder.
+      */
     def withEntityParsers(entParsers: List[NCEntityParser]): NCPipelineBuilder =
         require(entParsers != null, "List of entity parsers cannot be null.")
-        entParsers.foreach((p: NCEntityParser) => require(p != null, "Entity parser cannot be null."))
-        this.entParsers ++= entParsers
+        entParsers.foreach(withEntityParser)
         this
 
     /**
-      * @param entParser
-      * @return This instance for call chaining. */
+      * Adds given entity parser to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entParser Entity parser to add this pipeline builder.
+      */
     def withEntityParser(entParser: NCEntityParser): NCPipelineBuilder =
         require(entParser != null, "Entity parser cannot be null.")
         this.entParsers += entParser
         this
 
     /**
-      * @param tokVals
-      * @return This instance for call chaining. */
+      * Adds given token validators to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param tokVals Token validators to add this pipeline builder.
+      */
     def withTokenValidators(tokVals: List[NCTokenValidator]): NCPipelineBuilder =
         require(tokVals != null, "List of token validators cannot be null.")
-        tokVals.foreach((p: NCTokenValidator) => require(p != null, "Token validator cannot be null."))
-        this.tokVals ++= tokVals
+        tokVals.foreach(withTokenValidator)
         this
 
-
     /**
-      * @param tokVal
-      * @return This instance for call chaining. */
+      * Adds given token validator to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param tokVal Token validator to add this pipeline builder.
+      */
     def withTokenValidator(tokVal: NCTokenValidator): NCPipelineBuilder =
         require(tokVal != null, "Token validator cannot be null.")
         this.tokVals += tokVal
         this
 
     /**
-      * @param entVals
-      * @return This instance for call chaining. */
+      * Adds given entity validators to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entVals Entity validators to add this pipeline builder.
+      */
     def withEntityValidators(entVals: List[NCEntityValidator]): NCPipelineBuilder =
         require(entVals != null, "List of entity validators cannot be null.")
-        entVals.foreach((p: NCEntityValidator) => require(p != null, "Entity validators cannot be null."))
-        this.entVals ++= entVals
+        entVals.foreach(withEntityValidator)
         this
 
     /**
-      * @param entVal
-      * @return This instance for call chaining. */
+      * Adds given entity validator to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entVal Entity validator to add this pipeline builder.
+      */
     def withEntityValidator(entVal: NCEntityValidator): NCPipelineBuilder =
         require(entVal != null, "Entity validator cannot be null.")
         this.entVals += entVal
         this
 
     /**
-      * @param varFilters
-      * @return This instance for call chaining. */
+      * Adds given variant filters to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param varFilters Variant filters to add this pipeline builder.
+      */
     def withVariantFilters(varFilters: List[NCVariantFilter]): NCPipelineBuilder =
+        require(varFilters != null, "List of variant filters cannot be null.")
+        varFilters.foreach(withVariantFilter)
+        this
+
+    /**
+      * Adds given variant filter to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param varFilter Variant filter to add this pipeline builder.
+      */
+    def withVariantFilter(varFilter: NCVariantFilter): NCPipelineBuilder =
+        require(varFilter != null, "Variant filter cannot be null.")
         this.varFilters ++= varFilters
         this
 
     /**
+      * Adds given token parser to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
       *
-      * @param tokParser
-      * @return */
+      * @param tokParser Token parser to add this pipeline builder.
+      */
     def withTokenParser(tokParser: NCTokenParser): NCPipelineBuilder =
         require(tokParser != null, "Token parser cannot be null.")
         this.tokParser = tokParser.?
         this
 
     /**
+      * Adds given entity mappers to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
       *
-      * @param entMappers
-      * @return This instance for call chaining.
+      * @param entMappers Entity mappers to add this pipeline builder.
       */
     def withEntityMappers(entMappers: List[NCEntityMapper]): NCPipelineBuilder =
         require(entMappers != null, "List of entity mappers cannot be null.")
-        entMappers.foreach((p: NCEntityMapper) => require(p != null, "Entity mapper cannot be null."))
-        this.entMappers ++= entMappers
+        entMappers.foreach(withEntityMapper)
         this
 
     /**
-      * @param entMapper
-      * @return This instance for call chaining. */
+      * Adds given entity mapper to the pipeline builder. Note that this method returns
+      * this instance for convenient call chaining.
+      *
+      * @param entMapper Entity mapper to add this pipeline builder.
+      */
     def withEntityMapper(entMapper: NCEntityMapper): NCPipelineBuilder =
         require(entMapper != null, "Entity mapper cannot be null.")
         this.entMappers += entMapper
         this
 
     /**
-      * */
+      *
+      */
     private def setEnComponents(): Unit =
         tokParser = mkEnOpenNLPTokenParser.?
         tokEnrichers += new NCOpenNLPLemmaPosTokenEnricher(NCResourceReader.getPath("opennlp/en-pos-maxent.bin"), NCResourceReader.getPath("opennlp/en-lemmatizer.dict"))
@@ -180,11 +225,12 @@ class NCPipelineBuilder:
         tokEnrichers += new NCEnBracketsTokenEnricher
 
     /**
+      * Shortcut to configure pipeline with [[NCSemanticEntityParser]].
       *
-      * @param lang
-      * @param macros
-      * @param elms
-      * @return */
+      * @param lang ISO 639-1 language code. Currently, only "en" (English) is supported.
+      * @param macros Macros to use with [[NCSemanticEntityParser]].
+      * @param elms Semantic elements to use with [[NCSemanticEntityParser]].
+      */
     def withSemantic(lang: String, macros: Map[String, String], elms: List[NCSemanticElement]): NCPipelineBuilder =
         require(lang != null, "Language cannot be null.")
         require(macros != null, "Macros elements cannot be null.")
@@ -200,16 +246,18 @@ class NCPipelineBuilder:
         this
 
     /**
+      * Shortcut to configure pipeline with [[NCSemanticEntityParser]].
       *
-      * @param lang
-      * @param elms
-      * @return */
+      * @param lang ISO 639-1 language code. Currently, only "en" (English) is supported.
+      * @param elms Semantic elements to use with [[NCSemanticEntityParser]].
+      */
     def withSemantic(lang: String, elms: List[NCSemanticElement]): NCPipelineBuilder = withSemantic(lang, Map.empty, elms)
 
     /**
+      * Shortcut to configure pipeline with [[NCSemanticEntityParser]].
       *
-      * @param lang
-      * @param mdlSrc
+      * @param lang ISO 639-1 language code. Currently, only "en" (English) is supported.
+      * @param mdlSrc Classpath resource, file path or URL for YAML or JSON semantic model definition file.
       */
     def withSemantic(lang: String, mdlSrc: String): NCPipelineBuilder =
         require(lang != null, "Language cannot be null.")
@@ -220,10 +268,10 @@ class NCPipelineBuilder:
                 this.entParsers += NCSemanticEntityParser(mkEnStemmer, mkEnOpenNLPTokenParser, mdlSrc)
             case _ => require(false, s"Unsupported language: $lang")
         this
-
-
+    
     /**
-      * @return */
+      * Builds new [[NCPipeline]] instance with previously provided components.
+      */
     def build: NCPipeline =
         require(tokParser.nonEmpty, "Token parser must be defined.")
         require(entParsers.nonEmpty, "At least one entity parser must be defined.")
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 2b862fdf..f978fd1f 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
@@ -177,7 +177,7 @@ import org.apache.nlpcraft.nlp.parsers.NCSemanticEntityParser.*
   * @param parser
   * @param macros
   * @param elements
-  * @param mdlSrcOpt
+  * @param mdlSrcOpt Optional classpath resource, file path or URL for YAML or JSON semantic model definition file.
   */
 class NCSemanticEntityParser(
     stemmer: NCSemanticStemmer,
@@ -199,6 +199,7 @@ class NCSemanticEntityParser(
     private var elemsMap: Map[String, NCSemanticElement] = _
 
     init()
+
     /**
       *
       */