0% found this document useful (0 votes)
95 views15 pages

Information Retrieval: Assignment 1

The document summarizes an assignment completed by the author involving creating a text corpus from a specific domain using Scrapy or Feedparser. NLTK functions were then tested on the corpus, including analyzing word frequencies and concordances. The corpus was from a Wikipedia article on Sterjo Spasse and various NLTK analyses were conducted including word counts, frequencies, and concordances.

Uploaded by

DuaFetai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views15 pages

Information Retrieval: Assignment 1

The document summarizes an assignment completed by the author involving creating a text corpus from a specific domain using Scrapy or Feedparser. NLTK functions were then tested on the corpus, including analyzing word frequencies and concordances. The corpus was from a Wikipedia article on Sterjo Spasse and various NLTK analyses were conducted including word counts, frequencies, and concordances.

Uploaded by

DuaFetai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Assignment 1

Information Retrieval
Dua Fetai

2. Activity With Scrapy or Feedparser create a text corpus for a specific


domain. Then create the vocabulary from this corpus, where each word in the
vocabulary corresponds to the number indicating that this word is
represented in the sentence. Test NLTK functions for this corpus described in
http://www.nltk.org/book/ch01.html (at least 10 functions).

 The tools that I used to complete the assignment:


 Python, NLTK
 Anaconda, Spyder (3.7), text file

 I launched Spyder from Anaconda, it is a Scientific Python Development


Environment. Powerful Python IDE with advanced editing, interactive
testing, debugging and introspection features.

 The corpus information I got from Wikipedia, Sterjo Spasse.

 I created a project using Anaconda,Spyder.


 Importing NLTK, and processing my text file.
Here I made the importing and connection of the corpus text:

And we start with the functions:


The code:
# -*- coding: utf-8 -*-
# *** Spyder Python Console History Log ***

## ---(Fri Apr 3 20:30:56 2020)---


import nltk
nltk.download ()
import nltk
nltk.download()

## ---(Sat Apr 4 03:26:38 2020)---


import nltk

## ---(Sat Apr 4 03:34:38 2020)---


http://www.nltk.org/book/ch01.html
import nltk
from nltk.corpus import PlaintextCorpusReader
corpusText = PlaintextCorpusReader(r"/Users/duafetai/Desktop/corp","SterjoSpasse.txt")
text = nltk.Text(corp.words())
text = nltk.Text(corpusText.words())
text
text.concordance("Spasse")
text.concordance("Arsimit")
text.concordance("Veprimtaria")
text.similar("monstrous")
set(text)
len(text)
text.count("arsimi")
text.count("Spasse")
sorted(set(text))
text[10]
text[20]
text[2]
text[5:9]
from nltk.probability import FreqDist
fdist2 = FreqDist(text)
print(fdist2)
fdist2.most_common(50)
'fshati',
'fshatin',
'fshatrat',
'fundin',
'fundit',
'fushën',
'gazetën',
'gjithashtu',
'hartimin',
'here',
'herë',
'i',
'integral',
'ishin',
'ishte',
'iu',
'ja',
'jeta',
'jetë',
'jonë',
'jug',
'ka',
'kaloi',
'kaluar',
'katër',
'kishte',
'kohën',
'komplet',
'komuniste',
'korrespondencë',
'krahët',
'kreu',
'krijimet',
'kryevepra',
'ku',
'kurs',
'letrare',
'lindur',
'liqenit',
'liri',
'lirë',
'lufte',
'maqedonase',
'maqedonishtfolës',
'marrë',
'mbahet',
'me',
'monografi',
'muar',
'më',
'mësues',
'ndaj',
'ndryshme',
'ndryshëm',
'ndërsa',
'nga',
'nisi',
'njihet',
'një',
'njëri',
'nuk',
'në',
'nëntë',
'organin',
'pa',
'pak',
'pandehur',
'parisë',
'partiak',
'parë',
'pas',
'pashë',
'pedagogji',
'pedagogjike',
'periudhë',
'po',
'politike',
'popullor',
'por',
'porsaçliruar',
'pranë',
'preference',
'prejardhje',
'profesion',
'provimet',
'punime',
'punoi',
'punë',
'për',
'përkohshmes',
'përkthime',
'përkthye',
'përmbledhje',
'përsëri',
'qe',
'që',
're',
'realizmit',
'revistat',
'rinie',
'romane',
'romani',
'romanin',
'romanit',
'shekullit',
'shkak',
'shkollore',
'shkollën',
'shkrimtar',
'shkroi',
'shkruante',
'shkurt',
'shumëllojshme',
'si',
'sidomos',
'socialist',
'së',
'tekste',
'teksteve',
'tetë',
'tij',
'tregime',
'tregimesh',
'tregimit',
'tridhjetë',
'të',
'u',
'vdekje',
'vepra',
'veprash',
'veprën',
'veta',
'vetëm',
'vitet',
'vitit',
'vonë',
'vëllime',
'zë',
'është'}

len(text)
Out[13]: 525

text.count("arsimi")
Out[14]: 0

text.count("Spasse")
Out[15]: 3

