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 2021/12/23 22:30:31 UTC

[incubator-nlpcraft] branch NLPCRAFT-469 updated: WIP/CR.

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

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


The following commit(s) were added to refs/heads/NLPCRAFT-469 by this push:
     new d02c800  WIP/CR.
d02c800 is described below

commit d02c80063430dfe1797f93d8fc87bd2d855b43fb
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Dec 23 14:30:26 2021 -0800

    WIP/CR.
---
 .../internal/nlp/benchmark/NCBenchmarkAdapter.java | 15 ++--
 .../enricher/NCEnDictionaryTokenEnricherSpec.scala |  2 +-
 .../parser/opennlp/NCOpenNlpTokenParserSpec.scala  | 10 +--
 .../nlpcraft/internal/nlp/util/NCTestRequest.scala | 10 ++-
 .../nlpcraft/internal/nlp/util/NCTestToken.scala   |  4 +-
 .../nlpcraft/internal/nlp/util/NCTestUtils.scala   | 14 ++--
 nlpcraft/src/test/resources/lightswitch_model.json | 82 ----------------------
 nlpcraft/src/test/resources/lightswitch_model.yaml | 56 ---------------
 8 files changed, 23 insertions(+), 170 deletions(-)

diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
index 96a9a7a..3bf2f63 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
@@ -21,20 +21,15 @@ import org.apache.nlpcraft.NCRequest;
 import org.apache.nlpcraft.internal.nlp.util.NCTestRequest;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.runner.*;
 import org.openjdk.jmh.runner.options.OptionsBuilder;
 
 import java.util.concurrent.TimeUnit;
 
+/**
+ *
+ */
 @BenchmarkMode(Mode.AverageTime)
 @OutputTimeUnit(TimeUnit.MILLISECONDS)
 @State(Scope.Benchmark)
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/enricher/NCEnDictionaryTokenEnricherSpec.scala b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/enricher/NCEnDictionaryTokenEnricherSpec.scala
index c48751d..c8f2b5d 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/enricher/NCEnDictionaryTokenEnricherSpec.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/enricher/NCEnDictionaryTokenEnricherSpec.scala
@@ -36,7 +36,7 @@ class NCEnDictionaryTokenEnricherSpec:
     def test(): Unit =
         val toks = Seq(
             NCTestToken(txt = "milk", lemma = "milk"), // Valid english word.
-            NCTestToken(txt = "XYZ", lemma = "XYZ")    // Invalid english word.
+            NCTestToken(txt = "XYZ", lemma = "XYZ") // Invalid english word.
         )
 
         require(toks.head.getOpt[Boolean]("english").isEmpty)
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
index e507666..81a47d8 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
@@ -17,12 +17,11 @@
 
 package org.apache.nlpcraft.internal.nlp.token.parser.opennlp
 
-import com.google.gson.GsonBuilder
 import org.apache.nlpcraft.internal.ascii.NCAsciiTable
 import org.apache.nlpcraft.internal.nlp
-import org.apache.nlpcraft.internal.nlp.util.{NCTestRequest, NCTestUtils}
-import org.apache.nlpcraft.{NCRequest, NCToken}
-import org.junit.jupiter.api.{BeforeEach, Test}
+import org.apache.nlpcraft.internal.nlp.util.*
+import org.apache.nlpcraft.*
+import org.junit.jupiter.api.*
 
 import java.util
 import scala.jdk.CollectionConverters.*
@@ -45,11 +44,8 @@ class NCOpenNlpTokenParserSpec:
 
     private def test(txt: String, validate: Seq[NCToken] => _): Unit =
         val toks = parser.parse(nlp.util.NCTestRequest(txt)).asScala.toSeq
-
         assert(toks.nonEmpty)
-
         NCTestUtils.printTokens(txt, toks)
