You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
"""
|
|
key: remember 5
|
|
decomp: * i remember *
|
|
reasmb: Do you often think of (2) ?
|
|
reasmb: Does thinking of (2) bring anything else to mind ?
|
|
reasmb: What else do you recollect ?
|
|
reasmb: Why do you remember (2) just now ?
|
|
reasmb: What in the present situation reminds you of (2) ?
|
|
reasmb: What is the connection between me and (2) ?
|
|
reasmb: What else does (2) remind you of ?
|
|
"""
|
|
import sys
|
|
|
|
output = {}
|
|
output['pre'] = pre = []
|
|
output['post'] = post = []
|
|
output['synon'] = synon = []
|
|
output['quit'] = quit = []
|
|
output['keywords'] = keys = []
|
|
for line in sys.stdin:
|
|
line = line.strip()
|
|
if line.startswith("#") or not line:
|
|
continue
|
|
cmd, rest = line.split(" ", 1)
|
|
cmd = cmd.strip()
|
|
rest = rest.strip()
|
|
if cmd == "initial:":
|
|
output['initial'] = rest
|
|
elif cmd == "final:":
|
|
output['final'] = rest
|
|
elif cmd == "pre:":
|
|
pre.append(rest)
|
|
elif cmd == "post:":
|
|
post.append(rest)
|
|
elif cmd == "synon:":
|
|
synon.append(rest)
|
|
elif cmd == "key:":
|
|
try:
|
|
token, weight = rest.split()
|
|
except ValueError:
|
|
token = rest.strip()
|
|
weight = 0
|
|
print ("key", token, int(weight), file=sys.stderr)
|
|
keys.append({"token": token.strip(), "weight": int(weight), "rules": []})
|
|
elif line.startswith("decomp:"):
|
|
_, pattern = line.split(" ", 1)
|
|
print ("decomp", pattern, file=sys.stderr)
|
|
keys[-1]['rules'].append({"decomp": pattern.strip(), "reasmb": []})
|
|
elif line.startswith("reasmb:"):
|
|
_, pattern = line.split(" ", 1)
|
|
print ("reasmb", pattern, file=sys.stderr)
|
|
keys[-1]['rules'][-1]['reasmb'].append(pattern.strip())
|
|
# out = {}
|
|
# keywords = out['keywords'] = {}
|
|
# for obj in keys:
|
|
# keyname = obj.get("token")
|
|
# del obj['token']
|
|
# keywords[keyname] = obj
|
|
import json
|
|
print (json.dumps(output, indent=2))
|