برنامه نویسی

Corpus & Vocabulary – Community Dev

جسد مجموعه متن است. این می تواند چندین پاراگراف به کل کتاب باشد.

حالا سوال پیش می آید که چرا ما در مورد آن صحبت می کنیم؟

خوب به زبان پردازش طبیعی می تواند چندین پاراگراف وجود داشته باشد
یا متن طولانی برای تجزیه و تحلیل ما می خواهیم یاد بگیریم که چگونه با متن عظیم مقابله کنیم.

برای تجزیه و تحلیل متن باید این مراحل یا پیش پردازش Corpus را به خاطر بسپارید:

  1. تطابق
  2. حذف کلمه را متوقف کنید
  3. حذف شخصیت خاص
  4. تبدیل حروف کوچک

1.

from nltk.tokenize import word_tokenize

corpus="In order to make the corpora more useful for doing linguistic research, they are often subjected to a process known as annotation. An example of annotating a corpus is part-of-speech tagging, or POS-tagging, in which information about each word's part of speech (verb, noun, adjective, etc.) is added to the corpus in the form of tags. Another example is indicating the lemma (base) form of each word. When the language of the corpus is not a working language of the researchers who use it, interlinear glossing is used to make the annotation bilingual."

print(word_tokenize(word))

['In', 'order', 'to', 'make', 'the', 'corpora', 'more', 'useful', 'for', 'doing', 'linguistic', 'research', ',', 'they', 'are', 'often', 'subjected', 'to', 'a', 'process', 'known', 'as', 'annotation', '.', 'An', 'example', 'of', 'annotating', 'a', 'corpus', 'is', 'part-of-speech', 'tagging', ',', 'or', 'POS-tagging', ',', 'in', 'which', 'information', 'about', 'each', 'word', "'s", 'part', 'of', 'speech', '(', 'verb', ',', 'noun', ',', 'adjective', ',', 'etc', '.', ')', 'is', 'added', 'to', 'the', 'corpus', 'in', 'the', 'form', 'of', 'tags', '.', 'Another', 'example', 'is', 'indicating', 'the', 'lemma', '(', 'base', ')', 'form', 'of', 'each', 'word', '.', 'When', 'the', 'language', 'of', 'the', 'corpus', 'is', 'not', 'a', 'working', 'language', 'of', 'the', 'researchers', 'who', 'use', 'it', ',', 'interlinear', 'glossing', 'is', 'used', 'to', 'make', 'the', 'annotation', 'bilingual', '.']

2. حذف کلمه را متوقف کنید و مورد کمتری را تبدیل کنید:

from nltk.corpus import stopwords
for word in word_tokenize(corpus):
    if (word.lower() not in stopwords.words('english') and (len(word)>=2)):
        print(word)
Output:
order
make
corpora
useful
linguistic
research
often
subjected
process
known
annotation
example
annotating
corpus
part-of-speech
tagging
POS-tagging
information
word
's
part
speech
verb
noun
adjective
etc
added
corpus
form
tags
Another
example
indicating
lemma
base
form
word
language
corpus
working
language
researchers
use
interlinear
glossing
used
make
annotation
bilingual

3. در لیست قرار دهید:

words=[]
for word in word_tokenize(corpus):
    if (word.lower() not in stopwords.words('english') and (len(word)>=2)):
        words.append(word.lower())

print(words)
Output:
['order', 'make', 'corpora', 'useful', 'linguistic', 'research', 'often', 'subjected', 'process', 'known', 'annotation', 'example', 'annotating', 'corpus', 'part-of-speech', 'tagging', 'pos-tagging', 'information', 'word', "'s", 'part', 'speech', 'verb', 'noun', 'adjective', 'etc', 'added', 'corpus', 'form', 'tags', 'another', 'example', 'indicating', 'lemma', 'base', 'form', 'word', 'language', 'corpus', 'working', 'language', 'researchers', 'use', 'interlinear', 'glossing', 'used', 'make', 'annotation', 'bilingual']

4. کلمات منحصر به فرد:

print(set(words))
Output:
['order', 'make', 'corpora', 'useful', 'linguistic', 'research', 'often', 'subjected', 'process', 'known', 'annotation', 'example', 'annotating', 'corpus', 'part-of-speech', 'tagging', 'pos-tagging', 'information', 'word', "'s", 'part', 'speech', 'verb', 'noun', 'adjective', 'etc', 'added', 'corpus', 'form', 'tags', 'another', 'example', 'indicating', 'lemma', 'base', 'form', 'word', 'language', 'corpus', 'working', 'language', 'researchers', 'use', 'interlinear', 'glossing', 'used', 'make', 'annotation', 'bilingual']

واژگان در زمینه NLP ، به کلمات منحصر به فرد در جسد اشاره دارد. پس از پیش پردازش کل کلمات منحصر به فرد.

برای دیدن تفاوت پس از حذف کلمه توقف و دریافت ارزش منحصر به فرد از کلمات

print(len(words))
print(len(set(words)))
Output:
49
41

نوشته های مشابه

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

دکمه بازگشت به بالا