Skip to content

Commit

Permalink
self.confg bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
albertmeronyo committed Sep 23, 2013
1 parent 88007ff commit 8945d50
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/tablinker.py
Expand Up @@ -106,23 +106,23 @@ def initGraphs(self):

def addDataCellProperty(self):
"""Add definition of data cell resource to graph"""
if len(config.get('dataCell', 'propertyName')) > 0 :
self.dataCellPropertyName = config.get('dataCell', 'propertyName')
if len(self.config.get('dataCell', 'propertyName')) > 0 :
self.dataCellPropertyName = self.config.get('dataCell', 'propertyName')
else :
self.dataCellPropertyName = 'hasValue'

self.graph.add((self.namespaces['d2s'][self.dataCellPropertyName], RDF.type, self.namespaces['qb']['MeasureProperty']))

#Take labels from config
if len(config.get('dataCell', 'labels')) > 0 :
labels = config.get('dataCell', 'labels').split(':::')
if len(self.config.get('dataCell', 'labels')) > 0 :
labels = self.config.get('dataCell', 'labels').split(':::')
for label in labels :
labelProperties = label.split('-->')
if len(labelProperties[0]) > 0 and len(labelProperties[1]) > 0 :
self.graph.add((self.namespaces['d2s'][self.dataCellPropertyName], RDFS.label, Literal(labelProperties[1],labelProperties[0])))

if len(config.get('dataCell', 'literalType')) > 0 :
self.graph.add((self.namespaces['d2s'][self.dataCellPropertyName], RDFS.range, Namespace(config.get('dataCell', 'literalType'))))
if len(self.config.get('dataCell', 'literalType')) > 0 :
self.graph.add((self.namespaces['d2s'][self.dataCellPropertyName], RDFS.range, Namespace(self.config.get('dataCell', 'literalType'))))

def setScope(self, fileBasename):
"""Set the default namespace and base for all URIs of the current workbook"""
Expand Down
82 changes: 79 additions & 3 deletions src/tl-service.py
@@ -1,9 +1,85 @@
from bottle import route, run, template
import tablinker
from tablinker import TabLinker
import logging
from ConfigParser import SafeConfigParser
import glob
import sys
import traceback

@route('/tablinker/version')
def version():
return template('TabLinker version')
return "TabLinker version"

run(host = 'localhost', port = 8081, debug = True)
@route('/tablinker/')
@route('/tablinker/run')
def tablinker():
logging.basicConfig(level=logging.INFO)
logging.info('Reading configuration file')

config = SafeConfigParser()
try :
config.read('../config.ini')
srcMask = config.get('paths', 'srcMask')
targetFolder = config.get('paths','targetFolder')
verbose = config.get('debug','verbose')
if verbose == "1" :
logLevel = logging.DEBUG
else :
logLevel = logging.INFO
except :
logging.error("Could not find configuration file, using default settings!")
srcMask = '../input/*_marked.xls'
targetFolder = config.get('paths', 'targetFolder')
logLevel = logging.DEBUG

logging.basicConfig(level=logLevel)

# Get list of annotated XLS files
files = glob.glob(srcMask)
logging.info("Found {0} files to convert.".format(len(files)))

if len(files) == 0 :
logging.error("No files found. Are you sure the path to the annotated XLS files is correct?")
logging.info("Path searched: " + srcMask)
quit()

for filename in files :
logging.info('Starting TabLinker for {0}'.format(filename))

tLinker = TabLinker(filename, config, logLevel)

logging.debug('Calling linker')
tLinker.doLink()
logging.debug('Done linking')

turtleFile = targetFolder + tLinker.fileBasename +'.ttl'
turtleFileAnnotations = targetFolder + tLinker.fileBasename +'_annotations.ttl'
logging.info("Generated {} triples.".format(len(tLinker.graph)))
logging.info("Serializing graph to file {}".format(turtleFile))
try :
fileWrite = open(turtleFile, "w")
#Avoid rdflib writing the graph itself, as this is buggy in windows.
#Instead, retrieve string and then write (probably more memory intensive...)
turtle = tLinker.graph.serialize(destination=None, format=config.get('general', 'format'))
fileWrite.writelines(turtle)
fileWrite.close()

#Annotations
if tLinker.config.get('annotations', 'enabled') == "1":
logging.info("Generated {} triples.".format(len(tLinker.annotationGraph)))
logging.info("Serializing annotations to file {}".format(turtleFileAnnotations))
fileWriteAnnotations = open(turtleFileAnnotations, "w")
turtleAnnotations = tLinker.annotationGraph.serialize(None, format=config.get('general', 'format'))
fileWriteAnnotations.writelines(turtleAnnotations)
fileWriteAnnotations.close()
except :
logging.error("Whoops! Something went wrong in serializing to output file")
logging.info(sys.exc_info())
traceback.print_exc(file=sys.stdout)

logging.info("Done")
print "Done!"


run(host = 'lod.cedar-project.nl', port = 8081, debug = True)

0 comments on commit 8945d50

Please sign in to comment.