8000 tuples as tuples; digits as ints · ez-max/stanford-corenlp-python@9e2feed · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e2feed

Browse files
committed
tuples as tuples; digits as ints
1 parent 6026558 commit 9e2feed

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ Assuming you are running on port 8080, the code in `client.py` shows an example
4444
Produces a list with a parsed dictionary for each sentence:
4545

4646
Result [{"text": "hello world",
47-
"tuples": [["amod", "world", "hello"]],
48-
"words": {"world": {"NamedEntityTag": "O",
49-
"CharacterOffsetEnd": "11",
47+
"tuples": [("amod", "world", "hello")],
48+
"words": {"world": {"NamedEntityTag": O,
49+
"CharacterOffsetEnd": 11,
5050
"Lemma": "world",
5151
"PartOfSpeech": "NN",
52-
"CharacterOffsetBegin": "6"},
53-
"hello": {"NamedEntityTag": "O",
54-
"CharacterOffsetEnd": "5",
52+
"CharacterOffsetBegin": 6},
53+
"hello": {"NamedEntityTag": O,
54+
"CharacterOffsetEnd": 5,
5555
"Lemma": "hello",
5656
"PartOfSpeech": "JJ",
57-
"CharacterOffsetBegin": "0"}}}]
57+
"CharacterOffsetBegin": 0}}}]
5858

5959

6060
<!--

server.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ def parse_parser_results(text):
4242
raise Exception("Parse error. Could not find [Text=")
4343
tmp['words'] = {}
4444
exp = re.compile('\[([a-zA-Z0-9=. ]+)\]')
45-
m = exp.findall(line)
46-
for s in m:
47-
av = re.split("=| ", s) # attribute-value tuples
48-
tmp['words'][av[1]] = dict(zip(*[av[2:][x::2] for x in (0, 1)]))
49-
print tmp
45+
matches = exp.findall(line)
46+
for s in matches:
47+
# split into attribute-value list
48+
av = re.split("=| ", s)
49+
# make [ignore,ignore,a,b,c,d] into [[a,b],[c,d]]
50+
av = zip(*[av[2:][x::2] for x in (0, 1)])
51+
# save as attr-value dict, convert numbers into ints
52+
tmp['words'][av[1]] = dict(map(lambda x: (x[0], x.isdigit(x[1])
53+
and int(x[1]) or x[1]), av))
5054
state = 3
5155
elif state == 3:
5256
# skip over parse tree
@@ -60,7 +64,7 @@ def parse_parser_results(text):
6064
split_entry = re.split("\(|, ", line[:-1])
6165
if len(split_entry) == 3:
6266
rel, left, right = map(lambda x: remove_id(x), split_entry)
63-
tmp['tuples'].append((rel,left,right))
67+
tmp['tuples'].append(tuple(rel,left,right))
6468
print "\n", rel, left, right
6569
elif "Coreference links" in line:
6670
state = 5

0 commit comments

Comments
 (0)
0