-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
69 lines (59 loc) · 1.66 KB
/
test.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 json
from broca import Pipeline
from broca.tokenize.keyword import Overkill
from broca.preprocess import Cleaner, HTMLCleaner
from broca.vectorize import BoW
from geiger.pipes import LDA, SemSim, HSCluster, DBSCAN, AspectCluster, Distance
docs = [d['body'] for d in json.load(open('examples/climate_example.json', 'r'))]
preprocess = Pipeline(
HTMLCleaner(),
Cleaner()
)
pipelines = [
Pipeline(
preprocess,
BoW(),
LDA(n_topics=10),
Distance(metric='euclidean'),
[HSCluster(), DBSCAN()]
),
Pipeline(
preprocess,
Overkill(),
SemSim(),
[HSCluster(), DBSCAN()]
),
Pipeline(
preprocess,
BoW(),
Distance(metric='euclidean'),
[HSCluster(), DBSCAN()]
),
]
#for p in pipelines:
#print('Running pipeline:', p)
#outputs = p(docs)
#doc_clusters = []
#for out in outputs:
#for clus in out:
#clus_docs = []
#for id in clus:
#clus_docs.append(docs[id])
#doc_clusters.append(clus_docs)
#print(doc_clusters)
#print('----------------------------------------')
from nltk.tokenize import sent_tokenize
from geiger.sentences import prefilter
from geiger.pipes.aspect import markup_highlights
# Get sentences, filtered fairly aggressively
sents = [[sent for sent in sent_tokenize(d) if prefilter(sent)] for d in docs]
sents = [sent for s in sents for sent in s]
aspect = Pipeline(
preprocess,
Overkill(),
AspectCluster()
)
output = aspect(sents)
highlighted = []
for k, aspect_sents in output:
highlighted.append([markup_highlights(k, sents[i]) for i in aspect_sents])