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

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


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

commit a6429a5c29174fbf55c0ac305cd59ff72c3a47ba
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Dec 13 17:49:39 2021 +0300

    WIP.
---
 .../nlp/entity/parser/custom/NCElement.java        | 10 ++-
 .../nlp/entity/parser/custom/NCElementBuilder.java | 95 +++++++++++++++++++++-
 .../nlpcraft/alarm/LightSwitchModelTest.java       |  5 +-
 nlpcraft/src/test/resources/lightswitch_model.json | 74 ++++++++++-------
 nlpcraft/src/test/resources/lightswitch_model.yaml | 72 ++++++++++------
 5 files changed, 196 insertions(+), 60 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElement.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElement.java
index eb476d3..793131e 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElement.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElement.java
@@ -18,9 +18,11 @@
 
 package org.apache.nlpcraft.internal.nlp.entity.parser.custom;
 
+import org.apache.nlpcraft.NCParameterized;
+
+import java.util.List;
 import java.util.Optional;
 import java.util.Set;
-import org.apache.nlpcraft.NCParameterized;
 
 /**
  *
@@ -61,4 +63,10 @@ public interface NCElement extends NCParameterized {
      * @return
      */
     Optional<NCValueLoader> getValuesLoader();
+
+    /**
+     *
+     * @return
+     */
+    List<String> getSynonyms();
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElementBuilder.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElementBuilder.java
index f928919..4d4d335 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElementBuilder.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/nlp/entity/parser/custom/NCElementBuilder.java
@@ -17,21 +17,98 @@
 
 package org.apache.nlpcraft.internal.nlp.entity.parser.custom;
 
+import org.apache.nlpcraft.NCParameterizedAdapter;
+
+import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
 
 /**
  * 
  */
 public class NCElementBuilder {
+    private static class NCElementImpl extends NCParameterizedAdapter 
implements NCElement {
+        private final String id;
+        private final String desc;
+
+        private String parentId;
+        private Set<String> groups;
+        private Set<NCValue> values;
+        private NCValueLoader valuesLoader;
+        private List<String> synonyms;
+
+        NCElementImpl(String id, String desc) {
+            this.id = id;
+            this.desc = desc;
+        }
+
+        void setParentId(String parentId) {
+            this.parentId = parentId;
+        }
+
+        void setGroups(Set<String> groups) {
+            this.groups = groups;
+        }
+
+        void setValues(Set<NCValue> values) {
+            this.values = values;
+        }
+
+        void setValuesLoader(NCValueLoader valuesLoader) {
+            this.valuesLoader = valuesLoader;
+        }
+
+        void setSynonyms(List<String> synonyms) {
+            this.synonyms = synonyms;
+        }
+
+        @Override
+        public String getId() {
+            return id;
+        }
+
+        @Override
+        public String getDescription() {
+            return desc;
+        }
+
+        @Override
+        public Optional<String> getParentId() {
+            return Optional.ofNullable(parentId);
+        }
+
+        @Override
+        public Set<String> getGroups() {
+            return groups == null ? Collections.emptySet() : groups;
+        }
+
+        @Override
+        public Set<NCValue> getValues() {
+            return values == null ? Collections.emptySet() : values;
+        }
+
+        @Override
+        public Optional<NCValueLoader> getValuesLoader() {
+            return Optional.ofNullable(valuesLoader);
+        }
+
+        @Override
+        public List<String> getSynonyms() {
+            return synonyms;
+        }
+    }
+
+    private NCElementImpl impl = null;
+
     /**
      * 
      * @param id
      * @param desc
      */
     public NCElementBuilder(String id, String desc) {
-
+        impl = new NCElementImpl(id, desc);
     }
 
     /**
@@ -40,6 +117,8 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withParentId(String parentId) {
+        impl.setParentId(parentId);
+
         return this;
     }
 
@@ -49,6 +128,8 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withGroups(Set<String> groups) {
+        impl.setGroups(groups);
+
         return this;
     }
 
@@ -58,6 +139,8 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withValues(Set<NCValue> values) {
+        impl.setValues(values);
+
         return this;
     }
 
@@ -67,6 +150,8 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withValuesLoader(NCValueLoader loader) {
+        impl.setValuesLoader(loader);
+
         return this;
     }
 
@@ -76,6 +161,7 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withProperties(Map<String, String> props) {
+        // TODO:
         return this;
     }
 
@@ -85,6 +171,8 @@ public class NCElementBuilder {
      * @return
      */
     public NCElementBuilder withSynonyms(List<String> syns) {
+        impl.setSynonyms(syns);
+
         return this;
     }
 
@@ -93,6 +181,7 @@ public class NCElementBuilder {
      * @return
      */
     public NCElement make() {
-        return null;
+        // TODO: add validation
+        return impl;
     }
 }
diff --git 
a/nlpcraft/src/test/java/org/apache/nlpcraft/alarm/LightSwitchModelTest.java 
b/nlpcraft/src/test/java/org/apache/nlpcraft/alarm/LightSwitchModelTest.java
index 8c7db06..00448e5 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/alarm/LightSwitchModelTest.java
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/alarm/LightSwitchModelTest.java
@@ -21,15 +21,15 @@ import org.apache.nlpcraft.NCModelClient;
 import org.apache.nlpcraft.NCModelConfigAdapter;
 import org.apache.nlpcraft.internal.nlp.entity.parser.custom.NCElement;
 import org.apache.nlpcraft.internal.nlp.entity.parser.custom.NCElementBuilder;
-import org.apache.nlpcraft.internal.nlp.entity.parser.custom.NCMacro;
 import org.apache.nlpcraft.internal.nlp.entity.parser.custom.NCEntityParser;
+import org.apache.nlpcraft.internal.nlp.entity.parser.custom.NCMacro;
 import 
org.apache.nlpcraft.internal.nlp.token.parser.opennlp.NCOpenNlpTokenParser;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import java.io.File;
 import java.util.HashSet;
 import java.util.List;
-import java.io.File;
 
 import static java.util.Arrays.asList;
 
@@ -101,7 +101,6 @@ public class LightSwitchModelTest {
                 "Light Switch Example Model",
                 "1.0",
                 new NCOpenNlpTokenParser(new File("tagger.txt"), new 
File("lemmatizer.txt"))
-
             );
 
         // Order is important.
diff --git a/nlpcraft/src/test/resources/lightswitch_model.json 
b/nlpcraft/src/test/resources/lightswitch_model.json
index 9b48456..ecb3a3b 100644
--- a/nlpcraft/src/test/resources/lightswitch_model.json
+++ b/nlpcraft/src/test/resources/lightswitch_model.json
@@ -1,57 +1,75 @@
+/*
+ * 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.
+ */
+
 {
-  "elements": [
-    {
-      "id": "ls:loc",
-      "description": "ls:loc",
-      "groups": []
-    },
-    {
-      "id": "ls:on",
-      "description": "ls:on",
-      "groups": ["act"]
-    },
-    {
-      "id": "ls:off",
-      "description": "ls:off",
-      "groups": ["act"]
-    }
-  ],
   "macros": [
     {
-      "<ACTION>": "{turn|switch|dial|let|set|get|put}"
+      "id": "<ACTION>",
+      "macro": "{turn|switch|dial|let|set|get|put}"
     },
     {
-      "<KILL>": "{shut|kill|stop|eliminate}"
+      "id": "<KILL>",
+      "macro": "{shut|kill|stop|eliminate}"
     },
     {
-      "<ENTIRE_OPT>": "{entire|full|whole|total|_}"
+      "id": "<ENTIRE_OPT>",
+      "macro": "{entire|full|whole|total|_}"
     },
     {
-      "<FLOOR_OPT>": 
"{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground}
 floor|_}"
+      "id": "<FLOOR_OPT>",
+      "macro": 
"{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground}
 floor|_}"
     },
     {
-      "<TYPE>": "{room|closet|attic|loft|{store|storage} {room|_}}"
+      "id": "<TYPE>",
+      "macro": "{room|closet|attic|loft|{store|storage} {room|_}}"
     },
     {
-      "<LIGHT>": "{all|_} {it|them|light|illumination|lamp|lamplight}"
+      "id": "<LIGHT>",
+      "macro": "{all|_} {it|them|light|illumination|lamp|lamplight}"
     }
   ],
