opennlp.tools.util.Span.contains()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中opennlp.tools.util.Span.contains()方法的一些代码示例,展示了Span.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.contains()方法的具体详情如下:
包路径:opennlp.tools.util.Span
类名称:Span
方法名:contains

Span.contains介绍

[英]Returns true if the specified index is contained inside this span. An index with the value of end is considered outside the span.
[中]如果指定的索引包含在此范围内,则返回true。值为end的索引被视为跨度之外的索引。

代码示例

代码示例来源:origin: apache/opennlp

public void createFeatures(List<String> features, String[] tokens, int index,
   String[] preds) {
  // cache results for sentence
  if (currentSentence != tokens) {
   currentSentence = tokens;
   currentNames = finder.find(tokens);
  }

  // iterate over names and check if a span is contained
  for (Span currentName : currentNames) {
   if (currentName.contains(index)) {
    // found a span for the current token
    features.add(prefix + ":w=dic");
    features.add(prefix + ":w=dic=" + tokens[index]);

    // TODO: consider generation start and continuation features

    break;
   }
  }
 }
}

代码示例来源:origin: apache/opennlp

/**
 * Returns true if the specified span is the begin of this span and the
 * specified span is contained in this span.
 *
 * @param s The span to compare with this span.
 *
 * @return true if the specified span starts with this span and is contained
 *     in this span; false otherwise
 */
public boolean startsWith(Span s) {
 return getStart() == s.getStart() && contains(s);
}

代码示例来源:origin: apache/opennlp

