|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umn.cs.nlp.parser.Grammar
public class Grammar
Context-free grammar capable of parsing sentences using a variant of the CKY+ parsing algorithm.
Rules in this grammar are not required to be in Chomsky Normal Form (CNF).
This class uses a Berkeley DB Java Edition database to store the rules.
Constructor Summary | |
---|---|
Grammar(String databaseName,
String databaseDirectory,
boolean allowDuplicates)
Opens a grammar stored in the specified database. |
Method Summary | |
---|---|
void |
addRule(BasicRuleLHS lhs,
String... rhs)
Add a new rule to the grammar. |
void |
close()
Close 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 Grammar(String databaseName, String databaseDirectory, boolean allowDuplicates)
databaseName
- the name of the rules databasedatabaseDirectory
- the directory where the database file are stored - this directory must already existallowDuplicates
- indicates whether duplicate rules are allowed in the specified databaseMethod Detail |
---|
public void close()
public void addRule(BasicRuleLHS lhs, String... rhs)
lhs
- The left-hand-side of the rule. Must be a non-terminal.rhs
- The right-hand-side children of the rule. Each rhs element may be a terminal or a non-terminal.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 default 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 boolean parses(String sentence)
parses
in interface GrammarInterface
sentence
- The sentence to be parsed. Will be lowercased using the default 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 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 |