Skip to content

Instantly share code, notes, and snippets.

@Valindo
Created March 5, 2019 05:59
Show Gist options
  • Save Valindo/24fcb55e85f357a6ec945fd88b73be81 to your computer and use it in GitHub Desktop.
Save Valindo/24fcb55e85f357a6ec945fd88b73be81 to your computer and use it in GitHub Desktop.
Sheryl
sentence_list=['Tom drinks milk', 'Jack plays cricket', 'Tim ate rice']
tag_list={'Tom':'NP','Tim':'NP','Jack':'NP','drinks':'VF','milk':'NN','plays':'VF','cricket':'NN','ate':'VF','rice':'NN'}
tag_list_keys = tag_list.keys()
subject_list=[]
object_list=[]
verb_list=[]
def classify(item):
if item in tag_list_keys:
if tag_list[item] == 'NP': subject_list.append(item)
if tag_list[item] == 'NN': object_list.append(item)
if tag_list[item] == 'VF': verb_list.append(item)
def extract(item):
item_split = item.split(' ')
map(classify, item_split)
map(extract, sentence_list)
print('SUBJECT:',subject_list)
print('OBJECT',object_list)
print('VERB',verb_list)
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
for i in range(3):
G.add_node(object_list[i])
G.add_node(verb_list[i])
G.add_node(subject_list[i])
G.add_edge(verb_list[i],object_list[i])
G.add_edge(subject_list[i],verb_list[i])
nx.draw(G, with_labels= True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment