-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcorefResolution.py
More file actions
38 lines (32 loc) · 857 Bytes
/
corefResolution.py
File metadata and controls
38 lines (32 loc) · 857 Bytes
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
"""
INSTALLATIONS:
pip install neuralcoref --no-binary neuralcoref
pip install -U spacy
python -m spacy download en
"""
import neuralcoref
import spacy
nlp = spacy.load('en')
# Add neural coref to SpaCy's pipe
neuralcoref.add_to_pipe(nlp)
# You're done. You can now use NeuralCoref as you usually manipulate a SpaCy document annotations.
doc = nlp(u'My sister has a dog. She loves him.')
print(doc._.has_coref)
print(doc._.coref_clusters)
"""
result:
True
[My sister: [My sister, She], a dog: [a dog, him]]
"""
def testing():
sent = "My sister has a dog. She loves him."
doc = nlp(sent)
if doc._.has_coref:
corefgot = doc._.coref_clusters
for i in corefgot:
sent = sent.replace(str(i.mentions[1]), str(i.mentions[0]))
print(sent)
testing()
"""
Result: My sister has a dog. My sister loves a dog.
"""