You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by if...@apache.org on 2020/08/26 03:54:35 UTC
[incubator-nlpcraft] branch NLPCRAFT-50 updated: NLPCRAFT-50:
Abstract function enricher stub and average enricher draft
This is an automated email from the ASF dual-hosted git repository.
ifropc pushed a commit to branch NLPCRAFT-50
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-50 by this push:
new ef625c2 NLPCRAFT-50: Abstract function enricher stub and average enricher draft
ef625c2 is described below
commit ef625c2ee33715323f7a0a6adecdc1660075cbed
Author: Ifropc <if...@apache.org>
AuthorDate: Tue Aug 25 20:54:15 2020 -0700
NLPCRAFT-50: Abstract function enricher stub and average enricher draft
---
.../nlp/enrichers/function/NCAverageEnricher.scala | 49 ++++++++++++++++++++--
...rageEnricher.scala => NCFunctionEnricher.scala} | 22 ++--------
2 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala
index a570ea0..589cd4c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala
@@ -20,11 +20,21 @@ package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.function
import java.io
import _root_.io.opencensus.trace.Span
-import org.apache.nlpcraft.common.nlp.NCNlpSentence
+import org.apache.nlpcraft.common.nlp.{NCNlpSentence, NCNlpSentenceNote, NCNlpSentenceToken}
import org.apache.nlpcraft.probe.mgrs.NCModelDecorator
import org.apache.nlpcraft.probe.mgrs.nlp.NCProbeEnricher
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.limit.NCLimitEnricher.{isUserNotValue, startScopedSpan, techWords}
+import scala.collection.{Seq, mutable}
+
+object NCAverageEnricher extends NCFunctionEnricher {
+ override def funcType: String = "average"
+
+ case class Match(matched: Seq[NCNlpSentenceToken],
+ matchedHead: NCNlpSentenceToken,
+ refNotes: Set[String],
+ refIndexes: java.util.List[Int]
+ )
-object NCAverageEnricher extends NCProbeEnricher {
/**
*
* Processes this NLP sentence.
@@ -37,5 +47,38 @@ object NCAverageEnricher extends NCProbeEnricher {
override def enrich(mdl: NCModelDecorator,
ns: NCNlpSentence,
senMeta: collection.Map[String, io.Serializable],
- parent: Span): Unit = ???
+ parent: Span): Unit = startScopedSpan("enrich", parent,
+ "srvReqId" → ns.srvReqId,
+ "modelId" → mdl.model.getId,
+ "txt" → ns.text) { _ ⇒
+ val notes = mutable.HashSet.empty[NCNlpSentenceNote]
+
+ for (toks ← ns.tokenMixWithStopWords() if validImportant(ns, toks))
+ tryToMatch(toks) match {
+ case Some(m) ⇒
+ for (refNote ← m.refNotes) {
+ val note = NCNlpSentenceNote(
+ Seq(m.matchedHead.index),
+ TOK_ID,
+ "type" → funcType,
+ "indexes" → m.refIndexes,
+ "note" → refNote
+ )
+
+ if (!notes.exists(n ⇒ ns.notesEqualOrSimilar(n, note))) {
+ notes += note
+
+ m.matched.filter(_ != m.matchedHead).foreach(_.addStopReason(note))
+
+ m.matchedHead.add(note)
+ }
+ }
+ case None ⇒ // No-op.
+ }
+ }
+
+
+ private def validImportant(ns: NCNlpSentence, toks: Seq[NCNlpSentenceToken]): Boolean = ???
+
+ private def tryToMatch(toks: Seq[NCNlpSentenceToken]): Option[Match] = ???
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCFunctionEnricher.scala
similarity index 58%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCFunctionEnricher.scala
index a570ea0..3d01014 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCAverageEnricher.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/function/NCFunctionEnricher.scala
@@ -18,24 +18,10 @@
package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.function
-import java.io
-import _root_.io.opencensus.trace.Span
-import org.apache.nlpcraft.common.nlp.NCNlpSentence
-import org.apache.nlpcraft.probe.mgrs.NCModelDecorator
import org.apache.nlpcraft.probe.mgrs.nlp.NCProbeEnricher
-object NCAverageEnricher extends NCProbeEnricher {
- /**
- *
- * Processes this NLP sentence.
- *
- * @param mdl Model decorator.
- * @param ns NLP sentence to enrich.
- * @param senMeta Sentence metadata.
- * @param parent Span parent.
- */
- override def enrich(mdl: NCModelDecorator,
- ns: NCNlpSentence,
- senMeta: collection.Map[String, io.Serializable],
- parent: Span): Unit = ???
+abstract class NCFunctionEnricher extends NCProbeEnricher {
+ protected final val TOK_ID = "nlpcraft:relation"
+
+ def funcType: String
}