简体   繁体   English

如果情况发生,rdfs删除项目

[英]rdfs remove items if a condition happens

In a previous question 在上一个问题中

SPARQL if an instance has a property, others must as well 如果实例具有属性,则SPARQL其他实例也必须

I asked that if i have an instance that has a value for a specific predicate, then the all the output of my sparql query must have the same value for the same predicate. 我问如果我有一个实例,该实例具有特定谓词的值,那么我的sparql查询的所有输出必须对于相同谓词具有相同的值。

I got an excellent answer there, 我在那里得到了一个很好的答案,

now I am trying to expand it because i've found a new scenario, 现在我正在尝试扩展它,因为我发现了一个新的场景,

the new scenario is: 新方案是:

if an instance has a value to a specific predicate then all the output items must either have the same value for the same predicate or if they have another value, these two values must be from the same class 如果一个实例具有特定谓词的值,则所有输出项对于同一谓词必须具有相同的值,或者如果它们具有另一个值,则这两个值必须来自同一类

I extended that sparql query to the following: 我将该sparql查询扩展到以下内容:

    PREFIX : <http://example.org/rs#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?item ?predicate ?similarity where 
{
  values ?x {:instance1}
  ?x ?predicate ?value.
  ?item ?predicate ?value.
  ?predicate :hasSimilarityValue ?similarity.
  filter (?x != ?item)
  filter not exists {
    ?x ?p ?v1.
    ?v1 a   ?class.
    ?p  rdfs:subPropertyOf  :isCriticalPredicate.
    filter not exists {
        ?item ?p ?v2.
        ?p rdfs:subPropertyOf :isCriticalPredicate.
        ?v2 a   ?class.
        ?class  rdfs:subClassOf :ImportantClass
    }
  }
}

and here is my data: 这是我的数据:

  @prefix : <http://example.org/rs#>
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

:instance1  :p1 :value1.
:instance2  :p1 :value2.
:p1 :hasSimilarityValue 0.5.
:value1 a   :class1.
:value2 a   :class1.
:class1 rdfs:subClassOf :ImportantClass.
:p1 rdfs:subPropertyOf  :isCriticalPredicate.

but the result is always empty i don't know why. 但是结果总是空的,我不知道为什么。

note1 注意1

by specific predicate, i mean the predicate that are rdfs:subClassOf :isCriticalPredicate 通过特定谓词,我的意思是谓词rdfs:subClassOf:isCriticalPredicate

by specific class, I mean that class that are rdfs:subClassOf :ImportantClass 通过特定的类,我的意思是rdfs:subClassOf:ImportantClass的类

The Immediate Problem: There's No Matching Data! 眼前的问题:没有匹配的数据!

As written, this is a pretty simple issue: there's actually no data that matches the query you've written. 如所写,这是一个非常简单的问题:实际上没有与您编写的查询相匹配的数据。 As such, I don't think the data and query really reproduce the problem that you're describing. 因此,我认为数据和查询不能真正重现您所描述的问题。 You query begins with 您的查询始于

  values ?x {:instance1}
  ?x ?predicate ?value.
  ?item ?predicate ?value.
  filter (?x != ?item)

Your data has: 您的数据有:

:instance1  :p1 :value1.
:instance2  :p1 :value2.

There are no possible values for ?instance. 实例没有可能的值。 The only candidate would be :instance2, but it doesn't have any values in common with :instance1, so there's no candidate for ?value. 唯一的候选者将是:instance2,但与:instance1没有任何共同的值,因此没有候选值。

The Query You Want 您想要的查询

Now, even though the question as written doesn't really have the issue that you're describing, I think I see what you're asking about. 现在,即使所写的问题确实没有您要描述的问题,我想我也明白了您要问的问题。 When you're trying to create minimal data for your debugging process, you should try to include all the relevant cases . 当您尝试为调试过程创建最少的数据时,应尝试包括所有相关案例 In this case, you'd want to have at least an instance that has the same value for a critical predicate, and an instance that has a different value for a critical predicate but where both values are important. 在这种情况下,您需要至少有一个对关键谓词具有相同值的实例,以及一个对关键谓词具有不同值但两个值都很重要的实例。 Here's some data: 这里是一些数据:

@prefix : <urn:ex:>

:instance1 :p :v1 .
:instance1 :q :v2 .

:instance2 :p :v1 . 
:instance2 :q :v2 .  #-- same value for :q

:instance3 :p :v1 .
:instance3 :q :v3 .  #-- different, but important, value for :q

:instance4 :p :v1 .
:instance4 :q :v4 .  #-- different, non-important, value for :q

:q a :CriticalPredicate .

:v2 a :ImportantValue .
:v3 a :ImportantValue .

Given the query that you're already working with, I think this one will be relatively clear. 考虑到您已经在使用的查询,我认为这一点将相对清晰。 It's not much different from what you've already got. 它与您已经拥有的没有太大不同。

prefix : <urn:ex:>

select distinct ?item where  {
  values ?x { :instance1 }
  ?x    ?predicate ?value .
  ?item ?predicate ?value .
  filter (?x != ?item)

  #-- Exclude any results where
  #-- ?x has a value ?v1 for a
  #-- critical predicate ?p...
  filter not exists {
    ?x ?p ?v1 .
    ?p a :CriticalPredicate .

    #-- ...unless either ?item has
    #-- the same value ?v1 for the
    #-- predicate ?p, or ?item has
    #-- another value ?v2 and both
    #-- ?v1 and ?v2 are
    #-- :ImportantValues.
    filter not exists {
      { ?item ?p ?v1 }
      union
      { ?item ?p ?v2 .
        :ImportantValue ^a ?v1, ?v2 . }
    }
  }
}
--------------
| item       |
==============
| :instance2 |
| :instance3 |
--------------

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

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