mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Updated C# documentation
This commit is contained in:
@@ -56,7 +56,7 @@
|
|||||||
Choose a language: <a href="#haskell">Haskell</a> <a href="#python">Python</a> <a href="#java">Java</a> <a href="#csharp">C#</a>
|
Choose a language: <a href="#haskell">Haskell</a> <a href="#python">Python</a> <a href="#java">Java</a> <a href="#csharp">C#</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<h4>Krasimir Angelov, July 2015</h4>
|
<h4>Krasimir Angelov, July 2015 - August 2017</h4>
|
||||||
|
|
||||||
<h2>Loading the Grammar</h2>
|
<h2>Loading the Grammar</h2>
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ Prelude PGF2> let res = parse eng (startCat gr) "this is a small theatre"
|
|||||||
Iterable<ExprProb> iterable = eng.parse(gr.getStartCat(), "this is a small theatre");
|
Iterable<ExprProb> iterable = eng.parse(gr.getStartCat(), "this is a small theatre");
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
IEnumerable<Tuple<Expr, float>> enumerable = eng.Parse(gr.StartCat, "this is a small theatre");
|
IEnumerable<Tuple<Expr, float>> enumerable = eng.Parse("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
|
||||||
@@ -174,8 +174,9 @@ ExprProb ep = iter.next();
|
|||||||
This gives you an enumerable which can enumerate all possible
|
This gives you an enumerable which can enumerate all possible
|
||||||
abstract trees. You can get the next tree by calling <tt>MoveNext</tt>:
|
abstract trees. You can get the next tree by calling <tt>MoveNext</tt>:
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
enumerable.MoveNext();
|
IEnumerator<Tuple<Expr, float>> enumerator = enumerable.GetEnumerator();
|
||||||
Tuple<Expr, float> ep = enumerable.Current;
|
enumerator.MoveNext();
|
||||||
|
Tuple<Expr, float> ep = enumerator.Current;
|
||||||
</pre>
|
</pre>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -261,11 +262,16 @@ Iterable<ExprProb> iterable = eng.parseWithHeuristics(gr.startCat(), heuri
|
|||||||
</pre>
|
</pre>
|
||||||
</span>
|
</span>
|
||||||
<span class="csharp">
|
<span class="csharp">
|
||||||
There is also the method <tt>ParseWithHeuristics</tt> which
|
The <tt>Parse</tt> method has also the following optional parameters:
|
||||||
takes two more paramaters which let you to have a better control
|
<table border=1>
|
||||||
over the parser's behaviour:
|
<tr><td>cat</td><td>start category</td></tr>
|
||||||
|
<tr><td>heuristics</td><td>a real number from 0 to 1</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>By using these parameters it is possible for instance to change the start category for
|
||||||
|
the parser. For example parsing with a different start category can be done as follows:</p>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
IEnumerable<Tuple<Expr, float>> enumerable = eng.ParseWithHeuristics(gr.StartCat, heuristic_factor, callbacks);
|
IEnumerable<Tuple<Expr, float>> enumerable = eng.Parse("this is a small theatre", cat: Type.ReadType("NP"));
|
||||||
</pre>
|
</pre>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -343,7 +349,7 @@ red theatre
|
|||||||
red theater
|
red theater
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
for (String s : eng.LinearizeAll(e)) {
|
foreach (String s in eng.LinearizeAll(e)) {
|
||||||
Console.WriteLine(s);
|
Console.WriteLine(s);
|
||||||
}
|
}
|
||||||
red theatre
|
red theatre
|
||||||
@@ -369,7 +375,7 @@ s Pl Gen: red theatres'
|
|||||||
s Sg Gen: red theatre's
|
s Sg Gen: red theatre's
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
for (Map.Entry<String,String> entry : eng.TabularLinearize(e).EntrySet()) {
|
foreach (Map.Entry<String,String> entry in eng.TabularLinearize(e).EntrySet()) { //// TODO
|
||||||
Console.WriteLine(entry.Key + ": " + entry.Value);
|
Console.WriteLine(entry.Key + ": " + entry.Value);
|
||||||
}
|
}
|
||||||
s Sg Nom: red theatre
|
s Sg Nom: red theatre
|
||||||
@@ -395,7 +401,7 @@ Prelude PGF2> putStrLn (showBracketedString b)
|
|||||||
Object[] bs = eng.bracketedLinearize(e);
|
Object[] bs = eng.bracketedLinearize(e);
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
Object[] bs = eng.BracketedLinearize(e);
|
Bracket b = 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
|
||||||
@@ -469,7 +475,7 @@ System.out.println(eng.hasLinearization("apple_N"));
|
|||||||
true
|
true
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
Console.WriteLine(eng.HasLinearization("apple_N"));
|
Console.WriteLine(eng.HasLinearization("apple_N")); //// TODO
|
||||||
true
|
true
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@@ -497,7 +503,7 @@ for (Expr arg : app.getArguments()) {
|
|||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
ExprApplication app = e.UnApp();
|
ExprApplication app = e.UnApp();
|
||||||
System.out.println(app.Function);
|
System.out.println(app.Function);
|
||||||
for (Expr arg : app.Arguments) {
|
foreach (Expr arg in app.Arguments) {
|
||||||
Console.WriteLine(arg);
|
Console.WriteLine(arg);
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
@@ -782,8 +788,8 @@ for (FullFormEntry entry : eng.fullFormLexicon()) {
|
|||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
for (FullFormEntry entry in eng.FullFormLexicon) {
|
foreach (FullFormEntry entry in eng.FullFormLexicon) { //// TODO
|
||||||
for (MorphoAnalysis analysis : entry.Analyses) {
|
foreach (MorphoAnalysis analysis in entry.Analyses) {
|
||||||
Console.WriteLine(entry.Form+" "+analysis.Prob+" "+analysis.Lemma+" "+analysis.Field);
|
Console.WriteLine(entry.Form+" "+analysis.Prob+" "+analysis.Lemma+" "+analysis.Field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,7 +812,7 @@ letter_1_N, s Sg Nom, inf
|
|||||||
letter_2_N, s Sg Nom, inf
|
letter_2_N, s Sg Nom, inf
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
for (MorphoAnalysis an : eng.LookupMorpho("letter")) {
|
foreach (MorphoAnalysis an in eng.LookupMorpho("letter")) { //// TODO
|
||||||
Console.WriteLine(an.Lemma+", "+an.Field+", "+an.Prob);
|
Console.WriteLine(an.Lemma+", "+an.Field+", "+an.Prob);
|
||||||
}
|
}
|
||||||
letter_1_N, s Sg Nom, inf
|
letter_1_N, s Sg Nom, inf
|
||||||
@@ -830,7 +836,7 @@ List<String> funs = gr.getFunctions()
|
|||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
IList<String> funs = gr.Functions;
|
IEnumerable<String> funs = gr.Functions;
|
||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
or a list of categories:
|
or a list of categories:
|
||||||
@@ -847,7 +853,7 @@ List<String> cats = gr.getCategories();
|
|||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
IList<String> cats = gr.Categories;
|
IEnumerable<String> cats = gr.Categories;
|
||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
You can also access all functions with the same result category:
|
You can also access all functions with the same result category:
|
||||||
@@ -864,7 +870,7 @@ List<String> funsByCat = gr.getFunctionsByCat("Weekday");
|
|||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
IList<String> funsByCat = gr.FunctionsByCat("Weekday");
|
IList<String> funsByCat = gr.FunctionsByCat("Weekday"); //// TODO
|
||||||
....
|
....
|
||||||
</pre>
|
</pre>
|
||||||
The full type of a function can be retrieved as:
|
The full type of a function can be retrieved as:
|
||||||
@@ -906,7 +912,7 @@ System.out.println(te.getExpr()+" : "+te.getType());
|
|||||||
AdjCN (PositA red_A) (UseN theatre_N) : CN
|
AdjCN (PositA red_A) (UseN theatre_N) : CN
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
TypedExpr te = gr.InferExpr(e);
|
TypedExpr te = gr.InferExpr(e); //// TODO
|
||||||
Console.WriteLine(te.Expr+" : "+te.Type);
|
Console.WriteLine(te.Expr+" : "+te.Type);
|
||||||
AdjCN (PositA red_A) (UseN theatre_N) : CN
|
AdjCN (PositA red_A) (UseN theatre_N) : CN
|
||||||
</pre>
|
</pre>
|
||||||
@@ -933,7 +939,7 @@ Expr new_e = gr.checkExpr(e,Type.readType("CN"));
|
|||||||
System.out.println(e)
|
System.out.println(e)
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
Expr new_e = gr.CheckExpr(e,Type.ReadType("CN"));
|
Expr new_e = gr.CheckExpr(e,Type.ReadType("CN")); //// TODO
|
||||||
Console.WriteLine(e)
|
Console.WriteLine(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:
|
||||||
@@ -1095,7 +1101,7 @@ n0 -- n3 [style = "solid"]
|
|||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
Console.WriteLine(gr.GraphvizAbstractTree(e));
|
Console.WriteLine(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"]
|
||||||
@@ -1221,7 +1227,7 @@ graph {
|
|||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
<pre class="csharp">
|
<pre class="csharp">
|
||||||
Console.WriteLine(eng.GraphvizParseTree(e));
|
Console.WriteLine(eng.GraphvizParseTree(e)); //// TODO
|
||||||
graph {
|
graph {
|
||||||
node[shape=plaintext]
|
node[shape=plaintext]
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace PGFSharp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exprStr"></param>
|
/// <param name="exprStr"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Expr ReadExpr(string exprStr)
|
public static Expr ReadExpr(string exprStr)
|
||||||
{
|
{
|
||||||
var tmp_pool = new NativeGU.NativeMemoryPool();
|
var tmp_pool = new NativeGU.NativeMemoryPool();
|
||||||
var exn = new NativeGU.NativeExceptionContext(tmp_pool);
|
var exn = new NativeGU.NativeExceptionContext(tmp_pool);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace PGFSharp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="typeStr"></param>
|
/// <param name="typeStr"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Type ReadType(string typeStr)
|
public static Type ReadType(string typeStr)
|
||||||
{
|
{
|
||||||
var tmp_pool = new NativeGU.NativeMemoryPool();
|
var tmp_pool = new NativeGU.NativeMemoryPool();
|
||||||
var exn = new NativeGU.NativeExceptionContext(tmp_pool);
|
var exn = new NativeGU.NativeExceptionContext(tmp_pool);
|
||||||
|
|||||||
Reference in New Issue
Block a user