-
         validate(toks)
 
     @Test
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestRequest.scala b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestRequest.scala
index 28ab5df..190bb77 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestRequest.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestRequest.scala
@@ -38,7 +38,7 @@ case class NCTestRequest(
     ts: Long = -1,
     userAgent: String = null,
     data: util.Map[String, AnyRef] = null
-) extends NCRequest :
+) extends NCRequest:
     override def getUserId: String = userId
     override def getRequestId: String = reqId
     override def getNormalizedText: String = txt.toLowerCase
@@ -50,6 +50,10 @@ case class NCTestRequest(
 /**
   * Java side helper.
   */
-object NCTestRequest {
+object NCTestRequest:
+    /**
+      * 
+      * @param txt
+      * @return
+      */
     def apply(txt: String): NCTestRequest = new NCTestRequest(txt)
-}
\ No newline at end of file
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestToken.scala b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestToken.scala
index 4ea1118..1f4b6ac 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestToken.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestToken.scala
@@ -17,7 +17,7 @@
 
 package org.apache.nlpcraft.internal.nlp.util
 
-import org.apache.nlpcraft.{NCParameterizedAdapter, NCToken}
+import org.apache.nlpcraft.*
 
 /**
   * Token test implementation.
@@ -38,7 +38,7 @@ case class NCTestToken(
     isStop: Boolean = false,
     start: Int = -1,
     end: Int = -1
-) extends NCParameterizedAdapter with NCToken :
+) extends NCParameterizedAdapter with NCToken:
     override def getOriginalText: String = txt
     override def getNormalizedText: String = txt.toLowerCase
     override def getLemma: String = lemma
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestUtils.scala b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestUtils.scala
index b810b30..4d62c6c 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestUtils.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/util/NCTestUtils.scala
@@ -18,7 +18,7 @@
 package org.apache.nlpcraft.internal.nlp.util
 
 import org.apache.nlpcraft.internal.ascii.NCAsciiTable
-import org.apache.nlpcraft.{NCLifecycle, NCToken}
+import org.apache.nlpcraft.*
 
 /**
   *
@@ -30,9 +30,7 @@ object NCTestUtils:
       */
     def printTokens(req: String, toks: Seq[NCToken]): Unit =
         val tbl = new NCAsciiTable()
-
         tbl #= ("Text", "Normalized", "POS", "Stem", "Lemma", "Start", "End", "Length", "Stopword")
-
         toks.foreach(t =>
             tbl += (
                 t.getOriginalText,
@@ -57,14 +55,12 @@ object NCTestUtils:
       * @return
       */
     def makeAndStart[T <: NCLifecycle](make: => T): T =
-        def now = System.currentTimeMillis()
+        def now() = System.currentTimeMillis()
 
-        val start = now
+        val start = now()
         val t = make
-        val started = now
+        val started = now()
         
         t.start()
-
-        println(s"'${t.getClass.getSimpleName}' created with time=${started - start} ms and started=${now - started} ms.")
-
+        println(s"'${t.getClass.getSimpleName}' created with time=${started - start} ms and started=${now() - started} ms.")
         t
diff --git a/nlpcraft/src/test/resources/lightswitch_model.json b/nlpcraft/src/test/resources/lightswitch_model.json
deleted file mode 100644
index ecb3a3b..0000000
--- a/nlpcraft/src/test/resources/lightswitch_model.json
+++ /dev/null
@@ -1,82 +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
- *
- *      http://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.
- */
-
-{
-  "macros": [
-    {
-      "id": "<ACTION>",
-      "macro": "{turn|switch|dial|let|set|get|put}"
-    },
-    {
-      "id": "<KILL>",
-      "macro": "{shut|kill|stop|eliminate}"
-    },
-    {
-      "id": "<ENTIRE_OPT>",
-      "macro": "{entire|full|whole|total|_}"
-    },
-    {
-      "id": "<FLOOR_OPT>",
-      "macro": "{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground} floor|_}"
-    },
-    {
-      "id": "<TYPE>",
-      "macro": "{room|closet|attic|loft|{store|storage} {room|_}}"
-    },
-    {
-      "id": "<LIGHT>",
-      "macro": "{all|_} {it|them|light|illumination|lamp|lamplight}"
-    }
-  ],
-  "elements": [
-    {
-      "id": "ls:loc",
-      "desc": "ls:loc",
-      "synonyms": [
-        "<ENTIRE_OPT> <FLOOR_OPT> {kitchen|library|closet|garage|office|playroom|{dinning|laundry|play} <TYPE>}",
-        "<ENTIRE_OPT> <FLOOR_OPT> {master|kid|children|child|guest|_} {bedroom|bathroom|washroom|storage} {<TYPE>|_}",
-        "<ENTIRE_OPT> {house|home|building|{1st|first} floor|{2nd|second} floor}"
-      ]
-    },
-    {
-      "id": "ls:on",
-      "desc": "ls:on",
-      "groups": [
-        "act"
-      ],
-      "synonyms": [
-        "<ACTION> {on|up|_} <LIGHT> {on|up|_}",
-        "<LIGHT> {on|up}"
-      ]
-    },
-    {
-      "id": "ls:off",
-      "desc": "ls:off",
-      "groups": [
-        "act"
-      ],
-      "synonyms": [
-        "<ACTION> <LIGHT> {off|out|down}",
-        "{<ACTION>|<KILL>} {off|out|down} <LIGHT>",
-        "<KILL> <LIGHT>",
-        "<LIGHT> <KILL>",
-        "{out|no|off|down} <LIGHT>",
-        "<LIGHT> {out|off|down}"
-      ]
-    }
-  ]
-}
diff --git a/nlpcraft/src/test/resources/lightswitch_model.yaml b/nlpcraft/src/test/resources/lightswitch_model.yaml
deleted file mode 100644
index ca71931..0000000
--- a/nlpcraft/src/test/resources/lightswitch_model.yaml
+++ /dev/null
@@ -1,56 +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
-#
-#      http://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.
-#
-
----
-macros:
-  - id: "<ACTION>"
-    macro: "{turn|switch|dial|let|set|get|put}"
-  - id: "<KILL>"
-    macro: "{shut|kill|stop|eliminate}"
-  - id: "<ENTIRE_OPT>"
-    macro: "{entire|full|whole|total|_}"
-  - id: "<FLOOR_OPT>"
-    macro: "{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground} floor|_}"
-  - id: "<TYPE>"
-    macro: "{room|closet|attic|loft|{store|storage} {room|_}}"
-  - id: "<LIGHT>"
-    macro: "{all|_} {it|them|light|illumination|lamp|lamplight}"
-elements:
-  - id: "ls:loc"
-    desc: "ls:loc"
-    synonyms:
-      - "<ENTIRE_OPT> <FLOOR_OPT> {kitchen|library|closet|garage|office|playroom|{dinning|laundry|play} <TYPE>}"
-      - "<ENTIRE_OPT> <FLOOR_OPT> {master|kid|children|child|guest|_} {bedroom|bathroom|washroom|storage} {<TYPE>|_}"
-      - "<ENTIRE_OPT> {house|home|building|{1st|first} floor|{2nd|second} floor}"
-  - id: "ls:on"
-    desc: "ls:on"
-    groups:
-      - "act"
-    synonyms:
-      - "<ACTION> {on|up|_} <LIGHT> {on|up|_}"
-      - "<LIGHT> {on|up}"
-  - id: "ls:off"
-    desc: "ls:off"
-    groups:
-      - "act"
-    synonyms:
-      - "<ACTION> <LIGHT> {off|out|down}"
-      - "{<ACTION>|<KILL>} {off|out|down} <LIGHT>"
-      - "<KILL> <LIGHT>"
-      - "<LIGHT> <KILL>"
-      - "{out|no|off|down} <LIGHT>"
-      - "<LIGHT> {out|off|down}"
\ No newline at end of file