简体   繁体   English

SHACL SPARQLTarget 未验证 SPARQL 查询 output 个节点

[英]SHACL SPARQLTarget not validating the SPARQL query output nodes

I have a NodeShape with a sh:SPARQLTarget.我有一个带有 sh:SPARQLTarget 的 NodeShape。 I tried to run the Target SPARQL query in an ontology editor and it delivered results, but when I'm executing the same query in my custom target node shape in sh:select, it won't validate the target nodes returned by the SPARQL query.我尝试在本体编辑器中运行 Target SPARQL 查询并提供了结果,但是当我在 sh:select 中的自定义目标节点形状中执行相同的查询时,它不会验证 SPARQL 查询返回的目标节点. I am using pySHACL.我正在使用 pySHACL。 Did I do something wrong?我做错什么了吗? I'm out of ideas.我没主意了。 Here is my Nodeshape and data graph:这是我的节点形状和数据图:

I have used “” for sh:select instead of “”” “””, since I am defining the shapes_graph as a variable in my python code and it is already encoded in """ """.我在 sh:select 中使用了“”而不是“””“”,因为我在 python 代码中将 shapes_graph 定义为变量,并且它已经编码为“””“””。 I have also enabled meta_shacl=True in pyShacl to ensure that my shapes_graph is valid.我还在 pyShacl 中启用了 meta_shacl=True 以确保我的 shapes_graph 有效。 Also the nodeShape (snomed:dob363698007Shape) works well when provided with a normal TargetClass or TargetNode.此外,nodeShape (snomed:dob363698007Shape) 在提供普通 TargetClass 或 TargetNode 时也能正常工作。 What am I missing?我错过了什么?

I have already referred SPARQLRule not constructing我已经提到SPARQLRule 没有构建

**NodeShape**

snomed: 
    sh:declare [
        sh:prefix "snomed" ;
        sh:namespace <http://localhost:8890/snomed/> ; 
    ] .
    
snomed:dob363698007Shape
    a sh:NodeShape ;
    sh:target [
        a sh:SPARQLTarget ;
        sh:prefixes snomed: ;
        sh:select "SELECT ?this WHERE { ?node a snomed:24078009.?node a snomed:dob .?node snomed:609096000 ?this.?this a  snomed:dob363698007 .bind(?node as ?conceptName).bind(?this as ?RGName) .FILTER(REGEX(strafter(xsd:string(?RGName),'snomed/'),strafter(xsd:string(?conceptName),'snomed/')) ).}";
        ] ;
    sh:property [
        sh:path snomed:363698007;
        sh:minCount 1;
    ].```

**Data Graph**

```snomed:dob a rdfs:Class,snomed:dob ;
       rdfs:label "Semantic Pattern dob"^^xsd:string ;
        snomed:609096000 snomed:dob363698007 .

    snomed:dob363698007 a rdfs:Class,snomed:dob363698007;
       snomed:363698007 snomed:123037004 .  

    
    snomed:24078009 a rdfs:Class, snomed:24078009, snomed:dob;
        rdfs:label "Gangosa of yaws (disorder)"^^xsd:string ;
        snomed:609096000 snomed:24078009_3,snomed:24078009_5,snomed:24078009_6;
        rdfs:subClassOf snomed:128349005,
            snomed:140004,
            snomed:177010002,
            snomed:312118003,
            snomed:312129004,
            snomed:312422001,
            snomed:363166002,
            snomed:47841006,
            snomed:88037009 .

    snomed:24078009_3 a rdfs:Class, snomed:24078009_3, snomed:dob363698007 ;
        snomed:263502005 snomed:90734009 .

    snomed:24078009_5 a rdfs:Class, snomed:24078009_5,snomed:dob363698007;
        snomed:116676008 snomed:110435003 ;
        snomed:246075003 snomed:6246005 ;
        snomed:363698007 snomed:71836000 ;
        snomed:370135005 snomed:441862004 .

    snomed:24078009_6 a rdfs:Class, snomed:24078009_6,snomed:dob363698007 ;
        snomed:116676008 snomed:110435003 ;
        snomed:246075003 snomed:6246005 ;
        snomed:363698007 snomed:72914001 ;
        snomed:370135005 snomed:441862004 .

I've put your shacl shapes file and data graph into PySHACL to isolate the issue you are seeing.我已将您的 shacl 形状文件和数据图放入 PySHACL 中以隔离您遇到的问题。

There are two problems with your given setup that I have found.我发现您给定的设置有两个问题。

Firstly, SPARQL-Based Targets is a feature from the SHACL Advanced Specification .首先, SPARQL-Based TargetsSHACL Advanced Specification的一个特性。 PySHACL does not enable the Advanced-Spec features by default. PySHACL 默认不启用 Advanced-Spec 功能。 You can enable "advanced mode" by passing advanced=True to the validation module, or -a or --advanced on the commandline tool.您可以通过将advanced=True传递给验证模块或在命令行工具上传递-a--advanced来启用“高级模式”。

That is the main reason your SPARQL target was not selecting the nodes you expected.这是您的 SPARQL 目标未选择您期望的节点的主要原因。

Next, after enabling advanced mode, you will see that PySHACL fails when loading your SHACL Shape Graph.接下来,启用高级模式后,您将看到 PySHACL 在加载 SHACL Shape Graph 时失败。 That is because your prefix namespace is not declared correctly.那是因为你的前缀命名空间没有正确声明。

See the examples in the SPARQL-Prefixes section of the Spec document .请参阅规范文档的 SPARQL 前缀部分中的示例。 The specification states规范规定

"The values of sh:namespace are literals of datatype xsd:anyURI." “sh:namespace 的值是数据类型 xsd:anyURI 的文字。”

Your sh:namespace is a URIRef, not a Literal.您的sh:namespace是 URIRef,而不是文字。 Changing the namespace declaration to the following, fixes the error.将命名空间声明更改为以下内容,修复了错误。

sh:namespace "http://localhost:8890/snomed/"^^xsd:anyURI ;

I've run PySHACL with the corrected Shapes Graph, and it works as expected.我已经使用更正后的形状图运行 PySHACL,它按预期工作。

See this code for a complete working example: https://gist.github.com/ashleysommer/a319beeef33973906b76711675b2635c有关完整的工作示例,请参阅此代码: https://gist.github.com/ashleysommer/a319beeef33973906b76711675b2635c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM