Package edu.stanford.nlp.trees.tregex

Examples of edu.stanford.nlp.trees.tregex.TregexPattern


    try {
      BufferedReader br = new BufferedReader(new StringReader(editStr));
      List<TsurgeonPattern> tsp = new ArrayList<TsurgeonPattern>();
      while ((line = br.readLine()) != null) {
        if (DEBUG) System.err.print("Pattern is " + line);
        TregexPattern matchPattern = TregexPattern.compile(line);
        if (DEBUG) System.err.println(" [" + matchPattern + "]");
        tsp.clear();
        while (continuing(line = br.readLine())) {
          TsurgeonPattern p = Tsurgeon.parseOperation(line);
          if (DEBUG) System.err.println("Operation is " + line + " [" + p + "]");
View Full Code Here


    try {
      BufferedReader br = new BufferedReader(new StringReader(editStr));
      List<TsurgeonPattern> tsp = new ArrayList<TsurgeonPattern>();
      while ((line = br.readLine()) != null) {
        if (DEBUG) System.err.print("Pattern is " + line);
        TregexPattern matchPattern = TregexPattern.compile(line);
        if (DEBUG) System.err.println(" [" + matchPattern + "]");
        tsp.clear();
        while (continuing(line = br.readLine())) {
          TsurgeonPattern p = Tsurgeon.parseOperation(line);
          if (DEBUG) System.err.println("Operation is " + line + " [" + p + "]");
View Full Code Here

    }

    TreebankLangParserParams tlpp = new EnglishTreebankParserParams();
    DiskTreebank tb = null;
    String encoding = "UTF-8";
    TregexPattern rootMatch = null;
   
    for(int i = 0; i < args.length; i++) {
      if(args[i].startsWith("-")) {
        switch (args[i]) {
          case "-l":
            Language lang = Language.valueOf(args[++i].trim());
            tlpp = Languages.getLanguageParams(lang);

            break;
          case "-e":
            encoding = args[++i];

            break;
          default:
            System.out.println(usage.toString());
            System.exit(-1);
        }

      } else {
        rootMatch = TregexPattern.compile("@" + args[i++]);

        if(tb == null) {
          if(tlpp == null) {
            System.out.println(usage.toString());
            System.exit(-1);
          } else {
            tlpp.setInputEncoding(encoding);
            tlpp.setOutputEncoding(encoding);
            tb = tlpp.diskTreebank();
          }
        }
        tb.loadPath(args[i++]);
      }
    }

    Counter<String> rhsCounter = new ClassicCounter<String>();
    for(Tree t : tb) {
      TregexMatcher m = rootMatch.matcher(t);
      while(m.findNextMatchingNode()) {
        Tree match = m.getMatch();
        StringBuilder sb = new StringBuilder();
        for(Tree kid : match.children())
          sb.append(kid.value()).append(" ");
View Full Code Here

        }
      }

      final String enumerationPattern = "NP < (NP=tmp $.. (/,|CC/ $.. NP))";

      TregexPattern tgrepPattern = TregexPattern.compile(enumerationPattern);
      TregexMatcher m = tgrepPattern.matcher(this.mentionSubTree);
      while (m.find()) {
        //        Tree t = m.getMatch();
        if(this.mentionSubTree==m.getNode("tmp")
           && this.spanToString().toLowerCase().contains(" and ")) {
          number = Number.PLURAL;
View Full Code Here

      }
      compiler = new TregexPatternCompiler(hf);
    }
    Macros.addAllMacros(compiler, macroFilename, encoding);
    if (argsMap.containsKey(patternOperationOption)) {
      TregexPattern matchPattern = compiler.compile(argsMap.get(patternOperationOption)[0]);
      TsurgeonPattern p = parseOperation(argsMap.get(patternOperationOption)[1]);
      ops.add(new Pair<TregexPattern,TsurgeonPattern>(matchPattern,p));
    } else {
      for (String arg : args) {
        List<Pair<TregexPattern,TsurgeonPattern>> pairs = getOperationsFromFile(arg, encoding, compiler);
View Full Code Here

    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);
  }
View Full Code Here

   * @return tree visitor that contains the trees that were matched as well as the parts of those trees that matched
   */
  private TRegexGUITreeVisitor getMatchTreeVisitor(String patternString, Thread t) {
    TRegexGUITreeVisitor vis = null;
    try {
      TregexPattern pattern = compiler.compile(patternString);
      vis = new TRegexGUITreeVisitor(pattern); //handles);
      List<FileTreeNode> treebanks = FilePanel.getInstance().getActiveTreebanks();
      double multiplier = 100.0/treebanks.size();
      int treebankNum = 1;
      for (FileTreeNode treebank : treebanks) {
View Full Code Here

      this.sourcePattern = null;
    }

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

    }
    List<Pair<TregexPattern,TsurgeonPattern>> ops = new ArrayList<Pair<TregexPattern,TsurgeonPattern>>();


    if (argsMap.containsKey(patternOperationOption)) {
      TregexPattern matchPattern = TregexPattern.compile(argsMap.get(patternOperationOption)[0]);
      TsurgeonPattern p = parseOperation(argsMap.get(patternOperationOption)[1]);
      ops.add(new Pair<TregexPattern,TsurgeonPattern>(matchPattern,p));
    }
    else {
      for(String arg : args) {
View Full Code Here

   * @return A pair of a tregex and tsurgeon pattern read from a file
   * @throws IOException If any IO problem
   */
  public static Pair<TregexPattern, TsurgeonPattern> getOperationFromReader(BufferedReader reader) throws IOException {
    String patternString = getPatternFromFile(reader);
    TregexPattern matchPattern;
    try {
      matchPattern = TregexPattern.compile(patternString);
    } catch (edu.stanford.nlp.trees.tregex.ParseException e) {
      System.err.println("Error parsing your tregex pattern:\n" + patternString);
      throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.trees.tregex.TregexPattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.