-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse-with-libpgf.py
executable file
·54 lines (41 loc) · 1.08 KB
/
parse-with-libpgf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env python3
# Parsing using libpgf.
# TODO: does not work
#
# Author: Kaarel Kaljurand
# Version: 2013-06-18
#
# Examples:
#
# echo "hello" | python3 parse-with-libpgf.py -f Phrasebook.pgf -l en_US
#
from pgf.pygf import *
from pgf import *
import pgf.fun as f
import sys
import argparse
import os
import re
def process_strings():
"""
"""
count = 0
for line in sys.stdin:
line = line.strip()
count = count + 1
expr,*_ = parse(line, lang=args.lang)
l,*_ = linearize(expr, lang=args.lang)
print(l)
parser = argparse.ArgumentParser(description='Parser')
parser.add_argument('-f', '--pgf', type=str, action='store', dest='pgf',
help='path to the PGF-formatted grammar (OBLIGATORY)')
parser.add_argument('-l', '--lang', type=str, action='store', dest='lang',
default='en_US',
help='ISO language code (DEFAULT: en_US)')
parser.add_argument('-v', '--version', action='version', version='%(prog)s v0.1')
args = parser.parse_args()
if args.pgf is None:
print("ERROR: argument -f/--pgf is not specified", file=sys.stderr)
exit()
import_pgf(args.pgf)
process_strings()