File tree Expand file tree Collapse file tree 4 files changed +13
-2
lines changed
src/edu/stanford/nlp/trees/tregex Expand file tree Collapse file tree 4 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class TregexParser implements TregexParserConstants {
2828 // keep track of which variables we've seen, so that we can reject
2929 // some nonsense patterns such as ones that reset variables or link
3030 // to variables that haven't been set
31- private Set <String > knownVariables = Generics .newHashSet ();
31+ Set <String > knownVariables = Generics .newHashSet ();
3232
3333 public TregexParser (java .io .Reader stream ,
3434 Function <String , String > basicCatFunction ,
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ class TregexParser {
3333 // keep track of which variables we've seen, so that we can reject
3434 // some nonsense patterns such as ones that reset variables or link
3535 // to variables that haven't been set
36- private Set<String> knownVariables = Generics.newHashSet();
36+ Set<String> knownVariables = Generics.newHashSet();
3737
3838 public TregexParser(java.io.Reader stream,
3939 Function<String, String> basicCatFunction,
Original file line number Diff line number Diff line change @@ -361,6 +361,7 @@ public abstract class TregexPattern implements Serializable {
361361 private boolean neg ; // = false;
362362 private boolean opt ; // = false;
363363 private String patternString ;
364+ private Set <String > knownVariables ;
364365
365366 void negate () {
366367 neg = true ;
@@ -484,6 +485,15 @@ void setPatternString(String patternString) {
484485 this .patternString = patternString ;
485486 }
486487
488+ /** Only used by the TregexPatternCompiler to track the known variables in the tregex (and only at the root). Pseudo-final. */
489+ void setKnownVariables (Set <String > knownVariables ) {
490+ this .knownVariables = knownVariables ;
491+ }
492+
493+ public Set <String > knownVariables () {
494+ return Collections .unmodifiableSet (knownVariables );
495+ }
496+
487497 /**
488498 * @return A single-line string representation of the pattern
489499 */
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ public TregexPattern compile(String tregex) {
138138 TregexParser parser = new TregexParser (new StringReader (tregex + '\n' ),
139139 basicCatFunction , headFinder );
140140 pattern = parser .Root ();
141+ pattern .setKnownVariables (parser .knownVariables );
141142 } catch (TokenMgrError tme ) {
142143 throw new TregexParseException ("Could not parse " + tregex , tme );
143144 } catch (ParseException e ) {
You can’t perform that action at this time.
0 commit comments