mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 01:22:51 -06:00
some missing pieces of documentation for Java
This commit is contained in:
@@ -396,6 +396,13 @@ a tree into a function name and a list of arguments:
|
|||||||
Prelude PGF2> unApp e
|
Prelude PGF2> unApp e
|
||||||
Just ("AdjCN", [..., ...])
|
Just ("AdjCN", [..., ...])
|
||||||
</pre>
|
</pre>
|
||||||
|
<pre class="java">
|
||||||
|
ExprApplication app = e.unApp();
|
||||||
|
System.out.println(app.getFunction());
|
||||||
|
for (Expr arg : app.getArguments()) {
|
||||||
|
System.out.println(arg);
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="python">
|
<span class="python">
|
||||||
@@ -420,6 +427,17 @@ For example the result from:
|
|||||||
Prelude PGF2> readExpr "\"literal\"" >>= unStr
|
Prelude PGF2> readExpr "\"literal\"" >>= unStr
|
||||||
"literal"
|
"literal"
|
||||||
</pre>
|
</pre>
|
||||||
|
<span class="java">
|
||||||
|
The result from <tt>unApp</tt> is not <tt>null</tt> if the expression
|
||||||
|
is an application, and <tt>null</tt> in all other cases.
|
||||||
|
Similarly, if the tree is a literal string then the return value
|
||||||
|
from <tt>unStr</tt> will not be <tt>null</tt> with the actual literal.
|
||||||
|
For example the output from:
|
||||||
|
</span>
|
||||||
|
<pre class="java">
|
||||||
|
Expr e = Expr.readExpr("\"literal\"")
|
||||||
|
System.out.println(e.unStr())
|
||||||
|
</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
|
||||||
in Python by checking the type of the result from <tt>unpack</tt>.
|
in Python by checking the type of the result from <tt>unpack</tt>.
|
||||||
@@ -489,6 +507,14 @@ Prelude PGF2> print e2
|
|||||||
DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA red_A) (UseN theatre_N))
|
DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA red_A) (UseN theatre_N))
|
||||||
</pre>
|
</pre>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="java">
|
||||||
|
using the constructor for <tt>Expr</tt>:
|
||||||
|
<pre class="java">
|
||||||
|
Expr quant = Expr.readExpr("DetQuant IndefArt NumSg");
|
||||||
|
Expr e2 = new Expr("DetCN", new Expr[] {quant, e});
|
||||||
|
System.out.println(e2);
|
||||||
|
</pre>
|
||||||
|
</span>
|
||||||
|
|
||||||
<span class="python">
|
<span class="python">
|
||||||
<h2>Embedded GF Grammars</h2>
|
<h2>Embedded GF Grammars</h2>
|
||||||
@@ -653,8 +679,7 @@ AdjCN (PositA red_A) (UseN theatre_N)
|
|||||||
</pre>
|
</pre>
|
||||||
<pre class="java">
|
<pre class="java">
|
||||||
Expr e = gr.checkExpr(e,Type.readType("CN"))
|
Expr e = gr.checkExpr(e,Type.readType("CN"))
|
||||||
>>> System.out.println(e)
|
System.out.println(e)
|
||||||
AdjCN (PositA red_A) (UseN theatre_N)
|
|
||||||
</pre>
|
</pre>
|
||||||
<p>In case of type error you will get an error:
|
<p>In case of type error you will get an error:
|
||||||
<pre class="python">
|
<pre class="python">
|
||||||
@@ -668,7 +693,7 @@ Prelude PGF2> putStrLn msg
|
|||||||
</pre>
|
</pre>
|
||||||
<pre class="java">
|
<pre class="java">
|
||||||
Expr e = gr.checkExpr(e,Type.readType("A"))
|
Expr e = gr.checkExpr(e,Type.readType("A"))
|
||||||
pgf.TypeError: The expected type of the expression AdjCN (PositA red_A) (UseN theatre_N) is A but CN is infered
|
TypeError: The expected type of the expression AdjCN (PositA red_A) (UseN theatre_N) is A but CN is infered
|
||||||
</pre></p>
|
</pre></p>
|
||||||
|
|
||||||
<span class="python">
|
<span class="python">
|
||||||
@@ -800,6 +825,20 @@ n3 -- n4 [style = "solid"]
|
|||||||
n0 -- n3 [style = "solid"]
|
n0 -- n3 [style = "solid"]
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
<pre class="java">
|
||||||
|
System.out.println(gr.graphvizAbstractTree(e))
|
||||||
|
graph {
|
||||||
|
n0[label = "AdjCN", style = "solid", shape = "plaintext"]
|
||||||
|
n1[label = "PositA", style = "solid", shape = "plaintext"]
|
||||||
|
n2[label = "red_A", style = "solid", shape = "plaintext"]
|
||||||
|
n1 -- n2 [style = "solid"]
|
||||||
|
n0 -- n1 [style = "solid"]
|
||||||
|
n3[label = "UseN", style = "solid", shape = "plaintext"]
|
||||||
|
n4[label = "theatre_N", style = "solid", shape = "plaintext"]
|
||||||
|
n3 -- n4 [style = "solid"]
|
||||||
|
n0 -- n3 [style = "solid"]
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
<pre class="python">
|
<pre class="python">
|
||||||
>>> print(eng.graphvizParseTree(e))
|
>>> print(eng.graphvizParseTree(e))
|
||||||
@@ -874,6 +913,43 @@ graph {
|
|||||||
n0 -- n100000
|
n0 -- n100000
|
||||||
n2 -- n100001
|
n2 -- n100001
|
||||||
}
|
}
|
||||||
|
</pre>
|
||||||
|
<pre class="java">
|
||||||
|
System.out.println(eng.graphvizParseTree(e))
|
||||||
|
graph {
|
||||||
|
node[shape=plaintext]
|
||||||
|
|
||||||
|
subgraph {rank=same;
|
||||||
|
n4[label="CN"]
|
||||||
|
}
|
||||||
|
|
||||||
|
subgraph {rank=same;
|
||||||
|
edge[style=invis]
|
||||||
|
n1[label="AP"]
|
||||||
|
n3[label="CN"]
|
||||||
|
n1 -- n3
|
||||||
|
}
|
||||||
|
n4 -- n1
|
||||||
|
n4 -- n3
|
||||||
|
|
||||||
|
subgraph {rank=same;
|
||||||
|
edge[style=invis]
|
||||||
|
n0[label="A"]
|
||||||
|
n2[label="N"]
|
||||||
|
n0 -- n2
|
||||||
|
}
|
||||||
|
n1 -- n0
|
||||||
|
n3 -- n2
|
||||||
|
|
||||||
|
subgraph {rank=same;
|
||||||
|
edge[style=invis]
|
||||||
|
n100000[label="red"]
|
||||||
|
n100001[label="theatre"]
|
||||||
|
n100000 -- n100001
|
||||||
|
}
|
||||||
|
n0 -- n100000
|
||||||
|
n2 -- n100001
|
||||||
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user