Skip to content

Commit 78483e9

Browse files
committed
modified
1 parent ba7235c commit 78483e9

File tree

8 files changed

+18
-11
lines changed

8 files changed

+18
-11
lines changed

Storage.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys, os
22
projectpath = os.path.dirname(os.path.realpath('Storage.py'))
3+
#directory path
34
libpath = projectpath + '/lib'
5+
#lib path
46
sys.path.append(libpath)
57
os.chdir(projectpath)
68
import parsing
@@ -12,8 +14,10 @@
1214
index = {}
1315
# What collection to index?
1416
collection = 'New Testament'
17+
#mongo folder
1518
# Indicate the path where relative to the collection
1619
os.chdir(projectpath + '/data/' + collection)
20+
#added to project path
1721
# List all files in the collection
1822
files = [file for file in os.listdir('.') if os.path.isfile(file)]
1923
# Iterate through every file
@@ -23,12 +27,13 @@
2327
# Normalize the content
2428
words = parsing.clean(data)
2529
# Remove the extension from the file for storage
30+
#start of folder
2631
name = re.match('(^[^.]*)', file).group(0)
2732
# Add the words to the index
2833
parsing.index(name, words, index)
2934
print("Indexation took " + str(time.time() - startTime) + " seconds.")
3035

3136
# Storage
3237
startTime = time.time()
33-
parsing.store(index, collection)
38+
parsing.store(index, collection)#in mongo
3439
print("Storage took " + str(time.time() - startTime) + " seconds.")

cd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python3 Storage.py
2+
sudo python3 main.py
-4 Bytes
Binary file not shown.
-4 Bytes
Binary file not shown.
-4 Bytes
Binary file not shown.

lib/browser.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
3-
# Form implementation generated from reading ui file 'browser.ui'
4-
#
5-
# Created: Wed Feb 4 12:43:32 2015
6-
# by: PyQt4 UI code generator 4.10.4
7-
#
8-
# WARNING! All changes made in this file will be lost!
1+
92

103
from PyQt4 import QtCore, QtGui
114

lib/parsing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def clean(data):
2626
def index(file, words, index):
2727
for position in range(len(words)):
2828
word = words[position]
29+
#each word has frequency and has document and in tht document frequency and position
2930
# If the word is not in the index
3031
if words[position] not in index:
3132
index[word] = {'term frequency' : 1,
@@ -52,6 +53,6 @@ def index(file, words, index):
5253
def store(index, folder):
5354
collection = db[folder]
5455
for word in index:
55-
collection.save({'_id' : word, 'info' : index[word]})
56+
collection.save({'_id' : word, 'info' : index[word]})#storing in mongo db
5657

5758

main.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
folder = 'New Testament'
1616
collection = db[folder]
1717

18+
1819
class browser(QtGui.QMainWindow):
1920
def __init__(self, parent = None):
2021
QtGui.QWidget.__init__(self, parent)
@@ -33,8 +34,13 @@ def query(self):
3334
index[word] = collection.find({'_id' : word})[0]['info']
3435
# Rank the documents according to the query
3536
results = rankDocuments(index, words)
37+
i=0
3638
for result in results:
37-
self.ui.listWidget.addItem(result[0]+' : '+str(round(result[1], 2)))
39+
if(i<10):
40+
self.ui.listWidget.addItem(result[0]+' : '+str(round(result[1], 2)))
41+
i=i+1
42+
43+
3844

3945
if __name__ == "__main__":
4046
app = QtGui.QApplication(sys.argv)

0 commit comments

Comments
 (0)