This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-206
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-206 by this push:
new d947dac WIP.
d947dac is described below
commit d947dacf1ee76f48d651751c7eca6c26a0bd6f69
Author: Aaron Radzinski <[email protected]>
AuthorDate: Wed Mar 17 18:37:20 2021 -0700
WIP.
---
.../scala/org/apache/nlpcraft/model/NCToken.java | 4 ++--
.../apache/nlpcraft/model/impl/NCTokenImpl.scala | 2 +-
.../model/intent/compiler/NCDslCompiler.scala | 23 +++++++++++++++++++++-
3 files changed, 25 insertions(+), 4 deletions(-)
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 c429f59..7b0ea4f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
@@ -159,13 +159,13 @@ public interface NCToken extends NCMetadata {
}
/**
- * Gets optional list of aliases this token is known by. Token can get an
alias if it is a part of
+ * Gets optional set of aliases this token is known by. Token can get an
alias if it is a part of
* other composed token and token DSL expression that was used to match it
specified an alias. Note
* that token can have zero, one or more aliases.
*
* @return List of aliases this token is known by. Can be empty, but never
{@code null}.
*/
- List<String> getAliases();
+ Set<String> getAliases();
/**
* Tests whether or not this token has given alias. It is equivalent to:
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenImpl.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenImpl.scala
index b615cee..017ead1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenImpl.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCTokenImpl.scala
@@ -73,7 +73,7 @@ private[nlpcraft] class NCTokenImpl(
override lazy val getValue: String = value
override lazy val getStartCharIndex: Int = startCharIndex
override lazy val getEndCharIndex: Int = endCharIndex
- override lazy val getAliases: java.util.List[String] =
meta(TOK_META_ALIASES_KEY, Collections.emptyList())
+ override lazy val getAliases: java.util.Set[String] =
meta(TOK_META_ALIASES_KEY, Collections.emptySet())
override lazy val isAbstract: Boolean = isAbstractProp
override def getPartTokens: java.util.List[NCToken] = parts.asJava
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
index ddb7c3a..ac65656 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
@@ -178,7 +178,28 @@ object NCDslCompiler extends LazyLogging {
override def exitSynonym(ctx: IDP.SynonymContext): Unit = {
implicit val evidence: PRC = ctx
- synonym = NCDslSynonym(origin, Option(alias),
instrToPredicate("Synonym"))
+ val pred = instrToPredicate("Synonym")
+ val capture = alias
+ val wrapper: NCDslTokenPredicate = (tok: NCToken, ctx:
NCDslContext) ⇒ {
+ val (res, tokUses) = pred(tok, ctx)
+
+ // Store predicate's alias, if any, in token metadata if this
token satisfies this predicate.
+ // NOTE: token can have multiple aliases associated with it.
+ if (res && capture != null) { // NOTE: we ignore 'tokUses'
here on purpose.
+ val meta = tok.getMetadata
+
+ if (!meta.containsKey(TOK_META_ALIASES_KEY))
+ meta.put(TOK_META_ALIASES_KEY, new
java.util.HashSet[String]())
+
+ val aliases =
meta.get(TOK_META_ALIASES_KEY).asInstanceOf[java.util.Set[String]]
+
+ aliases.add(capture)
+ }
+
+ (res, tokUses)
+ }
+
+ synonym = NCDslSynonym(origin, Option(alias), wrapper)
alias = null
instrs.clear()