mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
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 \
|
||||
# g++
|
||||
|
||||
- name: Build runtime
|
||||
- name: Build C runtime
|
||||
working-directory: ./src/runtime/c
|
||||
run: |
|
||||
autoreconf -i
|
||||
@@ -36,9 +36,20 @@ jobs:
|
||||
# ghc-version: '8.6'
|
||||
# cabal-version: '2.4.1.0'
|
||||
|
||||
- name: Run testsuite
|
||||
- name: Run Haskell testsuite
|
||||
working-directory: ./src/runtime/haskell
|
||||
env:
|
||||
LD_LIBRARY_PATH: /usr/local/lib
|
||||
run: |
|
||||
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 sys
|
||||
import sets
|
||||
import readline
|
||||
import locale
|
||||
# import sets
|
||||
# import readline
|
||||
# import locale
|
||||
|
||||
sys.stdout.write("loading...")
|
||||
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")
|
||||
|
||||
source_lang = gr.languages["ParseEng"]
|
||||
target_lang = gr.languages["ParseBul"]
|
||||
|
||||
we = pgf.readExpr("UttImpSg PPos (ImpVP (UseV try_V))")
|
||||
print source_lang.linearize(we)
|
||||
|
||||
sys.stdout.write("start cat: "+gr.startCat+"\n\n")
|
||||
|
||||
class Completer():
|
||||
def __init__(self, lang):
|
||||
self.gr = lang
|
||||
|
||||
def complete(self, prefix, state):
|
||||
if state == 0:
|
||||
line = readline.get_line_buffer()
|
||||
line = line[0:readline.get_begidx()]
|
||||
self.i = source_lang.complete(line, prefix=prefix)
|
||||
self.tokens = sets.Set()
|
||||
|
||||
if len(self.tokens) > 50:
|
||||
return None
|
||||
|
||||
while True:
|
||||
try:
|
||||
(p,t,c) = self.i.next()
|
||||
if t not in self.tokens:
|
||||
self.tokens.add(t)
|
||||
return t
|
||||
except StopIteration:
|
||||
return None
|
||||
|
||||
completer = Completer(source_lang)
|
||||
readline.set_completer(completer.complete)
|
||||
readline.parse_and_bind("tab: complete")
|
||||
locale.setlocale(locale.LC_CTYPE, "")
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = raw_input("> ");
|
||||
except EOFError:
|
||||
sys.stdout.write("\n")
|
||||
readline.set_completer(None)
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
sys.stdout.write("\n")
|
||||
readline.set_completer(None)
|
||||
break
|
||||
|
||||
try:
|
||||
for (p,e) in source_lang.parse(line, n=1):
|
||||
sys.stdout.write("["+str(p)+"] "+str(e)+"\n")
|
||||
print target_lang.linearize(e)
|
||||
except pgf.ParseError as e:
|
||||
print e.message
|
||||
# source_lang = gr.languages["ParseEng"]
|
||||
# target_lang = gr.languages["ParseBul"]
|
||||
#
|
||||
# we = pgf.readExpr("UttImpSg PPos (ImpVP (UseV try_V))")
|
||||
# print source_lang.linearize(we)
|
||||
#
|
||||
# sys.stdout.write("start cat: "+gr.startCat+"\n\n")
|
||||
#
|
||||
# class Completer():
|
||||
# def __init__(self, lang):
|
||||
# self.gr = lang
|
||||
#
|
||||
# def complete(self, prefix, state):
|
||||
# if state == 0:
|
||||
# line = readline.get_line_buffer()
|
||||
# line = line[0:readline.get_begidx()]
|
||||
# self.i = source_lang.complete(line, prefix=prefix)
|
||||
# self.tokens = sets.Set()
|
||||
#
|
||||
# if len(self.tokens) > 50:
|
||||
# return None
|
||||
#
|
||||
# while True:
|
||||
# try:
|
||||
# (p,t,c) = self.i.next()
|
||||
# if t not in self.tokens:
|
||||
# self.tokens.add(t)
|
||||
# return t
|
||||
# except StopIteration:
|
||||
# return None
|
||||
#
|
||||
# completer = Completer(source_lang)
|
||||
# readline.set_completer(completer.complete)
|
||||
# readline.parse_and_bind("tab: complete")
|
||||
# locale.setlocale(locale.LC_CTYPE, "")
|
||||
#
|
||||
# while True:
|
||||
# try:
|
||||
# line = raw_input("> ");
|
||||
# except EOFError:
|
||||
# sys.stdout.write("\n")
|
||||
# readline.set_completer(None)
|
||||
# break
|
||||
# except KeyboardInterrupt:
|
||||
# sys.stdout.write("\n")
|
||||
# readline.set_completer(None)
|
||||
# break
|
||||
#
|
||||
# try:
|
||||
# for (p,e) in source_lang.parse(line, n=1):
|
||||
# sys.stdout.write("["+str(p)+"] "+str(e)+"\n")
|
||||
# print target_lang.linearize(e)
|
||||
# except pgf.ParseError as e:
|
||||
# print e.message
|
||||
|
||||
Reference in New Issue
Block a user