-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_filenames_and_titles.py
57 lines (44 loc) · 1.57 KB
/
print_filenames_and_titles.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
import json
import nltk
from util import (get_file_names,
extract_title,
is_monocase,
normalize_title,
get_document_content_paf)
from guess_language import guessLanguage
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def main():
"""print title each per one line from the corpus"""
year = 2014
# months = ['01', '02', '03', '04', '05', '06', '07'] # 2015-08-05
months = range(11, 13)
# months = ['02'] # 2015-08-13
# months = ['02', '03', '04', '05'], 2015-08-05
# months = ['03'] # 2015-08-13
days = xrange(1, 32)
paths = ['/cs/puls/Corpus/Business/Puls/{}/{}/{:2d}/'.format(year, month, day)
for month in months
for day in days]
collected = 0
for i, fname in enumerate(get_file_names(paths)):
if i % 100 == 0:
logger.info("{} / {}".format(collected, i))
try:
title = extract_title(fname)
except:
logger.debug('Fail to find title')
continue
if not title: # no title
continue
title = normalize_title(title)
# is not monocase and is English
if not is_monocase(nltk.word_tokenize(title)) and\
guessLanguage(title) == "en":
body = get_document_content_paf(fname)
if len(body.strip()) > 0: # non-empty
collected += 1
print json.dumps([fname, unicode(title).encode("utf8")])
if __name__ == "__main__":
main()