Skip to content
Snippets Groups Projects
Commit 81d5e89b authored by nwarslan's avatar nwarslan
Browse files

added code for Dynamic Event Structure

parent a11b19a2
No related branches found
No related tags found
No related merge requests found
Showing
with 2996 additions and 4 deletions
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 29 15:43:32 2022
@author: nadia
"""
import json
import pickle
SPEC_MERGED = '../amr_nx_story_graphs/spec_merged/'
GEN_MERGED = '../amr_nx_story_graphs/gen_merged/'
food_cluster = ['13','17','19','25','27','28']
with open('../story_graphs/topic2storyID.json', 'r') as f:
topics = json.load(f)
def open_amr_dict(file):
with open(file,'r') as f:
return(json.load(f))
amr_dict = open_amr_dict('../amr/amr_dict.json')
#print(topics['13'])
file = '4488_fa952f59-3b98-49a7-b8a6-ad5b83cd9af0.pkl'
#for file in topics_0:
with open('../story_graphs/coref/'+file, 'rb') as f:
graph = pickle.load(f)
with open(SPEC_MERGED+file,'rb') as f:
spec_merged_graph = pickle.load(f)
with open(GEN_MERGED+file,'rb') as f:
gen_merged_graph = pickle.load(f)
for node in graph.nodes:
if '_S' in node:
story = graph.nodes[node]['story']
print(story,'\n\n')
elif 'E' in node or 'O' in node:
continue
else:
#print(graph.nodes[node])
print(graph.nodes[node]['sentence'][0])
try:
print(amr_dict[graph.nodes[node]['sentence'][0]])
except:
print(amr_dict[graph.nodes[node]['sentence'][0][:-1]])
print('\n\nGENERALIZED\n')
for node in gen_merged_graph.nodes:
if 'G_' in node:
print('ARGUMENT:\n')
print(gen_merged_graph.nodes[node])
print('\n\nPARENTS:\n')
for n in gen_merged_graph.predecessors(node):
print(gen_merged_graph.nodes[n])
print('\n\nKIDS:\n')
for n in gen_merged_graph.neighbors(node):
print(gen_merged_graph.nodes[n])
print('#'*10)
print('\n\n\n')
print('SPECIALIZED\n')
for node in spec_merged_graph.nodes:
if 'G_' in node:
print('ARGUMENT:\n')
print(spec_merged_graph.nodes[node])
print('\n\nPARENTS:\n')
for n in spec_merged_graph.predecessors(node):
print(spec_merged_graph.nodes[n])
print('\n\nKIDS:\n')
for n in spec_merged_graph.neighbors(node):
print(spec_merged_graph.nodes[n])
print('#'*10)
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment