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

huangapple go评论39阅读模式
英文:

Unable to validate and serialize new inferred graph from pyshacl

问题

I'm here to assist with the translation. Here is the translated content:

我遇到了一个问题需要你的帮助我正在使用pyshacl验证工具这是一个用于验证RDF图与SHACL图的Python库我有一个SHACL形状图其中包含一个SPARQL构造子句用于创建新实例并将它们与其他实例关联起来然后我想将它们与现有数据序列化并创建一个新图但是当我运行验证时它成功了但没有任何输出我不知道出了什么问题而且当我在GraphDB查询编辑器上运行相同的查询时它显示可能的结果有人能帮助我解决这个错误吗

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

{prefixes}
      dmn:prepare_inspections
    a sh:NodeShape ;
    sh:targetNode owl:Thing ;
    
    sh:rule [
        a sh:SPARQLRule ;
        sh:comment "选择所有符合条件的对象并创建检查";
        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 .
        }
    }
   """ ;
    ] ;
.

如果需要更多帮助,请告诉我。

英文:

I'm stuck with a problem and I need your help. I'm working on pyshacl validation, which is a Python library for validating RDF graphs against SHACL graphs. I have a shacl shape graph that has a SPARQL construct clause to create new instances and link them with other instances. Then I want to serialize them with the existing data and make a new graph. But when I run the validation, it succeeds without any output. I don't know what went wrong. Also when I run the same query on the GraphDB query editor it is showing possible outcomes. Can anyone help me fix this error?


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")

Here is my rule graph: (removed prefixes since they are many)


{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 .
}
}
""" ;
] ;
.

答案1

得分: 0

我修复了它。我只是修改了 target 部分。

{prefixes}
dmn:prepare_inspections
a sh:NodeShape ;
sh:target [
a sh:SPARQLTarget ;
sh:comment "选择所有符合条件的对象";
sh:select """{prefixes}"""
]
sh:comment "为目标对象创建新的检查";
sh:rule [
a sh:SPARQLRule;
sh:construct """{prefixes}"""
]
CONSTRUCT {..conditions..}
WHERE{
SELECT ?this ?Inspection_Number_Of_Risers ?ISCode ?Agent ?InspectionEquipment ?one_time ?Location ?InspectionProcedure
WHERE {...conditions...} ; 
] ; .
英文:

I fixed it. I just modified the target

{prefixes}
dmn:prepare_inspections
a sh:NodeShape ; 
sh:target [
a sh:SPARQLTarget ;
sh:comment "Select all of eligible objects";
sh:select """
{prefixes}"""]
sh:comment "Create new Inspections to the target objects";
sh:rule [
a sh:SPARQLRule;
sh:construct """ 
{prefixes}"""]
CONSTRUCT {..conditions..}
WHERE{
SELECT ?this ?Inspection_Number_Of_Risers ?ISCode ?Agent ?InspectionEquipment ?one_time ?Location ?InspectionProcedure
WHERE {...conditions...}""" ; 
] ; .

huangapple
  • 本文由 发表于 2023年5月11日 06:41:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定