isd312 03-nltk
TRANSCRIPT
Pertemuan 3: NLTK, 27 September 2011
Penilaian Tugas 20% (ditentukan kemudian)
UTS 30% (27 Okt 2011, 0800 WIB; Buka catatan)
UAS 40% (12 Jan 2012, 0800 WIB; Buka catatan)
Catatan ujian
1 lembar A4
Bukan fotokopi
26 Okt 2011, 1200 WIB (UTS)
11 Jan 2011, 1200 WIB (UAS)
Model Boolean
Model Vektor
3 Information Retrieval – ISD312 NLTK dan Python
Menggunakan NLTK
Pemrograman Python
Latihan
4 Information Retrieval – ISD312 NLTK dan Python
Menggunakan package nltk import nltk
Mengunduh korpus-korpus yang tersedia online nltk.download()
Menggunakan korpus "Book"
from nltk.book import *
import nltk.book as buku
5 Information Retrieval – ISD312 NLTK dan Python
text1: Moby Dick
text2: Sense and Sensibility
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday
6 Information Retrieval – ISD312 NLTK dan Python
Konkordansi Menampilkan kalimat yang menggunakan sebuah kata
tertentu text1.concordance("monstrous")
Kemiripan berdasarkan konteks text1.similar("monstrous")
Menampilkan konteks dari kata-kata yang mirip text1.common_contexts(['monstrous',
'subtly'])
List sebagai paameter untuk fungsi common_contexts()
7 Information Retrieval – ISD312 NLTK dan Python
text1
Jumlah tokens dalam satu dokumen len(text1)
Perulangan kemunculan dihitung
Jumlah kata unik len(set(text1))
set() menghilangkan perulangan kemunculan
Mengurutkan data dalam list / set sorted(set(text1))
8 Information Retrieval – ISD312 NLTK dan Python
List dan Variabel sent1 = ['Kelas', 'Information',
'Retrieval', 'Teknik', 'Informatika']
Indeks dimulai dari 0
Slicing sent1[1:2]
sent1[:2]
sent1[2:]
sent1[-2:]
9 Information Retrieval – ISD312 NLTK dan Python
Concatenation sent1 + sent1
Append sent1.append('python')
String
Diapit oleh 'single quote' atau "double quote"
List of characters
10 Information Retrieval – ISD312 NLTK dan Python
Lexical richness
Perbandingan jumlah tokens dengan jumlah kata unik len(text1) / len(set(text1))
Integer division from __future__ import division
Jumlah kemunculan sebuah token text1.count('whale')
100 * text1.count('whale') / len(text1)
11 Information Retrieval – ISD312 NLTK dan Python
>>> def lexicalDiversity(text):
... return len(text) / len(set(text))
>>> def percentage(count, total):
... return 100 * count / total
lexicalDiversity(text5)
percentage(text1.count('whale'), len(text1))
12 Information Retrieval – ISD312 NLTK dan Python
df = FreqDist(text5)
vocabulary = df.keys()
vocabulary[:10]
df.plot(50)
df.plot(50, cumulative=True)
13 Information Retrieval – ISD312 NLTK dan Python
Kemunculan dua kata (bi-) dalam dokumen
N-grams: Kemunculan N kata dalam dokumen
kalimat = ['After', 'all', 'is', 'said',
'and', 'done', 'more', 'is', 'said', 'than',
'done']
tokens = set(kalimat)
tokens = sorted(tokens)
tokens[-2:]
bigrams(kalimat)
14 Information Retrieval – ISD312 NLTK dan Python
Muncul hanya satu kali dalam dokumen
H = df.hapaxes()
longHapaxes = [w for w in V if len(w) > 15]
15 Information Retrieval – ISD312 NLTK dan Python
Frase dua-kata yang sering muncul bersama
Melibatkan kata yang jarang muncul
text1.collocations()
text5.collocations()
16 Information Retrieval – ISD312 NLTK dan Python
Menghitung frekuensi terms dalam teks from nltk.book import *
fdist1 = FreqDist(text1)
vocabulary = fdist.keys()
vocabulary[:50]
vocabulary['whale']
17 Information Retrieval – ISD312 NLTK dan Python
Mengubah definisi fungsi percentage() agar bisa menerima satu parameter: nama dokumen
Buat sebuah fungsi python yang menerima dua buah vektor dan mengembalikan Hasil dot-product dari kedua vektor tersebut
Buat sebuah fungsi python yang menerima sebuah vektor dan mengembalikan Norm dari vektor tersebut
18 Information Retrieval – ISD312 NLTK dan Python
Hitung berapa jumlah kata unik di dalam korpus nltk.book
Tuliskan statement-statement progam Python yang anda gunakan untuk mendapatkannya
Batas waktu: 3 Oktober 2011, pukul 13.30 WIB
By e-mail [email protected] (Subject "ISD312 TM2", Nama, dan NIM)
Bonus sebelum batas waktu pengumpulan
Nilai kosong setelah batas waktu
19 Information Retrieval – ISD312 NLTK dan Python
http://www.nltk.org/book
http://tjerdastangkas.blogspot.com/search/label/isd312
20 Information Retrieval – ISD312 NLTK dan Python
Selasa, 27 September 2011