NLTK for Persian

How to use NLTK functions for Persian?

For example: "Consent." When I use “matching,” the answer is “not matching,” however there is a matching option in my text.

entry is very simple. It contains "hello سلام" when the parameter "concordance" is "hello", the correct answer, but if "سلام" the answer is "no match". the expected result for me is "Displaying 1 out of 1 matches."

import nltk from urllib import urlopen url = "file:///home/.../1.html" raw = urlopen(url).read() raw = nltk.clean_html(raw) tokens = nltk.word_tokenize(raw) tokens = tokens[:12] text = nltk.Text(tokens) print text.concordance('سلام') 
+6
source share
2 answers

Highly recommended Persian python library for NLP: https://github.com/sobhe/hazm

Using:

 >>> from __future__ import unicode_literals >>> from hazm import Normalizer >>> normalizer = Normalizer() >>> normalizer.normalize('اصلاح نويسه ها و استفاده از نیم‌فاصله پردازش را آسان مي كند') 'اصلاح نویسه‌ها و استفاده از نیم‌فاصله پردازش را آسان می‌کند' >>> from hazm import sent_tokenize, word_tokenize >>> sent_tokenize('ما هم برای وصل کردن آمدیم! ولی برای پردازش، جدا بهتر نیست؟') ['ما هم برای وصل کردن آمدیم!', 'ولی برای پردازش، جدا بهتر نیست؟'] >>> word_tokenize('ولی برای پردازش، جدا بهتر نیست؟') ['ولی', 'برای', 'پردازش', '،', 'جدا', 'بهتر', 'نیست', '؟'] >>> from hazm import Stemmer, Lemmatizer >>> stemmer = Stemmer() >>> stemmer.stem('کتاب‌ها') 'کتاب' >>> lemmatizer = Lemmatizer() >>> lemmatizer.lemmatize('می‌روم') 'رفت#رو' >>> from hazm import POSTagger >>> tagger = POSTagger() >>> tagger.tag(word_tokenize('ما بسیار کتاب می‌خوانیم')) [('ما', 'PR'), ('بسیار', 'ADV'), ('کتاب', 'N'), ('می‌خوانیم', 'V')] >>> from hazm import DependencyParser >>> parser = DependencyParser(tagger=POSTagger()) >>> parser.parse(word_tokenize('زنگ‌ها برای که به صدا درمی‌آید؟')) <DependencyGraph with 8 nodes> 
+19
source

Actually, I used hazm in windows and I could install HAzm, but when I ran this code:

 from __future__ import unicode_literals from hazm import * I have such Error: from hazm import x File "C:\Python34\lib\site-packages\hazm\__init__.py", line 13, in <module> from .SequenceTagger import SequenceTagger, IOBTagger File "C:\Python34\lib\site-packages\hazm\SequenceTagger.py", line 6, in <module> from wapiti import Model ImportError: No module named 'wapiti' 
0
source

Source: https://habr.com/ru/post/949588/


All Articles