I am begginer with NLP. I am using spaCy python library for my NLP project. Here is my requirement,
I have a JSON File with all country names. Now i need to parse and get goldmedal count for the each countries in the document. Given below the sample sentence,
"Czech Republic won 5 gold medals at olympics. Slovakia won 0 medals olympics"
I am able to fetch country names but not it medal count. Given below my code. Please help to proceed further.
import json
from spacy.lang.en import English
from spacy.matcher import PhraseMatcher
with open("C:\Python36\srclcl\countries.json") as f:
COUNTRIES = json.loads(f.read())
nlp = English()
nlp.add_pipe(nlp.create_pipe('sentencizer'))
doc = nlp("Czech Republic won 5 gold medals at olympics. Slovakia won 0 medals olympics")
matcher = PhraseMatcher(nlp.vocab)
patterns = list(nlp.pipe(COUNTRIES))
matcher.add("COUNTRY", None, *patterns)
for sent in doc.sents:
subdoc = nlp(sent.text)
matches = matcher(subdoc)
print (sent.text)
for match_id, start, end in matches:
print(subdoc[start:end].text)
Also, if the given text is like ,
"Czech Republic won 5 gold medals at olympics in 1995. Slovakia won 0 medals olympics"