diff --git a/doc/python-api.html b/doc/python-api.html index 01ce87e90..0cc4f2701 100644 --- a/doc/python-api.html +++ b/doc/python-api.html @@ -41,7 +41,7 @@ which respresents the language. For example the following will extract the English language:
>>> eng = gr.languages["AppEng"] ->>> print eng +>>> print(eng) <pgf.Concr object at 0x7f7dfa4471d0>@@ -58,18 +58,22 @@ abstract trees. You can get the next tree by calling next:
>>> p,e = i.next()+or by calling __next__ if you are using Python 3: +
+>>> p,e = i.__next__() +The results are always pairs of probability and tree. The probabilities are negated logarithmic probabilities and which means that the lowest number encodes the most probable result. The possible trees are returned in decreasing probability order (i.e. increasing negated logarithm). The first tree should have the smallest p:
->>> print p +>>> print(p) 35.9166526794and this is the corresponding abstract tree:
->>> print e +>>> 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@@ -116,7 +120,7 @@ a new expression like this: and then we can linearize it:
->>> print eng.linearize(e) +>>> print(eng.linearize(e)) red theatreThis method produces only a single linearization. If you use variants @@ -124,7 +128,7 @@ in the grammar then you might want to see all possible linearizations. For that purpouse you should use linearizeAll:
>>> for s in eng.linearizeAll(e): - print s + print(s) red theatre red theater@@ -140,7 +144,7 @@ Finally, you could also get a linearization which is bracketed into a list of phrases:
>>> [b] = eng.bracketedLinearize(e) ->>> print b +>>> print(b) (CN:4 (AP:1 (A:0 red)) (CN:3 (N:2 theatre)))Each bracket is actually an object of type pgf.Bracket. The property @@ -158,7 +162,7 @@ will just see the name of the function in the generated string. It is sometimes helpful to be able to see whether a function is linearizable or not. This can be done in this way:
->>> print eng.hasLinearization("apple_N")
+>>> print(eng.hasLinearization("apple_N"))
>>> class ExampleVisitor:
def on_DetCN(self,quant,cn):
- print "Found DetCN"
+ print("Found DetCN")
cn.visit(self)
def on_AdjCN(self,adj,cn):
- print "Found AdjCN"
+ print("Found AdjCN")
cn.visit(self)
def default(self,e):
@@ -228,7 +232,7 @@ using the constructor for pgf.Expr:
>>> quant = pgf.readExpr("DetQuant IndefArt NumSg")
>>> e2 = pgf.Expr("DetCN", [quant, e])
->>> print e2
+>>> print(e2)
DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA red_A) (UseN theatre_N))
@@ -250,7 +254,7 @@ After that you can simply import the module:
Now creating new trees is just a matter of calling ordinary Python
functions:
->>> print App.DetCN(quant,e)
+>>> print(App.DetCN(quant,e))
DetCN (DetQuant IndefArt NumSg) (AdjCN (PositA red_A) (UseN house_N))
@@ -262,12 +266,12 @@ The following code just iterates over the lexicon and prints each
word form with its possible analyses:
for entry in eng.fullFormLexicon():
- print entry
+ print(entry)
The second one implements a simple lookup. The argument is a word
form and the result is a list of analyses:
-print eng.lookupMorpho("letter")
+print(eng.lookupMorpho("letter"))
[('letter_1_N', 's Sg Nom', inf), ('letter_2_N', 's Sg Nom', inf)]
@@ -291,7 +295,7 @@ You can also access all functions with the same result category:
The full type of a function can be retrieved as:
->>> print gr.functionType("DetCN")
+>>> print(gr.functionType("DetCN"))
Det -> CN -> NP
@@ -302,9 +306,9 @@ for simple types. Dependent types are still not fully implemented
in the current runtime. The inference is done with method inferExpr:
>>> e,ty = gr.inferExpr(e) ->>> print e +>>> print(e) AdjCN (PositA red_A) (UseN theatre_N) ->>> print ty +>>> print(ty) CNThe result is a potentially updated expression and its type. In this @@ -316,7 +320,7 @@ wouldn't be true when dependent types are added.
Type checking is also trivial:
>>> e = gr.checkExpr(e,pgf.readType("CN"))
->>> print e
+>>> print(e)
AdjCN (PositA red_A) (UseN theatre_N)
In case of type error you will get an exception:
@@ -359,7 +363,7 @@ pgf.PGFError: The concrete syntax is not loaded
Before using the concrete syntax, you need to explicitly load it:
>>> eng.load("AppEng.pgf_c")
->>> print eng.lookupMorpho("letter")
+>>> print(eng.lookupMorpho("letter"))
[('letter_1_N', 's Sg Nom', inf), ('letter_2_N', 's Sg Nom', inf)]
@@ -376,7 +380,7 @@ In both cases the result is a GraphViz code that can be used for
rendering the trees. See the examples bellow.
->>> print gr.graphvizAbstractTree(e)
+>>> print(gr.graphvizAbstractTree(e))
graph {
n0[label = "AdjCN", style = "solid", shape = "plaintext"]
n1[label = "PositA", style = "solid", shape = "plaintext"]
@@ -391,7 +395,7 @@ n0 -- n3 [style = "solid"]
->>> print eng.graphvizParseTree(e)
+>>> print(eng.graphvizParseTree(e))
graph {
node[shape=plaintext]