forked from yk/nlpfs14
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathselectiontest.py
More file actions
39 lines (31 loc) · 1.04 KB
/
selectiontest.py
File metadata and controls
39 lines (31 loc) · 1.04 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
from nlpio import *
from trimming import *
from nlplearn import *
from sentenceselection import *
from sklearn.pipeline import Pipeline
import cPickle as pickle
import os.path
if __name__ == '__main__':
filename = 'testset'
if os.path.isfile('.'.join([filename, 'pk'])):
# Already parsed by stanford corenlp
documents = pickle.load(open('.'.join([filename, 'pk'])))
else:
# Brace yourself
documents = loadDocumentsFromFile('.'.join([filename, 'txt']))
ls = LinearSelector(n_learning_iterations=5)
ls.addFeature(Constant())
ls.addFeature(IsFirst())
ls.addFeature(Length())
ls.addFeature(WordCoverage(stop_words='english'))
ls.addFeature(PositionInDocument())
ls.addFeature(NamedEntityCount())
pipeline = Pipeline([
('clean', SimpleTextCleaner()),
('split', SentenceSplitter()),
('parse', StanfordParser()),
('select', ls),
])
pipeline.fit(documents)
scorer = RougeScorer()
print "ROUGE score: %f" % scorer(pipeline, documents)