edu.stanford.nlp.ie.pcfg
Class XRule

java.lang.Object
  |
  +--edu.stanford.nlp.ie.pcfg.XRule

public class XRule
extends Object

Grammar rules with probabilities.


Field Summary
 XLabel lhs
          the left-hand side of the rule
 double p
          the XRule's probability
 ArrayList rhs
          the right-hand side of the rule.
 
Constructor Summary
XRule(String s)
          creates a new XRule by parsing a string.
XRule(XLabel lhs)
          creates a new XRule with an empty RHS and p == 1
 
Method Summary
 void Copy(XRule fromRule, boolean includeHead, boolean includeTags)
          copies head and tag information from fromRule.
static List GetSimilar(XRule rule, List rules, boolean includeHead, boolean includeTags)
          Gets all the rules in a list that are similar to a key rule.
 List GetTags()
          gets a list of all tags found anywhere in the rule
static List GetTags(List rules)
          gets a list of all tags found anywhere in a list of XRules
 int hashCode()
          compares this XRule to another object.
static ArrayList ReadRules(String fn)
          Reads XRules from a file
 boolean Similar(XRule rule2, boolean includeHead, boolean includeTags)
          compares two rules.
static boolean Similar(XRule rule1, XRule rule2, boolean includeHead, boolean includeTags)
          compares two rules.
 String toString()
          produces full string representation of XRule.
 String toString(boolean isLex)
          XRules have the following string format: "LHS -> RHS %% p".
 String toString(boolean includeHead, boolean includeTags)
          XRules have the following string format: "LHS -> RHS %% p".
 String toString(boolean includeHead, boolean includeLHSTags, boolean includeRHSTags)
          XRules have the following string format: "LHS -> RHS %% p".
static void WriteRules(List rules, String fn, boolean isLex)
          Writes rules to a file.
static void WriteRules(List rules, String fn, boolean includeHead, boolean includeLHSTags, boolean includeRHSTags)
          Writes rules to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lhs

public XLabel lhs
the left-hand side of the rule


rhs

public ArrayList rhs
the right-hand side of the rule. a list of XLabels


p

public double p
the XRule's probability

Constructor Detail

XRule

public XRule(XLabel lhs)
creates a new XRule with an empty RHS and p == 1


XRule

public XRule(String s)
creates a new XRule by parsing a string. see toString for format information

Method Detail

toString

public String toString(boolean includeHead,
                       boolean includeLHSTags,
                       boolean includeRHSTags)
XRules have the following string format: "LHS -> RHS %% p". e.g., "S[{purchaser}] -> NP[{purchaser}] VP+bought %% 0.38".

Parameters:
includeHead - true if head information should be included in the output string.
includeLHSTags - true if tag information should be included in the LHS of the output string

toString

public String toString(boolean includeHead,
                       boolean includeTags)
XRules have the following string format: "LHS -> RHS %% p". e.g., "S[{purchaser}] -> NP[{purchaser}] VP+bought %% 0.38".

Parameters:
includeHead - true if head information should be included in the output string.
includeTags - true if tag information should be included in the output string.

toString

public String toString(boolean isLex)
XRules have the following string format: "LHS -> RHS %% p". e.g., "S[{purchaser}] -> NP[{purchaser}] VP+bought %% 0.38".

Parameters:
isLex - calls toString(true, true, !isLex)

toString

public String toString()
produces full string representation of XRule. calls toString(false)

Overrides:
toString in class Object

hashCode

public int hashCode()
compares this XRule to another object.

Overrides:
hashCode in class Object
Returns:
true iff the o is an XRule and it is exactly equal to this XRule. / public boolean equals (Object o) { if (!(o instanceof XRule)) return false; return (toString().equals(o.toString())); } /** returns a hash code for this XRule. Useful when storing XRules in a HashMap

Copy

public void Copy(XRule fromRule,
                 boolean includeHead,
                 boolean includeTags)
copies head and tag information from fromRule. DOES NOT copy type information. Expects that this rule and fromRule have the same RHS length.

Parameters:
fromRule - the rule supplying the head, tag information
includeHead - copy head information
includeTags - copy tag information

Similar

public boolean Similar(XRule rule2,
                       boolean includeHead,
                       boolean includeTags)
compares two rules. ignores (i.e., doesn't consider) XRule probability.

Parameters:
includeHead - if false, ignore head information when making comparison.
includeTags - if false, ignore tag information when making comparison.
Returns:
true if rules are exactly the same (except for ignored information).

Similar

public static boolean Similar(XRule rule1,
                              XRule rule2,
                              boolean includeHead,
                              boolean includeTags)
compares two rules. ignores (i.e., doesn't consider) XRule probability.

Parameters:
includeHead - if false, ignore head information when making comparison
includeTags - if false, ignore tag information when making comparison

GetTags

public List GetTags()
gets a list of all tags found anywhere in the rule


GetTags

public static List GetTags(List rules)
gets a list of all tags found anywhere in a list of XRules

Parameters:
rules - a list of XRules

ReadRules

public static ArrayList ReadRules(String fn)
                           throws IOException
Reads XRules from a file

IOException

WriteRules

public static void WriteRules(List rules,
                              String fn,
                              boolean includeHead,
                              boolean includeLHSTags,
                              boolean includeRHSTags)
                       throws IOException
Writes rules to a file.

Parameters:
rules - a list of XRules
fn - filename
includeHead - write head information
includeLHSTags - write left-hand side tags
includeRHSTags - write right-hand side tags
IOException

WriteRules

public static void WriteRules(List rules,
                              String fn,
                              boolean isLex)
                       throws IOException
Writes rules to a file. Calls WriteRules(rules, fn, true, true, !isLex)

Parameters:
rules - a list of XRules
fn - filename
isLex - if writing a lexicon (as opposed to a grammar). See README
IOException

GetSimilar

public static List GetSimilar(XRule rule,
                              List rules,
                              boolean includeHead,
                              boolean includeTags)
Gets all the rules in a list that are similar to a key rule.

Parameters:
rule - the key
rules - a list of XRules.
includeHead - use head information when computing similarity. see XRule.Similar
includeTags - use tag information when computing similarity. see XRule.Similar
Returns:
every element of rules that is "similar" to rule.


Stanford NLP Group