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; } } } }
/** * 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); }
/** * 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(); }
/** * 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()); }
/** * 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)); }
/** * Test for {@link Span#contains(Span)}. */ @Test public void testContainsWithEqual() { Span a = new Span(500, 900); Assert.assertEquals(true, a.contains(a)); }
if (sentence.contains(entitySpan)) { entityIdSet.remove(ann.getId());
/** * 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)); }
/** * 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)); }
/** * 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)); }
if (cSpan.contains(tokens[ti])) { if (!foundTrainingTokens) { firstTrainingToken = ti;
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(); } } }
/** * 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); }
/** * 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); }
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; }
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; }
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()));
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; } }
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; }