-
Notifications
You must be signed in to change notification settings - Fork 0
/
garden.py
66 lines (46 loc) · 2.15 KB
/
garden.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
63
64
# import spacy, NLP module for Python
import spacy
# create list of garden path sentences, 3 provided add 3 of your own
# GPS is a grammatically correct sentence which starts in such a way
# that the reader is likely to misinterpret it
# ref: https://en.wikipedia.org/wiki/Garden-path_sentence
gardenpathSentences = [
"Mary gave the child a Band-Aid.",
"That Jill is never here hurts.",
"Have the students who failed the exam take the supplementary.",
"The cotton clothing is made of grows in Mississippi.",
"British Left Waffles on Falklands"
]
# Tokenise each sentence in the list and perform named entity recognition.
# tokenise: Splitting text into words
# enitity recognitiion, process of classifying named entities found in a text
# into pre-defined categories
# load english NLP model
nlp = spacy.load('en_core_web_sm')
# Tokenize each sentence and perform named entity recognition
for sentence in gardenpathSentences:
doc = nlp(sentence)
# Print the entities in the sentence
print(f'The Entities in the sentence "{sentence}" are:')
for ent in doc.ents:
print(f'{ent.text} ({ent.label_})')
# spacy.explain to look up entities which you dont understand, I added all
print("\nExplaining entities:\n")
print("GPE:", spacy.explain("GPE"))
print("PERSON:", spacy.explain("PERSON"))
print("NORP:", spacy.explain("NORP"))
print("ORG:", spacy.explain("ORG"))
# At the bottom of your file, write a comment about two entities that you looked up.
# For each entity answer the following questions:
# ○ What was the entity and its explanation that you looked up?
# ○ Did the entity make sense in terms of the word associated with it?
# 1. NORP - Nationalities or religious or political groups
# Yes, its a country and people there have a nationality called british,
# British is a NORP enitity
# 1. ORG - Companies, agencies, institutions, etc.
# Falklands is an island however it picked it up as
# ref: https://www.falklands.gov.fk/our-history
# Falkland Islands Government
# Therefore Flaklands itself I think should be and island, aka GPE enitity
# but there was a war, so ORG applies, I think, based on actual
# newspaper article, org is sufficient.