summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/Semantics/InformationModel.py.old
diff options
context:
space:
mode:
authorpikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
committer pikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
commit2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch)
tree2d313cdf0068af368d4de6067d676be16f6a6464 /Monitoring/src/main/python/Semantics/InformationModel.py.old
parentff8aa232b071a9b54dff833714a870fd0aec0b30 (diff)
downloadnovi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2
project commit and dir tree change
Diffstat (limited to 'Monitoring/src/main/python/Semantics/InformationModel.py.old')
-rw-r--r--Monitoring/src/main/python/Semantics/InformationModel.py.old79
1 files changed, 79 insertions, 0 deletions
diff --git a/Monitoring/src/main/python/Semantics/InformationModel.py.old b/Monitoring/src/main/python/Semantics/InformationModel.py.old
new file mode 100644
index 0000000..9de648e
--- /dev/null
+++ b/Monitoring/src/main/python/Semantics/InformationModel.py.old
@@ -0,0 +1,79 @@
+'''
+Created on Aug 10, 2011
+
+@author: steger
+'''
+from urllib2 import URLError
+from rdflib import Graph, Namespace, URIRef, plugin
+from rdflib.query import Processor, Result
+
+class IMError(Exception):
+ pass
+
+class Ontology(object):
+ ontology = {
+ 'owl': (None, "http://www.w3.org/2002/07/owl#"),
+ 'unit': ('unit.owl', "http://fp7-novi.eu/unit.owl#"),
+ 'param': ('monitoring_parameters.owl', "http://fp7-novi.eu/monitoring_parameter.owl#"),
+ 'feature': ('monitoring_features.owl', "http://fp7-novi.eu/monitoring_features.owl#"),
+ 'task': ('monitoring_task.owl', "http://fp7-novi.eu/monitoring_task.owl#"),
+ 'query': (None, "http://fp7-novi.eu/monitoring_query.owl#"), #('monitoring_query.owl', ...)
+ 'conf': (None, "http://fp7-novi.eu/config.owl#"),
+ 'stat': (None, 'http://fp7-novi.eu/monitoring_stat.owl#'),
+ 'core': ('novi-im.owl', "http://fp7-novi.eu/im.owl#"),
+ }
+
+ def __init__(self, baseurl, config_owl):
+
+ plugin.register(
+ 'sparql', Processor,
+ 'rdfextras.sparql.processor', 'Processor')
+ plugin.register(
+ 'sparql', Result,
+ 'rdfextras.sparql.query', 'SPARQLQueryResult')
+
+
+ self.baseurl = baseurl
+ self.graph = Graph()
+ # load owl files and bind name spaces
+ try:
+ self.graph += Graph().parse(source = config_owl)
+ except URLError:
+ raise IMError("URLError: Cannot read model %s" % config_owl)
+ for prefix, (owl, ns) in self.ontology.iteritems():
+ if owl:
+ url = "%s/%s" % (self.baseurl, owl)
+ try:
+ self.graph += Graph().parse(source = url)
+ except URLError:
+ raise IMError("URLError: Cannot read model %s" % url)
+ try:
+ self.graph.bind(prefix, Namespace(ns))
+ except:
+ pass
+
+ @staticmethod
+ def _float(f):
+ if '.' in f or 'e' in f or 'E' in f:
+ return float(f)
+ else:
+ return int(f)
+
+ @staticmethod
+ def _tail(uriref):
+ if not isinstance(uriref, URIRef):
+ raise IMError("Wrong uriref %s" % uriref)
+ return str(uriref).split("#")[-1]
+
+ def query(self, query):
+ return self.graph.query(query, initNs = dict(self.graph.namespaces()))
+
+ def ns(self, prefix):
+ for p, ns in self.graph.namespaces():
+ if p == prefix:
+ return Namespace(ns)
+ raise IMError("Unknown prefix: %s" % prefix)
+
+ def dump(self):
+ for t in self.graph.triples((None, None, None)):
+ print t