Individuals) Causes => Cause_1,Agging => A" />
开发者

whats wrong with this Sparql query

开发者 https://www.devze.com 2023-04-12 20:27 出处:网络
I have a Parent Class \"Causes\" which has SubClasses \"Agging\",\"BadLifeStyle\" Each Class Causes has a datatype property \"name\" with individuals (Class=>Individuals) Causes => Cause_1,Agging => A

I have a Parent Class "Causes" which has SubClasses "Agging","BadLifeStyle" Each Class Causes has a datatype property "name" with individuals (Class=>Individuals) Causes => Cause_1,Agging => Agging_1,BadLifeStyle => BadLifeStyle_1 I want to get resul开发者_运维问答ts like this

Ind                SubCLassOF               type
Agging_1           Causes                   Agging
BadLifeStyle_1     Causes                   BadLifeStyle
Cause_1                                     Causes

I wrote this query

SELECT *
    WHERE {

          ?cause rdf:type ?typename.
          ?cause rdfs:subClassOf ?subClass.
          OPTIONAL{?cause NS:name ?name.}
           FILTER(REGEX(STR(?typename),"Causes","i")
          || REGEX(STR(?subClass),"Causes","i"))
    }

It didnt give me Cause_1 individual


Syntactically your query looks fine, not sure what's the problem...

Usually I prefer to perform a UNION for such kind of operations, in our case something like:

SELECT *
WHERE {
  {
    ?cause rdf:type ?typename .
    FILTER(REGEX(STR(?typename), "Causes", "i"))  
  } UNION {
    ?cause rdfs:subClassOf ?subClass .
    FILTER(REGEX(STR(?subClass), "Causes", "i"))
  }
  OPTIONAL{?cause NS:name ?name.}
}


I am using virtuoso server for RDF and sparql. In virtuoso, we have to add one space or enter before OPTIONAL then OPTIONAL will work in virtuoso. So Add one space or enter befor OPTIONAL then u will able to get results. Hope this will work for this Query.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号