public void setCorrectTags(List<? extends HasTag> sentence) { int len = sentence.size(); correctTags = new String[len]; for (int i = 0; i < len; i++) { correctTags[i] = sentence.get(i).tag(); } }
/** * Create a new <code>TaggedWord</code>. * * @param oldLabel A Label. If it implements the HasWord and/or * HasTag interface, then the corresponding value will be set */ public TaggedWord(Label oldLabel) { super(oldLabel.value()); if (oldLabel instanceof HasTag) { this.tag = ((HasTag) oldLabel).tag(); } }
public <E extends Label & HasTag> WordTag(E word) { this(word.value(), word.tag()); }
/** * Creates a new CategoryWordTag label from an existing label. * The oldLabel value() -- i.e., category -- is used for the new label. * The tag and word * are initialized iff the current label implements HasTag and HasWord * respectively. * * @param oldLabel The label to use as a basis of this Label */ public CategoryWordTag(Label oldLabel) { super(oldLabel); if (oldLabel instanceof HasTag) { this.tag = ((HasTag) oldLabel).tag(); } if (oldLabel instanceof HasWord) { this.word = ((HasWord) oldLabel).word(); } }
@Override public boolean test(Dependency<G, D, N> d) { /* log.info("DRF: Checking " + d + ": hasTag?: " + (d.dependent() instanceof HasTag) + "; value: " + ((d.dependent() instanceof HasTag)? ((HasTag) d.dependent()).tag(): null)); */ if (d == null) { return false; } if ( ! (d.dependent() instanceof HasTag)) { return false; } String tag = ((HasTag) d.dependent()).tag(); return tagRejectFilter.test(tag); }
hw.getClass()); String tag = ((HasTag) hw).tag(); sb.append(" <word wid=\"").append(wordIndex).append("\" pos=\"").append(XMLUtils.escapeAttributeXML(tag)).append("\""); if (outputLemmas && hasCoreLabels) {
/** * Construct a fall through tree in case we can't parse this sentence. * * @param words Words of the sentence that didn't parse * @return A tree with X for all the internal nodes. * Preterminals have the right tag if the words are tagged. */ public static Tree xTree(List<? extends HasWord> words) { TreeFactory treeFactory = new LabeledScoredTreeFactory(); List<Tree> lst2 = new ArrayList<>(); for (HasWord obj : words) { String s = obj.word(); Tree t = treeFactory.newLeaf(s); String tag = "XX"; if (obj instanceof HasTag) { if (((HasTag) obj).tag() != null) { tag = ((HasTag) obj).tag(); } } Tree t2 = treeFactory.newTreeNode(tag, Collections.singletonList(t)); lst2.add(t2); } return treeFactory.newTreeNode("X", lst2); }
private static boolean vpContainsParticiple(Tree t) { for (Tree kid : t.children()) { if (DEBUG) { log.info("vpContainsParticiple examining " + kid); } if (kid.isPreTerminal()) { Label kidLabel = kid.label(); String tag = null; if (kidLabel instanceof HasTag) { tag = ((HasTag) kidLabel).tag(); } if (tag == null) { tag = kid.value(); } if ("VBN".equals(tag) || "VBG".equals(tag) || "VBD".equals(tag)) { if (DEBUG) { log.info("vpContainsParticiple found VBN/VBG/VBD VP"); } return true; } } } return false; }
private static boolean vpContainsParticiple(Tree t) { for (Tree kid : t.children()) { if (DEBUG) { log.info("vpContainsParticiple examining " + kid); } if (kid.isPreTerminal()) { Label kidLabel = kid.label(); String tag = null; if (kidLabel instanceof HasTag) { tag = ((HasTag) kidLabel).tag(); } if (tag == null) { tag = kid.value(); } if ("VBN".equals(tag) || "VBG".equals(tag) || "VBD".equals(tag)) { if (DEBUG) { log.info("vpContainsParticiple found VBN/VBG/VBD VP"); } return true; } } } return false; }
@Override public Tree transformTree(Tree t) { Morphology morphology = new Morphology(); List<TaggedWord> tagged = null; int index = 0; for (Tree leaf : t.getLeaves()) { Label label = leaf.label(); if (label == null) { continue; } String tag; if (!(label instanceof HasTag) || ((HasTag) label).tag() == null) { if (tagged == null) { tagged = t.taggedYield(); } tag = tagged.get(index).tag(); } else { tag = ((HasTag) label).tag(); } if (!(label instanceof HasLemma)) { throw new IllegalArgumentException("Got a tree with labels which do not support lemma"); } ((HasLemma) label).setLemma(morphology.lemma(label.value(), tag, true)); ++index; } return t; }
/** * Create a new <code>WordTag Label</code>, where the label is * formed from * the <code>Label</code> object passed in. Depending on what fields * each label has, other things will be <code>null</code>. * * @param oldLabel The Label that the new label is being created from * @return a new label of a particular type */ public Label newLabel(Label oldLabel) { if (oldLabel instanceof HasTag) { return new WordTag(oldLabel.value(), ((HasTag) oldLabel).tag()); } else { return new WordTag(oldLabel.value()); } } }
/** * Create a sentence as a List of {@code CoreLabel} objects from * a List of other label objects. * * @param words The words to make it from * @return The Sentence */ public static List<CoreLabel> toCoreLabelList(List<? extends HasWord> words) { List<CoreLabel> sent = new ArrayList<>(words.size()); for (HasWord word : words) { CoreLabel cl = new CoreLabel(); if (word instanceof Label) { cl.setValue(((Label) word).value()); } cl.setWord(word.word()); if (word instanceof HasTag) { cl.setTag(((HasTag) word).tag()); } if (word instanceof HasLemma) { cl.setLemma(((HasLemma) word).lemma()); } sent.add(cl); } return sent; }
/** * Do nothing other than decorate the label with @ */ private static Label makeSimpleSyntheticLabel(Tree t) { String topCat = t.label().value(); String labelStr = '@' + topCat; String word = ((HasWord) t.label()).word(); String tag = ((HasTag) t.label()).tag(); return new CategoryWordTag(labelStr, word, tag); }
/** * Returns the input sentence for the parser. */ private List<CoreLabel> getInputSentence(Tree t) { if (op.testOptions.forceTags) { if (op.testOptions.preTag) { List<TaggedWord> s = tagger.apply(t.yieldWords()); if(op.testOptions.verbose) { log.info("Guess tags: "+Arrays.toString(s.toArray())); log.info("Gold tags: "+t.labeledYield().toString()); } return SentenceUtils.toCoreLabelList(s); } else if(op.testOptions.noFunctionalForcing) { ArrayList<? extends HasWord> s = t.taggedYield(); for (HasWord word : s) { String tag = ((HasTag) word).tag(); tag = tag.split("-")[0]; ((HasTag) word).setTag(tag); } return SentenceUtils.toCoreLabelList(s); } else { return SentenceUtils.toCoreLabelList(t.taggedYield()); } } else { return SentenceUtils.toCoreLabelList(t.yieldWords()); } }
"with part-of-speech tag annotations"); label.setTag(((HasTag) wd).tag());
/** * Given a tree, set the tags on the leaf nodes if they are not * already set. Do this by using the preterminal's value as a tag. */ public static void setLeafTagsIfUnset(Tree tree) { if (tree.isPreTerminal()) { Tree leaf = tree.children()[0]; if (!(leaf.label() instanceof HasTag)) { return; } HasTag label = (HasTag) leaf.label(); if (label.tag() == null) { label.setTag(tree.value()); } } else { for (Tree child : tree.children()) { setLeafTagsIfUnset(child); } } }
/** * Convert a constituency label to a dependency label. Options are provided for selecting annotations * to copy. * * @param oldLabel * @param copyLabel * @param copyIndex * @param copyPosTag */ private static Label makeDependencyLabel(Label oldLabel, boolean copyLabel, boolean copyIndex, boolean copyPosTag) { if ( ! copyLabel) return oldLabel; String wordForm = (oldLabel instanceof HasWord) ? ((HasWord) oldLabel).word() : oldLabel.value(); Label newLabel = oldLabel.labelFactory().newLabel(wordForm); if (newLabel instanceof HasWord) ((HasWord) newLabel).setWord(wordForm); if (copyPosTag && newLabel instanceof HasTag && oldLabel instanceof HasTag) { String tag = ((HasTag) oldLabel).tag(); ((HasTag) newLabel).setTag(tag); } if (copyIndex && newLabel instanceof HasIndex && oldLabel instanceof HasIndex) { int index = ((HasIndex) oldLabel).index(); ((HasIndex) newLabel).setIndex(index); } return newLabel; }
private CoreLabel getCoreLabel(int labelIndex) { if (originalCoreLabels[labelIndex] != null) { CoreLabel terminalLabel = originalCoreLabels[labelIndex]; if (terminalLabel.value() == null && terminalLabel.word() != null) { terminalLabel.setValue(terminalLabel.word()); } return terminalLabel; } String wordStr = wordIndex.get(words[labelIndex]); CoreLabel terminalLabel = new CoreLabel(); terminalLabel.setValue(wordStr); terminalLabel.setWord(wordStr); terminalLabel.setBeginPosition(beginOffsets[labelIndex]); terminalLabel.setEndPosition(endOffsets[labelIndex]); if (originalTags[labelIndex] != null) { terminalLabel.setTag(originalTags[labelIndex].tag()); } return terminalLabel; }
newLabel.setCategory(s); if (lab instanceof HasTag) { String tag = ((HasTag) lab).tag(); tag = treebankLanguagePack().basicCategory(tag); tag = treebankLanguagePack().stripGF(tag);
@Override public Label newLabel(Label oldLabel) { if (oldLabel instanceof CoreLabel) { return new CoreLabel((CoreLabel)oldLabel); } else { //Map the old interfaces to the correct key/value pairs //Don't need to worry about HasIndex, which doesn't appear in any legacy code CoreLabel label = new CoreLabel(); if (oldLabel instanceof HasWord) label.setWord(((HasWord) oldLabel).word()); if (oldLabel instanceof HasTag) label.setTag(((HasTag) oldLabel).tag()); if (oldLabel instanceof HasOffset) { label.setBeginPosition(((HasOffset) oldLabel).beginPosition()); label.setEndPosition(((HasOffset) oldLabel).endPosition()); } if (oldLabel instanceof HasCategory) label.setCategory(((HasCategory) oldLabel).category()); if (oldLabel instanceof HasIndex) label.setIndex(((HasIndex) oldLabel).index()); label.setValue(oldLabel.value()); return label; } }