|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.uzh.ifi.attempto.chartparser.Grammar
public class Grammar
This class represents a grammar that is needed to run the chart parser. A grammar can be created either directly in Java or on the basis of a file in the ACGN format.
ACGN stands for "Attempto Chartparser Grammar Notation" and uses Prolog notation to provide a nicer
grammar representation. Simple grammar rules in ACGN look almost the same as common Prolog DCG rules.
Just replace the operator
"-->
" by "=>
":
Complex grammar rules in ACGN are different from common Prolog DCG rules in the sense that they are using features rather than arguments with fixed positions. Arguments are not recognized by their position but by their name:vp => v, np. v => [does, not], verb.
Every feature has the formvp(num:Num,neg:Neg) => v(num:Num,neg:Neg,type:tr), np(case:acc). v(neg:plus,type:Type) => [does, not], verb(type:Type).
Name:Value
where Name
has to be an atom and Value
can be a variable, an atom, or a number (but not a compound term).
ACGN supports a special type of rules that are called "inaccessible rules". The operator "~>
"
instead of "=>
" is used for inaccessible rules:
In the case of an inaccessible rule, the potential antecedents that are covered by this rule are not accessible for anaphoric references from outside. In this way, the information about which tokens are accessible for anaphoric references can be retrieved by the methodvp(num:Num,neg:plus) ~> v(num:Num,neg:plus,type:tr), np(case:acc).
getAccessiblePositions
of the ChartParser
class.
ACGN grammars can be translated automatically into a Java class or into a Prolog DCG using the SWI Prolog programs "generate_java.pl" or "generate_dcg.pl", respectively. Those programs can be found in the directory "src/ch/uzh/ifi/attempto/utils" of the source code of this package. The Java class can be generated like this:
Note that the SWI Prolog command might be different on your machine (e.g. "swipl -s generate_java.pl -g "generate_java('my_acgn_grammar.pl', 'my.package', 'MyJavaGrammar', 'my_start_category')" -t halt
plcon
" or "pl
").
The Prolog DCG file can be generated like this:
Note that the information about accessible and inaccessible rules gets lost in the Prolog DCG file.swipl -s generate_dcg.pl -g "generate_dcg('my_acgn_grammar.pl', 'my_dcg_grammar.pl')" -t halt
Constructor Summary | |
---|---|
Grammar(Nonterminal startCategory)
Creates a empty grammar with the given start category. |
|
Grammar(java.lang.String startCategoryName)
Creates a empty grammar with a start category of the given name. |
Method Summary | |
---|---|
void |
addRule(Rule rule)
Adds the rule to the grammar. |
java.util.ArrayList<Rule> |
getEpsilonRules()
Returns all the rules that have no body categories. |
java.util.ArrayList<Rule> |
getRulesByHeadName(java.lang.String name)
Returns the rules whose head category has the given name. |
Nonterminal |
getStartCategory()
Returns the start category. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Grammar(Nonterminal startCategory)
startCategory
- The start category for the grammar.public Grammar(java.lang.String startCategoryName)
startCategoryName
- The name of the start category for the grammar.Method Detail |
---|
public Nonterminal getStartCategory()
public void addRule(Rule rule)
rule
- The rule to be added.public java.util.ArrayList<Rule> getRulesByHeadName(java.lang.String name)
name
- The name of the head category.
public java.util.ArrayList<Rule> getEpsilonRules()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |