本文整理汇总了Java中edu.stanford.nlp.ling.HasTag类的典型用法代码示例。如果您正苦于以下问题:Java HasTag类的具体用法?Java HasTag怎么用?Java HasTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HasTag类属于edu.stanford.nlp.ling包,在下文中一共展示了HasTag类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: myExtractor
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
private static Sentence<TaggedWord> myExtractor(Tree t, Sentence<TaggedWord> ty) {
Tree[] kids = t.children();
// this inlines the content of t.isPreTerminal()
if (kids.length == 1 && kids[0].isLeaf()) {
if (t.label() instanceof HasTag) {
// System.err.println("Object is: " + ((CategoryWordTag) t.label()).toString("full"));
ty.add(new TaggedWord(kids[0].label().value(), ((HasTag) t.label()).tag()));
} else {
// System.err.println("Object is: " + StringUtils.getShortClassName(t.label()) + " " + t.label());
ty.add(new TaggedWord(kids[0].label().value(), t.label().value()));
}
} else {
for (int i = 0; i < kids.length; i++) {
myExtractor(kids[i], ty);
}
}
return ty;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:19,代码来源:TaggingEval.java
示例2: makeDependencyLabel
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
/**
* 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;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:28,代码来源:Tree.java
示例3: vpContainsParticiple
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
private static boolean vpContainsParticiple(Tree t) {
for (Tree kid : t.children()) {
if (DEBUG) {
System.err.println("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) {
System.err.println("vpContainsParticiple found VBN/VBG/VBD VP");
}
return true;
}
}
}
return false;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:25,代码来源:SemanticHeadFinder.java
示例4: setMissingTags
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
/**
* Set the tags of the original tokens and the leaves if they
* aren't already set
*/
public static void setMissingTags(CoreMap sentence, Tree tree) {
List<TaggedWord> taggedWords = null;
List<Label> leaves = null;
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
for (int i = 0; i < tokens.size(); ++i) {
CoreLabel token = tokens.get(i);
if (token.tag() == null) {
if (taggedWords == null) {
taggedWords = tree.taggedYield();
}
if (leaves == null) {
leaves = tree.yield();
}
token.setTag(taggedWords.get(i).tag());
Label leaf = leaves.get(i);
if (leaf instanceof HasTag) {
((HasTag) leaf).setTag(taggedWords.get(i).tag());
}
}
}
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:26,代码来源:ParserAnnotatorUtils.java
示例5: setMissingTags
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
/**
* Set the tags of the original tokens and the leaves if they
* aren't already set
*/
public static void setMissingTags(CoreMap sentence, Tree tree) {
List<TaggedWord> taggedWords = null;
List<Label> leaves = null;
List<CoreLabel> tokens = sentence.get(TokensAnnotation.class);
for (int i = 0; i < tokens.size(); ++i) {
CoreLabel token = tokens.get(i);
if (token.tag() == null) {
if (taggedWords == null) {
taggedWords = tree.taggedYield();
}
if (leaves == null) {
leaves = tree.yield();
}
token.setTag(taggedWords.get(i).tag());
Label leaf = leaves.get(i);
if (leaf instanceof HasTag) {
((HasTag) leaf).setTag(taggedWords.get(i).tag());
}
}
}
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:26,代码来源:ParserAnnotatorUtils.java
示例6: transformTree
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
public Tree transformTree(Tree tree) {
Label lab = tree.label();
if (tree.isLeaf()) {
Tree leaf = tf.newLeaf(lab);
leaf.setScore(tree.score());
return leaf;
}
String s = lab.value();
s = treebankLanguagePack().basicCategory(s);
int numKids = tree.numChildren();
List<Tree> children = new ArrayList<Tree>(numKids);
for (int cNum = 0; cNum < numKids; cNum++) {
Tree child = tree.getChild(cNum);
Tree newChild = transformTree(child);
// cdm 2007: for just subcategory stripping, null shouldn't happen
// if (newChild != null) {
children.add(newChild);
// }
}
// if (children.isEmpty()) {
// return null;
// }
CategoryWordTag newLabel = new CategoryWordTag(lab);
newLabel.setCategory(s);
if (lab instanceof HasTag) {
String tag = ((HasTag) lab).tag();
tag = treebankLanguagePack().basicCategory(tag);
newLabel.setTag(tag);
}
Tree node = tf.newTreeNode(newLabel, children);
node.setScore(tree.score());
return node;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:34,代码来源:AbstractTreebankParserParams.java
示例7: accept
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
public boolean accept(Dependency<G, D, N> d) {
if (d == null) {
return false;
}
if ( ! (d.dependent() instanceof HasTag)) {
return false;
}
String tag = ((HasTag) d.dependent()).tag();
return tagRejectFilter.accept(tag);
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:11,代码来源:Dependencies.java
示例8: transformTree
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
@Override
public Tree transformTree(Tree tree) {
Label lab = tree.label();
if (tree.isLeaf()) {
Tree leaf = tf.newLeaf(lab);
leaf.setScore(tree.score());
return leaf;
}
String s = lab.value();
s = treebankLanguagePack().basicCategory(s);
int numKids = tree.numChildren();
List<Tree> children = new ArrayList<Tree>(numKids);
for (int cNum = 0; cNum < numKids; cNum++) {
Tree child = tree.getChild(cNum);
Tree newChild = transformTree(child);
// cdm 2007: for just subcategory stripping, null shouldn't happen
// if (newChild != null) {
children.add(newChild);
// }
}
// if (children.isEmpty()) {
// return null;
// }
CategoryWordTag newLabel = new CategoryWordTag(lab);
newLabel.setCategory(s);
if (lab instanceof HasTag) {
String tag = ((HasTag) lab).tag();
tag = treebankLanguagePack().basicCategory(tag);
newLabel.setTag(tag);
}
Tree node = tf.newTreeNode(newLabel, children);
node.setScore(tree.score());
return node;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:35,代码来源:AbstractTreebankParserParams.java
示例9: accept
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
public boolean accept(Dependency<G, D, N> d) {
/*
System.err.println("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.accept(tag);
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:16,代码来源:Dependencies.java
示例10: isVerbalAuxiliary
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
private boolean isVerbalAuxiliary(Tree preterminal, Set<String> verbalSet, boolean allowJustTagMatch) {
if (preterminal.isPreTerminal()) {
Label kidLabel = preterminal.label();
String tag = null;
if (kidLabel instanceof HasTag) {
tag = ((HasTag) kidLabel).tag();
}
if (tag == null) {
tag = preterminal.value();
}
Label wordLabel = preterminal.firstChild().label();
String word = null;
if (wordLabel instanceof HasWord) {
word = ((HasWord) wordLabel).word();
}
if (word == null) {
word = wordLabel.value();
}
if (DEBUG) {
System.err.println("Checking " + preterminal.value() + " head is " + word + '/' + tag);
}
String lcWord = word.toLowerCase();
if (allowJustTagMatch && unambiguousAuxiliaryTags.contains(tag) || verbalTags.contains(tag) && verbalSet.contains(lcWord)) {
if (DEBUG) {
System.err.println("isAuxiliary found desired type of aux");
}
return true;
}
}
return false;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:33,代码来源:SemanticHeadFinder.java
示例11: transformTree
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
@Override
public Tree transformTree(Tree t, Tree root) {
String baseCat = t.value();
StringBuilder newCategory = new StringBuilder();
//Add manual state splits
for (Pair<TregexPattern,Function<TregexMatcher,String>> e : activeAnnotations) {
TregexMatcher m = e.first().matcher(root);
if (m.matchesAt(t))
newCategory.append(e.second().apply(m));
}
// WSGDEBUG
//Add morphosyntactic features if this is a POS tag
if(t.isPreTerminal() && tagSpec != null) {
if( !(t.firstChild().label() instanceof CoreLabel) || ((CoreLabel) t.firstChild().label()).originalText() == null )
throw new RuntimeException(String.format("%s: Term lacks morpho analysis: %s",this.getClass().getName(),t.toString()));
String morphoStr = ((CoreLabel) t.firstChild().label()).originalText();
MorphoFeatures feats = tagSpec.strToFeatures(morphoStr);
baseCat = feats.getTag(baseCat);
}
//Update the label(s)
String newCat = baseCat + newCategory.toString();
t.setValue(newCat);
if (t.isPreTerminal() && t.label() instanceof HasTag)
((HasTag) t.label()).setTag(newCat);
return t;
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:33,代码来源:ArabicTreebankParserParams.java
示例12: transformTree
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
@Override
public Tree transformTree(Tree t, Tree root) {
String baseCat = t.value();
StringBuilder newCategory = new StringBuilder();
//Add manual state splits
for (Pair<TregexPattern,Function<TregexMatcher,String>> e : activeAnnotations) {
TregexMatcher m = e.first().matcher(root);
if (m.matchesAt(t))
newCategory.append(e.second().apply(m));
}
//Add morphosyntactic features if this is a POS tag
if(t.isPreTerminal() && tagSpec != null) {
if( !(t.firstChild().label() instanceof CoreLabel) || ((CoreLabel) t.firstChild().label()).originalText() == null )
throw new RuntimeException(String.format("%s: Term lacks morpho analysis: %s",this.getClass().getName(),t.toString()));
String morphoStr = ((CoreLabel) t.firstChild().label()).originalText();
Pair<String,String> lemmaMorph = MorphoFeatureSpecification.splitMorphString("", morphoStr);
MorphoFeatures feats = tagSpec.strToFeatures(lemmaMorph.second());
baseCat = feats.getTag(baseCat);
}
//Update the label(s)
String newCat = baseCat + newCategory.toString();
t.setValue(newCat);
if (t.isPreTerminal() && t.label() instanceof HasTag)
((HasTag) t.label()).setTag(newCat);
return t;
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:33,代码来源:FrenchTreebankParserParams.java
示例13: setCorrectTags
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
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();
}
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:8,代码来源:TestSentence.java
示例14: tagSentence
import edu.stanford.nlp.ling.HasTag; //导入依赖的package包/类
/**
* Tags the sentence s by running maxent model. Returns a sentence (List) of
* TaggedWord objects.
*
* @param s Input sentence (List). This isn't changed.
* @return Tagged sentence
*/
public ArrayList<TaggedWord> tagSentence(List<? extends HasWord> s,
boolean reuseTags) {
this.origWords = new ArrayList<HasWord>(s);
int sz = s.size();
this.sent = new ArrayList<String>(sz + 1);
for (int j = 0; j < sz; j++) {
if (maxentTagger.wordFunction != null) {
sent.add(maxentTagger.wordFunction.apply(s.get(j).word()));
} else {
sent.add(s.get(j).word());
}
}
sent.add(TaggerConstants.EOS_WORD);
if (reuseTags) {
this.originalTags = new ArrayList<String>(sz + 1);
for (int j = 0; j < sz; ++j) {
if (s.get(j) instanceof HasTag) {
originalTags.add(((HasTag) s.get(j)).tag());
} else {
originalTags.add(null);
}
}
originalTags.add(TaggerConstants.EOS_TAG);
}
size = sz + 1;
if (VERBOSE) {
System.err.println("Sentence is " + Sentence.listToString(sent, false, tagSeparator));
}
init();
result = testTagInference();
if (maxentTagger.wordFunction != null) {
for (int j = 0; j < sz; ++j) {
result.get(j).setWord(s.get(j).word());
}
}
return result;
}
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:45,代码来源:TestSentence.java
注:本文中的edu.stanford.nlp.ling.HasTag类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论