You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
2.0 KiB

# Klasse zum Austauschen von Genitiv durch Dativ
import spacy
class GenitivSolve(object):
def __init__(self):
#print('loading the german spacy model..')
self.nlp = spacy.load('de_core_news_sm')
#print('done')
return
def ReplaceGenitivWithDativ(self, sentences):
count = 0
for sentence in sentences:
count += 1
#print('processing sentence', count)
tokens = self.nlp(' '.join(sentence))
for n in range(1, len(sentence)):
#print(sentence[n])
if (sentence[n][-1] == 's' or sentence[n][-1] == 'n') and (sentence[n - 1] == 'des' or sentence[n - 1] == 'Des'):
#print('oi')
#print('genitiv', sentence[n], sentence[n][:-2])
if sentence[n][-2] == 'e':
sentence[n] = sentence[n][:-2]
else:
sentence[n] = sentence[n][:-1]
sentence[n - 1] = 'dem'
sentence.insert(n - 1, 'von')
if sentence[n] == 'der' and sentence[n - 1][-1] != ',' and (tokens[n - 1].tag_ == 'NN' and tokens[n-1].text == sentence[n]) and sentence[n][-2:] != 'en':
sentence.insert(n, 'von')
if sentence[n] == 'der' and sentence[n - 1][-1] != ',' and (tokens[n - 1].tag_ == 'NN' and tokens[n-1].text == sentence[n]) and ((sentence[n+1][-2:] == 'en' or sentence[n+1][-1] == 'n' or sentence[n+1][-1] == 'e' or sentence[n+1][-2:] == 'er')):
if sentence[n+1][-1] == 'e':
sentence[n+1] + 'n'
sentence[n] == 'den'
sentence.insert(n, 'von')
return sentences