edu.stanford.nlp.trees.tregex
Class TregexPatternCompiler

java.lang.Object
  extended by edu.stanford.nlp.trees.tregex.TregexPatternCompiler

public class TregexPatternCompiler
extends java.lang.Object

A class for compiling TregexPatterns with specific HeadFinders and or basicCategoryFunctions.

Author:
Galen Andrew

Field Summary
static TregexPatternCompiler defaultCompiler
           
 
Constructor Summary
TregexPatternCompiler()
           
TregexPatternCompiler(Function<java.lang.String,java.lang.String> basicCatFunction)
          A compiler that uses this basicCatFunction and the default HeadFinder.
TregexPatternCompiler(HeadFinder headFinder)
          A compiler that uses this HeadFinder and the default basicCategoryFunction
TregexPatternCompiler(HeadFinder headFinder, Function<java.lang.String,java.lang.String> basicCatFunction)
          A compiler that uses this HeadFinder and this basicCategoryFunction
 
Method Summary
 void addMacro(java.lang.String original, java.lang.String replacement)
          Define a macro for rewriting a pattern in any tregex expression compiled by this compiler.
 TregexPattern compile(java.lang.String tregex)
          Create a TregexPattern from this tregex string using the headFinder and basicCat function this TregexPatternCompiler was created with.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultCompiler

public static final TregexPatternCompiler defaultCompiler
Constructor Detail

TregexPatternCompiler

public TregexPatternCompiler()

TregexPatternCompiler

public TregexPatternCompiler(Function<java.lang.String,java.lang.String> basicCatFunction)
A compiler that uses this basicCatFunction and the default HeadFinder.

Parameters:
basicCatFunction - the function mapping Strings to Strings

TregexPatternCompiler

public TregexPatternCompiler(HeadFinder headFinder)
A compiler that uses this HeadFinder and the default basicCategoryFunction

Parameters:
headFinder - the HeadFinder

TregexPatternCompiler

public TregexPatternCompiler(HeadFinder headFinder,
                             Function<java.lang.String,java.lang.String> basicCatFunction)
A compiler that uses this HeadFinder and this basicCategoryFunction

Parameters:
headFinder - the HeadFinder
basicCatFunction - The function mapping Strings to Strings
Method Detail

addMacro

public void addMacro(java.lang.String original,
                     java.lang.String replacement)
Define a macro for rewriting a pattern in any tregex expression compiled by this compiler. The semantics of this is that all instances of the original in the pattern are replaced by the replacement, using exactly the semantics of String.replaceAll(original, replacement) and the result will then be compiled by the compiler. As such, note that a macro can replace any part of a tregex expression, in a syntax insensitive way. Here's an example: tpc.addMacro("FINITE_BE_AUX", "/^(?i:am|is|are|was|were)$/");

Parameters:
original - The String to match; becomes the first argument of a String.replaceAll()
replacement - The replacement String; becomes the second argument of a String.replaceAll()

compile

public TregexPattern compile(java.lang.String tregex)
Create a TregexPattern from this tregex string using the headFinder and basicCat function this TregexPatternCompiler was created with. Implementation note: If there is an invalid token in the Tregex parser, JavaCC will throw a TokenMgrError. This is a class that extends Error, not Exception (OMG! - bad!), and so rather than requiring clients to catch it, we wrap it in a ParseException. (The original Error's are thrown in TregexParserTokenManager.)

Parameters:
tregex - The pattern to parse
Returns:
A new TregexPattern object based on this string
Throws:
TregexParseException - If the expression is syntactically invalid


Stanford NLP Group