if (span.contains(ic)) {
  else if (ic.contains(sp)) {
  else if (sp.contains(ic)) {

代码示例来源:origin: apache/opennlp

/**
 * Returns true if the specified span intersects with this span.
 *
 * @param s The span to compare with this span.
 *
 * @return true is the spans overlap; false otherwise.
 */
public boolean intersects(Span s) {
 int sstart = s.getStart();
 //either s's start is in this or this' start is in s
 return this.contains(s) || s.contains(this)
     || getStart() <= sstart && sstart < getEnd()
     || sstart <= getStart() && getStart() < s.getEnd();
}

代码示例来源:origin: apache/opennlp

/**
 * Returns true is the specified span crosses this span.
 *
 * @param s The span to compare with this span.
 *
 * @return true is the specified span overlaps this span and contains a
 *     non-overlapping section; false otherwise.
 */
public boolean crosses(Span s) {
 int sstart = s.getStart();
 //either s's start is in this or this' start is in s
 return !this.contains(s) && !s.contains(this)
     && (getStart() <= sstart && sstart < getEnd()
     || sstart <= getStart() && getStart() < s.getEnd());
}

代码示例来源:origin: apache/opennlp

/**
 * Test for {@link Span#contains(int)}.
 */
@Test
public void testContainsInt() {
 Span a = new Span(10, 300);
 /* NOTE: here the span does not contain the endpoint marked as the end
  * for the span.  This is because the end should be placed one past the
  * true end for the span.  The indexes used must observe the same
  * requirements for the contains function.
  */
 Assert.assertFalse(a.contains(9));
 Assert.assertTrue(a.contains(10));
 Assert.assertTrue(a.contains(200));
 Assert.assertTrue(a.contains(299));
 Assert.assertFalse(a.contains(300));
}

代码示例来源:origin: apache/opennlp

/**
 * Test for {@link Span#contains(Span)}.
 */
@Test
public void testContainsWithEqual() {
 Span a = new Span(500, 900);
 Assert.assertEquals(true, a.contains(a));
}

代码示例来源:origin: apache/opennlp

if (sentence.contains(entitySpan)) {
 entityIdSet.remove(ann.getId());

代码示例来源:origin: apache/opennlp

/**
 * Test for {@link Span#contains(Span)}.
 */
@Test
public void testContainsWithLowerIntersect() {
 Span a = new Span(500, 900);
 Span b = new Span(450, 1000);
 Assert.assertEquals(false, a.contains(b));
}

代码示例来源:origin: apache/opennlp

/**
 * Test for {@link Span#contains(Span)}.
 */
@Test
public void testContains() {
 Span a = new Span(500, 900);
 Span b = new Span(520, 600);
 Assert.assertEquals(true, a.contains(b));
}

代码示例来源:origin: apache/opennlp

/**
 * Test for {@link Span#contains(Span)}.
 */
@Test
public void testContainsWithHigherIntersect() {
 Span a = new Span(500, 900);
 Span b = new Span(500, 1000);
 Assert.assertEquals(false, a.contains(b));
}

代码示例来源:origin: apache/opennlp

if (cSpan.contains(tokens[ti])) {
 if (!foundTrainingTokens) {
  firstTrainingToken = ti;

代码示例来源:origin: Ailab403/ailab-mltk4j

private void clearMentions(Set<Parse> mentions, Parse np) {
 Span npSpan =np.getSpan();
 for(Iterator<Parse> mi=mentions.iterator();mi.hasNext();) {
  Parse mention = mi.next();
  if (!mention.getSpan().contains(npSpan)) {
   //System.err.println("clearing "+mention+" for "+np);
   mi.remove();
  }
 }
}

代码示例来源:origin: ai.idylnlp/idylnlp-opennlp-tools-1.8.3

/**
 * Returns true if the specified span is the begin of this span and the
 * specified span is contained in this span.
 *
 * @param s The span to compare with this span.
 *
 * @return true if the specified span starts with this span and is contained
 *     in this span; false otherwise
 */
public boolean startsWith(Span s) {
 return getStart() == s.getStart() && contains(s);
}

代码示例来源:origin: org.apache.opennlp/opennlp-tools

/**
 * Returns true if the specified span is the begin of this span and the
 * specified span is contained in this span.
 *
 * @param s The span to compare with this span.
 *
 * @return true if the specified span starts with this span and is contained
 *     in this span; false otherwise
 */
public boolean startsWith(Span s) {
 return getStart() == s.getStart() && contains(s);
}

代码示例来源:origin: org.cogroo/cogroo-ruta

private List<Token> getTokens(Sentence sentence, int begin, int end) {
  List<Token> tokens = new ArrayList<>();
  Span span = new Span(begin, end);
  for (Token token : sentence.getTokens()) {
    if (span.contains(token.getSpan())) {
      tokens.add(token);
    }
  }
  return tokens;
}

代码示例来源:origin: cogroo/cogroo4

private List<Token> getTokens(Sentence sentence, int begin, int end) {
  List<Token> tokens = new ArrayList<>();
  Span span = new Span(begin, end);
  for (Token token : sentence.getTokens()) {
    if (span.contains(token.getSpan())) {
      tokens.add(token);
    }
  }
  return tokens;
}

代码示例来源:origin: apache/opennlp

if (commonParent.getType().equals("NP")) {
 Parse[] grandKids = kids[0].getChildren();
 if (grandKids.length > 1 && nameSpan.contains(grandKids[grandKids.length - 1].getSpan())) {
  commonParent.insert(new Parse(commonParent.getText(), commonParent.getSpan(),
    tag, 1.0, commonParent.getHeadIndex()));

代码示例来源:origin: org.cogroo/cogroo-gc

public static List<Token> getMistakeCoveredTokens(Sentence sent, Mistake mistake) {
  List<Token> out = new ArrayList<Token>();
  Span s = new Span(mistake.getStart(), mistake.getEnd());
  for (Token token : sent.getTokens()) {
   if(s.contains(token.getStart())) {
    out.add(token);
   }
  }
  
  return out;
 }
}

代码示例来源:origin: org.cogroo/cogroo-gc

public static Sentence getMistakeStartSentence(Document doc, Mistake mistake) {
 for (Sentence sent : doc.getSentences()) {
  Span s = new Span(sent.getStart(), sent.getEnd());
  if (s.contains(mistake.getStart())) {
   return sent;
  }
 }
 return null;
}

相关文章