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

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


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

commit 26bba0a10d65272fdfb6e5fc963145f2f4180cc3
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Dec 16 21:58:48 2022 +0400

    WIP.
---
 .../apache/nlpcraft/internal/util/NCUtils.scala    | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index 818aa25d..6c0160a6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -471,21 +471,20 @@ object NCUtils extends LazyLogging:
         filterText: Boolean = false,
         log: Logger = logger
     ): Iterator[String] =
-        def process(is: InputStream, name: String) =
-            try
-                val out = Source.fromInputStream(is, enc).getLines().flatMap(p 
=>
-                    var x = if strip then p.strip else p
-                    x = convert(p)
-                    Option.when(!filterText || x.nonEmpty && x.head != '#')(x)
-                )
-                log.info(s"Loaded resource: $name")
-                out
-            catch case e: IOException => E(s"Failed to read stream: $res", e)
-
-        res match
-            case is: InputStream => process(is, is.getClass.getName)
-            case s: String => process(new BufferedInputStream(getStream(s)), s)
-            case f: File => process(new BufferedInputStream(new 
FileInputStream(f)), f.getAbsolutePath)
+        try
+            val (stream, name) =
+                res match
+                    case is: InputStream => (is, is.getClass.getName)
+                    case s: String => (new BufferedInputStream(getStream(s)), 
s)
+                    case f: File => (new BufferedInputStream(new 
FileInputStream(f)), f.getAbsolutePath)
+
+            val out = Source.fromInputStream(stream, 
enc).getLines().flatMap(line =>
+                val s = convert(if strip then line.strip else line)
+                Option.when(!filterText || s.nonEmpty && s.head != '#')(s)
+            )
+            log.info(s"Loaded resource: $name")
+            out
+        catch case e: IOException => E(s"Failed to read stream: $res", e)
 
     /**
       *

Reply via email to