|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umn.cs.nlp.parser.CNFGrammar
public class CNFGrammar
Grammar capable of parsing using the CKY parsing algorithm.
Rules in this grammar are required to be in Chomsky Normal Form (CNF).
Constructor Summary | |
---|---|
CNFGrammar()
Constructs a new grammar, the rules of which are required to be in Chomsky Normal Form (CNF). |
Method Summary | |
---|---|
void |
addLexicalRule(String lhs,
String rhs)
Add a new unary rule to the grammar. |
void |
addRule(String lhs,
String rhs1,
String rhs2)
Add a new binary rule to the grammar. |
static void |
main(String[] args)
Example usage of this class with a small sample grammar and test sentences. |
ParseTree |
parse(String... token)
Attempts to parse the given series of tokens using this grammar. |
ParseTree |
parse(String sentence)
Attempts to parse the given sentence using this grammar. |
Collection<ParseTree> |
parseAll(String... sentences)
Attempts to parse each of the given sentences using parse(String sentence) . |
boolean |
parses(String... token)
Determines if the given series of tokens can be successfully parsed by this grammar. |
boolean |
parses(String sentence)
Determines if the given sentence can be successfully parsed by this grammar. |
void |
setLocale(Locale locale)
Sets the locale. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CNFGrammar()
Method Detail |
---|
public void addRule(String lhs, String rhs1, String rhs2)
lhs
- The left-hand-side of the rule. Must be a non-terminal.rhs1
- The left child of the rule. Must be a non-terminal.rhs2
- The right child of the rule. Must be a non-terminal.public void addLexicalRule(String lhs, String rhs)
lhs
- The left-hand-side of the rule. Must be a non-terminal.rhs
- The child of the rule. Must be a terminal.public boolean parses(String sentence)
parses
in interface GrammarInterface
sentence
- The sentence to be parsed. Will be lowercased using the current locale and then tokenized prior to parsing.
true
if this grammar can parse the given sentence;
false
otherwise.setLocale(Locale)
public boolean parses(String... token)
parses
in interface GrammarInterface
token
- Array of tokens specifying the sentence to be parsed. No lowercasing will be performed by this method.
true
if this grammar can parse the given sentence;
false
otherwise.public ParseTree parse(String sentence)
If the grammar produces more than one parse of the sentence, an arbitrary valid parse is returned.
parse
in interface GrammarInterface
sentence
- The sentence to be parsed. Will be lowercased using the current locale and then tokenized prior to parsing.
ParseTree.NULL_PARSE
otherwise.setLocale(Locale)
public ParseTree parse(String... token)
If the grammar produces more than one parse of the sentence, an arbitrary valid parse is returned.
parse
in interface GrammarInterface
token
- Array of tokens specifying the sentence to be parsed. No lowercasing will be performed by this method.
ParseTree.NULL_PARSE
otherwise.public Collection<ParseTree> parseAll(String... sentences)
parse(String sentence)
.
parseAll
in interface GrammarInterface
sentences
- the sentences to be parsed.
ParseTree
per sentencepublic void setLocale(Locale locale)
parse(String sentence)
and by parses(String sentence)
when lowercasing the sentence.
locale
- the locale to use when performing lowercasingString.toLowerCase(Locale)
public static void main(String[] args)
args
- arguments are ignored
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |