forked from GitHub/gf-core
Update Python instructions, add simple testsuite (which fails with segmentation fault)
This commit is contained in:
15
.github/workflows/build-majestic.yml
vendored
15
.github/workflows/build-majestic.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
|||||||
# make \
|
# make \
|
||||||
# g++
|
# g++
|
||||||
|
|
||||||
- name: Build runtime
|
- name: Build C runtime
|
||||||
working-directory: ./src/runtime/c
|
working-directory: ./src/runtime/c
|
||||||
run: |
|
run: |
|
||||||
autoreconf -i
|
autoreconf -i
|
||||||
@@ -36,9 +36,20 @@ jobs:
|
|||||||
# ghc-version: '8.6'
|
# ghc-version: '8.6'
|
||||||
# cabal-version: '2.4.1.0'
|
# cabal-version: '2.4.1.0'
|
||||||
|
|
||||||
- name: Run testsuite
|
- name: Run Haskell testsuite
|
||||||
working-directory: ./src/runtime/haskell
|
working-directory: ./src/runtime/haskell
|
||||||
env:
|
env:
|
||||||
LD_LIBRARY_PATH: /usr/local/lib
|
LD_LIBRARY_PATH: /usr/local/lib
|
||||||
run: |
|
run: |
|
||||||
cabal test --extra-lib-dirs=/usr/local/lib
|
cabal test --extra-lib-dirs=/usr/local/lib
|
||||||
|
|
||||||
|
- name: Install Python bindings
|
||||||
|
working-directory: ./src/runtime/python
|
||||||
|
run: |
|
||||||
|
python setup.py build
|
||||||
|
sudo python setup.py install
|
||||||
|
|
||||||
|
- name: Run Python testsuite
|
||||||
|
working-directory: ./src/runtime/python
|
||||||
|
run: |
|
||||||
|
python test.py
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
You will need the python-devel package or similar.
|
|
||||||
You must have installed the PGF C runtime (see ../c/INSTALL)
|
|
||||||
|
|
||||||
$ python setup.py build
|
|
||||||
$ sudo python setup.py install
|
|
||||||
19
src/runtime/python/README.md
Normal file
19
src/runtime/python/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Python bindings to C runtime
|
||||||
|
|
||||||
|
## Pre-requisites
|
||||||
|
|
||||||
|
1. You must have installed the PGF C runtime (see `../c/README.md`)
|
||||||
|
2. You will need the system Python development package, e.g.:
|
||||||
|
- RedHat: `yum install python-devel`
|
||||||
|
- Debian: `apt install python-dev`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
$ python setup.py build
|
||||||
|
$ sudo python setup.py install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
See `examples/`.
|
||||||
@@ -1,65 +1,66 @@
|
|||||||
import pgf
|
import pgf
|
||||||
import sys
|
import sys
|
||||||
import sets
|
# import sets
|
||||||
import readline
|
# import readline
|
||||||
import locale
|
# import locale
|
||||||
|
|
||||||
sys.stdout.write("loading...")
|
sys.stdout.write("loading...")
|
||||||
sys.stdout.flush();
|
sys.stdout.flush();
|
||||||
gr = pgf.readPGF("../../../treebanks/PennTreebank/ParseEngAbs.pgf")
|
# gr = pgf.readPGF("../../../treebanks/PennTreebank/ParseEngAbs.pgf")
|
||||||
|
gr = pgf.readPGF("../haskell/tests/basic.pgf")
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("\n")
|
||||||
|
|
||||||
source_lang = gr.languages["ParseEng"]
|
# source_lang = gr.languages["ParseEng"]
|
||||||
target_lang = gr.languages["ParseBul"]
|
# target_lang = gr.languages["ParseBul"]
|
||||||
|
#
|
||||||
we = pgf.readExpr("UttImpSg PPos (ImpVP (UseV try_V))")
|
# we = pgf.readExpr("UttImpSg PPos (ImpVP (UseV try_V))")
|
||||||
print source_lang.linearize(we)
|
# print source_lang.linearize(we)
|
||||||
|
#
|
||||||
sys.stdout.write("start cat: "+gr.startCat+"\n\n")
|
# sys.stdout.write("start cat: "+gr.startCat+"\n\n")
|
||||||
|
#
|
||||||
class Completer():
|
# class Completer():
|
||||||
def __init__(self, lang):
|
# def __init__(self, lang):
|
||||||
self.gr = lang
|
# self.gr = lang
|
||||||
|
#
|
||||||
def complete(self, prefix, state):
|
# def complete(self, prefix, state):
|
||||||
if state == 0:
|
# if state == 0:
|
||||||
line = readline.get_line_buffer()
|
# line = readline.get_line_buffer()
|
||||||
line = line[0:readline.get_begidx()]
|
# line = line[0:readline.get_begidx()]
|
||||||
self.i = source_lang.complete(line, prefix=prefix)
|
# self.i = source_lang.complete(line, prefix=prefix)
|
||||||
self.tokens = sets.Set()
|
# self.tokens = sets.Set()
|
||||||
|
#
|
||||||
if len(self.tokens) > 50:
|
# if len(self.tokens) > 50:
|
||||||
return None
|
# return None
|
||||||
|
#
|
||||||
while True:
|
# while True:
|
||||||
try:
|
# try:
|
||||||
(p,t,c) = self.i.next()
|
# (p,t,c) = self.i.next()
|
||||||
if t not in self.tokens:
|
# if t not in self.tokens:
|
||||||
self.tokens.add(t)
|
# self.tokens.add(t)
|
||||||
return t
|
# return t
|
||||||
except StopIteration:
|
# except StopIteration:
|
||||||
return None
|
# return None
|
||||||
|
#
|
||||||
completer = Completer(source_lang)
|
# completer = Completer(source_lang)
|
||||||
readline.set_completer(completer.complete)
|
# readline.set_completer(completer.complete)
|
||||||
readline.parse_and_bind("tab: complete")
|
# readline.parse_and_bind("tab: complete")
|
||||||
locale.setlocale(locale.LC_CTYPE, "")
|
# locale.setlocale(locale.LC_CTYPE, "")
|
||||||
|
#
|
||||||
while True:
|
# while True:
|
||||||
try:
|
# try:
|
||||||
line = raw_input("> ");
|
# line = raw_input("> ");
|
||||||
except EOFError:
|
# except EOFError:
|
||||||
sys.stdout.write("\n")
|
# sys.stdout.write("\n")
|
||||||
readline.set_completer(None)
|
# readline.set_completer(None)
|
||||||
break
|
# break
|
||||||
except KeyboardInterrupt:
|
# except KeyboardInterrupt:
|
||||||
sys.stdout.write("\n")
|
# sys.stdout.write("\n")
|
||||||
readline.set_completer(None)
|
# readline.set_completer(None)
|
||||||
break
|
# break
|
||||||
|
#
|
||||||
try:
|
# try:
|
||||||
for (p,e) in source_lang.parse(line, n=1):
|
# for (p,e) in source_lang.parse(line, n=1):
|
||||||
sys.stdout.write("["+str(p)+"] "+str(e)+"\n")
|
# sys.stdout.write("["+str(p)+"] "+str(e)+"\n")
|
||||||
print target_lang.linearize(e)
|
# print target_lang.linearize(e)
|
||||||
except pgf.ParseError as e:
|
# except pgf.ParseError as e:
|
||||||
print e.message
|
# print e.message
|
||||||
|
|||||||
Reference in New Issue
Block a user