isd312 03-nltk

21
Pertemuan 3: NLTK, 27 September 2011

Upload: anung-ariwibowo

Post on 09-May-2015

558 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Isd312 03-nltk

Pertemuan 3: NLTK, 27 September 2011

Page 2: Isd312 03-nltk

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)

Page 3: Isd312 03-nltk

Model Boolean

Model Vektor

3 Information Retrieval – ISD312 NLTK dan Python

Page 4: Isd312 03-nltk

Menggunakan NLTK

Pemrograman Python

Latihan

4 Information Retrieval – ISD312 NLTK dan Python

Page 5: Isd312 03-nltk

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

Page 6: Isd312 03-nltk

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

Page 7: Isd312 03-nltk

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

Page 8: Isd312 03-nltk

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

Page 9: Isd312 03-nltk

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

Page 10: Isd312 03-nltk

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

Page 11: Isd312 03-nltk

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

Page 12: Isd312 03-nltk

>>> 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

Page 13: Isd312 03-nltk

df = FreqDist(text5)

vocabulary = df.keys()

vocabulary[:10]

df.plot(50)

df.plot(50, cumulative=True)

13 Information Retrieval – ISD312 NLTK dan Python

Page 14: Isd312 03-nltk

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

Page 15: Isd312 03-nltk

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

Page 16: Isd312 03-nltk

Frase dua-kata yang sering muncul bersama

Melibatkan kata yang jarang muncul

text1.collocations()

text5.collocations()

16 Information Retrieval – ISD312 NLTK dan Python

Page 17: Isd312 03-nltk

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

Page 18: Isd312 03-nltk

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

Page 19: Isd312 03-nltk

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

Page 20: Isd312 03-nltk

http://www.nltk.org/book

http://tjerdastangkas.blogspot.com/search/label/isd312

20 Information Retrieval – ISD312 NLTK dan Python

Page 21: Isd312 03-nltk

Selasa, 27 September 2011