-  "synonyms": [
+  "elements": [
     {
-      "ls:loc": [
+      "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}"
       ]
     },
     {
-      "ls:on": [
+      "id": "ls:on",
+      "desc": "ls:on",
+      "groups": [
+        "act"
+      ],
+      "synonyms": [
         "<ACTION> {on|up|_} <LIGHT> {on|up|_}",
         "<LIGHT> {on|up}"
       ]
     },
     {
-      "ls:off": [
+      "id": "ls:off",
+      "desc": "ls:off",
+      "groups": [
+        "act"
+      ],
+      "synonyms": [
         "<ACTION> <LIGHT> {off|out|down}",
         "{<ACTION>|<KILL>} {off|out|down} <LIGHT>",
         "<KILL> <LIGHT>",
@@ -61,4 +79,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/nlpcraft/src/test/resources/lightswitch_model.yaml 
b/nlpcraft/src/test/resources/lightswitch_model.yaml
index f0ca303..ca71931 100644
--- a/nlpcraft/src/test/resources/lightswitch_model.yaml
+++ b/nlpcraft/src/test/resources/lightswitch_model.yaml
@@ -1,34 +1,56 @@
-elements:
-  - id: ls:loc
-    description: ls:loc
-    groups: []
-  - id: ls:on
-    description: ls:on
-    groups:
-      - act
-  - id: ls:off
-    description: ls:off
-    groups:
-      - act
+#
+# 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:
-  - "<ACTION>": "{turn|switch|dial|let|set|get|put}"
-  - "<KILL>": "{shut|kill|stop|eliminate}"
-  - "<ENTIRE_OPT>": "{entire|full|whole|total|_}"
-  - "<FLOOR_OPT>": 
"{upstairs|downstairs|{1st|first|2nd|second|3rd|third|4th|fourth|5th|fifth|top|ground}
 floor|_}"
-  - "<TYPE>": "{room|closet|attic|loft|{store|storage} {room|_}}"
-  - "<LIGHT>": "{all|_} {it|them|light|illumination|lamp|lamplight}"
-synonyms:
-  - "ls:loc":
-      - "<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>|_}",
+  - 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}"
-  - "ls:on":
+  - id: "ls:on"
+    desc: "ls:on"
+    groups:
+      - "act"
+    synonyms:
       - "<ACTION> {on|up|_} <LIGHT> {on|up|_}"
       - "<LIGHT> {on|up}"
-  - "ls:off":
+  - 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}"
+      - "<LIGHT> {out|off|down}"
\ No newline at end of file

Reply via email to