当前位置: 首页>>代码示例>>Java>>正文


Java GrammaticalRelation.valueOf方法代码示例

本文整理汇总了Java中edu.stanford.nlp.trees.GrammaticalRelation.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java GrammaticalRelation.valueOf方法的具体用法?Java GrammaticalRelation.valueOf怎么用?Java GrammaticalRelation.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.trees.GrammaticalRelation的用法示例。


在下文中一共展示了GrammaticalRelation.valueOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStanfordTypedDependencies

import edu.stanford.nlp.trees.GrammaticalRelation; //导入方法依赖的package包/类
public List<TypedDependency> getStanfordTypedDependencies(DependencyForm form) {
    List<TypedDependency> dependencies = new ArrayList<TypedDependency>();
    if (this.nodes == null)
    	nodes = getStanfordTreeGraphNodes(form);

    List<AgigaTypedDependency> agigaDeps = getAgigaDeps(form);
    for (AgigaTypedDependency agigaDep : agigaDeps) {
        // Add one, since the tokens are zero-indexed but the TreeGraphNodes are one-indexed
        TreeGraphNode gov = nodes.get(agigaDep.getGovIdx() + 1);
        TreeGraphNode dep = nodes.get(agigaDep.getDepIdx() + 1);
        // Create the typed dependency
        TypedDependency typedDep = new TypedDependency(GrammaticalRelation.valueOf(agigaDep.getType()), gov, dep);
        dependencies.add(typedDep);
    }
    return dependencies;
}
 
开发者ID:mgormley,项目名称:agiga,代码行数:17,代码来源:StanfordAgigaSentence.java

示例2: getGrammaticalRelation

import edu.stanford.nlp.trees.GrammaticalRelation; //导入方法依赖的package包/类
/**
 * Get the predefined GrammaticalRelation instance or make a new GrammaticalRelation instance
 * 
 * @param name
 * @return
 */
public static GrammaticalRelation getGrammaticalRelation(String name) {
	GrammaticalRelation reln = GrammaticalRelation.valueOf(name, COMMON_RELATIONS);
	if (reln == null)
		reln = GrammaticalRelation.valueOf(Language.English, name);
	return reln;
}
 
开发者ID:hakchul77,项目名称:irnlp_toolkit,代码行数:13,代码来源:StanfordNlpWrapper.java

示例3: convertIntermediateGraph

import edu.stanford.nlp.trees.GrammaticalRelation; //导入方法依赖的package包/类
static SemanticGraph convertIntermediateGraph(IntermediateSemanticGraph ig, List<CoreLabel> sentence) {
  SemanticGraph graph = new SemanticGraph();

  // first construct the actual nodes; keep them indexed by their index
  Map<Integer, IndexedWord> nodes = Generics.newHashMap();
  for(IntermediateNode in: ig.nodes){
    CoreLabel token = sentence.get(in.index - 1); // index starts at 1!
    IndexedWord word = new IndexedWord(in.docId, in.sentIndex, in.index, token);
    word.set(CoreAnnotations.ValueAnnotation.class, word.get(CoreAnnotations.TextAnnotation.class));
    if(in.copyAnnotation >= 0){
      word.set(CoreAnnotations.CopyAnnotation.class, in.copyAnnotation);
    }
    nodes.put(word.index(), word);
  }
  for(IndexedWord node: nodes.values()){
    graph.addVertex(node);
  }

  // add all edges to the actual graph
  for(IntermediateEdge ie: ig.edges){
    IndexedWord source = nodes.get(ie.source);
    assert(source != null);
    IndexedWord target = nodes.get(ie.target);
    assert(target != null);
    synchronized (LOCK) {
      // this is not thread-safe: there are static fields in GrammaticalRelation
      GrammaticalRelation rel = GrammaticalRelation.valueOf(ie.dep);
      graph.addEdge(source, target, rel, 1.0, ie.isExtra);
    }
  }

  // compute root nodes if non-empty
  if( ! graph.isEmpty()){
    graph.resetRoots();
  }

  return graph;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:39,代码来源:CustomAnnotationSerializer.java

示例4: createDependency

import edu.stanford.nlp.trees.GrammaticalRelation; //导入方法依赖的package包/类
/**
 * Given string representations of the dependency's relation, governor and dependent, create
 * the JavaNLP object.
 * @param strReln e.g., nsubj
 * @param strGov  e.g., testified-17
 * @param strDep  e.g., dealer-16
 */
public static TypedDependency createDependency(String strReln, String strGov, String strDep) {
  if( strReln == null || strGov == null || strDep == null ) {
    System.out.println("ERROR: unknown dep format: " + strReln + " " + strGov + " " + strDep);
    System.exit(-1);
  }

  GrammaticalRelation rel = GrammaticalRelation.valueOf(strReln);

  try {
    // "happy-12"
    int hyphen = strGov.length()-2;
    while( hyphen > -1 && strGov.charAt(hyphen) != '-' ) hyphen--;
    if( hyphen < 0 ) return null;
    
    TreeGraphNode gov = new TreeGraphNode(new Word(strGov.substring(0,hyphen)));
    int end = strGov.length();
    // "happy-12'"  -- can have many apostrophes, each indicates the nth copy of this relation
    int copies = 0;
    while( strGov.charAt(end-1) == '\'' ) {
      copies++;
      end--;
    }
    if( copies > 0 ) gov.label().set(CopyAnnotation.class, copies);
    gov.label().setIndex(Integer.parseInt(strGov.substring(hyphen+1,end)));

    // "sad-3"
    hyphen = strDep.length()-2;
    while( hyphen > -1 && strDep.charAt(hyphen) != '-' ) hyphen--;
    if( hyphen < 0 ) return null;
    TreeGraphNode dep = new TreeGraphNode(new Word(strDep.substring(0,hyphen)));
    end = strDep.length();
    // "sad-3'"  -- can have many apostrophes, each indicates the nth copy of this relation
    copies = 0;
    while( strDep.charAt(end-1) == '\'' ) {
      copies++;
      end--;
    }
    if( copies > 0 ) dep.label().set(CopyAnnotation.class, copies);
    dep.label().setIndex(Integer.parseInt(strDep.substring(hyphen+1,end)));

    return new TypedDependency(rel,gov,dep);
  } catch( Exception ex ) {
    System.out.println("createDependency() error with input: " + strReln + " " + strGov + " " + strDep);
    ex.printStackTrace();
  }
  return null;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:55,代码来源:TreeOperator.java

示例5: valueOf

import edu.stanford.nlp.trees.GrammaticalRelation; //导入方法依赖的package包/类
public static GrammaticalRelation valueOf(String s) {
  return GrammaticalRelation.valueOf(s, values());
}
 
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:4,代码来源:ChineseGrammaticalRelations.java


注:本文中的edu.stanford.nlp.trees.GrammaticalRelation.valueOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。