无法验证和序列化来自 pyshacl 的新推断图

问题描述 投票:0回答:0

我遇到了一个问题,我需要你的帮助。我正在研究 pyshacl 验证,这是一个 Python 库,用于根据 SHACL 图验证 RDF 图。我有一个 shacl 形状图,它有一个 SPARQL 构造子句来创建新实例并将它们与其他实例链接。然后我想用现有数据序列化它们并制作一个新图。但是当我运行验证时,它成功了,没有任何输出。我不知道出了什么问题。此外,当我在 GraphDB 查询编辑器上运行相同的查询时,它会显示可能的结果。谁能帮我解决这个错误?


from rdflib import *
from pyshacl import validate

ontology = Graph().parse("./graphs/DMN-RDF-Dicon-OCQA-Tbox.ttl",
                             format="ttl")
example_building = Graph().parse("./graphs/Duplex_A_20110505_LBD.ttl",
                                     format="ttl")

combined_graph = ontology + example_building  # Combine the graphs
rules_graph = Graph().parse("testing.ttl",
                                format="ttl")  # Load the SHACL rules graph

# Validate the combined graph and apply the rules
conforms, inferred_graph, string = validate(combined_graph, shacl_graph=rules_graph,
                                            data_graph_format='turtle', shacl_graph_format='turtle',
                                            debug=True, advanced=True, inplace=True)

# Merge the original graph with the inferred graph
new_graph = combined_graph + inferred_graph

# Save the new graph to a new file
new_graph.serialize(
        destination="Inferred_geometry_inspections.ttl", format="ttl")

这是我的规则图:(删除前缀,因为它们很多)


{prefixes}
      dmn:prepare_inspections
    a sh:NodeShape ;
    sh:targetNode owl:Thing ;
    
    sh:rule [
        a sh:SPARQLRule ;
        sh:comment "Select all of eligible objects and create inspections";
        sh:construct """        
 {prefixes}

        CONSTRUCT {
            ?this ocqa:hasInspection ?Inspection_Number_Of_Risers.
?Inspection_Number_Of_Risers a <http://www.DMN-RDF.org/DMN#Inspection_Number_Of_Risers>.
?ISCode a <http://www.DMN-RDF.org/DMN#ISCode>.
?Agent a <https://w3id.org/digitalconstruction/0.5/Agents#Agent>.
?InspectionEquipment a <https://w3id.org/ocqa#InspectionEquipment>.
?one_time a <http://www.DMN-RDF.org/DMN#one_time>.
?Location a <https://w3id.org/digitalconstruction/0.5/Entities#Location>.
?InspectionProcedure a <https://w3id.org/ocqa#InspectionProcedure>.
}

    WHERE{
        SELECT ?this ?Inspection_Number_Of_Risers ?ISCode ?Agent ?InspectionEquipment ?one_time ?Location ?InspectionProcedure
 WHERE {
BIND(IRI(CONCAT("inst:Inspection_Number_Of_Risers_", STR(CEIL((RAND() * 30000))))) as ?Inspection_Number_Of_Risers)
BIND(IRI(CONCAT("inst:ISCode_", STR(CEIL((RAND() * 30000))))) as ?ISCode)
BIND(IRI(CONCAT("inst:Agent_", STR(CEIL((RAND() * 30000))))) as ?Agent)
BIND(IRI(CONCAT("inst:InspectionEquipment_", STR(CEIL((RAND() * 30000))))) as ?InspectionEquipment)
BIND(IRI(CONCAT("inst:one_time_", STR(CEIL((RAND() * 30000))))) as ?one_time)
BIND(IRI(CONCAT("inst:Location_", STR(CEIL((RAND() * 30000))))) as ?Location)
BIND(IRI(CONCAT("inst:InspectionProcedure_", STR(CEIL((RAND() * 30000))))) as ?InspectionProcedure)
?this a <https://pi.pauwel.be/voc/buildingelement#Stair> .
?Property a <https://w3id.org/opm#Property> .
        ?this <http://lbd.arch.rwth-aachen.de/props#actualNumberOfRisers> ?Property .
        }
    }
   """ ;
    ] ;
.
owl ontology rdfs rdflib shacl
© www.soinside.com 2019 - 2024. All rights reserved.