• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

AUTHORSH A D03-May-2022185 149

LICENSEH A D03-May-20221.6 KiB3225

Makefile.amH A D03-May-20221.4 KiB4830

Makefile.inH A D03-May-202227.9 KiB910792

README.mdH A D03-May-20224.3 KiB141114

example.pyH A D03-May-20222.2 KiB6846

lg_testutils.pyH A D03-May-20223.7 KiB9175

sentence-check.pyH A D03-May-20226.1 KiB181145

tests.pyH A D03-May-202252.8 KiB1,254898

README.md

1Python bindings for Link Grammar
2================================
3This directory contains an example program, and a unit test for the
4python bindings to Link Grammar.
5
6The example programs `example.py` and `sentence-check.py` illustrates
7how the to use the Link Grammar Python bindings.
8
9A unit test for the Link Grammar Python bindings can be found in
10in `tests.py`.
11
12Configuring (if needed)
13-----------------------
14The python bindings will be built by default, if the required python
15system libraries are detected on the build system.  Thus, no special
16configuration should be needed. However, configure can be forced with
17the following commands.
18
19### For Python2 and Python3
20   `$ ./configure --enable-python-bindings`
21(This is the default if Python development packages are installed.)
22
23### For Python2 or Python3 only
24   `$ ./configure --enable-python-bindings=2`
25Or:<br>
26   `$ ./configure --enable-python-bindings=3`
27
28### To disable the Python bindings
29   `$ ./configure --disable-python-bindings`
30(This is the default if no Python is installed.)
31
32How to use
33----------
34The python bindings will be installed automatically into default system
35locations, and no additional steps should be needed to use python.
36However, in some cases, therere might be a need to manually set the
37`PYTHONPATH` environment variable.  See the discussion below, in
38the section **Testing the installation** .
39
40Parsing simple sentences:
41
42```
43`$ python`
44
45>>> from linkgrammar import Sentence, ParseOptions, Dictionary
46>>> sent = Sentence("This is a simple sentence.", Dictionary(), ParseOptions())
47>>> linkages = sent.parse()
48>>> len(linkages)
49>>> for linkage in linkages:
50...    print linkage.diagram()
51...
52```
53```
54      +-------------------Xp------------------+
55      |              +--------Osm-------+     |
56      +----->WV----->+  +-----Ds**x-----+     |
57      +---Wd---+-Ss*b+  |     +----A----+     |
58      |        |     |  |     |         |     |
59  LEFT-WALL this.p is.v a simple.a sentence.n .
60```
61Additional examples can be found in `examples.py` and `sentence-cehck.py`.
62
63Testing
64-------
65The test collection `tests.py` should run 76 tests; none of them should
66fail.  However, 3 tests will be skipped, if the library is not configured
67with a spell guesser, and one test will be skipped if the library is not
68configured with the SAT solver (this is currently the case for native
69Windows builds).
70
71The test procedure is outlined below.  For native Windows/MinGW, see
72the `msvc/README.md` file:
73[Running Python programs in Windows](/msvc/README.md#running-python-programs).
74
75### Testing the build directory
76The following is assumed:
77
78**$SRC_DIR** - Link Grammar source directory.
79
80**$BUILD_DIR** - Link Grammar build directory.
81
82#### Using `make`
83The tests can be run using the `make` command, as follows:
84```
85$ cd $BUILD_DIR/bindings/python-examples
86$ make [-s] check
87```
88The `make` command can be made less verbose by using the `-s` flag.
89
90The test results are saved in the current directory, in the file
91`tests.log`.
92
93To run the tests in the **$SRC_DIR/tests/** directory, issue `make check`
94directly from **$BUILD_DIR**.
95
96#### Manually
97To run `tests.py` manually, or to run `example.py`, without installing
98the bindings, the `PYTHONPATH` environment variable must be set:
99```
100PYTHONPATH=$SRC_DIR/bindings/python:$BUILD_DIR/bindings/python:$BUILD_DIR/bindings/python/.libs
101```
102(Export it, or prepend it it the `make` command.)
103```
104$ cd $SRC_DIR
105$ python tests.py [-v]
106```
107
108### Testing the installation
109This can be done only after `make install`.
110
111#### Using `make`
112```
113$ cd $BUILD_DIR/bindings/python-examples
114$ make [-s] installcheck
115```
116To run the whole package installcheck, issue `make installcheck` from
117$BUILD_DIR.
118
119#### Manually
120Set the `PYTHONPATH` environment variable to the location of the installed
121Python's **linkgrammar** module, e.g.:
122
123```
124PYTHONPATH=/usr/local/lib/python2.7/dist-packages
125```
126(Export it, or prepend it to the `python` command.)
127
128Setting the `PYTHONPATH` is not needed if the default package
129configuration is used.  The default configuration installs the python
130bindings into the standard operating system locations.
131
132To correctly test the system installation, make sure that `tests.py` is
133invoked from a directory from which the **$SRCDIR/data.** directory
134cannot be found. This is needed to ensure that the system-installed data
135directory is used. For example:
136
137```
138$ cd $SRCDIR/binding/python-examples
139$ python tests.py
140```
141