|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.umn.cs.nlp.parser.PGrammar
public class PGrammar
Probabilistic 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 | |
---|---|
PGrammar(String databaseName,
String databaseDirectory)
Opens a grammar stored in the specified database. |
|
PGrammar(String databaseName,
String databaseDirectory,
boolean allowDuplicates,
int maximumUnaryChainDepth,
boolean treatTerminalRulesSpecially)
Opens a grammar stored in the specified database. |
Method Summary | |
---|---|
void |
addRule(BasicRuleLHS lhs,
String rhs)
|
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. |
String |
toString()
Returns a string representation of the grammar, with one line per rule. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PGrammar(String databaseName, String databaseDirectory, boolean allowDuplicates, int maximumUnaryChainDepth, boolean treatTerminalRulesSpecially)
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 databasemaximumUnaryChainDepth
- the maximum depth that unary rule chains are allowedtreatTerminalRulesSpecially
- if true
, rules of the form (NT => terminal) do not count towards the unary chain depthpublic PGrammar(String databaseName, String databaseDirectory)
This constructor is equivalent to PGrammar(databaseName,databaseDirectory,true,Integer.MAX_VALUE,false)
databaseName
- the name of the rules databasedatabaseDirectory
- the directory where the database file are stored - this directory must already existMethod 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 void addRule(BasicRuleLHS lhs, String rhs)
public ParseTree parse(String sentence)
Returns the most likely complete parse of the sentence.
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)
Returns the most likely complete parse of the sentence.
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 String toString()
WARNING: This method calls PRuleDatabase.toString. That method involves creating a Collection that contains every rule in the database. If the rule database that backs the grammar is large, calling this method will use very large amounts of memory.
toString
in class Object
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 |