[英]Dynamic predicates in SPARQL CONSTRUCT
我試圖在 CONSTRUCT 中只獲得一個關系。
請讓我介紹一下問題.... 有一個 Actor (actorURI) 與另一個 Actor (actor2URI) 有關系。 只有一種關系可能。 使用 BIND(IF 命令,我試圖為特定關系獲取正確的 URI,如果沒有關系,則使用字符串 'blanko'。
基於數據中的變量(?RelatieSoort),我想區分 5 種類型的關系(ChronologischeOpvolger、ChronologischeVoorganger 等)。
我大概是在問一個愚蠢的問題。 但我不知道該怎么辦......我希望有人能幫助我。 提前致謝!
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"
在上面的結果中,您可以看到正在發生的事情.... 顯示了實際的關系 (act:heeftRelatieChronologischeOpvolger) 並將兩個參與者相互聯系起來。 但其他關系不存在,但謂詞顯示在 CONSTRUCT 中。 我的願望是不顯示 CONSTRUCT 中的其他關系。
問題是查詢正在為CONSTRUCT
中所有定義的三元組返回一些值,無論是您的字符串還是空白字符串。 如果參與者之間的關系不存在,則 where 子句不應返回任何內容。 在這種情況下bind
可以返回一個空白節點,然后過濾如果是這種情況,讓我們看看:
BIND(IF(?RelatieSoort = "Chronologische opvolger", ?actor2URI, bnode()) as ?chronologischeOpvolgerAgentURI)
FILTER(!isBlank(?chronologischeOpvolgerAgentURI))
如果您向我們提供數據集,我們可以為您提供更好的幫助。
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)
}
高溫高壓
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.