Reputation: 67
I am trying to validate a data graph against a shape graph in pyshacl. The objective is to check the distance between two walls from a linked building data representation of a small building. The code I am using is below:
#Importing Datagraph from a file in computer
from pyshacl import validate
from rdflib import Graph
g=Graph()
Datagraph = g.parse("C:/Users/aagr657/OneDrive - The University of Auckland/UoA/Outcomes/RQ2/Models/Walls_with_Crane_LBD.ttl", format="ttl")
#Writing Shapes Graph
Shapegraph = '''
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix bot: <https://w3id.org/bot#> .
@prefix ifc: <https://standards.buildingsmart.org/IFC/DEV/IFC2x3/TC1/OWL#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix lbd: <https://linkebuildingdata.org/LBD#> .
@prefix props: <http://lbd.arch.rwth-aachen.de/props#> .
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
@prefix unit: <http://qudt.org/vocab/unit/> .
@prefix IFC4-PSD: <https://www.linkedbuildingdata.net/IFC4-PSD#> .
@prefix smls: <https://w3id.org/def/smls-owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix inst: <https://www.ugent.be/myAwesomeFirstBIMProject#> .
@prefix fog: <https://w3id.org/fog#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
ifc:geometricconstraintshape a sh:NodeShape ;
sh:targetClass bot:Element;
sh:sparql[
sh:message "The geometric constraint is violated" ;
sh:select " " "
SELECT $this
WHERE{
inst:wall_1eec9390-5f68-4a64-aaa9-34a883f3c353 a bot:element .
inst:wall_1eec9390-5f68-4a64-aaa9-34a883f3c0dd a bot:element .
inst:wall_1eec9390-5f68-4a64-aaa9-34a883f3c353_geometry_bb lbd:x-min ?x_min .
inst:wall_1eec9390-5f68-4a64-aaa9-34a883f3c0dd_geometry_bb lbd:x-max ?x_max .
FILTER (ifc:computedistance(?x_min,?x_max)<=12.0) .
} """ ;
] .
ifc:computedistance a sh:SPARQLFunction;
rdfs:comment "Finds the distance between the two elements";
sh:parameter[
sh:path lbd:x_min ;
sh:datatype xsd:double;
sh:description "The inner x coordinate of the wall on the right side";
];
sh:parameter[
sh:path lbd:x_max ;
sh:datatype xsd:double;
sh:description "The outer x coordinate of the wall on the left side";
];
sh:returnType xsd:double;
sh:select"""
SELECT (($x_min - $x_max) AS ?result)
WHERE {
}
""".
'''
#Validation
r = validate(data_graph = Datagraph, shacl_graph = Shapegraph, data_graph_format="ttl", shacl_graph_format="ttl", inference = "rdfs", debug = True, abort_on_error = False, meta_shacl = False, serialize_report_graph = "ttl")
conforms, results_graph, results_text = r
On running the code, I am getting the following error:
File ~\AppData\Roaming\Python\Python311\site-packages\IPython\core\interactiveshell.py:3505 in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
Cell In[15], line 61
r = validate(data_graph = Datagraph, shacl_graph = Shapegraph, data_graph_format="ttl", shacl_graph_format="ttl", inference = "rdfs", debug = True, abort_on_error = False, meta_shacl = False, serialize_report_graph = "ttl")
File ~\AppData\Local\anaconda3\Lib\site-packages\pyshacl\validate.py:439 in validate
loaded_sg = load_from_source(
File ~\AppData\Local\anaconda3\Lib\site-packages\pyshacl\rdfutil\load.py:406 in load_from_source
target_g.parse(source=cast(IO[bytes], _source), format=rdf_format, publicID=public_id)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\graph.py:2473 in parse
c = ConjunctiveGraph.parse(
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\graph.py:2251 in parse
context.parse(source, publicID=publicID, format=format, **args)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\graph.py:1503 in parse
raise se
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\graph.py:1494 in parse
parser.parse(source, self, **args)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:2021 in parse
p.loadStream(stream)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:479 in loadStream
return self.loadBuf(stream.read()) # Not ideal
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:485 in loadBuf
self.feed(buf)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:511 in feed
i = self.directiveOrStatement(s, j)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:530 in directiveOrStatement
j = self.statement(argstr, i)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:778 in statement
j = self.property_list(argstr, i, r[0])
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:1140 in property_list
i = self.objectList(argstr, j, objs)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:1190 in objectList
i = self.object(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:1487 in object
j = self.subject(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:785 in subject
return self.item(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:877 in item
return self.path(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:884 in path
j = self.nodeOrLiteral(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:1515 in nodeOrLiteral
j = self.node(argstr, i, res)
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:973 in node
self.BadSyntax(argstr, j, "']' expected")
File ~\AppData\Local\anaconda3\Lib\site-packages\rdflib\plugins\parsers\notation3.py:1730 in BadSyntax
raise BadSyntax(self._thisDoc, self.lines, argstr, i, msg)
File <string>
BadSyntax
Is it because of some problem in the Data graph, or I am making some syntax error in the shape I have written? I think the Data Graph should be alright as it is generated in the turtle format from a pre-existing converter. However, I am not able to identify the syntax error in the shape.
Thanks in advance.
Upvotes: 1
Views: 55