mirror of
https://github.com/GrammaticalFramework/comp-syntax-gu-mlt.git
synced 2026-05-04 15:22:50 -06:00
lecture 6 code
This commit is contained in:
19
lectures/lecture06/comments.py
Normal file
19
lectures/lecture06/comments.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import pgf
|
||||
|
||||
grammar = pgf.readPGF("Foods.pgf")
|
||||
parse_lang = grammar.languages["FoodsEng"]
|
||||
|
||||
with open("data.csv") as data:
|
||||
lines = data.readlines()
|
||||
|
||||
for line in lines:
|
||||
[polarity, kind, quality] = line.split(",")
|
||||
k = [e for (_,e) in parse_lang.parse(kind, cat=pgf.readType("Kind"))][0]
|
||||
q = [e for (_,e) in parse_lang.parse(quality, cat=pgf.readType("Quality"))][0]
|
||||
expr_string = "{} (This ({})) ({})".format("Pred" if polarity == "+" else "PredNeg", k, q)
|
||||
print(expr_string)
|
||||
expr = pgf.readExpr(expr_string)
|
||||
|
||||
for lin_lang in grammar.languages.values():
|
||||
print(lin_lang.linearize(expr))
|
||||
print()
|
||||
Reference in New Issue
Block a user