Quá trình chuyển đổi dữ liệu thành một cái gì đó mà máy tính có thể hiểu được gọi là xử lý trước. Một trong những hình thức chính của xử lý trước là lọc ra dữ liệu vô dụng. Trong xử lý ngôn ngữ tự nhiên, các từ vô dụng [dữ liệu], được gọi là các từ dừng. & Nbsp; & nbsp;pre-processing. One of the major forms of pre-processing is to filter out useless data. In natural language processing, useless words [data], are referred to as stop words.
Những từ dừng là gì?
Các từ dừng: Một từ dừng là một từ thường được sử dụng [chẳng hạn như là The The The, một Do kết quả của một truy vấn tìm kiếm. & nbsp; chúng tôi sẽ không muốn những từ này chiếm không gian trong cơ sở dữ liệu của chúng tôi hoặc chiếm thời gian xử lý có giá trị. Đối với điều này, chúng ta có thể loại bỏ chúng một cách dễ dàng, bằng cách lưu trữ một danh sách các từ mà bạn xem xét để ngăn chặn các từ. NLTK [Bộ công cụ ngôn ngữ tự nhiên]
trong Python có một danh sách các từ dừng được lưu trữ trong 16 ngôn ngữ khác nhau. Bạn có thể tìm thấy chúng trong thư mục NLTK_DATA. Trang chủ/Pratima/NLTK_DATA/Corpora/Stopwords là địa chỉ thư mục. A stop word is a commonly used word [such as “the”, “a”, “an”, “in”] that a search engine has been programmed to ignore, both when indexing entries for searching and when retrieving them as the result of a search query.
We would not want these words to take up space in our
database, or taking up valuable processing time. For this, we can remove them easily, by storing a list of words that you consider to stop words. NLTK[Natural Language Toolkit] in python has a list of stopwords stored in 16 different languages. You can find them in the nltk_data directory. home/pratima/nltk_data/corpora/stopwords is the directory address.[Do not forget to change your home directory name]
Để kiểm tra danh sách các từ dừng, bạn có thể nhập các lệnh sau vào vỏ Python. & NBSP; & nbsp;
import nltk from nltk.corpus import stopwords print[stopwords.words['english']]
s
Có ',' với ',' họ ',' riêng ',' an ',' be ',' some ',' for ',' do ',' its ',' yours ',' như ',' thành 'thành' , 'của', 'hầu hết', 'chính nó', 'khác', 'off', 'là', 's', 'am', 'hoặc', 'who', 'as', 'from', '' anh ấy ',' mỗi ',' ',' chính họ ',' cho đến ',' bên dưới ',' là ',' chúng tôi ',' những 'này', 'của bạn', 'của anh ấy', 'qua', 'don' , 'cũng không', 'tôi', 'là', 'cô ấy', 'hơn', 'chính anh ấy', 'cái này', 'xuống', 'nên', 'của chúng tôi', 'của họ', 'trong khi', ' Ở trên ',' cả ',' lên ',' thành
',' của chúng tôi ',' đã ',' cô ấy ',' tất cả ',' không ',' khi ',' tại ',' bất kỳ ',' trước 'trước' , 'họ', 'giống nhau', 'và', 'đã', 'có', 'trong', 'will', 'on', 'không', 'chính mình', 'sau đó', 'đó', ',' bởi vì ',' cái gì ',' trên ',' tại sao ',' vì vậy ',' có thể ',' đã làm ',' không ',' bây giờ ',' dưới ',' anh ',' bạn ',' cô ấy ' , 'có', 'công bằng', 'ở đâu', 'quá', 'chỉ', 'bản thân mình', 'mà', 'những người', 'i', 'sau', 'vài', 'ai', '' T ',' là ',' nếu ',' của họ ',' của tôi ',' chống
lại ',' a ',' bởi ',' làm ',' nó ',' làm thế nào ',' hơn nữa ',' là 'là' , 'đây', 'tha Nát} & nbsp; Lưu ý: Bạn thậm chí có thể sửa đổi danh sách bằng cách thêm các từ bạn chọn vào tiếng Anh .txt. tệp trong thư mục stopwords. & nbsp; & nbsp;
Note: You can even modify the list by adding words of your choice in the english .txt. file in the stopwords directory.
Xóa các từ dừng bằng NLTK
Chương trình sau đây loại bỏ các từ
dừng khỏi một đoạn văn bản: & nbsp; & nbsp;
Python3
from
nltk.corpus
import
stopwords
from
nltk.tokenize
import
word_tokenize
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']0
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']4
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']5
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']6
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']7
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']8
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
from
0from
1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
from
3from
4 from
5from
6 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']8__
from
1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
nltk.corpus
5from
4 from
5from
6 nltk.corpus
9
import
0from
8 from
5from
9 from
6 import
5
import
6import
7
import
8import
9
import
8stopwords
1
Output:
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']
Thực hiện các hoạt động stopwords trong một tệp
Trong mã bên dưới, Text.txt là tệp đầu vào gốc trong đó các từ dừng sẽ được xóa. FilteredText.txt là tệp đầu ra. Nó có thể được
thực hiện bằng cách sử dụng mã sau: & nbsp; & nbsp;
Python3
import
stopwords
3
from
nltk.corpus
import
stopwords
7
from
nltk.tokenize
import
from
1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']4
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']5
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']6
from
7from
8
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
nltk.tokenize
0nltk.tokenize
1nltk.tokenize
2__nltk.tokenize
4
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
nltk.tokenize
6nltk.tokenize
7
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']1
nltk.tokenize
9from
4 import
1from
6 import
3
import
0from
8 from
9 import
1from
6 import
9
Các
import
6
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']00
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']01
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']02
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']03
import
6
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']05
Đây là cách chúng tôi làm cho nội dung được xử lý của chúng tôi hiệu quả hơn bằng cách loại bỏ các từ không đóng góp cho bất kỳ hoạt động nào trong tương lai. Bài viết này được đóng góp bởi Pratima Upadhyay. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên
máy tính khác. Xin vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên. & NBSP;
This article is contributed by Pratima Upadhyay. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find
anything incorrect, or you want to share more information about the topic discussed above.