简体   繁体   English

SPARQL CONSTRUCT 中的动态谓词

[英]Dynamic predicates in SPARQL CONSTRUCT

I'm trying to get only ONE relation in the CONSTRUCT.我试图在 CONSTRUCT 中只获得一个关系。

Please let me introduce the problem.... There is an Actor (actorURI) which has a relation with another Actor (actor2URI).请让我介绍一下问题.... 有一个 Actor (actorURI) 与另一个 Actor (actor2URI) 有关系。 There is only ONE relation possible.只有一种关系可能。 With an BIND(IF command i'm trying to get the right URI's for the specific relations and used the string 'blanko' if there is no relation.使用 BIND(IF 命令,我试图为特定关系获取正确的 URI,如果没有关系,则使用字符串 'blanko'。

Based on a variable (?RelatieSoort) in the data i would like to distinct 5 types of relationships (ChronologischeOpvolger, ChronologischeVoorganger etc.).基于数据中的变量(?RelatieSoort),我想区分 5 种类型的关系(ChronologischeOpvolger、ChronologischeVoorganger 等)。

I'm propably asking a stupid question.我大概是在问一个愚蠢的问题。 But I don't know what to do.... I hope somebody can help me out.但我不知道该怎么办......我希望有人能帮助我。 Thanks in advance!提前致谢!

CONSTRUCT {

      ?actorURI a rico:Agent;
          act:heeftRelatie ?relatieURI;
          act:heeftRelatieChronologischeOpvolger ?chronologischeOpvolgerAgentURI;
          act:heeftRelatieChronologischeVoorganger ?chronologischeVoorgangerAgentURI;
          act:heeftRelatieHierarchischBovenliggend ?hierarchischBovenliggendAgentURI;
          act:heeftRelatieHierarchischOnderliggend ?hierarchischOnderliggendAgentURI;
          act:heeftRelatieAssociatief ?associatiefAgentURI.

}
WHERE {

      ?row a mydata:Row ;
          optional { ?row mydata:RelatieUUID ?RelatieUUID }.
          optional { ?row mydata:ActorUUID ?ActorUUID }.
          optional { ?row mydata:Actor2UUID ?Actor2UUID }.
          optional { ?row mydata:RelatieSoort ?RelatieSoort }.
          optional { ?row mydata:Toelichting ?Toelichting }.
          optional { ?row mydata:Begin ?Begin }.
          optional { ?row mydata:Eind ?Eind }.

      # ActorURI
      BIND(IRI(spif:buildString("https://test.nl/id/actordb/actor/{?1}", ENCODE_FOR_URI(?ActorUUID))) AS ?actorURI)

  
      # Actor2URI
      BIND(IRI(spif:buildString("https://test.nl/id/actordb/actor/{?1}", ENCODE_FOR_URI(?Actor2UUID))) AS ?actor2URI) 

    BIND(IF(?RelatieSoort = "Chronologische opvolger", ?actor2URI, "blanko") as ?chronologischeOpvolgerAgentURI)
    BIND(IF(?RelatieSoort = "Chronologische voorganger", ?actor2URI, "blanko") as ?chronologischeVoorgangerAgentURI)  
    BIND(IF(?RelatieSoort = "Hiërarchisch bovenliggend", ?actor2URI, "blanko") as ?hierarchischBovenliggendAgentURI)   
    BIND(IF(?RelatieSoort = "Hiërarchisch onderliggend", ?actor2URI, "blanko") as ?hierarchischOnderliggendAgentURI)  
    BIND(IF(?RelatieSoort = "Associatief", ?actor2URI, "blanko") as ?associatiefAgentURI)   

}
RESULT
https://test/id/actor/actor1 act:heeftRelatieChronologischeOpvolger https://test/id/actor/actor2
?actorURI act:heeftRelatieChronologischeVoorganger "blanko"
?actorURI act:heeftRelatieHierarchischBovenliggend "blanko"
?actorURI act:heeftRelatieHierarchischOnderliggend "blanko"
?actorURI act:heeftRelatieAssociatief "blanko"

In the result above you can see what is happening.... The actual relation is shown (act:heeftRelatieChronologischeOpvolger) and links the two actors with eachother.在上面的结果中,您可以看到正在发生的事情.... 显示了实际的关系 (act:heeftRelatieChronologischeOpvolger) 并将两个参与者相互联系起来。 But the other relations are not existing, but the predicates are shown in the CONSTRUCT.但其他关系不存在,但谓词显示在 CONSTRUCT 中。 My wish here is to NOT SHOW the other relations in the CONSTRUCT.我的愿望是不显示 CONSTRUCT 中的其他关系。

The thing is that the query is returning some value for all the defined triples in the CONSTRUCT , either your strings or a blanko string.问题是查询正在为CONSTRUCT中所有定义的三元组返回一些值,无论是您的字符串还是空白字符串。 In case the relationships between the actors does not exist the where clause should return nothing.如果参与者之间的关系不存在,则 where 子句不应返回任何内容。 The bind can return a blank node in this case and then filter if it the case, let's see:在这种情况下bind可以返回一个空白节点,然后过滤如果是这种情况,让我们看看:

BIND(IF(?RelatieSoort = "Chronologische opvolger", ?actor2URI, bnode()) as ?chronologischeOpvolgerAgentURI)
FILTER(!isBlank(?chronologischeOpvolgerAgentURI))

If you provide us the data set we could help you better.如果您向我们提供数据集,我们可以为您提供更好的帮助。

The way to go is to use a var as property in the construct , and set its value based on the value match from ?RelatieSoort , eg something along the following lines: go 的方法是在construct中使用 var 作为属性,并根据来自?RelatieSoort的值匹配设置其值,例如以下几行:

CONSTRUCT {
      ?actorURI a rico:Agent;
          act:heeftRelatie ?relatieURI;
          ?prop ?actor2URI.

} where { 
...

    BIND(IF(?RelatieSoort = "Chronologische opvolger", act:heeftRelatieChronologischeOpvolger, 
    IF(?RelatieSoort = "Chronologische voorganger", act:heeftRelatieChronologischeVoorganger, 
    IF(?RelatieSoort = "Hiërarchisch bovenliggend", act:heeftRelatieHierarchischBovenliggend, 
    IF(?RelatieSoort = "Hiërarchisch onderliggend", act:heeftRelatieHierarchischOnderliggend, 
    IF(?RelatieSoort = "Associatief", act:heeftRelatieAssociatief, ?unbound_var))))) as ?prop)   
}

HTH高温高压

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

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