-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
69 lines (47 loc) · 1.97 KB
/
run.py
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
import logging
import os
from model import USE,SBERT,Scrap
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
logging.basicConfig(filename='app.log', filemode='w',format='%(message)s', level=logging.CRITICAL)
def printAndLogInfo(customMessage,exceptionMessage=None):
print(customMessage)
try:
logging.critical(customMessage)
except Exception as err:
logging.critical('error while logging : {}'.format(str(err)))
if exceptionMessage:
print(str(exceptionMessage))
logging.critical(exceptionMessage)
# Function to print & log errors
def printAndLogError(customMessage,exceptionMessage=None):
print('ERROR!!! ' +customMessage)
logging.critical(customMessage)
if exceptionMessage:
print(str(exceptionMessage))
logging.critical(exceptionMessage)
time.sleep(10)
#Initializing the model
model=SBERT()
while True:
link_1=str(input('Paste the first url...'))
content_1=Scrap.get_web_content(link_1)
web_content_1,noise=model.cluster(content_1)
printAndLogInfo('\n\n\n\t\t###### Printing the Web content ######\n')
printAndLogInfo(web_content_1)
printAndLogInfo('\t\t######Printing the noise filtered out ######\n')
printAndLogInfo(noise)
link_2=str(input('Paste the second url..'))
content_2=Scrap.get_web_content(link_2)
web_content_2,noise=model.cluster(content_2)
printAndLogInfo('\n\n\n\\t\t###### Printing the Web content ######\n')
printAndLogInfo(web_content_2)
printAndLogInfo('\t\t######Printing the noise filtered out ######\n')
printAndLogInfo(noise)
score_smd=model.sentence_movers_distance(web_content_1,web_content_2)*100
score_one_to_one=model.one_to_one(web_content_1,web_content_2)*100
score=(score_smd+score_one_to_one)/2
printAndLogInfo("\n\n\nThe percentage of similarity is : {}".format(score))
next_action=input('\n\n\nCheck another set of URLs ? y/n \n')
if next_action=='n':
break