Debian Codegraph @

docs/source/pythonfrog.rst

raw
1 .. _pythonfrog:
2
3
4 Using Frog from Python
5 -----------------------
6
7 It is possible to call Frog directly from Python using the
8 ``python-frog`` software library. Contrary to the Frog client for Python
9 discussed in Section [servermode], this library is a direct binding with
10 code from Frog and does not use a client/server model. It therefore
11 offers the tightest form of integration, and highest performance,
12 possible.
13
14 Installation
15 ~~~~~~~~~~~~~
16
17 The Python-Frog library is not included with Frog itself, but is shipped
18 separately from https://github.com/proycon/python-frog.
19
20 Users who installed Frog using LaMachine, however, will already find
21 that this software has been installed.
22
23 Other users will need to compile and install it from source. First
24 ensure Frog itself is installed, then install the dependency
25 ``cython``\ [14]_. Installation of Python-Frog is then done by running:
26 ``$ python setup.py install`` from its directory.
27
28 Usage
29 ~~~~~~
30
31 The Python 3 example below illustrates how to parse text with Frog:
32
33 ::
34
35 from frog import Frog, FrogOptions
36
37 frog = Frog(FrogOptions(parser=False))
38
39 output = frog.process_raw("Dit is een test")
40 print("RAW OUTPUT=",output)
41 output = frog.process("Dit is nog een test.")
42 print("PARSED OUTPUT=",output)
43
44 To instantiate the ``Frog`` class, two arguments are needed. The first
45 is a ``FrogOptions`` instance that specifies the configuration options
46 you want to pass to Frog.
47
48 The ``Frog`` instance offers two methods: ``process_raw(text)`` and
49 ``process(text)``. The former just returns a string containing the usual
50 multiline, columned, and TAB delimiter output. The latter parses this
51 string into a dictionary. The example output of this from the script
52 above is shown below:
53
54 ::
55
56 PARSED OUTPUT = [
57 {'chunker': 'B-NP', 'index': '1', 'lemma': 'dit', 'ner': 'O',
58 'pos': 'VNW(aanw,pron,stan,vol,3o,ev)', 'posprob': 0.777085, 'text': 'Dit', 'morph': '[dit]'},
59 {'chunker': 'B-VP', 'index': '2', 'lemma': 'zijn', 'ner': 'O',
60 'pos': 'WW(pv,tgw,ev)', 'posprob': 0.999966, 'text': 'is', 'morph': '[zijn]'},
61 {'chunker': 'B-NP', 'index': '3', 'lemma': 'nog', 'ner': 'O',
62 'pos': 'BW()', 'posprob': 0.99982, 'text': 'nog', 'morph': '[nog]'},
63 {'chunker': 'I-NP', 'index': '4', 'lemma': 'een', 'ner': 'O',
64 'pos': 'LID(onbep,stan,agr)', 'posprob': 0.995781, 'text': 'een', 'morph': '[een]'},
65 {'chunker': 'I-NP', 'index': '5', 'lemma': 'test', 'ner': 'O',
66 'pos': 'N(soort,ev,basis,zijd,stan)', 'posprob': 0.903055, 'text': 'test', 'morph': '[test]'},
67 {'chunker': 'O', 'index': '6', 'eos': True, 'lemma': '.', 'ner': 'O',
68 'pos': 'LET()', 'posprob': 1.0, 'text': '.', 'morph': '[.]'}
69 ]
70
71 There are various options you can set when creating an instance of
72 ``FrogOptions``, they are set as keyword arguments:
73
74 - ``tok`` – *bool* – Do tokenisation? (default: True)
75
76 - ``lemma`` – *bool* – Do lemmatisation? (default: True)
77
78 - ``morph`` – *bool* – Do morphological analysis? (default: True)
79
80 - ``daringmorph`` – *bool* – Do morphological analysis in new
81 experimental style? (default: False)
82
83 - ``mwu`` – *bool* – Do Multi Word Unit detection? (default: True)
84
85 - ``chunking`` – *bool* – Do Chunking/Shallow parsing? (default: True)
86
87 - ``ner`` – *bool* – Do Named Entity Recognition? (default: True)
88
89 - ``parser`` – *bool* – Do Dependency Parsing? (default: False).
90
91 - ``xmlin`` – *bool* – Input is FoLiA XML (default: False)
92
93 - ``xmlout`` – *bool* – Output is FoLiA XML (default: False)
94
95 - ``docid`` – *str* – Document ID (for FoLiA)
96
97 - ``numThreads`` – *int* – Number of threads to use (default: unset,
98 unlimited)
99
100
101 .. [14]
102 Versions for Python 3 may be called ``cython3`` on distributions such
103 as Debian or Ubuntu