Python ile Cümle Sonu Bulma


Python - Metni cümlelere bölmek için RegEx (cümle belirteci) Bir dizgeden cümle listesi yapmak ve sonra bunları yazdırmak istiyorum. Bunu yapmak için NLTK kullanmak istemiyorum. Bu yüzden cümlenin sonunda bir döneme ayrılması gerekir, ondalık, kısaltma veya bir ismin unvanına veya cümlenin bir .com'a sahip olmaması gerekir.
 import re text = """\ Mr. Smith bought cheapsite.com for 1.5 million dollars, i.e. he paid a lot for it. Did he mind? Adam Jones Jr. thinks he didn't. In any case, this isn't true... Well, with a probability of .9 it isn't. """
sentences = re.split(r' *[\.\?!][\'"\)\]]* *', text)
for stuff in sentences:
      print(stuff)
 Neye benzemesi gerektiğine dair örnek çıktı
 Mr. Smith bought cheapsite.com for 1.5 million dollars, i.e.
he paid a lot for it.
 Did he mind?
Adam Jones Jr. thinks he didn't.
In any case, this isn't true...
Well, with a probability of .
9 it isn't.

Denemesini yapaağım. Burayada yazarım. Ancak daha gelişmiş ve doğru sonuçlar veren bir cümle sonu bulma algoritması için https://jn7.net/turkce-metinlerde-cumle-sonu-bulma-uygulamasi/ adresine bakabilirsiniz.
static Regex _sentenseRegex = new Regex(@"(?<=['""a-zıüöşğç\""\]\)][\!\?\:\.\…\n\r\n\t]{1,3})\s+(?=[""A-ZİÜÖŞĞÇ0-9\(\-\(\''\‘\““\""\[\+])", RegexOptions.Compiled);
Bu regex kodları ile kurallı bir cümle sonu bulma işlemi gerçekleştirebilirsiniz.

Yorum Gönder

0 Yorumlar