|
@@ -3,6 +3,7 @@ import sys
|
|
|
from collections import defaultdict
|
|
|
import os
|
|
|
import rdflib
|
|
|
+import json
|
|
|
|
|
|
import cPickle as pickle
|
|
|
|
|
@@ -34,10 +35,10 @@ class ModelverseState(object):
|
|
|
self.to_delete = set()
|
|
|
|
|
|
def parse(self, filename):
|
|
|
- triplestore = filename + ".n3"
|
|
|
+ triplestore = filename + ".nt"
|
|
|
try:
|
|
|
if os.path.getmtime(triplestore) > os.path.getmtime(filename):
|
|
|
- self.graph.parse(filename, format="n3")
|
|
|
+ self.graph.parse(triplestore, format="nt")
|
|
|
else:
|
|
|
raise Exception("Invalid triplestore")
|
|
|
except Exception as e:
|
|
@@ -84,7 +85,7 @@ class ModelverseState(object):
|
|
|
raise Exception("Failed to process line for reason %s: %s" % (status, line))
|
|
|
|
|
|
# Creation successful, now also create a pickle
|
|
|
- self.graph.serialize(triplestore, format="n3")
|
|
|
+ self.graph.serialize(triplestore, format="nt")
|
|
|
#TODO this loses information about the root!
|
|
|
return symbols["root"]
|
|
|
|
|
@@ -120,7 +121,7 @@ class ModelverseState(object):
|
|
|
if not self.is_valid_datavalue(value):
|
|
|
return (None, status.FAIL_CNV_OOB)
|
|
|
node = rdflib.BNode()
|
|
|
- self.graph.add((node, self.mv.hasValue, rdflib.Literal(value)))
|
|
|
+ self.graph.add((node, self.mv.hasValue, rdflib.Literal(json.dumps(value))))
|
|
|
return (node, status.SUCCESS)
|
|
|
|
|
|
def create_dict(self, source, data, destination):
|
|
@@ -133,7 +134,7 @@ class ModelverseState(object):
|
|
|
|
|
|
n = self.create_nodevalue(data)[0]
|
|
|
e = self.create_edge(source, destination)[0]
|
|
|
- self.create_edge(e, n)
|
|
|
+ t = self.create_edge(e, n)
|
|
|
return (None, status.SUCCESS)
|
|
|
|
|
|
def read_value(self, node):
|
|
@@ -157,7 +158,7 @@ class ModelverseState(object):
|
|
|
"""
|
|
|
SELECT ?link
|
|
|
WHERE {
|
|
|
- _:%s "hasTarget" ?link .
|
|
|
+ _:%s MV:hasTarget ?link .
|
|
|
}
|
|
|
""" % elem)
|
|
|
return (list(result), status.SUCCESS)
|
|
@@ -180,7 +181,7 @@ class ModelverseState(object):
|
|
|
SELECT ?source, ?target
|
|
|
WHERE {
|
|
|
_:%s MV:hasSource ?source ;
|
|
|
- MV:hasTarget ?target .
|
|
|
+ MV:hasTarget ?target .
|
|
|
}
|
|
|
""" % edge)
|
|
|
if len(result) == 0:
|
|
@@ -190,7 +191,7 @@ class ModelverseState(object):
|
|
|
|
|
|
def read_dict(self, node, value):
|
|
|
if not isinstance(node, rdflib.BNode):
|
|
|
- return (None, status.FAIL_RDICT_UNKNWON)
|
|
|
+ return (None, status.FAIL_RDICT_UNKNOWN)
|
|
|
if not self.is_valid_datavalue(value):
|
|
|
return (None, status.FAIL_RDICT_OOB)
|
|
|
|
|
@@ -199,21 +200,20 @@ class ModelverseState(object):
|
|
|
WHERE {
|
|
|
?main_edge MV:hasSource _:%s .
|
|
|
?main_edge MV:hasTarget ?value_node .
|
|
|
- ?attr_edge MV:hasSource ?main_edge ;
|
|
|
- MV:hasTarget ?attr_node .
|
|
|
- ?attr_node MV:hasValue %s .
|
|
|
?value_node MV:hasValue ?value .
|
|
|
}
|
|
|
- """ % (node, value)
|
|
|
+ """ % (node)
|
|
|
print(q)
|
|
|
result = self.graph.query(q)
|
|
|
+ print(len(result))
|
|
|
+ print([i for i in result])
|
|
|
if len(result) == 0:
|
|
|
return (None, status.FAIL_RDICT_NOT_FOUND)
|
|
|
return (result[0], status.SUCCESS)
|
|
|
|
|
|
def read_dict_keys(self, node):
|
|
|
if not isinstance(node, rdflib.BNode):
|
|
|
- return (None, status.FAIL_RDICT_UNKNWON)
|
|
|
+ return (None, status.FAIL_RDICT_UNKNOWN)
|
|
|
|
|
|
result = self.graph.query(
|
|
|
"""
|
|
@@ -239,7 +239,7 @@ class ModelverseState(object):
|
|
|
MV:hasTarget ?value_node .
|
|
|
?attr_edge MV:hasSource ?main_edge ;
|
|
|
MV:hasTarget ?attr_node .
|
|
|
- ?attr_node MV:hasValue %s .
|
|
|
+ ?attr_node MV:hasValue '%s' .
|
|
|
}
|
|
|
""" % (node, value))
|
|
|
if len(result) == 0:
|
|
@@ -292,7 +292,7 @@ class ModelverseState(object):
|
|
|
?main_edge MV:hasTarget _:%s .
|
|
|
?attr_edge MV:hasSource ?main_edge ;
|
|
|
MV:hasTarget ?value_node .
|
|
|
- ?value_node MV:hasValue %s .
|
|
|
+ ?value_node MV:hasValue '%s' .
|
|
|
}
|
|
|
""" % (node, value))
|
|
|
|