-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (51 loc) · 1.61 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
58
59
60
61
62
63
64
65
66
#/usr/bin/python
# -*- coding: utf-8 -*-
"""
Natural Language Processing homework assignment.
Valentin Lemière - Guillaume Desquesnes
"""
import glob
import sys
from Config import Config
from Document import Document
from Corpus import Corpus
from Terminology import load_terminology
if "__main__" == __name__:
config = Config()
config.load("config.json")
print "*******************************************"
print "* DEFT 2012 *"
print "* Valentin Lemière - Guillaume Desquesnes *"
print "*******************************************"
files = glob.glob(config.corpus_path + "/*.xml")
nb_files = len(files)
# Terminology
if config.termino_path == "":
termino = None
else:
termino = load_terminology(config.termino_path)
print "\nTerminology loaded"
print "\nLoading %i files"%nb_files
print "-------------------------------------------"
docs = []
# Load the files
for i, f in enumerate(files):
sys.stdout.write( "\r%3i/%i %s"%( i+1, nb_files, '{:<70}'.format(f) ) )
sys.stdout.flush()
docs.append(Document(f))
corpus = Corpus(docs, termino)
print "\n\nCorpus preprocessing"
print "-------------------------------------------"
corpus.preprocess()
print "\n\nExtracting the keywords"
print "-------------------------------------------"
corpus.process()
if Config().testing:
print "\n\nResults (%s average)"%("Macro" if config.macro_average else "Micro")
print "-------------------------------------------"
corpus.results()
else:
print "\n"
if config.save_file != "":
print "\nResults saved in %s"%config.save_file
corpus.save(config.save_file)