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 3ac6a53 WIP.
3ac6a53 is described below
commit 3ac6a530b0abeed205990e5853e8050855f73fbf
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Wed Mar 10 19:40:12 2021 -0800
WIP.
---
.../nlpcraft/examples/alarm/alarm_model.json | 5 ++--
.../lightswitch/LightSwitchGroovyModel.groovy | 2 +-
.../examples/lightswitch/lightswitch_model.yaml | 2 +-
.../apache/nlpcraft/examples/phone/PhoneModel.java | 4 +--
.../apache/nlpcraft/examples/time/TimeModel.java | 4 +--
.../nlpcraft/examples/weather/WeatherModel.java | 8 +++---
.../apache/nlpcraft/model/NCModelFileAdapter.java | 33 +++++++++++++---------
.../intent/compiler/NCDslSyntaxHighlighter.scala | 2 +-
.../probe/mgrs/deploy/NCDeployManager.scala | 25 ++++++++--------
.../nlpcraft/probe/mgrs/model/NCModelManager.scala | 1 +
10 files changed, 46 insertions(+), 40 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
index 1ff9bf1..798c343 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/alarm_model.json
@@ -34,7 +34,8 @@
}
],
"intents": [
- "fragment=f1 term(t1)~{id() == 'x:alarm'}",
- "intent=alarm fragment(f1) term(nums)~{id() == 'nlpcraft:num' &&
meta_token('nlpcraft:num:unittype') == 'datetime' &&
meta_token('nlpcraft:num:isequalcondition') == true}[0,7]"
+ "fragment=buzz term~{id() == 'x:alarm'}",
+ "fragment=when term(nums)~{id() == 'nlpcraft:num' &&
meta_token('nlpcraft:num:unittype') == 'datetime' &&
meta_token('nlpcraft:num:isequalcondition') == true}[0,7]",
+ "intent=alarm fragment(buzz) fragment(when)"
]
}
\ No newline at end of file
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
index 4d1aff9..0cadb57 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
@@ -61,7 +61,7 @@ class LightSwitchGroovyModel extends NCModelFileAdapter {
"Light up the garage, please!",
"Kill the illumination now!"
])
- NCResult onMatch(
+ static NCResult onMatch(
@NCIntentTerm("act") NCToken actTok,
@NCIntentTerm("loc") List<NCToken> locToks) {
String status = actTok.id == "ls:on" ? "on" : "off"
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml
index e4744ae..0b15316 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml
@@ -60,4 +60,4 @@ elements:
- "<LIGHT> <KILL>"
- "no <LIGHT>"
intents:
- - "intent=ls term(act)={groups @@ 'act'} term(loc)={id == 'ls:loc'}*"
\ No newline at end of file
+ - "intent=ls term(act)={has(groups(), 'act')} term(loc)={id() == 'ls:loc'}*"
\ No newline at end of file
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
index 250c492..340b086 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
@@ -51,9 +51,9 @@ public class PhoneModel extends NCModelFileAdapter {
*/
@NCIntent("" +
"intent=action " +
- "term={id == 'phone:act'} " +
+ "term={id() == 'phone:act'} " +
// Either organization, person or a phone number (or a combination of).
- "term(rcpt)={id == 'google:organization' || id == 'google:person' ||
id == 'google:phone_number'}[1,3]"
+ "term(rcpt)={id() == 'google:organization' || id() == 'google:person'
|| id() == 'google:phone_number'}[1,3]"
)
@NCIntentSample({
"Call to Apple office",
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
index 63b7090..1601943 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
@@ -92,7 +92,7 @@ public class TimeModel extends NCModelFileAdapter {
* @param cityTok Token for 'geo' term.
* @return Query result.
*/
- @NCIntent("intent=intent2 term~{id=='x:time'}
term(city)~{id=='nlpcraft:city'}")
+ @NCIntent("intent=intent2 term~{id() == 'x:time'} term(city)~{id() ==
'nlpcraft:city'}")
@NCIntentSample({
"What time is it now in New York City?",
"What's the current time in Moscow?",
@@ -119,7 +119,7 @@ public class TimeModel extends NCModelFileAdapter {
* @param ctx Intent solver context.
* @return Query result.
*/
- @NCIntent("intent=intent1 term={id=='x:time'}")
+ @NCIntent("intent=intent1 term={id() == 'x:time'}")
@NCIntentSample({
"What's the local time?"
})
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
index 44ab50a..e706494 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
@@ -124,10 +124,10 @@ public class WeatherModel extends NCModelFileAdapter {
*/
@NCIntent(
"intent=req " +
- "term~{id == 'wt:phen'}* " + // Zero or more weather phenomenon.
- "term(ind)~{groups @@ 'indicator'}* " + // Optional indicator words
(zero or more).
- "term(city)~{id == 'nlpcraft:city'}? " + // Optional city.
- "term(date)~{id == 'nlpcraft:date'}?" // Optional date (overrides
indicator words).
+ "term~{id() == 'wt:phen'}* " + // Zero or more weather phenomenon.
+ "term(ind)~{has(groups(), 'indicator')}* " + // Optional indicator
words (zero or more).
+ "term(city)~{id() == 'nlpcraft:city'}? " + // Optional city.
+ "term(date)~{id() == 'nlpcraft:date'}?" // Optional date (overrides
indicator words).
)
// NOTE: each samples group will reset conversation STM.
@NCIntentSample({
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelFileAdapter.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelFileAdapter.java
index ac32ef8..015a1a5 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelFileAdapter.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelFileAdapter.java
@@ -60,7 +60,7 @@ abstract public class NCModelFileAdapter extends
NCModelAdapter {
private final Set<String> abstractToks;
private final Set<String> addStopwords;
private final Set<String> exclStopwords;
- private final Set<String> intents;
+ private final List<String> intents;
private final Map<String, String> macros;
private final Map<String, Object> metadata;
private final Set<NCElement> elems;
@@ -112,15 +112,15 @@ abstract public class NCModelFileAdapter extends
NCModelAdapter {
super(proxy.getId(), proxy.getName(), proxy.getDescription());
this.proxy = proxy;
- this.suspWords = convert(proxy.getSuspiciousWords(), null);
- this.enabledToks = convert(proxy.getEnabledBuiltInTokens(),
NCModelView.DFLT_ENABLED_BUILTIN_TOKENS);
- this.abstractToks = convert(proxy.getAbstractTokens(),
Collections.emptySet());
- this.addStopwords = convert(proxy.getAdditionalStopWords(), null);
- this.exclStopwords = convert(proxy.getExcludedStopWords(), null);
+ this.suspWords = convertToSet(proxy.getSuspiciousWords(), null);
+ this.enabledToks = convertToSet(proxy.getEnabledBuiltInTokens(),
NCModelView.DFLT_ENABLED_BUILTIN_TOKENS);
+ this.abstractToks = convertToSet(proxy.getAbstractTokens(),
Collections.emptySet());
+ this.addStopwords = convertToSet(proxy.getAdditionalStopWords(), null);
+ this.exclStopwords = convertToSet(proxy.getExcludedStopWords(), null);
this.elems = convertElements(proxy, proxy.getElements());
this.macros = convertMacros(proxy.getMacros());
this.metadata = convertMeta(proxy.getMetadata());
- this.intents = convert(proxy.getIntents(), null);
+ this.intents = convertToList(proxy.getIntents(), null);
this.parsers = convertParsers(proxy.getParsers());
this.restrictedCombinations =
convertRestrictedCombinations(proxy.getRestrictedCombinations());
@@ -229,12 +229,17 @@ abstract public class NCModelFileAdapter extends
NCModelAdapter {
* @param arr
* @return
*/
- private static Set<String> convert(String[] arr, Set<String> dflt) {
- return arr != null ?
- new HashSet<>(Arrays.asList(arr)) :
- dflt != null ?
- new HashSet<>(dflt) :
- new HashSet<>();
+ private static Set<String> convertToSet(String[] arr, Set<String> dflt) {
+ return arr != null ? new HashSet<>(Arrays.asList(arr)) : dflt != null
? new HashSet<>(dflt) : Collections.emptySet();
+ }
+
+ /**
+ *
+ * @param arr
+ * @return
+ */
+ private static List<String> convertToList(String[] arr, List<String> dflt)
{
+ return arr != null ? Arrays.asList(arr) : dflt != null ? dflt :
Collections.emptyList();
}
/**
@@ -374,7 +379,7 @@ abstract public class NCModelFileAdapter extends
NCModelAdapter {
*
* @return List of intents and/or fragments declared in JSON/YML model
definition, potentially empty.
*/
- public Set<String> getIntents() {
+ public List<String> getIntents() {
return intents;
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
index a54b8f9..9033136 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslSyntaxHighlighter.scala
@@ -177,7 +177,7 @@ object NCDslSyntaxHighlighter {
val tok = toks.nextToken()
if (KEYWORDS.contains(tok))
- res ++= (if (tok == "intent" || tok == "fragment")
bold(cyan(tok)) else blue(tok))
+ res ++= (if (tok == "intent") bold(blue(tok)) else cyan(tok))
else if (LITERALS.contains(tok) ||
NUM_REGEX.matcher(tok).matches())
res ++= green(tok)
else if (FUNCTIONS.contains(tok))
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index 6d8a251..ed42815 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -193,7 +193,7 @@ object NCDeployManager extends NCService with
DecorateAsScala {
if (hasWhitespace(word))
throw new NCE(s"Model property cannot contain a string
with whitespaces [" +
s"mdlId=$mdlId, " +
- s"name=$name, " +
+ s"property=$name, " +
s"word='$word'" +
s"]")
else
@@ -404,8 +404,7 @@ object NCDeployManager extends NCService with
DecorateAsScala {
s"mdlId=$mdlId, " +
s"cnt=$cnt, " +
s"max=$maxCnt" +
- s"]"
- )
+ s"]")
// Discard value loaders.
for (elm ← mdl.getElements.asScala)
@@ -419,9 +418,9 @@ object NCDeployManager extends NCService with
DecorateAsScala {
.flatten
.toList
- // Check for DSl alias uniqueness.
+ // Check for DSL alias uniqueness.
if (U.containsDups(allAliases))
- throw new NCE(s"Duplicate DSL alias found [" +
+ throw new NCE(s"Duplicate DSL synonym alias found [" +
s"mdlId=$mdlId, " +
s"dups=${allAliases.diff(allAliases.distinct).mkString(", ")}"
+
s"]")
@@ -430,7 +429,7 @@ object NCDeployManager extends NCService with
DecorateAsScala {
// Check that DSL aliases don't intersect with element IDs.
if (idAliasDups.nonEmpty)
- throw new NCE(s"Model element IDs and DSL aliases intersect [" +
+ throw new NCE(s"Model element IDs and DSL synonym aliases
intersect [" +
s"mdlId=$mdlId, " +
s"dups=${idAliasDups.mkString(", ")}" +
"]")
@@ -468,6 +467,7 @@ object NCDeployManager extends NCService with
DecorateAsScala {
// Scan for intent annotations in the model class.
val intents = scanIntents(mdl)
+
var solver: NCIntentSolver = null
if (intents.nonEmpty) {
@@ -634,16 +634,15 @@ object NCDeployManager extends NCService with
DecorateAsScala {
data = ArrayBuffer.empty[NCProbeModel]
- mdlFactory = new NCBasicModelFactory
-
- // Initialize model factory (if configured).
- Config.modelFactoryType match {
+ mdlFactory = Config.modelFactoryType match {
case Some(mft) ⇒
- mdlFactory = makeModelFactory(mft)
+ val mf = makeModelFactory(mft)
-
mdlFactory.initialize(Config.modelFactoryProps.getOrElse(Map.empty[String,
String]).asJava)
+
mf.initialize(Config.modelFactoryProps.getOrElse(Map.empty[String,
String]).asJava)
+
+ mf
- case None ⇒ // No-op.
+ case None ⇒ new NCBasicModelFactory
}
data ++= U.splitTrimFilter(Config.models, ",").map(makeModelWrapper)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
index 8991339..f90327d 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelManager.scala
@@ -73,6 +73,7 @@ object NCModelManager extends NCService with DecorateAsScala {
),
w.intents.flatMap(i ⇒ i.dsl
.replaceAll(" term", s"\n term")
+ .replaceAll(" fragment", s"\n fragment")
.split("\n").map(NCDslSyntaxHighlighter.color)
)
)