-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (65 loc) · 3.01 KB
/
Copy pathmain.py
File metadata and controls
80 lines (65 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import time
import pandas as pd
import shingle
import preprocess
import signature
import minhashing
import lsh
import os
def main():
"""
This functions is main function in your folder which should run first
calls other functions and calculate time taken to execute for evry function call and serializing all Dataframes obtained
Parametrs
---------
similar_docs: Python Dictionary()
Dictionary of similar documents to Query Document
query: string
string representig query document's file name
jscore : float
User threshold for jaccard similarity score between two documents
Returns
-------
Precision_count : int
Returns number of documents from input similar_docs dictionary that have higher jaccard score than User threshold
"""
shingle_length = 4 #set shingle length
if os.path.exists("./shingle_pickle4.py") == False :
time_start=time.time()
preprocess.preprocess('./temp') #Time calculation for pre processing files
time_end=time.time()
print(time_end-time_start) # 0.01327657699584961
if os.path.exists("./shingle_pickle4.py") == False :
time_start=time.time()
shingleDf = shingle.get_shingles(shingle_length) #Time calculation fro shingling
time_end=time.time()
print(time_end-time_start) # 207.01369958496123463
# shingleDf.to_pickle("./shingle_pickle4.py")
# shingleDf.to_pickle("./shingle_pickle.py")
# un_pickle_df=pd.read_pickle("./shingle_pickle.py")
if os.path.exists("./sig_nat.pickle") == False :
time_start=time.time()
signatureDf= minhashing.generate_signature_matrix(shingleDf,100) # Time calculation for min hashing
time_end=time.time()
print(time_end-time_start) # 2041.65769958496173297
# signatureDf.to_pickle("./signature_pickle4shingles.py")
# un_pickle_df=pd.read_pickle("./signature_pickle.py")
output0 = "Please Enter document number : " # taking user input query and threshold jaccard score
print(output0)
query = (int)(input())
output1 = "Please Enter threshold jscore: "
print(output1)
sig_matrix=pd.read_pickle("./sig_matc_4shigles.pickle")
jscore = (float)(input())
for i in range(query,query+1):
similar_documents = lsh.lsh(sig_matrix,sig_matrix.columns[i],100) # applying Lsh on signature matrix
print(similar_documents)
if(len(similar_documents)==0):
print("No similar Documents found")
else:
p_count = lsh.precision(similar_documents,sig_matrix.columns[i],jscore = 0.1) #calculating precision for retreivs documents
print("precision is = "+ (str)(p_count/len(similar_documents)))
r_count = lsh.recall(sig_matrix.columns,sig_matrix.columns[i],jscore = 0.1 ) #calculating recall for retreived documents
print("recall is = "+ (str)(p_count/r_count))
if (__name__=="__main__"):
main()