sorted(set(text))
Out[16]:
['!?"',
'!?.',
'"',
'",',
'(',
')',
'),',
').',
',',
'-',
'.',
'..."',
'.[',
'15',
'1934',
'1935',
'1944',
'1946',
'1952',
'1954',
'1958',
'1965',
'1968',
'1972',
'1973',
'1975',
'1978',
'1980',
'1983',
'1985',
'2',
'3',
'4',
':',
'Afërdita',
'Aleksandër',
'Arsimi',
'Arsimit',
'Artistëve',
'Ata',
'Botimeve',
'Botoi',
'Buzë',
'Derviçan',
'Dhimitër',
'Draçinin',
'Elbasan',
'Firencë',
'Gjirokastrës',
'Gollomboç',
'Hakiun',
'Harbutët',
'Italisë',
'Ja',
'Kjo',
'Kokonën',
'Korçë',
'Korçës',
'Kryengritësit',
'Kulturës',
'Kuror',
'Kutelin',
'Lidhjes',
'Literatura',
'Me',
'Min',
'Më',
'Ndërsa',
'Nga',
'Normale',
'Nusja',
'Në',
'Nëntori',
'Pishtarë',
'Po',
'Prespës',
'Pse',
'Punoi',
'Përpara',
'Qemal',
'Redaksia',
'Revista',
'Rilindja',
'Shkolla',
'Shkrimtarëve',
'Shkroi',
'Shqipërisë',
'Shuteriqin',
'Shuteriqit',
'Si',
'Sipas',
'Spasse',
'Spasses',
'Sterjo',
'Tiranë',
'Tiranën',
'Trebeshinës',
'Të',
'Vepra',
'Veprimtaria',
'Xhuvanin',
'Zgjimi',
'Zjarre',
'[',
']',
'].',
'ai',
'ajo',
'anglisht',
'arriti',
'artikuj',
'ashtu',
'atë',
'bashkëthemelues',
'botimi',
'botoi',
'botua',
'botuan',
'botuar',
'buzë',
'cili',
'cilën',
'dallua',
'dhe',
'dhjetë',
'duvak',
'e',
'etj',
'fala',
'femre',
'fill',
'fillore',
'fitores',
'fshat',
'fshati',
'fshatin',
'fshatrat',
'fundin',
'fundit',
'fushën',
'gazetën',
'gjithashtu',
'hartimin',
'here',
'herë',
'i',
'integral',
'ishin',
'ishte',
'iu',
'ja',
'jeta',
'jetë',
'jonë',
'jug',
'ka',
'kaloi',
'kaluar',
'katër',
'kishte',
'kohën',
'komplet',
'komuniste',
'korrespondencë',
'krahët',
'kreu',
'krijimet',
'kryevepra',
'ku',
'kurs',
'letrare',
'lindur',
'liqenit',
'liri',
'lirë',
'lufte',
'maqedonase',
'maqedonishtfolës',
'marrë',
'mbahet',
'me',
'monografi',
'muar',
'më',
'mësues',
'ndaj',
'ndryshme',
'ndryshëm',
'ndërsa',
'nga',
'nisi',
'njihet',
'një',
'njëri',
'nuk',
'në',
'nëntë',
'organin',
'pa',
'pak',
'pandehur',
'parisë',
'partiak',
'parë',
'pas',
'pashë',
'pedagogji',
'pedagogjike',
'periudhë',
'po',
'politike',
'popullor',
'por',
'porsaçliruar',
'pranë',
'preference',
'prejardhje',
'profesion',
'provimet',
'punime',
'punoi',
'punë',
'për',
'përkohshmes',
'përkthime',
'përkthye',
'përmbledhje',
'përsëri',
'qe',
'që',
're',
'realizmit',
'revistat',
'rinie',
'romane',
'romani',
'romanin',
'romanit',
'shekullit',
'shkak',
'shkollore',
'shkollën',
'shkrimtar',
'shkroi',
'shkruante',
'shkurt',
'shumëllojshme',
'si',
'sidomos',
'socialist',
'së',
'tekste',
'teksteve',
'tetë',
'tij',
'tregime',
'tregimesh',
'tregimit',
'tridhjetë',
'të',
'u',
'vdekje',
'vepra',
'veprash',
'veprën',
'veta',
'vetëm',
'vitet',
'vitit',
'vonë',
'vëllime',
'zë',
'është']

text[10]
Out[17]: ','

text[20]
Out[18]: 'Sterjo'

text[2]
Out[19]: 'me'

text[5:9]
Out[20]: [',', 'i', 'lindur', 'në']

from nltk.probability import FreqDist

from nltk.probability import FreqDist

fdist2 = FreqDist(text)

print(fdist2)
<FreqDist with 273 samples and 525 outcomes>

fdist2.most_common(50)
Out[25]:
[('"', 42),
('e', 22),
(',', 21),
('të', 21),
('në', 18),
('(', 13),
('.', 12),
('),', 10),
('dhe', 8),
('me', 7),
('i', 5),
('që', 5),
('një', 5),
('Më', 4),
('pas', 4),
('si', 4),
('letrare', 4),
('më', 4),
('1944', 4),
('[', 4),
('].', 4),
(':', 4),
('",', 4),
('Spasse', 3),
('nga', 3),
('Sterjo', 3),
('nisi', 3),
('për', 3),
('nuk', 3),
('Tiranë', 3),
('2', 3),
('tij', 3),
('-', 3),
('ishte', 2),
('liqenit', 2),
('shkollën', 2),
('ndërsa', 2),
('shkurt', 2),
('Pse', 2),
('fundit', 2),
('Në', 2),
('botuar', 2),
('shkollore', 2),
('Dhimitër', 2),
('pedagogjike', 2),
('etj', 2),
('Veprimtaria', 2),
('u', 2),
('shkroi', 2),
('romane', 2)]

You might also like