Skip to content

Commit 4c33190

Browse files
committed
Version 0.2
1 parent c40f758 commit 4c33190

File tree

11 files changed

+383
-281
lines changed

11 files changed

+383
-281
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
StreamSide is a annotation toolkit that derives a semantic network from plain text.
44
This project is maintained by the [Emory NLP](http://nlp.cs.emory.edu/) research laboratory and under the [Apache 2](http://www.apache.org/licenses/LICENSE-2.0) license.
55

6-
* Latest release: [0.1](../../releases/tag/streamside-0.1) (8/12/2020).
6+
* Latest release: [0.2](../../releases/tag/streamside-0.2) (8/13/2020).
77

88
## Documentations
99

1010
* [Getting Started](docs/getting_started.md)
1111
* [Graph Annotator](docs/graph_annotator.md)
12+
* [JSON to Penman Convertor](docs/json_to_penman.md)

docs/json_to_penman.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# JSON to Penman Converter
2+
3+
The following command converts the JSON files generated by StreamSide to the Penman notation:
4+
5+
```bash
6+
python -m streamside.json_to_penman -i INPUT_PATH [-o OUTPUT_PATH] &
7+
```
8+
* `-i` or `--input`: the path to a JSON file or a directory containing JSON files (required).
9+
* `-o` or `--output`: the path to the output file(s) (default: the input directory).

docs/training-examples.jdchoi.json

Lines changed: 0 additions & 252 deletions
This file was deleted.

samples/training-examples.jdchoi.json

Lines changed: 254 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ::id training-examples.0 ::save-date 13/08/2020 01:51:30 ::annotator jdchoi
2+
# ::snt The boy wants to be believed by the girl .
3+
(c1 / want-01
4+
:ARG0 (c0 / boy)
5+
:ARG1 (c2 / believe-01
6+
:ARG0 (c3 / girl)
7+
:ARG1 c0)
8+
:polarity +)
9+
10+
# ::id training-examples.199 ::save-date 13/08/2020 01:39:25 ::annotator jdchoi
11+
# ::snt the Nobel Prize
12+
(c0 / award
13+
:name (c1 / name
14+
:op1 "Nobel"
15+
:op2 "Prize")
16+
:wiki "Nobel_Prize")
17+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='streamside',
8-
version='0.1',
8+
version='0.2',
99
scripts=[],
1010
author='Jinho D. Choi',
1111
author_email='[email protected]',

streamside/annotator.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def exec_(self) -> Optional[str]:
123123

124124
class RelationDialog(InputDialog):
125125
def __init__(self, parent, title: str, parent_desc: str, child_desc: str, label: str = '', update: bool = False):
126-
super().__init__(parent, title, 350, parent.relation_list, 50)
126+
super().__init__(parent, title, 550, parent.relation_list, 50)
127127
self.relation_dict = parent.relation_dict
128128
layout = QVBoxLayout()
129129
self.setLayout(layout)
@@ -135,6 +135,16 @@ def __init__(self, parent, title: str, parent_desc: str, child_desc: str, label:
135135
self.lb_desc = QPlainTextEdit('Description')
136136
self.lb_desc.setReadOnly(True)
137137

138+
# AMR only
139+
self.concept_desc = None
140+
if parent.mode == 'amr':
141+
parent_id = parent_desc.split()[0][1:]
142+
con = parent.current_graph.get_concept(parent_id)
143+
d = parent.concept_dict.get(con.name, None)
144+
if d and d['type'] == 'pred':
145+
self.concept_desc = d['description']
146+
self.lb_desc.setPlainText(self.concept_desc)
147+
138148
# child + referent
139149
wg_child = QWidget()
140150
l = QHBoxLayout()
@@ -177,10 +187,11 @@ def __init__(self, parent, title: str, parent_desc: str, child_desc: str, label:
177187
self.sct_inverse.activated.connect(self.check_inverse)
178188

179189
def edit_finished(self):
180-
v = self.relation_dict.get(self.ledit.text().strip(), None)
181-
text = v['description'] if v else 'No description available'
182-
self.lb_desc.setPlainText(text)
183-
self.lb_desc.repaint()
190+
if self.concept_desc is None:
191+
v = self.relation_dict.get(self.ledit.text().strip(), None)
192+
text = v['description'] if v else 'No description available'
193+
self.lb_desc.setPlainText(text)
194+
self.lb_desc.repaint()
184195

185196
def check_referent(self):
186197
self.referent.setChecked(not self.referent.isChecked())
@@ -367,8 +378,8 @@ def open_txt(txt_file):
367378
def open_json(json_file):
368379
self.filename = json_file
369380
with open(self.filename) as fin:
370-
graphs = json.load(fin)
371-
self.graphs = [Graph.factory(graph) for graph in graphs]
381+
d = json.load(fin)
382+
self.graphs = [Graph.factory(graph) for graph in d['graphs']]
372383

373384
# get filename
374385
filename = QFileDialog.getOpenFileName(self, 'Open File')[0]
@@ -397,8 +408,8 @@ def menu_file_save(self):
397408

398409
self.current_graph.last_saved = current_time()
399410
with open(self.filename, 'w') as fout:
400-
d = [' ' + graph.json_dumps() for graph in self.graphs]
401-
fout.write('[\n{}\n]\n'.format(',\n'.join(d)))
411+
d = [' ' + graph.json_dumps() for graph in self.graphs]
412+
fout.write('{{\n "graphs": [\n{}\n ]\n}}\n'.format(',\n'.join(d)))
402413

403414
self.statusbar.showMessage('Save: {}'.format(self.filename))
404415

streamside/json_to_penman.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2020 Emory University
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__author__ = 'Jinho D. Choi'
16+
17+
import argparse
18+
import glob
19+
import json
20+
import os
21+
22+
from streamside.struct import Graph
23+
24+
25+
def convert(input_file: str, output_dir: str):
26+
output_file = os.path.join(output_dir, os.path.basename(input_file)[:-4] + 'penman')
27+
fout = open(output_file, 'w')
28+
d = json.load(open(input_file))
29+
30+
for g in d['graphs']:
31+
graph = Graph.factory(g)
32+
if graph.concepts:
33+
fout.write('\n'.join(graph.penman_graphs(True)) + '\n\n')
34+
35+
36+
def main():
37+
parser = argparse.ArgumentParser(description='JSON to Penman Converter')
38+
parser.add_argument('-i', '--input', type=str, help='the path to a JSON file or a directory containing JSON files')
39+
parser.add_argument('-o', '--output', type=str, default=None, help='the path to the output file(s)')
40+
args = parser.parse_args()
41+
42+
output_dir = args.output if args.output else os.path.dirname(args.input)
43+
if os.path.isdir(args.input):
44+
for input_file in glob.glob(os.path.join(args.input, '*.json')):
45+
convert(input_file, output_dir)
46+
else:
47+
convert(args.input, output_dir)
48+
49+
50+
if __name__ == "__main__":
51+
main()

streamside/resources/amr/concepts.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35467,6 +35467,10 @@
3546735467
"description": "Quantity entity",
3546835468
"type": "quant"
3546935469
},
35470+
"name": {
35471+
"description": "Miscellaneous entity",
35472+
"type": "misc"
35473+
},
3547035474
"date-entity": {
3547135475
"description": "Miscellaneous entity",
3547235476
"type": "misc"

0 commit comments

Comments
 (0)