corrected and tested documentation for Java

This commit is contained in:
Krasimir Angelov
2017-08-29 14:42:52 +02:00
parent 09d5d9b091
commit 634ec20b38

View File

@@ -81,7 +81,7 @@ A grammar is loaded by calling <span class="python">the method pgf.readPGF</span
Prelude PGF2> gr &lt;- readPGF "App12.pgf" Prelude PGF2> gr &lt;- readPGF "App12.pgf"
</pre> </pre>
<pre class="java"> <pre class="java">
PGF gr = PGF.readPGF("App12.pgf") PGF gr = PGF.readPGF("App12.pgf");
</pre> </pre>
From the grammar you can query the set of available languages. From the grammar you can query the set of available languages.
@@ -100,7 +100,7 @@ Prelude PGF2> :t eng
eng :: Concr eng :: Concr
</pre> </pre>
<pre class="java"> <pre class="java">
Concr eng = gr.getLanguages().get("AppEng") Concr eng = gr.getLanguages().get("AppEng");
</pre> </pre>
<h2>Parsing</h2> <h2>Parsing</h2>
@@ -115,7 +115,7 @@ For example to invoke the parser, you can call:
Prelude PGF2> let res = parse eng (startCat gr) "this is a small theatre" Prelude PGF2> let res = parse eng (startCat gr) "this is a small theatre"
</pre> </pre>
<pre class="java"> <pre class="java">
Iterable&lt;ExprProb&gt; iterable = eng.parse(gr.startCat(), "this is a small theatre") Iterable&lt;ExprProb&gt; iterable = eng.parse(gr.getStartCat(), "this is a small theatre");
</pre> </pre>
<span class="python"> <span class="python">
This gives you an iterator which can enumerate all possible This gives you an iterator which can enumerate all possible
@@ -141,8 +141,8 @@ Prelude PGF2> let Right ((e,p):rest) = res
This gives you an iterable which can enumerate all possible This gives you an iterable which can enumerate all possible
abstract trees. You can get the next tree by calling <tt>next</tt>: abstract trees. You can get the next tree by calling <tt>next</tt>:
<pre class="java"> <pre class="java">
Iterator&lt;ExprProb&gt; iter = iterable.iterator() Iterator&lt;ExprProb&gt; iter = iterable.iterator();
ExprProb ep = iter.next() ExprProb ep = iter.next();
</pre> </pre>
</span> </span>
@@ -161,7 +161,7 @@ Prelude PGF2> print p
35.9166526794 35.9166526794
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(ep.getProb()) System.out.println(ep.getProb());
35.9166526794 35.9166526794
</pre> </pre>
and this is the corresponding abstract tree: and this is the corresponding abstract tree:
@@ -174,7 +174,7 @@ Prelude PGF2> print e
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetNP (DetQuant this_Quant NumSg)) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA small_A) (UseN theatre_N)))))))) NoVoc PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetNP (DetQuant this_Quant NumSg)) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA small_A) (UseN theatre_N)))))))) NoVoc
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(ep.getExpr()) System.out.println(ep.getExpr());
PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetNP (DetQuant this_Quant NumSg)) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA small_A) (UseN theatre_N)))))))) NoVoc PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetNP (DetQuant this_Quant NumSg)) (UseComp (CompNP (DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA small_A) (UseN theatre_N)))))))) NoVoc
</pre> </pre>
@@ -216,7 +216,7 @@ There is also the method <tt>parseWithHeuristics</tt> which
takes two more paramaters which let you to have a better control takes two more paramaters which let you to have a better control
over the parser's behaviour: over the parser's behaviour:
<pre class="java"> <pre class="java">
Iterable&lt;ExprProb&gt; iterable = eng.parseWithHeuristics(gr.startCat(), heuristic_factor, callbacks) Iterable&lt;ExprProb&gt; iterable = eng.parseWithHeuristics(gr.startCat(), heuristic_factor, callbacks);
</pre> </pre>
</span> </span>
@@ -250,7 +250,7 @@ a new expression like this:
Prelude PGF2> let Just e = readExpr "AdjCN (PositA red_A) (UseN theatre_N)" Prelude PGF2> let Just e = readExpr "AdjCN (PositA red_A) (UseN theatre_N)"
</pre> </pre>
<pre class="java"> <pre class="java">
Expr e = Expr.readExpr("AdjCN (PositA red_A) (UseN theatre_N)") Expr e = Expr.readExpr("AdjCN (PositA red_A) (UseN theatre_N)");
</pre> </pre>
and then we can linearize it: and then we can linearize it:
<pre class="python"> <pre class="python">
@@ -262,7 +262,7 @@ Prelude PGF2> putStrLn (linearize eng e)
red theatre red theatre
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(eng.linearize(e)) System.out.println(eng.linearize(e));
red theatre red theatre
</pre> </pre>
This method produces only a single linearization. If you use variants This method produces only a single linearization. If you use variants
@@ -281,7 +281,7 @@ red theater
</pre> </pre>
<pre class="java"> <pre class="java">
for (String s : eng.linearizeAll(e)) { for (String s : eng.linearizeAll(e)) {
System.out.println(s) System.out.println(s);
} }
red theatre red theatre
red theater red theater
@@ -297,7 +297,7 @@ Prelude PGF2> tabularLinearize eng e
fromList [("s Pl Gen","red theatres'"),("s Pl Nom","red theatres"),("s Sg Gen","red theatre's"),("s Sg Nom","red theatre")] fromList [("s Pl Gen","red theatres'"),("s Pl Nom","red theatres"),("s Sg Gen","red theatre's"),("s Sg Nom","red theatre")]
</pre> </pre>
<pre class="java"> <pre class="java">
for (Map.Entry&lt;String,String&gt; entry : eng.tabularLinearize(e)) { for (Map.Entry&lt;String,String&gt; entry : eng.tabularLinearize(e).entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue()); System.out.println(entry.getKey() + ": " + entry.getValue());
} }
s Sg Nom: red theatre s Sg Nom: red theatre
@@ -320,7 +320,7 @@ Prelude PGF2> putStrLn (showBracketedString b)
(CN:4 (AP:1 (A:0 red)) (CN:3 (N:2 theatre))) (CN:4 (AP:1 (A:0 red)) (CN:3 (N:2 theatre)))
</pre> </pre>
<pre class="java"> <pre class="java">
Object[] bs = eng.bracketedLinearize(e) Object[] bs = eng.bracketedLinearize(e);
</pre> </pre>
<span class="python"> <span class="python">
Each element in the sequence above is either a string or an object Each element in the sequence above is either a string or an object
@@ -378,7 +378,7 @@ Prelude PGF2> print (hasLinearization eng "apple_N")
True True
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(eng.hasLinearization("apple_N")) System.out.println(eng.hasLinearization("apple_N"));
true true
</pre> </pre>
@@ -435,8 +435,8 @@ from <tt>unStr</tt> will not be <tt>null</tt> with the actual literal.
For example the output from: For example the output from:
</span> </span>
<pre class="java"> <pre class="java">
Expr e = Expr.readExpr("\"literal\"") Expr elit = Expr.readExpr("\"literal\"");
System.out.println(e.unStr()) System.out.println(elit.unStr());
</pre> </pre>
is just the string "literal". is just the string "literal".
<span class="python">Situations like this can be detected <span class="python">Situations like this can be detected
@@ -446,6 +446,9 @@ for the other possible literal types in GF.</span>
<span class="haskell"> <span class="haskell">
There are also the functions <tt>unAbs</tt>, <tt>unInt</tt>, <tt>unFloat</tt> and <tt>unMeta</tt> for all other possible cases. There are also the functions <tt>unAbs</tt>, <tt>unInt</tt>, <tt>unFloat</tt> and <tt>unMeta</tt> for all other possible cases.
</span> </span>
<span class="java">
There are also the methods <tt>unAbs</tt>, <tt>unInt</tt>, <tt>unFloat</tt> and <tt>unMeta</tt> for all other possible cases.
</span>
</p> </p>
<span class="python"> <span class="python">
@@ -554,7 +557,7 @@ word form with its possible analyses:
Prelude PGF2> mapM_ print [(form,lemma,analysis,prob) | (form,analyses) &lt;- fullFormLexicon eng, (lemma,analysis,prob) &lt- analyses] Prelude PGF2> mapM_ print [(form,lemma,analysis,prob) | (form,analyses) &lt;- fullFormLexicon eng, (lemma,analysis,prob) &lt- analyses]
</pre> </pre>
<pre class="java"> <pre class="java">
for (FullFormEntry entry in eng.fullFormLexicon()) { for (FullFormEntry entry in eng.fullFormLexicon()) { ///// TODO
for (MorphoAnalysis analysis : entry.getAnalyses()) { for (MorphoAnalysis analysis : entry.getAnalyses()) {
System.out.println(entry.getForm()+" "+analysis.getProb()+" "+analysis.getLemma()+" "+analysis.getField()); System.out.println(entry.getForm()+" "+analysis.getProb()+" "+analysis.getLemma()+" "+analysis.getField());
} }
@@ -603,7 +606,7 @@ Prelude PGF2> categories gr
.... ....
</pre> </pre>
<pre class="java"> <pre class="java">
List&lt;String&gt; cats = gr.getCategories() List&lt;String&gt; cats = gr.getCategories();
.... ....
</pre> </pre>
You can also access all functions with the same result category: You can also access all functions with the same result category:
@@ -616,7 +619,7 @@ Prelude PGF2> functionsByCat gr "Weekday"
['friday_Weekday', 'monday_Weekday', 'saturday_Weekday', 'sunday_Weekday', 'thursday_Weekday', 'tuesday_Weekday', 'wednesday_Weekday'] ['friday_Weekday', 'monday_Weekday', 'saturday_Weekday', 'sunday_Weekday', 'thursday_Weekday', 'tuesday_Weekday', 'wednesday_Weekday']
</pre> </pre>
<pre class="java"> <pre class="java">
List&lt;String&gt; cats = gr.getFunctionsByCat("Weekday") List&lt;String&gt; funsByCat = gr.getFunctionsByCat("Weekday");
.... ....
</pre> </pre>
The full type of a function can be retrieved as: The full type of a function can be retrieved as:
@@ -629,7 +632,7 @@ Prelude PGF2> print (functionType gr "DetCN")
Det -> CN -> NP Det -> CN -> NP
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(gr.getFunctionType("DetCN")) System.out.println(gr.getFunctionType("DetCN"));
Det -> CN -> NP Det -> CN -> NP
</pre> </pre>
@@ -653,11 +656,9 @@ Prelude PGF2> print ty
CN CN
</pre> </pre>
<pre class="java"> <pre class="java">
TypedExpr te = gr.inferExpr(e) TypedExpr te = gr.inferExpr(e);
System.out.println(te.getExpr()) System.out.println(te.getExpr()+" : "+te.getType());
AdjCN (PositA red_A) (UseN theatre_N) AdjCN (PositA red_A) (UseN theatre_N) : CN
System.out.println(te.getType())
CN
</pre> </pre>
The result is a potentially updated expression and its type. In this The result is a potentially updated expression and its type. In this
case we always deal with simple types, which means that the new case we always deal with simple types, which means that the new
@@ -678,7 +679,7 @@ Prelude PGF2> print e'
AdjCN (PositA red_A) (UseN theatre_N) AdjCN (PositA red_A) (UseN theatre_N)
</pre> </pre>
<pre class="java"> <pre class="java">
Expr e = gr.checkExpr(e,Type.readType("CN")) Expr new_e = gr.checkExpr(e,Type.readType("CN")); //// TODO
System.out.println(e) System.out.println(e)
</pre> </pre>
<p>In case of type error you will get an error: <p>In case of type error you will get an error:
@@ -826,7 +827,7 @@ n0 -- n3 [style = "solid"]
} }
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(gr.graphvizAbstractTree(e)) System.out.println(gr.graphvizAbstractTree(e)); //// TODO
graph { graph {
n0[label = "AdjCN", style = "solid", shape = "plaintext"] n0[label = "AdjCN", style = "solid", shape = "plaintext"]
n1[label = "PositA", style = "solid", shape = "plaintext"] n1[label = "PositA", style = "solid", shape = "plaintext"]
@@ -915,7 +916,7 @@ graph {
} }
</pre> </pre>
<pre class="java"> <pre class="java">
System.out.println(eng.graphvizParseTree(e)) System.out.println(eng.graphvizParseTree(e)); //// TODO
graph { graph {
node[shape=plaintext] node[shape=plaintext]