forked from gitter-badger/Dismantled-Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleSpacy.py
62 lines (48 loc) · 1.27 KB
/
sampleSpacy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import spacy
import sys
def spacy_data(docu):
nlp = spacy.load('en_core_web_sm')
doc = nlp(docu)
people = []
info_people = ['people', 'People', 'peoples', 'men','Men','women','Women','child','children','boy','Boy','boys']
for token in doc:
for k in info_people:
if str(token.head)== str(k):
if token.pos_ == 'NUM':
people.append(str(token)+' '+str(token.head))
ailment = []
for token in doc:
if token.head.pos_ == 'NOUN':
if token.pos_ == 'ADJ' :
ailment.append(str(token)+' '+str(token.head))
elif token.pos_ == 'VERB':
ailment.append(str(token)+' '+str(token.head))
ner = doc.ents
i = 0
address = []
for token in doc:
i = i + 1
if token.tag_ == 'IN':
if token.text != 'with':
for j in range(i,len(doc)):
for k in doc.ents:
if str(k) != str(doc[j]):
address.append(doc[j])
else:
address.append(doc[j])
break
break
donation = []
for r in doc.ents:
if r.label_ == 'MONEY' or 'TIME' or 'CARDINAL' or 'PRODUCT':
donation.append(r.text)
name = []
for k in doc.ents:
if k.label_ == 'PERSON':
name.append(k.text)
modified_add = []
for k in address:
modified_add.append(str(k))
for k in address and people:
address.remove(k)
return (name,ailment,donation,modified_add,people)