-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (46 loc) · 1.9 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
# -*- coding: utf-8 -*-
# @Author: Sparna
import sys
import logging
from datetime import datetime, date
# import glottolog2rdf_converter
from glottolog2rdf_converter import Glottolog2RdfConverter
class Main():
log = logging.getLogger(__name__)
def __init__(self):
pass
def run(self, glottolog_dir, outputTurtleFile):
# Now
start_time = datetime.now().time()
self.log.info("Glottolog2rdf starting")
converter = Glottolog2RdfConverter(glottolog_dir)
graph = converter.parse_glottolog()
self.log.info("Output graph contains "+str(graph.__len__())+" triples")
# output data in output file
self.log.info("Writing in Turtle to output file "+str(outputTurtleFile)+"...")
graph.serialize(destination=outputTurtleFile, format='turtle')
end_time = datetime.now().time()
self.log.info(
"Glottolog2rdf executed in " +
str(datetime.combine(date.min, end_time) -
datetime.combine(date.min, start_time)))
if __name__ == "__main__":
# configure logging
logname = 'glottolog2rdf.log'
logging.basicConfig(filename=logname,
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', # noqa
datefmt='%H:%M:%S',
level=logging.DEBUG)
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(
logging.Formatter(
'%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s'))
# Here : adjust global legging Level
out_hdlr.setLevel(logging.DEBUG)
rootLogger = logging.getLogger(None)
rootLogger.addHandler(out_hdlr)
# Convert by giving the path to Glottolog directory and expected output file
main = Main()
# main.run('samples/glottolog-single-languoid', 'output.ttl')
main.run(sys.argv[1], sys.argv[2])