@Override public void setValue(String value) { label.setValue(value); }
@Override public Label newLabel(String labelStr) { CoreLabel label = new CoreLabel(); label.setValue(labelStr); return label; }
public static List<HasWord> toWordList(String... words) { List<HasWord> sent = new ArrayList<>(); for (String word : words) { CoreLabel cl = new CoreLabel(); cl.setValue(word); cl.setWord(word); sent.add(cl); } return sent; }
/** * Create a sentence as a List of {@code CoreLabel} objects from * an array (or varargs) of String objects. * * @param words The words to make it from * @return The Sentence */ public static List<CoreLabel> toCoreLabelList(String... words) { List<CoreLabel> sent = new ArrayList<>(words.length); for (String word : words) { CoreLabel cl = new CoreLabel(); cl.setValue(word); cl.setWord(word); sent.add(cl); } return sent; }
@Override public Label newLabel(String labelStr) { CoreLabel coreLabel = new CoreLabel(); coreLabel.setValue(labelStr); return new IndexedWord(coreLabel); }
public UnnamedDependency(String regent, String dependent) { if (regent == null || dependent == null) { throw new IllegalArgumentException("governor or dependent cannot be null"); } CoreLabel headLabel = new CoreLabel(); headLabel.setValue(regent); headLabel.setWord(regent); this.regent = headLabel; CoreLabel depLabel = new CoreLabel(); depLabel.setValue(dependent); depLabel.setWord(dependent); this.dependent = depLabel; regentText = regent; dependentText = dependent; }
/** * Splits a compound marked by the lexer. */ private CoreLabel processCompound(CoreLabel cl) { cl.remove(ParentAnnotation.class); String[] parts = cl.word().replaceAll("-", " - ").split("\\s+"); for (String part : parts) { CoreLabel newLabel = new CoreLabel(cl); newLabel.setWord(part); newLabel.setValue(part); newLabel.set(OriginalTextAnnotation.class, part); compoundBuffer.add(newLabel); } return compoundBuffer.remove(0); }
/** This is provided as a simple way to make a CoreLabel for a word from a String. * It's often useful in fixup or test code. It sets all three of the Text, OriginalText, * and Value annotations to the given value. * * @param word The word string to make a CoreLabel for * @return A CoreLabel for this word string */ public static CoreLabel wordFromString(String word) { CoreLabel cl = new CoreLabel(); cl.setWord(word); cl.setOriginalText(word); cl.setValue(word); return cl; }
/** * Splits a compound marked by the lexer. */ private CoreLabel processCompound(CoreLabel cl) { cl.remove(ParentAnnotation.class); String[] parts = pSpace.split(pDash.matcher(cl.word()).replaceAll(" - ")); int lengthAccum = 0; for (String part : parts) { CoreLabel newLabel = new CoreLabel(cl); newLabel.setWord(part); newLabel.setValue(part); newLabel.setBeginPosition(cl.beginPosition() + lengthAccum); newLabel.setEndPosition(cl.beginPosition() + lengthAccum + part.length()); newLabel.set(OriginalTextAnnotation.class, part); compoundBuffer.add(newLabel); lengthAccum += part.length(); } return compoundBuffer.remove(0); }
private static CoreLabel initCoreLabel(String token) { CoreLabel label = new CoreLabel(); label.setWord(token); label.setValue(token); label.set(CoreAnnotations.TextAnnotation.class, token); label.set(CoreAnnotations.ValueAnnotation.class, token); return label; }
private CoreLabel makeXmlToken(String tokenText, boolean doNormalization, int charOffsetBegin, int charOffsetEnd) { CoreLabel token = new CoreLabel(); token.setOriginalText(tokenText); if (separatorPattern.matcher(tokenText).matches()) { // Map to CoreNLP newline token tokenText = AbstractTokenizer.NEWLINE_TOKEN; } else if (doNormalization && normalizeSpace) { tokenText = tokenText.replace(' ', '\u00A0'); // change space to non-breaking space } token.setWord(tokenText); token.setValue(tokenText); token.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, charOffsetBegin); token.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, charOffsetEnd); if (VERBOSE) { log.info("Adding token " + token.toShorterString()); } return token; }
/** Copies the CoreLabel cl with the new word part */ private static CoreLabel copyCoreLabel(CoreLabel cl, String part, int beginPosition, int endPosition) { CoreLabel newLabel = new CoreLabel(cl); newLabel.setWord(part); newLabel.setValue(part); newLabel.setBeginPosition(beginPosition); newLabel.setEndPosition(endPosition); newLabel.set(OriginalTextAnnotation.class, part); return newLabel; }
/** Copies the CoreLabel cl with the new word part */ private static CoreLabel copyCoreLabel(CoreLabel cl, String part, int beginPosition, int endPosition) { CoreLabel newLabel = new CoreLabel(cl); newLabel.setWord(part); newLabel.setValue(part); newLabel.setBeginPosition(beginPosition); newLabel.setEndPosition(endPosition); newLabel.set(OriginalTextAnnotation.class, part); return newLabel; }
private static void convertToCoreLabels(Tree tree) { Label l = tree.label(); if (! (l instanceof CoreLabel)) { CoreLabel cl = new CoreLabel(); cl.setValue(l.value()); tree.setLabel(cl); } for (Tree kid : tree.children()) { convertToCoreLabels(kid); } }
private static void convertToCoreLabels(Tree tree) { Label l = tree.label(); if (! (l instanceof CoreLabel)) { CoreLabel cl = new CoreLabel(); cl.setValue(l.value()); tree.setLabel(cl); } for (Tree kid : tree.children()) { convertToCoreLabels(kid); } }
/** * Converts the tree labels to CoreLabels. * We need this because we store additional info in the CoreLabel, like token span. * @param tree */ public static void convertToCoreLabels(Tree tree) { Label l = tree.label(); if(! (l instanceof CoreLabel)){ CoreLabel cl = new CoreLabel(); cl.setValue(l.value()); tree.setLabel(cl); } for (Tree kid : tree.children()) { convertToCoreLabels(kid); } }
/** * Converts the tree labels to CoreLabels. * We need this because we store additional info in the CoreLabel, like token span. * @param tree */ public static void convertToCoreLabels(Tree tree) { Label l = tree.label(); if (!(l instanceof CoreLabel)) { CoreLabel cl = new CoreLabel(); cl.setValue(l.value()); tree.setLabel(cl); } for (Tree kid : tree.children()) { convertToCoreLabels(kid); } }
/** * Constructs a CoreLabel as a String with a corresponding BEGIN and END position, * when the original OriginalTextAnnotation is different from TextAnnotation * (Does not take substring). */ public CoreLabel makeToken(String tokenText, String originalText, int begin, int length) { CoreLabel cl = addIndices ? new CoreLabel(5) : new CoreLabel(); cl.setValue(tokenText); cl.setWord(tokenText); cl.setOriginalText(originalText); if(addIndices) { cl.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, begin); cl.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, begin+length); } return cl; }
static Tree createNode(Tree top, String label, Tree ... children) { CoreLabel headLabel = (CoreLabel) top.label(); CoreLabel production = new CoreLabel(); production.setValue(label); production.set(TreeCoreAnnotations.HeadWordLabelAnnotation.class, headLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class)); production.set(TreeCoreAnnotations.HeadTagLabelAnnotation.class, headLabel.get(TreeCoreAnnotations.HeadTagLabelAnnotation.class)); Tree newTop = new LabeledScoredTreeNode(production); for (Tree child : children) { newTop.addChild(child); } return newTop; }
/** * Remove everything but the skeleton, the predictions, and the labels */ private Tree simplifyTree(Tree tree) { CoreLabel newLabel = new CoreLabel(); newLabel.set(RNNCoreAnnotations.Predictions.class, RNNCoreAnnotations.getPredictions(tree)); newLabel.setValue(tree.label().value()); if (tree.isLeaf()) { return tree.treeFactory().newLeaf(newLabel); } List<Tree> children = Generics.newArrayList(tree.children().length); for (int i = 0; i < tree.children().length; ++i) { children.add(simplifyTree(tree.children()[i])); } return tree.treeFactory().newTreeNode(newLabel, children); }