diff options
| author | Krasimir Angelov <kr.angelov@gmail.com> | 2017-08-29 14:17:28 +0200 |
|---|---|---|
| committer | Krasimir Angelov <kr.angelov@gmail.com> | 2017-08-29 14:17:28 +0200 |
| commit | 09d5d9b0912907210a14acd4a051ec9248b11bc7 (patch) | |
| tree | e6054f1a4b0c3d3a1757a95ca63edca043f764f2 /doc | |
| parent | 2f4ed211090cc26c40fd885cd97e759324becbae (diff) | |
some missing pieces of documentation for Java
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/runtime-api.html | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/doc/runtime-api.html b/doc/runtime-api.html index d6a46149e..374060403 100644 --- a/doc/runtime-api.html +++ b/doc/runtime-api.html @@ -396,6 +396,13 @@ a tree into a function name and a list of arguments: Prelude PGF2> unApp e Just ("AdjCN", [..., ...]) </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> <span class="python"> @@ -420,6 +427,17 @@ For example the result from: Prelude PGF2> readExpr "\"literal\"" >>= unStr "literal" </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". <span class="python">Situations like this can be detected 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)) </pre> </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"> <h2>Embedded GF Grammars</h2> @@ -653,8 +679,7 @@ AdjCN (PositA red_A) (UseN theatre_N) </pre> <pre class="java"> Expr e = gr.checkExpr(e,Type.readType("CN")) ->>> System.out.println(e) -AdjCN (PositA red_A) (UseN theatre_N) +System.out.println(e) </pre> <p>In case of type error you will get an error: <pre class="python"> @@ -668,7 +693,7 @@ Prelude PGF2> putStrLn msg </pre> <pre class="java"> 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> <span class="python"> @@ -800,6 +825,20 @@ n3 -- n4 [style = "solid"] n0 -- n3 [style = "solid"] } </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"> >>> print(eng.graphvizParseTree(e)) @@ -875,6 +914,43 @@ graph { 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> </body> </html> |
