List of usage examples for edu.stanford.nlp.ling CoreLabel setIndex
@Override public void setIndex(int index)
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.util.TreeUtils.java
License:Open Source License
private static int reIndexLeaves(Tree t, int startIndex) { if (t.isLeaf()) { CoreLabel afl = (CoreLabel) t.label(); afl.setIndex(startIndex); startIndex++;/* w w w . j a va2s . c o m*/ } else { for (Tree child : t.children()) { startIndex = reIndexLeaves(child, startIndex); } } return startIndex; }
From source file:edu.illinois.cs.cogcomp.pipeline.handlers.StanfordParseHandler.java
License:Open Source License
static List<CoreMap> buildStanfordSentences(TextAnnotation ta) { View tokens = ta.getView(ViewNames.TOKENS); View sentences = ta.getView(ViewNames.SENTENCE); String rawText = ta.getText(); List<CoreMap> stanfordSentences = new LinkedList<>(); List<CoreLabel> stanfordTokens = new LinkedList<>(); int tokIndex = 0; int sentIndex = 0; Constituent currentSentence = sentences.getConstituents().get(0); String sentText = rawText.substring(currentSentence.getStartCharOffset(), currentSentence.getEndCharOffset()); CoreLabelTokenFactory tf = new CoreLabelTokenFactory(); for (Constituent tok : tokens.getConstituents()) { if (tok.getStartSpan() >= currentSentence.getEndSpan()) { CoreMap stanfordSentence = buildStanfordSentence(currentSentence, sentText, sentIndex++, stanfordTokens);//from w ww .j ava 2s . co m stanfordSentences.add(stanfordSentence); stanfordTokens = new LinkedList<>(); currentSentence = sentences.getConstituents().get(sentIndex); sentText = rawText.substring(currentSentence.getStartCharOffset(), currentSentence.getEndCharOffset()); } int tokStart = tok.getStartCharOffset(); int tokLength = tok.getEndCharOffset() - tokStart; String form = rawText.substring(tokStart, tok.getEndCharOffset()); CoreLabel stanfordTok = tf.makeToken(form, tokStart, tokLength); stanfordTok.setIndex(tokIndex++); stanfordTokens.add(stanfordTok); } // should be one last sentence CoreMap stanfordSentence = buildStanfordSentence(currentSentence, sentText, sentIndex, stanfordTokens); stanfordSentences.add(stanfordSentence); return stanfordSentences; }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteToStanfordMapper.java
License:Open Source License
private static List<CoreLabel> tokenizationToCoreLabelList(final Tokenization tkz, int sentIdx, int offset) { List<CoreLabel> clList = new ArrayList<CoreLabel>(); TokenList tl = tkz.getTokenList();//from w w w . j a v a 2s.co m List<Token> tokList = tl.getTokenList(); for (Token tok : tokList) { final TextSpan ts = tok.getTextSpan(); final int idx = tok.getTokenIndex(); final int idxPlusOne = idx + 1; final int begin = ts.getStart() - offset; final int length = ts.getEnding() - ts.getStart(); CoreLabel cl = factory.makeToken(tok.getText(), begin, length); cl.setIndex(idxPlusOne); cl.setSentIndex(sentIdx); // cl.setOriginalText(tok.getText()); // cl.set(OriginalTextAnnotation.class, tok.getText()); clList.add(cl); } return clList; }
From source file:lv.pipe.NerTagger.java
License:Open Source License
public static CoreLabel makeCoreLabel(Annotation a) { CoreLabel wi = new CoreLabel(); if (!a.has(LabelText.class) || a.getText().equals(BOUNDARY)) { wi.setWord(BOUNDARY);//from ww w.j a v a 2 s . c om wi.set(AnswerAnnotation.class, OTHER); wi.set(NamedEntityTagGoldAnnotation.class, OTHER); wi.setLemma("_"); } else { wi.setWord(a.getText()); } wi.setIndex(a.get(LabelIndex.class, -1)); wi.setLemma(a.get(LabelLemma.class, "_")); wi.set(LVFullTagAnnotation.class, a.get(LabelPosTag.class, "_")); wi.setTag(a.get(LabelPosTagSimple.class, "_")); wi.set(MorphologyFeatureStringAnnotation.class, a.get(LabelMorphoFeatures.class, "_")); wi.set(ParentAnnotation.class, Integer.toString((Integer) a.get(LabelParent.class, -1))); wi.set(LabelAnnotation.class, a.get(LabelDependency.class, "_")); return wi; }
From source file:semRewrite.substitutor.CoreLabelSequence.java
License:Open Source License
/** ************************************************************* * Change the value() of each CoreLabel to be all caps *//*from w w w .j a va 2 s. c om*/ public semRewrite.substitutor.CoreLabelSequence toUpperCase() { //System.out.println("CoreLabelSequence.toUpperCase(): labels: " + labels); List<CoreLabel> lcl = new ArrayList<>(); for (CoreLabel cl : labels) { CoreLabel newcl = new CoreLabel(); newcl.setValue(cl.value().toUpperCase()); newcl.setIndex(cl.index()); lcl.add(newcl); } semRewrite.substitutor.CoreLabelSequence cls = new semRewrite.substitutor.CoreLabelSequence(lcl); //System.out.println("CoreLabelSequence.toUpperCase(): cls: " + cls); return cls; }
From source file:semRewrite.substitutor.SubstitutionUtil.java
License:Open Source License
/** ************************************************************** *//*w w w . j a v a2 s . c o m*/ public static void test() { CoreLabel cl1 = new CoreLabel(); cl1.setValue("C."); cl1.setIndex(4); List<CoreLabel> lcl = new ArrayList<>(); List<CoreLabel> lcl2 = new ArrayList<>(); lcl.add(cl1); lcl2.add(cl1); CoreLabel cl2 = new CoreLabel(); cl2.setValue("S."); cl2.setIndex(5); lcl.add(cl2); lcl2.add(cl2); CoreLabel cl3 = new CoreLabel(); cl3.setValue("Lewis".toUpperCase()); cl3.setIndex(6); lcl.add(cl3); cl3 = new CoreLabel(); cl3.setValue("Lewis"); cl3.setIndex(6); lcl2.add(cl3); CoreLabelSequence cls = new CoreLabelSequence(lcl); CoreLabelSequence cls2 = new CoreLabelSequence(lcl2); //subst = [{[C.-4, S.-5, Lewis-6]=[C.-4, S.-5, Lewis-6]}, {}]; String clause = "number(SINGULAR, Lewis-6)"; List<String> clauses = new ArrayList<>(); clauses.add(clause); SimpleSubstitutorStorage sss = new SimpleSubstitutorStorage(); Map<CoreLabelSequence, CoreLabelSequence> m = new HashMap<>(); m.put(cls, cls2); sss.addGroups(m); System.out.println("SubstitutionUtil.test(): " + groupClauses(sss, clauses)); }