Stopwords adalah kata-kata bahasa Inggris yang tidak menambahkan banyak arti kalimat. Mereka dapat dengan aman diabaikan tanpa mengorbankan makna kalimat. Misalnya, kata-kata seperti, dia, memiliki dll. Kata-kata seperti ini sudah terekam dalam corpus yang bernama corpus. Kami pertama kali mengunduhnya ke lingkungan python kami Show import nltk nltk.download('stopwords') Ini akan mengunduh file dengan stopword bahasa Inggris Memverifikasi Stopwordsfrom nltk.corpus import stopwords stopwords.words('english') print stopwords.words() [620:680]_ Ketika kami menjalankan program di atas, kami mendapatkan output berikut - [u'your', u'yours', u'yourself', u'yourselves', u'he', u'him', u'his', u'himself', u'she', u"she's", u'her', u'hers', u'herself', u'it', u"it's", u'its', u'itself', u'they', u'them', u'their', u'theirs', u'themselves', u'what', u'which', u'who', u'whom', u'this', u'that', u"that'll", u'these', u'those', u'am', u'is', u'are', u'was', u'were', u'be', u'been', u'being', u'have', u'has', u'had', u'having', u'do', u'does', u'did', u'doing', u'a', u'an', u'the', u'and', u'but', u'if', u'or', u'because', u'as', u'until', u'while', u'of', u'at'] Macam-macam bahasa selain bahasa Inggris yang memiliki stopword tersebut adalah sebagai berikut from nltk.corpus import stopwords print stopwords.fileids() Ketika kami menjalankan program di atas, kami mendapatkan output berikut - [u'arabic', u'azerbaijani', u'danish', u'dutch', u'english', u'finnish', u'french', u'german', u'greek', u'hungarian', u'indonesian', u'italian', u'kazakh', u'nepali', u'norwegian', u'portuguese', u'romanian', u'russian', u'spanish', u'swedish', u'turkish']_ ContohKami menggunakan contoh di bawah ini untuk menunjukkan bagaimana stopwords dihapus dari daftar kata from nltk.corpus import stopwords en_stops = set(stopwords.words('english')) all_words = ['There', 'is', 'a', 'tree','near','the','river'] for word in all_words: if word not in en_stops: print(word) Ketika kami menjalankan program di atas, kami mendapatkan output berikut - There tree near river_ Anda mencoba memeriksa apakah daftar (hasil dari regex) ada dalam satu set. operasi ini tidak dapat dilakukan. Anda perlu mengulang daftar (atau melakukan semacam operasi set, mis. g. Hanya untuk kejelasan
Kemudian tambahkan saja _Terakhir, Anda dapat menentukan Proses mengubah data menjadi sesuatu yang dapat dipahami komputer disebut sebagai pra-pemrosesan. Salah satu bentuk utama pra-pemrosesan adalah menyaring data yang tidak berguna. Dalam pemrosesan bahasa alami, kata-kata (data) yang tidak berguna, disebut sebagai kata-kata berhenti Apa itu kata-kata Hentikan? Hentikan Kata-kata. Stop word adalah kata yang umum digunakan (seperti "the", "a", "an", "in") yang telah diprogram untuk diabaikan oleh mesin telusur, baik saat mengindeks entri untuk penelusuran maupun saat mengambilnya sebagai hasilnya . Untuk memeriksa daftar stopwords Anda dapat mengetikkan perintah berikut di shell python. import nltk from nltk.corpus import stopwords print(stopwords.words('english'))_ {'diri kita', 'miliknya', 'antara', 'dirimu', 'tetapi', 'lagi', 'di sana', 'tentang', 'sekali', 'selama', 'keluar', 'sangat', ' Menghapus kata berhenti dengan NLTK Program berikut menghapus kata berhenti dari sepotong teks. Python3
['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', '.']3 ________10 [u'arabic', u'azerbaijani', u'danish', u'dutch', u'english', u'finnish', u'french', u'german', u'greek', u'hungarian', u'indonesian', u'italian', u'kazakh', u'nepali', u'norwegian', u'portuguese', u'romanian', u'russian', u'spanish', u'swedish', u'turkish']_10_______5 ['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', '.']7 ['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', '.']9 from 0from 1from 2['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', '.']2 from 6
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 nltk.corpus 1nltk.corpus 2 nltk.corpus 3nltk.corpus 4 from 4nltk.corpus 6 nltk.corpus 7 _________50______8nltk.corpus 4 _______4
________49 import nltk from nltk.corpus import stopwords print(stopwords.words('english'))_10_______2 import 4['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']_0
________52______0
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']_0 ________52 import nltk from nltk.corpus import stopwords print(stopwords.words('english'))_49_______0 ________52 import nltk from nltk.corpus import stopwords print(stopwords.words('english'))_49_______2 Keluaran ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']
Melakukan operasi Stopwords dalam file Pada kode di bawah ini, teks. txt adalah file input asli di mana stopwords harus dihapus. filteredtext. txt adalah file keluaran. Itu dapat dilakukan dengan menggunakan kode berikut. Python3
['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', '.']7 ['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', '.']9 from 0from 1import 1
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 import 4import 5import 6import 7['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', '.']2 word_tokenize 2
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 word_tokenize 5
________52______0 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']05 ________52______6 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']07 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']2 import 4import 5['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']11 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']12 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']13 import 7________52______6 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']16 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']17 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']18 ['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']19
['This', 'is', 'a', 'sample', 'sentence', ',', 'showing', 'off', 'the', 'stop', 'words', 'filtration', '.'] ['This', 'sample', 'sentence', ',', 'showing', 'stop', 'words', 'filtration', '.']21 Inilah cara kami membuat konten yang diproses menjadi lebih efisien dengan menghapus kata-kata yang tidak berkontribusi pada operasi apa pun di masa mendatang Artikel ini disumbangkan oleh Pratima Upadhyay. Jika Anda menyukai GeeksforGeeks dan ingin berkontribusi, Anda juga dapat menulis artikel menggunakan tulis. geeksforgeeks. org atau kirimkan artikel Anda ke review-team@geeksforgeeks. org. Lihat artikel Anda muncul di halaman utama GeeksforGeeks dan bantu Geeks lainnya Silakan tulis komentar jika Anda menemukan sesuatu yang salah, atau jika Anda ingin berbagi informasi lebih lanjut tentang topik yang dibahas di atas. Bagaimana Anda menghapus kata-kata berhenti di Python tanpa NLTK?Ada beberapa cara untuk melakukannya. ==> Hapus semua s di akhir kata, atau gandakan stopword Anda dan tambahkan s ke masing-masing, atau gunakan metode len() untuk melihat apakah suatu bagian sama persis . Hal kedua yang mungkin ingin Anda pertimbangkan (dan ini paling baik dilakukan sebelum melakukan stemming). . A second thing you might want to consider (and this is best done before stemming).
Bagaimana cara menghapus kata berhenti dari Excel dengan Python?Akhirnya, Anda juga dapat menghapus kata henti dari daftar kata henti default NLTK. Untuk melakukannya, gunakan fungsi remove() dan berikan kata stop yang ingin Anda hapus .
Bagaimana Anda menghapus kata berhenti dan tanda baca dengan Python?Untuk menghapus stopwords dan tanda baca menggunakan NLTK, kita harus mendownload semua stopwords menggunakan nltk. download('stopwords'), maka kita harus menentukan bahasa yang ingin kita hapus stopwordsnya, oleh karena itu, kita menggunakan stopwords. kata-kata ('bahasa Inggris') untuk menentukan dan menyimpannya ke variabel
Modul Python mana yang digunakan untuk menghapus kata berhenti?Menghapus kata berhenti dengan NLTK dengan Python. |