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

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


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

commit 22894b92fd2b8abaea58b62b89236e2ef398320f
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Oct 11 23:09:31 2021 +0300

    WIP.
---
 .../scala/org/apache/nlpcraft/model/NCContext.java |   3 +-
 .../org/apache/nlpcraft/model/NCConversation.java  |   2 +-
 .../apache/nlpcraft/model/NCDialogFlowItem.java    |   2 +-
 .../org/apache/nlpcraft/model/NCIntentMatch.java   |   3 +-
 .../org/apache/nlpcraft/model/NCMetadata.java      | 122 ---------------------
 .../org/apache/nlpcraft/model/NCModelConfig.java   |   2 +-
 .../scala/org/apache/nlpcraft/model/NCRequest.java |   2 +-
 .../scala/org/apache/nlpcraft/model/NCResult.java  |   4 +-
 .../scala/org/apache/nlpcraft/model/NCToken.java   |  42 ++-----
 .../scala/org/apache/nlpcraft/model/NCVariant.java |   2 +-
 .../nlpcraft/model/impl/NCMetadataAdapter.java     |  50 ---------
 .../model/impl/ner/NCSynonymsNerElement.java       |   3 +-
 .../apache/nlpcraft/model/nlp/NCNlpNerToken.java   |   3 +-
 .../apache/nlpcraft/model/nlp/NCNlpRichWord.java   |  12 +-
 14 files changed, 30 insertions(+), 222 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
index 3b5ae62..8e812c2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
@@ -17,7 +17,6 @@
 
 package org.apache.nlpcraft.model;
 
-import java.io.Serializable;
 import java.util.Collection;
 
 /**
@@ -26,7 +25,7 @@ import java.util.Collection;
  * 
  * @see NCIntentMatch#getContext() 
  */
