This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-504
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-504 by this push:
new f795584b Minor fixes.
f795584b is described below
commit f795584b8ed82bd4ec4d2d579de7095802fcbeb3
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Jul 15 21:18:07 2022 +0300
Minor fixes.
---
nlpcraft-examples/lightswitch/pom.xml | 72 +---------------------
.../nlpcraft/internal/util/NCResourceReader.scala | 19 +++---
2 files changed, 12 insertions(+), 79 deletions(-)
diff --git a/nlpcraft-examples/lightswitch/pom.xml
b/nlpcraft-examples/lightswitch/pom.xml
index a786cd75..412426c1 100644
--- a/nlpcraft-examples/lightswitch/pom.xml
+++ b/nlpcraft-examples/lightswitch/pom.xml
@@ -18,7 +18,7 @@
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>NLPCraft Example Light Switch</name>
@@ -31,12 +31,6 @@
<relativePath>../../pom.xml</relativePath>
</parent>
- <properties>
- <kotlin.ver>1.6.10</kotlin.ver>
- <groovy.ver>3.0.10</groovy.ver>
- <gmavenplus.ver>1.13.1</gmavenplus.ver>
- </properties>
-
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -44,17 +38,6 @@
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.jetbrains.kotlin</groupId>
- <artifactId>kotlin-stdlib-jdk8</artifactId>
- <version>${kotlin.ver}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy</artifactId>
- <version>${groovy.ver}</version>
- </dependency>
-
<!-- Test dependencies. -->
<dependency>
<groupId>org.junit.jupiter</groupId>
@@ -74,59 +57,6 @@
<target>${java.ver}</target>
</configuration>
</plugin>
- <plugin>
- <groupId>org.jetbrains.kotlin</groupId>
- <artifactId>kotlin-maven-plugin</artifactId>
- <version>${kotlin.ver}</version>
- <executions>
- <execution>
- <id>compile</id>
- <phase>process-sources</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- <execution>
- <id>test-compile</id>
- <phase>test-compile</phase>
- <goals>
- <goal>test-compile</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <jvmTarget>${java.ver}</jvmTarget>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.gmavenplus</groupId>
- <artifactId>gmavenplus-plugin</artifactId>
- <version>${gmavenplus.ver}</version>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <sources>
- <source>
-
<directory>${project.basedir}/src/main/java</directory>
- <includes>
- <include>**/*.groovy</include>
- </includes>
- </source>
- </sources>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy</artifactId>
- <version>${groovy.ver}</version>
- </dependency>
- </dependencies>
- </plugin>
</plugins>
</build>
</project>
\ No newline at end of file
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCResourceReader.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCResourceReader.scala
index d3e9388d..531be528 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCResourceReader.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCResourceReader.scala
@@ -25,7 +25,7 @@ import org.apache.nlpcraft.internal.util.NCUtils.*
import java.io.*
import java.net.URL
-import java.nio.file.Files
+import java.nio.file.{Files, Path}
import scala.collection.immutable.Map
import scala.io.Source
import scala.util.Using
@@ -57,7 +57,7 @@ object NCResourceReader extends LazyLogging:
* @param url
* @return
*/
- private def readMd5(url: String): Map[String, String] =
+ private def readMd5(url: String): Map[Path, String] =
try
Using.resource(Source.fromURL(url)) { src =>
src.getLines().map(_.trim()).filter(s => s.nonEmpty &&
!s.startsWith("#")).map(p => {
@@ -66,7 +66,10 @@ object NCResourceReader extends LazyLogging:
if seq.length != 2 || seq.exists(_.isEmpty) then
throw new NCException(s"Unexpected '$url' file line
format: '$p'")
- seq.head -> seq.last
+ val file = seq.head
+ val md5 = seq.last
+
+ Path.of(file) -> md5
}).toList.toMap
}
catch case e: IOException => throw new NCException(s"Failed to read:
'$url'", e)
@@ -85,12 +88,12 @@ object NCResourceReader extends LazyLogging:
* @param md5
* @return
*/
- private def getMd5(f: File, md5: Map[String, String]): String =
- val path = f.getAbsolutePath
+ private def getMd5(f: File, md5: Map[Path, String]): String =
+ val path = Path.of(f.getAbsolutePath)
val nameLen = f.getName.length
md5.
- flatMap { (resPath, md5) => Option.when(path.endsWith(resPath) &&
resPath.length >= nameLen)(md5) }.
+ flatMap { (resPath, md5) => Option.when(path.endsWith(resPath) &&
resPath.toString.length >= nameLen)(md5) }.
to(LazyList).
headOption.
getOrElse(throw new NCException(s"MD5 data not found for:
'$path'"))
@@ -101,7 +104,7 @@ object NCResourceReader extends LazyLogging:
* @param md5
* @return
*/
- private def isValid(f: File, md5: Map[String, String]): Boolean =
+ private def isValid(f: File, md5: Map[Path, String]): Boolean =
val v1 = getMd5(f, md5)
val v2 =
try Using.resource(Files.newInputStream(f.toPath)) { in =>
DigestUtils.md5Hex(in) }
@@ -124,7 +127,7 @@ object NCResourceReader extends LazyLogging:
* @param md5
* @return
*/
- private def download(path: String, outFile: String, md5: Map[String,
String]): File =
+ private def download(path: String, outFile: String, md5: Map[Path,
String]): File =
mkDir(new File(outFile).getParent)
val url = s"$BASE_URL/$path"
try