You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/03/14 07:00:43 UTC
[incubator-nlpcraft] 11/13: WIP.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 1970603c7a7f49bc4935daa2d71b59af6b1f34ea
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Fri Mar 13 21:54:09 2020 +0300
WIP.
---
.../aggregation/NCAggregationEnricher.scala | 24 +++-------------------
.../mgrs/nlp/enrichers/limit/NCLimitEnricher.scala | 12 +----------
.../mgrs/nlp/enrichers/sort/NCSortEnricher.scala | 15 +-------------
3 files changed, 5 insertions(+), 46 deletions(-)
diff --git a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCAggregationEnricher.scala b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCAggregationEnricher.scala
index 6fa6a2a..b9f4afd 100644
--- a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCAggregationEnricher.scala
+++ b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/aggregation/NCAggregationEnricher.scala
@@ -42,18 +42,6 @@ object NCAggregationEnricher extends NCProbeEnricher {
)
private final val TOK_ID = "nlpcraft:aggregation"
- private final val AGGR_TYPES = Seq(
- "nlpcraft:continent",
- "nlpcraft:subcontinent",
- "nlpcraft:country",
- "nlpcraft:metro",
- "nlpcraft:region",
- "nlpcraft:city",
- "nlpcraft:coordinate",
- "nlpcraft:date",
- "nlpcraft:num"
- )
-
@volatile private var FUNCS: Map[String, String] = _
/**
@@ -123,23 +111,17 @@ object NCAggregationEnricher extends NCProbeEnricher {
/**
*
- * @param n
- */
- private def isRefCandidate(n: NCNlpSentenceNote): Boolean = n.isUser || AGGR_TYPES.contains(n.noteType)
-
- /**
- *
* @param toks
*/
private def tryToMatch(toks: Seq[NCNlpSentenceToken]): Option[Match] = {
- val matchedCands = toks.takeWhile(!_.exists(isRefCandidate))
+ val matchedCands = toks.takeWhile(!_.exists(_.isUser))
def try0(stem: String): Option[Match] =
FUNCS.get(stem) match {
case Some(funcType) ⇒
val afterMatched = toks.drop(matchedCands.length)
- val refCands = afterMatched.filter(_.exists(isRefCandidate))
- val commonNotes = getCommonNotes(refCands, Some(isRefCandidate))
+ val refCands = afterMatched.filter(_.exists(_.isUser))
+ val commonNotes = getCommonNotes(refCands, Some((n: NCNlpSentenceNote) ⇒ n.isUser))
val ok =
commonNotes.nonEmpty &&
diff --git a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
index bcde957..8d739c7 100644
--- a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
+++ b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
@@ -45,16 +45,6 @@ object NCLimitEnricher extends NCProbeEnricher {
private final val TOK_ID = "nlpcraft:limit"
- private final val LIMIT_TYPES = Seq(
- "nlpcraft:continent",
- "nlpcraft:subcontinent",
- "nlpcraft:country",
- "nlpcraft:metro",
- "nlpcraft:region",
- "nlpcraft:city",
- "nlpcraft:date"
- )
-
/**
* Group of neighbouring tokens. All of them numbers or all of the not.
*
@@ -249,7 +239,7 @@ object NCLimitEnricher extends NCProbeEnricher {
groupsMap: Map[Seq[NCNlpSentenceToken], GroupsHolder],
toks: Seq[NCNlpSentenceToken]
): Option[Match] = {
- val refCands = toks.filter(t ⇒ t.exists(n ⇒ n.isUser || LIMIT_TYPES.contains(n.noteType)))
+ val refCands = toks.filter(_.exists(_.isUser))
val commonNotes = getCommonNotes(refCands)
if (commonNotes.nonEmpty) {
diff --git a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala
index 59628c6..973fb9c 100644
--- a/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala
+++ b/src/main/scala/org/nlpcraft/probe/mgrs/nlp/enrichers/sort/NCSortEnricher.scala
@@ -65,19 +65,6 @@ object NCSortEnricher extends NCProbeEnricher {
private final val TOK_ID = "nlpcraft:sort"
- // TODO: DROP it.
- private final val SORT_TYPES = Seq(
- "nlpcraft:continent",
- "nlpcraft:subcontinent",
- "nlpcraft:country",
- "nlpcraft:metro",
- "nlpcraft:region",
- "nlpcraft:city",
- "nlpcraft:coordinate",
- "nlpcraft:date",
- "nlpcraft:num"
- )
-
// Elemens: SORT, BY, ORDER, x.
// Note that SORT, BY, ORDER - are sets of words (not single words)
// x - means one or multiple words. x must be at least one for each line, maximum two.
@@ -278,7 +265,7 @@ object NCSortEnricher extends NCProbeEnricher {
val others = toks.filter(t ⇒ !h.all.contains(t))
if (others.nonEmpty) {
- val othersRefs = others.filter(t ⇒ t.exists(n ⇒ n.isUser || SORT_TYPES.contains(n.noteType)))
+ val othersRefs = others.filter(_.exists(_.isUser))
if (
othersRefs.nonEmpty &&