У меня есть набор данных, и я извлек их, основываясь на фразе-уровне, это означает, что каждое предложение является элементом списка.
REL_LIST = np.array(['CEO', 'born', 'Professor', 'Employee', 'president']) # Relationship
len(SENT_LIST) # is 4 (`SENT_LIST` is list of sentences from a file)
len(REL_LIST) # is 5 (`REL_LISt` is the words or relations in each sentence)
vector1 # is a numpy array, contains those elements extracted by NAMED ENTITY Recognition of Polyglot. such as (I-PER(['M.', 'Ashraf']) I-LOC(['Afghanistan'])
LEN_SENT = 0
word = 0
while word <= len(REL_LIST):
if REL_LIST[word] in SENT_LIST[LEN_SENT][:]:
k = np.insert(vector1[LEN_SENT], word, REL_LIST[word])
print(k) # `vector1` is a numpy array include NER from polyglot.
LEN_SENT = LEN_SENT + 1
word = word + 1
if LEN_SENT == len(SENT_LIST) and word == LEN_SENT:
break # because length of `sentence` and `REL_LIST` is not the same
Выводит только связь первого элемента, но не всех.почему?
['President' I-PER(['M.', 'Ashraf']) I-LOC(['Afghanistan'])]