This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-383
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-383 by this push:
new 7bee550 WIP.
7bee550 is described below
commit 7bee55029b74487bbadbcdce7d22b676f8f958c3
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Aug 24 15:58:26 2021 +0300
WIP.
---
.../examples/solarsystem/SolarSystemModel.scala | 20 +++++++++--
.../solarsystem/intents/SolarSystemDate.scala | 5 +--
.../intents/SolarSystemDiscoverer.scala | 5 +--
.../intents/SolarSystemIntentsAdapter.scala | 39 ----------------------
.../intents/SolarSystemPlanetInfo.scala | 5 +--
.../probe/mgrs/deploy/NCDeployManager.scala | 9 +++--
6 files changed, 33 insertions(+), 50 deletions(-)
diff --git
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/SolarSystemModel.scala
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/SolarSystemModel.scala
index e4426cc..aa5c804 100644
---
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/SolarSystemModel.scala
+++
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/SolarSystemModel.scala
@@ -18,7 +18,23 @@
package org.apache.nlpcraft.examples.solarsystem
import com.typesafe.scalalogging.LazyLogging
+import org.apache.nlpcraft.examples.solarsystem.api.SolarSystemOpenApiService
import org.apache.nlpcraft.model.{NCModelAddPackage, NCModelFileAdapter}
-@NCModelAddPackage(Array("org.apache.nlpcraft.examples.solarsystem.intents"))
-class SolarSystemModel extends NCModelFileAdapter("solarsystem_model.yaml")
with LazyLogging
\ No newline at end of file
+@NCModelAddPackage(Array("org.apache.nlpcraft.examples.solarsystem.api"))
+class SolarSystemModel extends NCModelFileAdapter("solarsystem_model.yaml")
with LazyLogging {
+ protected var api: SolarSystemOpenApiService = _
+
+ override def onInit(): Unit = {
+ api = SolarSystemOpenApiService.getInstance()
+
+ logger.info("Solar System API initialized.")
+ }
+
+ override def onDiscard(): Unit = {
+ if (api != null)
+ api.stop()
+
+ logger.info("Solar System API closed.")
+ }
+}
\ No newline at end of file
diff --git
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDate.scala
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDate.scala
index 8de6410..709fcd5 100644
---
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDate.scala
+++
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDate.scala
@@ -17,13 +17,14 @@
package org.apache.nlpcraft.examples.solarsystem.intents
+import org.apache.nlpcraft.examples.solarsystem.api.SolarSystemOpenApiService
import org.apache.nlpcraft.model.{NCIntent, NCIntentSample, NCIntentTerm,
NCResult, NCToken}
import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder,
DateTimeParseException}
import java.time.temporal.ChronoField.{DAY_OF_MONTH, MONTH_OF_YEAR}
import java.time.{LocalDate, ZoneOffset}
-class SolarSystemDate extends SolarSystemIntentsAdapter {
+class SolarSystemDate {
@NCIntentSample(
Array(
"After 1900 year",
@@ -40,7 +41,7 @@ class SolarSystemDate extends SolarSystemIntentsAdapter {
def date(@NCIntentTerm("date") date: NCToken): NCResult = {
// API doesn't support filter by dates.
// We do it here.
- var res = api.bodyRequest().execute()
+ var res =
SolarSystemOpenApiService.getInstance().bodyRequest().execute()
val supportedFmts =
Seq (
diff --git
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDiscoverer.scala
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDiscoverer.scala
index 3747ac0..fcc2497 100644
---
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDiscoverer.scala
+++
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemDiscoverer.scala
@@ -17,9 +17,10 @@
package org.apache.nlpcraft.examples.solarsystem.intents
+import org.apache.nlpcraft.examples.solarsystem.api.SolarSystemOpenApiService
import org.apache.nlpcraft.model.{NCIntent, NCIntentSample, NCIntentTerm,
NCResult, NCToken}
-class SolarSystemDiscoverer extends SolarSystemIntentsAdapter {
+class SolarSystemDiscoverer {
@NCIntentSample(
Array(
"What was discovered by Asaph Hall",
@@ -36,5 +37,5 @@ class SolarSystemDiscoverer extends SolarSystemIntentsAdapter
{
" term(discoverer)={tok_id() == 'discoverer'}"
)
def discoverer(@NCIntentTerm("discoverer") discoverer: NCToken): NCResult =
- NCResult.text(api.bodyRequest().withFilter("discoveredBy", "cs",
discoverer.getNormalizedText).execute().toString())
+
NCResult.text(SolarSystemOpenApiService.getInstance().bodyRequest().withFilter("discoveredBy",
"cs", discoverer.getNormalizedText).execute().toString())
}
\ No newline at end of file
diff --git
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemIntentsAdapter.scala
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemIntentsAdapter.scala
deleted file mode 100644
index 2cf76ad..0000000
---
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemIntentsAdapter.scala
+++ /dev/null
@@ -1,39 +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.examples.solarsystem.intents
-
-import com.typesafe.scalalogging.LazyLogging
-import org.apache.nlpcraft.examples.solarsystem.api.SolarSystemOpenApiService
-import org.apache.nlpcraft.model.NCLifecycle
-
-private[intents] class SolarSystemIntentsAdapter extends NCLifecycle with
LazyLogging {
- protected var api: SolarSystemOpenApiService = _
-
- override def onInit(): Unit = {
- api = SolarSystemOpenApiService.getInstance()
-
- logger.info("Solar System API initialized.")
- }
-
- override def onDiscard(): Unit = {
- if (api != null)
- api.stop()
-
- logger.info("Solar System API closed.")
- }
-}
diff --git
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemPlanetInfo.scala
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemPlanetInfo.scala
index 24c281a..b164a9b 100644
---
a/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemPlanetInfo.scala
+++
b/nlpcraft-examples/solarsystem/src/main/java/org/apache/nlpcraft/examples/solarsystem/intents/SolarSystemPlanetInfo.scala
@@ -17,9 +17,10 @@
package org.apache.nlpcraft.examples.solarsystem.intents
+import org.apache.nlpcraft.examples.solarsystem.api.SolarSystemOpenApiService
import org.apache.nlpcraft.model.{NCIntent, NCIntentSample, NCIntentTerm,
NCResult, NCToken}
-class SolarSystemPlanetInfo extends SolarSystemIntentsAdapter {
+class SolarSystemPlanetInfo {
@NCIntentSample(
Array(
"Moon!",
@@ -34,5 +35,5 @@ class SolarSystemPlanetInfo extends SolarSystemIntentsAdapter
{
" term(planet)={tok_id() == 'planet'}"
)
def planetInfo(@NCIntentTerm("planet") planet: NCToken): NCResult =
- NCResult.text(api.bodyRequest().withFilter("id", "eq",
planet.getNormalizedText).execute().toString())
+
NCResult.text(SolarSystemOpenApiService.getInstance().bodyRequest().withFilter("id",
"eq", planet.getNormalizedText).execute().toString())
}
\ No newline at end of file
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 02939d3..c01801e 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
@@ -1669,17 +1669,20 @@ object NCDeployManager extends NCService {
CLS_MDL_PKGS_REF,
(a: NCModelAddPackage) =>
a.value().toIndexedSeq.flatMap(p => {
+ //noinspection UnstableApiUsage
+ val res =
ClassPath.from(cl).getTopLevelClassesRecursive(p).asScala.map(_.load())
+
+ // Check should be after classes loading attempt.
if (cl.getDefinedPackage(p) == null)
throw new NCE(
s"Invalid additional references in
@${CLS_MDL_PKGS_REF.getSimpleName} annotation [" +
s"mdlId=$mdlId, " +
s"origin=${mdl.getOrigin}, " +
s"package=$p" +
- s"]"
+ s"]"
)
- //noinspection UnstableApiUsage
-
ClassPath.from(cl).getTopLevelClassesRecursive(p).asScala.map(_.load())
+ res
})
)