File size: 2,127 Bytes
a3864e2 81a8a6e 1342024 a3864e2 81a8a6e 1342024 a3864e2 81a8a6e a3864e2 81a8a6e a3864e2 81a8a6e a3864e2 1342024 a3864e2 |
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 65 66 67 68 69 70 71 72 |
from collections import defaultdict
import pandas as pd
import random
from sentence import SentenceBuilder
file = "./2024-01/position_names.csv"
sentence = SentenceBuilder()
dtype={"Name": "string"}
df = pd.read_csv(file,dtype=dtype)
titles = df["Name"]
tokens = []
for i,t in enumerate(titles):
e=0
entities=[]
entity=""
token={}
words=[]
word=""
for j,c in enumerate(t):
if e==0 and (c == " " or j==len(t)-1):
entity += c
entity = entity.strip()
entities.append(entity)
entity=""
e+=1
if e==1:
words.append(random.choice(sentence.get_adjectives()))
elif e>0 and (c == " " or j==len(t)-1):
entity += c
entity = entity.strip()
entities.append(entity)
entity=""
e+=1
if e==2:
words.append(random.choice(sentence.get_verbs()))
elif e==3:
words.append(random.choice(sentence.get_adverbs()))
elif e==4:
words.append(random.choice(sentence.get_nouns()))
elif e==5:
words.append(random.choice(sentence.get_conjunctions()))
elif e==6:
words.append(random.choice(sentence.get_prepositions()))
elif e==7:
words.append(random.choice(sentence.get_pronouns()))
else:
entity += c
token["entities"] = entities
token["words"] = words
tokens.append(token)
token={}
entities=[]
words=[]
random.shuffle(tokens)
f = open("./2024-01/position_names_tags_new.txt", "w", encoding="utf-8")
entity_shortname = "POS"
for i,t in enumerate(tokens):
ner_sentence=""
ner_tags=""
for j,e in enumerate(t["entities"]):
ner_sentence += e + " "
if j == 0:
ner_tags += "B-"+entity_shortname + " "
else:
ner_tags += "I-"+entity_shortname + " "
for k,w in enumerate(t["words"]):
ner_sentence += w + " "
ner_tags += "O" + " "
f.write(ner_sentence + ner_tags + "\n")
f.close() |