-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
57 lines (40 loc) · 1.44 KB
/
Main.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
from Algo.ClusteringAlgo import Tfif, LDA, HierarchalCluster
from ObjectHandler.NeoConnector import Neo4jConnector
from Util.NLPHelper import NERTagging, POSTagging
__author__ = 'moiz'
from ObjectHandler.Crawler import WikiCrawler
try:
error_file = open("Dump/log/mainerror.txt", "a")
storageHandler= Neo4jConnector()
print("welcome to wiki clustering ")
#crawl pages from wikipedia
crawler = WikiCrawler(3)
docList=[]
for i in range(0,1):
pages=[]
pages= crawler.crawl()
for page in pages:
docList.append(page)
#crawl 10 documents
dict={}
#get topic distribution based out of LDA
for document in docList:
LdaAlgo = LDA(6,80)
#LdaAlgo.train(docList)
resDict={}
resDict= LdaAlgo.analyze(document.getTitle(), document.getContent())
#document.setTags(resDict['word_list'])
document.setTopicmatrix(resDict['topicMatrix'])
dict[document.getTitle()]=resDict['word_list']
resDict =None
LdaAlgo.__del__()
clusterAlgo = LDA(6,80)
#calculate similarity against all documents
sim_Score= clusterAlgo.get_sim_score(dict)
hirAlgo = HierarchalCluster(dict.keys())
hirAlgo.create_hierarchy(sim_Score)
#self.storageHandler.createNodes(page)
except Exception, e:
error_file.write('Search failed:{ %s } \n' % ( e))
print 'main failed: %s' % e.message
pass