This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-246
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-246 by this push:
new bc7bba5 WIP.
bc7bba5 is described below
commit bc7bba53cf3d0d49b6e969aa1f6b6885cfed3de4
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Feb 25 14:24:38 2021 +0300
WIP.
---
.../apache/nlpcraft/common/nlp/NCNlpSentence.scala | 30 ++++++++++++++--------
.../nlpcraft/probe/mgrs/NCProbeVariants.scala | 10 ++++----
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentence.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentence.scala
index 42ff9af..113e088 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentence.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentence.scala
@@ -34,7 +34,9 @@ import scala.language.implicitConversions
object NCNlpSentence extends LazyLogging {
implicit def toTokens(x: NCNlpSentence): ArrayBuffer[NCNlpSentenceToken] =
x.tokens
- private case class NoteLink(note: String, indexes: Seq[Int])
+ case class NoteKey(start: Int, end: Int)
+ case class TokenKey(id: String, start: Int, end: Int)
+ case class NoteLink(note: String, indexes: Seq[Int])
case class PartKey(id: String, start: Int, end: Int) {
require(start <= end)
@@ -556,8 +558,8 @@ class NCNlpSentence(
val enabledBuiltInToks: Set[String],
override val tokens: mutable.ArrayBuffer[NCNlpSentenceToken] = new
mutable.ArrayBuffer[NCNlpSentenceToken](32),
private val deletedNotes: mutable.HashMap[NCNlpSentenceNote,
Seq[NCNlpSentenceToken]] = mutable.HashMap.empty,
- private var initNlpNotes: Map[(Int, Int), NCNlpSentenceNote] = null,
- private val allNlpTokens: mutable.HashMap[(Int, Int), NCNlpSentenceToken]
= mutable.HashMap.empty
+ private var initNlpNotes: Map[NoteKey, NCNlpSentenceNote] = null,
+ private val nlpTokens: mutable.HashMap[TokenKey, NCNlpSentenceToken] =
mutable.HashMap.empty
) extends NCNlpSentenceTokenBuffer(tokens) with JSerializable {
@transient
private var hash: java.lang.Integer = _
@@ -895,29 +897,35 @@ class NCNlpSentence(
/**
*
*/
- def saveNlpNotes(): Unit = initNlpNotes = this.map(t ⇒ (t.startCharIndex,
t.endCharIndex) → t.getNlpNote).toMap
+ def saveNlpNotes(): Unit =
+ initNlpNotes = this.map(t ⇒ NoteKey(t.startCharIndex, t.endCharIndex)
→ t.getNlpNote).toMap
/**
*
* @return
*/
def findInitialNlpNote(startCharIndex: Int, endCharIndex: Int):
Option[NCNlpSentenceNote] =
- initNlpNotes.get((startCharIndex, endCharIndex))
+ initNlpNotes.get(NoteKey(startCharIndex, endCharIndex))
/**
*
- * @param startCharIndex
- * @param endCharIndex
* @param nlp
*/
- def addNlpToken(startCharIndex: Int, endCharIndex: Int, nlp:
NCNlpSentenceToken): Unit =
- allNlpTokens += (startCharIndex, endCharIndex) → nlp
+ def addNlpToken(nlp: NCNlpSentenceToken): Unit = {
+ require(nlp.size <= 2)
+
+ nlp.foreach(n ⇒ nlpTokens += TokenKey(n.noteType, nlp.startCharIndex,
nlp.endCharIndex) → nlp)
+ }
/**
*
+ * @param noteType
+ * @param startCharIndex
+ * @param endCharIndex
+ * @return
*/
- def findNlpToken(startCharIndex: Int, endCharIndex: Int):
Option[NCNlpSentenceToken] =
- allNlpTokens.get((startCharIndex, endCharIndex))
+ def findNlpToken(noteType: String, startCharIndex: Int, endCharIndex:
Int): Option[NCNlpSentenceToken] =
+ nlpTokens.get(TokenKey(noteType, startCharIndex, endCharIndex))
/**
*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
index a8c92ab..aefdbd1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
@@ -194,7 +194,7 @@ object NCProbeVariants {
def mkToken(nlpTok: NlpToken): NCTokenImpl = {
val ncTok = NCTokenImpl(mdl, srvReqId, nlpTok)
- nlpSen.addNlpToken(ncTok.getStartCharIndex,
ncTok.getEndCharIndex, nlpTok)
+ nlpSen.addNlpToken(nlpTok)
ncTok
}
@@ -259,11 +259,11 @@ object NCProbeVariants {
require(parts.nonEmpty)
- for (p ← parts)
- process(p,
+ for (tok ← parts)
+ process(tok,
nlpSen.
- findNlpToken(p.getStartCharIndex,
p.getEndCharIndex).
- getOrElse(throw new NCE(s"Token not
found for $p"))
+ findNlpToken(tok.getId,
tok.getStartCharIndex, tok.getEndCharIndex).
+ getOrElse(throw new NCE(s"Token not
found for $tok"))
)
ok = ok && !toks.exists(t ⇒ t.getId !=
"nlpcraft:nlp" && keys.contains(Key(t)))