-public interface NCContext extends NCMetadata, Serializable {
+public interface NCContext {
     /**
      * Tests if given token is part of the query this context is associated 
with.
      *
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
index 5bf63de..6e2ba33 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
@@ -43,7 +43,7 @@ import java.util.function.Predicate;
  * @see NCModelConfig#getConversationDepth()
  * @see NCModelConfig#getConversationTimeout()
  */
-public interface NCConversation extends NCMetadata {
+public interface NCConversation {
     /**
      * Gets an ordered list of tokens stored in the conversation STM for the 
current
      * user and data model. Tokens in the returned list are ordered by their 
conversational depth, i.e.
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
index 59f44a3..6ed3c2f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
@@ -29,7 +29,7 @@ import java.util.Optional;
  * Read full documentation in <a target=_ 
href="https://nlpcraft.apache.org/intent-matching.html";>Intent Matching</a> 
section and review
  * <a target=_ 
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples";>examples</a>.
  */
-public interface NCDialogFlowItem extends NCMetadata {
+public interface NCDialogFlowItem {
     /**
      * Gets ID of the matched intent.
      *
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
index f2219a2..d208eb1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
@@ -17,7 +17,6 @@
 
 package org.apache.nlpcraft.model;
 
-import java.io.Serializable;
 import java.util.List;
 
 /**
@@ -38,7 +37,7 @@ import java.util.List;
  * @see NCIntentSampleRef
  * @see NCIntentRef
  */
-public interface NCIntentMatch extends NCMetadata, Serializable {
+public interface NCIntentMatch  {
     /**
      * Gets ID of the matched intent.
      *
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCMetadata.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCMetadata.java
deleted file mode 100644
index 801edaf..0000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCMetadata.java
+++ /dev/null
@@ -1,122 +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.
- */
-
-package org.apache.nlpcraft.model;
-
-import org.apache.nlpcraft.common.NCException;
-
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Provides support for mutable runtime-only metadata.
- * <p>
- * Read full documentation in <a target=_ 
href="https://nlpcraft.apache.org/data-model.html";>Data Model</a> section and 
review
- * <a target=_ 
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples";>examples</a>.
- */
-public interface NCMetadata {
-    /**
-     * Factory for creating metadata out of standard map.
-     *
-     * @param map Map to convert to metadata.
-     * @return Newly created metadata container.
-     */
-    static NCMetadata apply(Map<String, Object> map) {
-        return () -> map;
-    }
-
-    /**
-     * Gets mutable metadata underlying container.
-     * Returned map can be used to mutate the metadata or perform any other 
operations.
-     *
-     * @return Mutable, underlying metadata container.
-     * @see #meta(String)
-     * @see #metaOpt(String)
-     * @see #meta(String, Object)
-     */
-    Map<String, Object> getMetadata();
-
-    /**
-     * Shortcut method to get given optional metadata property. Equivalent to:
-     * <pre class="brush: java">
-     *      Optional.ofNullable((T)getMetadata().get(prop));
-     * </pre>
-     *
-     * @param prop Metadata property name.
-     * @param <T> Type of the metadata property.
-     * @return Metadata optional property value.
-     */
-    @SuppressWarnings("unchecked")
-    default <T> Optional<T> metaOpt(String prop) {
-        return Optional.ofNullable((T)getMetadata().get(prop));
-    }
-
-    /**
-     * Shortcut method to get given metadata property. Equivalent to:
-     * <pre class="brush: java">
-     *      (T)getMetadata().get(prop);
-     * </pre>
-     *
-     * @param prop Metadata property name.
-     * @param <T> Type of the metadata property.
-     * @return Metadata property value or {@code null} if given metadata 
property not found.
-     */
-    @SuppressWarnings("unchecked")
-    default <T> T meta(String prop) {
-        return (T)getMetadata().get(prop);
-    }
-
-    /**
-     * Shortcut method to get given mandatory metadata property. Equivalent to:
-     * <pre class="brush: java">
-     *     T t = (T)getMetadata().get(prop);
-     *     if (t == null)
-     *         throw new NCException("Mandatory metadata property not found: " 
+ prop);
-     *     else
-     *         return t;
-     * </pre>
-     *
-     * @param prop Metadata property name.
-     * @param <T> Type of the metadata property.
-     * @return Metadata property value or throws an exception if given 
metadata property not found.
-     * @throws NCException Thrown if given metadata property not found.
-     */
-    default <T> T metax(String prop) throws NCException {
-        T t = meta(prop);
-
-        if (t == null)
-            throw new NCException("Mandatory metadata property not found: " + 
prop);
-        else
-            return t;
-    }
-
-    /**
-     * Shortcut method to get given metadata property. Equivalent to:
-     * <pre class="brush: java">
-     *      getMetadata().get(tokId, prop, dflt);
-     * </pre>
-     *
-     * @param prop Metadata property name.
-     * @param dflt Default value to return if specified one isn't set.
-     * @param <T> Type of the metadata property.
-     * @return Metadata property value or default value if one isn't set.
-     */
-    @SuppressWarnings("unchecked")
-    default <T> T meta(String prop, T dflt) {
-        return (T)getMetadata().getOrDefault(prop, dflt);
-    }
-}
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
index ac32ac7..c3f82dc 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
@@ -41,7 +41,7 @@ import java.util.Set;
  * @see NCModelAdapter
  * @see NCModelFileAdapter
  */
-public interface NCModelConfig extends NCMetadata {
+public interface NCModelConfig {
     /**
      * Minimum value for {@link #getConversationTimeout()} method.
      */
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
index 1cfd499..b266922 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
@@ -25,7 +25,7 @@ import java.util.Optional;
  *
  * @see NCContext#getRequest()
  */
-public interface NCRequest extends NCMetadata {
+public interface NCRequest {
     /**
      * TODO: optional?
      * Gets descriptor of the user on behalf of which this request was 
submitted.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCResult.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCResult.java
index f26d6bb..1a3db7c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCResult.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCResult.java
@@ -19,9 +19,7 @@ package org.apache.nlpcraft.model;
 
 import org.apache.nlpcraft.common.NCException;
 import org.apache.nlpcraft.common.util.NCUtils;
-import org.apache.nlpcraft.model.impl.NCMetadataAdapter;
 
-import java.io.Serializable;
 import java.util.Collection;
 
 /**
@@ -59,7 +57,7 @@ import java.util.Collection;
  * accordingly. For example, the REST client interfacing between NLPCraft and 
Amazon Alexa or Apple HomeKit can only
  * accept {@code text} result type and ignore everything else.
  */
-public class NCResult extends NCMetadataAdapter implements Serializable, 
NCMetadata {
+public class NCResult {
     /** Data Model result text. */
     private String body;
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
index 6397d74..a643b40 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
@@ -27,7 +27,7 @@ import java.util.List;
  *
  * @see NCDefaultNerElement
  */
-public interface NCToken extends NCMetadata {
+public interface NCToken {
     /**
      * TODO: drop it.
      * Gets reference to the model this token belongs to.
@@ -145,9 +145,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Whether this token is a stopword.
      */
-    default boolean isStopWord() {
-        return meta("nlpcraft:nlp:stopword");
-    }
+    boolean isStopWord();
 
     /**
      * A shortcut method checking whether this token represents a free word. A 
free word is a
@@ -161,9 +159,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Whether this token is a freeword.
      */
-    default boolean isFreeWord() {
-        return meta("nlpcraft:nlp:freeword");
-    }
+    boolean isFreeWord();
 
     /**
      * A shortcut method that gets original user input text for this token.
@@ -176,9 +172,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Original user input text for this token.
      */
-    default String getOriginalText() {
-        return meta("nlpcraft:nlp:origtext");
-    }
+    String getOriginalText();
 
     /**
      * A shortcut method that gets index of this token in the sentence.
@@ -191,9 +185,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Index of this token in the sentence.
      */
-    default int getIndex() {
-        return meta("nlpcraft:nlp:index");
-    }
+    int getIndex();
 
     /**
      * A shortcut method that gets normalized user input text for this token.
@@ -206,9 +198,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Normalized user input text for this token.
      */
-    default String getNormalizedText() {
-        return meta("nlpcraft:nlp:normtext");
-    }
+    String getNormalizedText();
 
     /**
      * A shortcut method on whether this token is a swear word. NLPCraft has 
built-in list of
@@ -222,9 +212,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Whether this token is a swear word.
      */
-    default boolean isSwear() {
-        return meta("nlpcraft:nlp:swear");
-    }
+    boolean isSwear();
 
     /**
      * A shortcut method to get lemma of this token, i.e. a canonical form of 
this word. Note that
@@ -241,9 +229,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Lemma of this token, i.e. a canonical form of this word.
      */
-    default String getLemma() {
-        return meta("nlpcraft:nlp:lemma");
-    }
+    String getLemma();
 
     /**
      * A shortcut method to get stem of this token. Note that stemming and 
lemmatization allow to reduce
@@ -259,9 +245,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Stem of this token.
      */
-    default String getStem() {
-        return meta("nlpcraft:nlp:stem");
-    }
+    String getStem();
 
     /**
      * A shortcut method to get Penn Treebank POS tag for this token. Note 
that additionally to standard Penn
@@ -275,9 +259,7 @@ public interface NCToken extends NCMetadata {
      *
      * @return Penn Treebank POS tag for this token.
      */
-    default String getPos() {
-        return meta("nlpcraft:nlp:pos");
-    }
+    String getPos();
 
     /**
      * A shortcut method that gets internal globally unique system ID of the 
token.
@@ -289,7 +271,5 @@ public interface NCToken extends NCMetadata {
      *
      * @return Internal globally unique system ID of the token.
      */
-    default String getUnid() {
-        return meta("nlpcraft:nlp:unid");
-    }    
+    String getUnid();
 }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
index 4f76d56..8e83463 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
  * @see NCModel#onParsedVariant(NCVariant)
  * @see NCContext#getVariants()
  */
-public interface NCVariant extends List<NCToken>, NCMetadata {
+public interface NCVariant extends List<NCToken> {
     /**
      * Utility method that returns all non-freeword tokens. It's equivalent to:
      * <pre class="brush: java">
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCMetadataAdapter.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCMetadataAdapter.java
deleted file mode 100644
index b3b9d09..0000000
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCMetadataAdapter.java
+++ /dev/null
@@ -1,50 +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.
- */
-
-package org.apache.nlpcraft.model.impl;
-
-import org.apache.nlpcraft.model.NCMetadata;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Abstract adapter for metadata.
- */
-public abstract class NCMetadataAdapter implements NCMetadata {
-    final private Map<String, Object> meta;
-
-    /**
-     *
-     */
-    protected NCMetadataAdapter() {
-        meta = new HashMap<>();
-    }
-
-    /**
-     *
-     * @param meta Metadata container to use.
-     */
-    protected NCMetadataAdapter(Map<String, Object> meta) {
-        this.meta = meta;
-    }
-
-    @Override
-    public Map<String, Object> getMetadata() {
-        return meta;
-    }
-}
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/ner/NCSynonymsNerElement.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/ner/NCSynonymsNerElement.java
index 8834394..d16ac7d 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/ner/NCSynonymsNerElement.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/ner/NCSynonymsNerElement.java
@@ -18,7 +18,6 @@
 package org.apache.nlpcraft.model.impl.ner;
 
 import org.apache.nlpcraft.model.NCConversation;
-import org.apache.nlpcraft.model.NCMetadata;
 import org.apache.nlpcraft.model.NCToken;
 
 import java.util.Collections;
@@ -39,7 +38,7 @@ import java.util.Optional;
  *
  * @see NCCustomParser
  */
-public interface NCSynonymsNerElement extends NCMetadata {
+public interface NCSynonymsNerElement {
     /**
      * Gets unique ID of this element.
      * <p>
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpNerToken.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpNerToken.java
index 894c4b8..4c92afa 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpNerToken.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpNerToken.java
@@ -17,7 +17,6 @@
 
 package org.apache.nlpcraft.model.nlp;
 
-import org.apache.nlpcraft.model.NCMetadata;
 import org.apache.nlpcraft.model.NCModel;
 import org.apache.nlpcraft.model.NCModelConfig;
 import org.apache.nlpcraft.model.NCRequest;
@@ -27,7 +26,7 @@ import java.util.Collections;
 import java.util.List;
 
 // NCNlpNerTokensParser parsing result.
-public interface NCNlpNerToken extends NCMetadata {
+public interface NCNlpNerToken {
     /**
      * Gets ID of the detected model element. Note that it <b>must 
correspond</b> to one of the elements
      * defined in the model. In other words, the parser doesn't define a new 
model element but rather
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpRichWord.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpRichWord.java
index b32397d..1396825 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpRichWord.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpRichWord.java
@@ -23,8 +23,14 @@ package org.apache.nlpcraft.model.nlp;
  */
 public interface NCNlpRichWord extends NCNlpWord {
     boolean isStopWord();
-    boolean isBracketed();
-    boolean isQuoted();
-    boolean isKnownWord();
     boolean isSwearWord();
+
+    // TODO: add
+    boolean isSuspiciousWord();
+
+    // TODO: drop
+//    boolean isBracketed();
+//    boolean isQuoted();
+//    boolean isKnownWord();
+
 }

Reply via email to