mirror of
https://github.com/GrammaticalFramework/comp-syntax-gu-mlt.git
synced 2026-02-08 22:41:05 -07:00
26 lines
702 B
Python
26 lines
702 B
Python
# minimal translator that reads one line from stdio and translates from Eng to Swe with Minilang
|
|
# presupposes 'make minilang'
|
|
|
|
import pgf
|
|
|
|
# change these three to translate with other grammars and languages
|
|
absmodule = "MicroLang"
|
|
fromname = absmodule + "Eng"
|
|
toname = absmodule + "Swe"
|
|
|
|
def main():
|
|
# read in the grammar, set up to and from languages
|
|
grammar = pgf.readPGF(absmodule + ".pgf")
|
|
fromlang = grammar.languages[fromname]
|
|
tolang = grammar.languages[toname]
|
|
|
|
# read a line of input, parse in "from" language, linearize in "to" language
|
|
line = input("")
|
|
parseresult = fromlang.parse(line)
|
|
prob,tree = parseresult.__next__()
|
|
print(tolang.linearize(tree))
|
|
|
|
main()
|
|
|
|
|