Код: Выделить всё
başlar
_______________|________
| | taklit
| | ________|_________
| sanatçı | | sanatçıları
| | | | |
işe Her başlangıçta ederek büyük
Код: Выделить всё
nlp = spacy.load(
r"C:\ProgramData\anaconda3\envs\b\Lib\site-packages\tr_core_news_trf\tr_core_news_trf-3.4.2")
def to_nltk_tree(node):
if node.n_lefts + node.n_rights > 0:
return Tree(node.orth_, [to_nltk_tree(child) for child in node.children])
else:
return node.orth_
query = u'Her sanatçı başlangıçta büyük sanatçıları taklit ederek işe başlar'
doc = nlp(query)
[to_nltk_tree(sent.root).pretty_print() for sent in doc.sents]
for sent in doc.sents:
d = to_nltk_tree(sent.root)
rr = repr(d).split("Tree")
print("rr out :" )
print(rr )
['', "('begins', [", "('artist' , ['каждый']), ", "('подражал', ['изначально', ", "('художники', ['великие']), 'по']), 'рекрутировал'])"]< /p>
Я пробовал:
Код: Выделить всё
we=[""]*200
w=0
print("------------------------------------")
def print_list2(nested_list,w):
words = []
for value in nested_list:
if isinstance(value, list):
words.extend(print_list2(value,w))
# we[w]=" ".join(words[::-1])
else:
words.append(value)
# we[w]=" ".join(words[::-1])
we[w]=" ".join(words)
w=w+1
print(" ".join(words ))
# we[w]=" ".join(words[::-1])
return words
we1=print_list2(rr,w)
print(we)
('begins', [ ('artist', ['Her']), ( 'подражать', ['в начале', ('художники', ['великие']), 'под']), 'работать'])
[" (' начинается', [('художник', ['каждый']), ('подражать', ['изначально', ('художники', ['великие']), 'по']), 'нанимать'])" , '' , '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ' ', ' ','','','','','','','','','','','','','',''', '' ,'','','','','','','','','','','','','','' , '', '', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', ' ','','', '','','','','','','','','','','',''', '','','','',' ','','','','','','','','','','' , '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ' ','','','','','','' ,'','','','','','','',''', '','','','','','','','', '','','','','','','' , '', '', '', '', '', '', '', '', '', '' , '', '', '', '', '', '', ' ','','','','','','','','','',' ','','','',''', '', '', '', '', '', '', '', '', '', '', '', '' , '', '', '']
Я пытаюсь захватить значения:
Код: Выделить всё
we[w]=" ".join(words)
мне нужно получить доступ к каждому списку или кортежу, как показано ниже:
Код: Выделить всё
insede we[0] or not mater which index
('sanatçı', ['Her'])
we[1]='taklit', ['başlangıçta', ('sanatçıları', ['büyük']), 'ederek'])
....
..
.
Her sanatçı
başlangıçta
büyük sanatçıları taklit ederek
işe
başlar
Дерево выше нужно разделить, как указано выше...
Надеюсь, понятно, что мне нужно
Подробнее здесь: https://stackoverflow.com/questions/791 ... ted-string
Мобильная версия