-
Notifications
You must be signed in to change notification settings - Fork 0
/
nerTrainerHelp.py
46 lines (34 loc) · 1.35 KB
/
nerTrainerHelp.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
# This class takes your sentence and turns it into code for nerTrainer.py
# Please follow the 4 steps below to add your test case
# Step 1: Put your sentence here
sentence = "I was wondering who plays Peter Parker in Spider-Man: Far From Home?"
# Step 2: put the EXACT spelling of the PERSON, MOVIE, ORGANIZATION from your sentence below
person = "Peter Parker" # Put the person name here
pLen = len(person)
pFirst = sentence.find(person)
pLast = pFirst + pLen
movie = "Spider-Man: Far From Home" # Put the movie name here
mLen = len(movie)
mFirst = sentence.find(movie)
mLast = mFirst + mLen
org = "" # Put the organization name here
oLen = len(org)
oFirst = sentence.find(org)
oLast = oFirst + oLen
# Step 3: Run the code
part1 = "(\"" + str(sentence) + "\""
part2 = ", {\"entities\": ["
lines = []
if person != "":
pLine = "(" + str(pFirst) + ", " + str(pLast) + ", \"PERSON\")"
lines.append(pLine)
if movie != "":
mLine = "(" + str(mFirst) + ", " + str(mLast) + ", \"WORK_OF_ART\")"
lines.append(mLine)
if org != "":
oLine = "(" + str(oFirst) + ", " + str(oLast) + ", \"ORG\")"
lines.append(oLine)
part3 = ", ".join(lines)
part4 = "]}),"
print(str(part1) + str(part2) + str(part3) + str(part4))
# Step 4: Copy and paste the output into nerTrainer.py in TRAIN_DATA