PunktSentenceTokenizer
stanowi klasę domyślnego zdanie tokenizera tj sent_tokenize()
, znajdujące się w NLTK. Jest to domena Unsupervised Multilingual Sentence Boundary Detection (Kiss and Strunk (2005). Zobacz https://github.com/nltk/nltk/blob/develop/nltk/tokenize/init.py#L79
Biorąc pod paragraf o zdaniu wielokrotnej, np:
>>> from nltk.corpus import state_union
>>> train_text = state_union.raw("2005-GWBush.txt").split('\n')
>>> train_text[11]
u'Two weeks ago, I stood on the steps of this Capitol and renewed the commitment of our nation to the guiding ideal of liberty for all. This evening I will set forth policies to advance that ideal at home and around the world. '
Można użyć sent_tokenize()
:
>>> sent_tokenize(train_text[11])
[u'Two weeks ago, I stood on the steps of this Capitol and renewed the commitment of our nation to the guiding ideal of liberty for all.', u'This evening I will set forth policies to advance that ideal at home and around the world. ']
>>> for sent in sent_tokenize(train_text[11]):
... print sent
... print '--------'
...
Two weeks ago, I stood on the steps of this Capitol and renewed the commitment of our nation to the guiding ideal of liberty for all.
--------
This evening I will set forth policies to advance that ideal at home and around the world.
--------
The sent_tokenize()
wykorzystuje wstępnie przeszkoleni modelu z nltk_data/tokenizers/punkt/english.pickle
.Można również określić inne języki, lista dostępnych języków z wcześniej przeszkoleni modeli NLTK są:
[email protected]:~/nltk_data/tokenizers/punkt$ ls
czech.pickle finnish.pickle norwegian.pickle slovene.pickle
danish.pickle french.pickle polish.pickle spanish.pickle
dutch.pickle german.pickle portuguese.pickle swedish.pickle
english.pickle greek.pickle PY3 turkish.pickle
estonian.pickle italian.pickle README
Biorąc tekst w innym języku, to zrobić:
>>> german_text = u"Die Orgellandschaft Südniedersachsen umfasst das Gebiet der Landkreise Goslar, Göttingen, Hameln-Pyrmont, Hildesheim, Holzminden, Northeim und Osterode am Harz sowie die Stadt Salzgitter. Über 70 historische Orgeln vom 17. bis 19. Jahrhundert sind in der südniedersächsischen Orgellandschaft vollständig oder in Teilen erhalten. "
>>> for sent in sent_tokenize(german_text, language='german'):
... print sent
... print '---------'
...
Die Orgellandschaft Südniedersachsen umfasst das Gebiet der Landkreise Goslar, Göttingen, Hameln-Pyrmont, Hildesheim, Holzminden, Northeim und Osterode am Harz sowie die Stadt Salzgitter.
---------
Über 70 historische Orgeln vom 17. bis 19. Jahrhundert sind in der südniedersächsischen Orgellandschaft vollständig oder in Teilen erhalten.
---------
Aby trenować swój własny punkt modelu, patrz https://github.com/nltk/nltk/blob/develop/nltk/tokenize/punkt.py i training data format for nltk punkt
źródło kodu https://pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/ –