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


Java TregexPatternCompiler.compile方法代码示例

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


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

示例1: getOperationFromReader

import edu.stanford.nlp.trees.tregex.TregexPatternCompiler; //导入方法依赖的package包/类
/**
 * Parses a tsurgeon script text input and compiles a tregex pattern and a list
 * of tsurgeon operations into a pair.
 *
 * @param reader Reader to read patterns from
 * @return A pair of a tregex and tsurgeon pattern read from a file, or <code>null</code>
 *    when the operations in the Reader have been exhausted
 * @throws IOException If any IO problem
 */
public static Pair<TregexPattern, TsurgeonPattern> getOperationFromReader(BufferedReader reader, TregexPatternCompiler compiler) throws IOException {
  String patternString = getTregexPatternFromReader(reader);
  // System.err.println("Read tregex pattern: " + patternString);
  if ("".equals(patternString)) {
    return null;
  }
  TregexPattern matchPattern = compiler.compile(patternString);

  TsurgeonPattern collectedPattern = getTsurgeonOperationsFromReader(reader);
  return new Pair<TregexPattern,TsurgeonPattern>(matchPattern,collectedPattern);
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:21,代码来源:Tsurgeon.java

示例2: GrammaticalRelation

import edu.stanford.nlp.trees.tregex.TregexPatternCompiler; //导入方法依赖的package包/类
private GrammaticalRelation(Language language,
                           String shortName,
                           String longName,
                           Class<? extends GrammaticalRelationAnnotation> annotation,
                           GrammaticalRelation parent,
                           String sourcePattern,
                           TregexPatternCompiler tregexCompiler,
                           String[] targetPatterns,
                           String specificString) {
  this.language = language;
  this.shortName = shortName;
  this.longName = longName;
  this.parent = parent;
  this.specific = specificString; // this can be null!

  if (parent != null) {
    parent.addChild(this);
  }

  if (annotation != null) {
    if (GrammaticalRelation.annotationsToRelations.put(annotation, this) != null) {
      throw new IllegalArgumentException("Annotation cannot be associated with more than one relation!");
    }
    if (GrammaticalRelation.relationsToAnnotations.put(this, annotation) != null) {
      throw new IllegalArgumentException("There should only ever be one instance of each relation!");
    }
  }

  if (sourcePattern != null) {
    try {
      this.sourcePattern = Pattern.compile(sourcePattern);
    } catch (java.util.regex.PatternSyntaxException e) {
      throw new RuntimeException("Bad pattern: " + sourcePattern);
    }
  } else {
    this.sourcePattern = null;
  }

  for (String pattern : targetPatterns) {
    try {
      TregexPattern p = tregexCompiler.compile(pattern);
      this.targetPatterns.add(p);
    } catch (edu.stanford.nlp.trees.tregex.TregexParseException pe) {
      throw new RuntimeException("Bad pattern: " + pattern, pe);
    }
  }

  Map<String, GrammaticalRelation> sToR = stringsToRelations.get(language);
  if (sToR == null) {
    sToR = Generics.newHashMap();
    stringsToRelations.put(language, sToR);
  }
  GrammaticalRelation previous = sToR.put(toString(), this);
  if (previous != null) {
    if (!previous.isFromString() && !isFromString()) {
      throw new IllegalArgumentException("There is already a relation named " + toString() + '!');
    } else {
      /* We get here if we previously just built a fake relation from a string
       * we previously read in from a file.
       */
      // TODO is it worth copying all of the information from this real
      //      relation into the old fake one?
    }
  }
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:66,代码来源:GrammaticalRelation.java


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