未绑定变量的可选 Sparql 语句在 Stardog 中不起作用
Optional Sparql-Statement for unbound variable is not working in Stardog
上下文
嗨!
我有一个规范显示与另一个规范中的某些关系相关的问题。我的规范中的所有对象都有所谓的片段语言化(关系:hasFragmentVerbalisation)。
为了正确显示我的问题,我需要区分以下情况:我有一个“简单”的 Iri,我可以直接使用它的语言表达,或者它是否属于某种类型(在这种情况下,如果它是房间或员工的 iri)在哪些情况下我想 return 所述类型的所有资源的首选标签(所以基本上如果我的对象代表一个房间,我想 return 我数据库中的所有房间)。
我目前正在处理查询并尝试添加如下所示的语句部分:
OPTIONAL {
FILTER(isIRI(?object)).
?object relation:hasFragmentVerbalisation ?objectVerb .
}
OPTIONAL {
FILTER (?objectVerb= "Person"@en || ?objectVerb = "Teacher"@en)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?final ) .
}
OPTIONAL {
FILTER (?objectVerb= "room"@en || ?objectVerb = "lecture hall"@en)
?b room:prefLabel ?roomnumber .
BIND( ?roomnumber as ?final) .
FILTER (regex(?roomnumber, "20" ))
}
#OPTIONAL {
# FILTER (!BOUND(?final))
# BIND( IF ( isURI(?object), ?objectVerb, ?object) as ?final ) .
#}
我想在这里发生什么
我检索到了 ? 对象。我查询的主要结果是 ?final 对象。我现在想介绍三种可能的情况:
- 第一个可选语句:这里我只想检索片段语言。
- 第二个可选语句:如果我的 IRI 实际上指向一个员工,我想 return 我所有员工的首选标签为 ?final。基本上,我正在 return 列出我所有员工的名单。
- 第三个可选语句:如果我的 IRI 指向一个房间,我想 return 所有房间号为 ?final。正则表达式过滤器对我这里的问题并不重要。
- 第四条(取消注释)可选语句:如果第二条和第三条语句不适合,则不应绑定 ?final
问题
总的来说,除了出局的人都评论了一部作品。
但是,我在这里遇到两个问题:
- 对于第二个和第三个 Optionals 而不是将 ?objectVerb 与预定义字符串进行比较,我宁愿问(仅伪代码:)
Do this only if ?object rdf:type iri:for:person:or:room
。但是,我似乎无法做出这样的声明。
- “outcommented”可选调用(最后一个)不起作用
完全没有,我对为什么有点困惑。我在这里尝试的是:
- 如果我的 ?final 变量还没有被任何东西绑定,我想检查一下
如果 ?object 是 IRI,如果不是,我希望将先前检索到的 ?objectVerb-value 设置为 ?final
的值
这里有人能指出解决方案吗?
感谢您的帮助。
编辑:
完整查询:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
SELECT DISTINCT ?first ?second ?third ?fourth ?fourt4 ?fifth ?resulttype
WHERE {
?wording rdf:first ?first1 .
?wording rdf:rest/rdf:first ?second2 .
?wording rdf:rest/rdf:rest/rdf:first ?third3 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:first ?fourt4 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:rest/rdf:first ?fifth5 .
relation:hasBureau rdfs:range ?resulttype .
{
SELECT distinct ?wording (COUNT(?wording) AS ?sum)
WHERE {
relation:hasBureau relation:bigWord ?wording .
?wording rdf:rest*/rdf:first ?element .
}
GROUP BY ?wording
HAVING (?sum = 5)
}
OPTIONAL {
FILTER(isIRI(?first1)).
?first1 relation:fragmentWord ?firstVerb.
}
BIND( IF ( isURI(?first1), ?firstVerb , ?first1) as ?first ) .
FILTER(BOUND(?first)).
OPTIONAL {
FILTER(isIRI(?second2)).
?second2 relation:fragmentWord ?secondVerb.
}
OPTIONAL {
FILTER(isIRI(?third3)).
?third3 relation:fragmentWord ?thirdVerb.
}
BIND( IF ( isURI(?third3), ?thirdVerb , ?third3) as ?third ) .
FILTER(BOUND(?third)).
OPTIONAL {
FILTER(isIRI(?fourt4)).
?fourt4 relation:fragmentWord ?fourthVerb .
}
OPTIONAL {
FILTER(isIRI(?fifth5)).
?fifth5 relation:fragmentWord ?fifthVerb.
}
BIND( IF ( isURI(?fifth5), ?fifthVerb, ?fifth5) as ?fifth ) .
FILTER(BOUND(?fifth)).
OPTIONAL {
FILTER (?fourthVerb = "Person"@de || ?fourthVerb = "Dozent"@de || ?fourthVerb = "Lehrender"@de || ?fourthVerb = "Angestellter"@de)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?fourth ) .
}
OPTIONAL {
FILTER (?fourthVerb = "Hörsaal"@de || ?fourthVerb = "Zimmer"@de || ?fourthVerb = "Seminarraum"@de)
?b room:prefLabel ?roomnumber .
BIND( ?roomnumber as ?fourth ) .
}
FILTER(BOUND(?fourth)).
#OPTIONAL {
# FILTER (!BOUND(?fourth))
# BIND( IF ( isURI(?fourt4), ?fourthVerb, ?fourt4) as ?fourth ) .
#}
OPTIONAL {
FILTER (?secondVerb = "Büro"@de)
BIND( "Büro"@de as ?second ) .
}
OPTIONAL {
FILTER (?secondVerb = "Buero"@de)
BIND( "Buero"@de as ?second ) .
}
OPTIONAL {
FILTER (?secondVerb = "Person"@de || ?secondVerb = "Dozent"@de || ?secondVerb = "Lehrender"@de || ?secondVerb = "Angestellter"@de)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?second ) .
}
#OPTIONAL {
# FILTER (!BOUND(?second))
# BIND( IF ( isURI(?second2), ?secondVerb, ?second2) as ?second ) .
#}
}
还有一个极短的数据集 运行 它适用于它:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
<urn:xxx:fb5:employee#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Person"@de , "Dozent"@de, "Lehrender"@de, "Angestellter"@de .
<urn:yyy:assets:location:room#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Raum"@de , "Zimmer"@de, "Seminarraum"@de, "Hörsaal"@de .
relation:hasBureau
rdf:type rdf:Property ;
owl:minCardinality "1" ;
rdfs:domain employee:name ;
rdfs:range room:number ;
rdfs:label "hat ein Büro"@de, "has a bureau"@en ;
relation:fragmentWord "Büro"@de , "Buero"@de ;
relation:bigWord ("In welchem" relation:hasBureau "ist" <urn:xxx:fb5:employee#> "?") ;
relation:bigWord ("Finde ich" <urn:xxx:fb5:employee#> "in" <urn:yyy:assets:location:room#> "?") .
employee:PersonOne employee:prefLabel "Employee One".
employee:PersonOne relation:hasBureau room:23129 .
room:23129 room:prefLabel "23-129".
employee:PersonTwo employee:prefLabel "Employee Two".
employee:PersonTwo relation:hasBureau room:23232 .
room:23232 room:prefLabel "23-232".
不是要回答而是显示一些问题以获得反馈:
数据:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
<urn:xxx:fb5:employee#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Person"@de , "Dozent"@de, "Lehrender"@de, "Angestellter"@de .
<urn:yyy:assets:location:room#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Raum"@de , "Zimmer"@de, "Seminarraum"@de, "Hörsaal"@de .
relation:hasBureau
rdf:type rdf:Property ;
owl:minCardinality "1" ;
rdfs:domain employee:name ;
rdfs:range room:number ;
rdfs:label "hat ein Büro"@de, "has a bureau"@en ;
relation:fragmentWord "Büro"@de , "Buero"@de ;
relation:bigWord ("In welchem" relation:hasBureau "ist" <urn:xxx:fb5:employee#> "?") ;
relation:bigWord ("Finde ich" <urn:xxx:fb5:employee#> "in" <urn:yyy:assets:location:room#> "?") .
employee:PersonOne employee:prefLabel "Employee One".
employee:PersonOne relation:hasBureau room:23129 .
room:23129 room:prefLabel "23-129".
employee:PersonTwo employee:prefLabel "Employee Two".
employee:PersonTwo relation:hasBureau room:23232 .
room:23232 room:prefLabel "23-232".
查询:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
SELECT DISTINCT ?first ?second ?third ?fourth ?fifth ?resulttype
WHERE {
?wording rdf:first ?first1 .
?wording rdf:rest/rdf:first ?second2 .
?wording rdf:rest/rdf:rest/rdf:first ?third3 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:first ?fourth4 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:rest/rdf:first ?fifth5 .
relation:hasBureau rdfs:range ?resulttype .
?a employee:prefLabel ?employeename .
?b room:prefLabel ?roomnumber .
{
SELECT ?wording (COUNT(?wording) AS ?sum)
WHERE {
relation:hasBureau relation:bigWord ?wording .
?wording rdf:rest*/rdf:first ?element .
}
GROUP BY ?wording
HAVING (?sum = 5)
}
OPTIONAL {
?first1 relation:fragmentWord ?firstVerb .
}
BIND( COALESCE(?firstVerb, ?first1) as ?first )
OPTIONAL {
?second2 relation:fragmentWord ?secondVerb .
}
BIND( IF(?second2 = <urn:xxx:fb5:employee#>, ?employeename, IF(?second2 = room:, ?roomnumber, COALESCE(?secondVerb, ?second2))) as ?second )
OPTIONAL {
?third3 relation:fragmentWord ?thirdVerb .
}
BIND( COALESCE(?thirdVerb, ?third3) as ?third )
OPTIONAL {
?fourth4 relation:fragmentWord ?fourthVerb .
}
BIND( IF(?fourth4 = <urn:xxx:fb5:employee#>, ?employeename, IF(?fourth4 = room:, ?roomnumber, COALESCE(?fourthVerb, ?fourth4))) as ?fourth )
OPTIONAL {
?fifth5 relation:fragmentWord ?fifthVerb .
}
BIND( COALESCE(?fifthVerb, ?fifth5) as ?fifth )
}
结果:
--------------------------------------------------------------------------------
| first | second | third | fourth | fifth | resulttype |
================================================================================
| "In welchem" | "Buero"@de | "ist" | "Employee Two" | "?" | room:number |
| "In welchem" | "Büro"@de | "ist" | "Employee Two" | "?" | room:number |
| "In welchem" | "Buero"@de | "ist" | "Employee One" | "?" | room:number |
| "In welchem" | "Büro"@de | "ist" | "Employee One" | "?" | room:number |
| "Finde ich" | "Employee Two" | "in" | "23-232" | "?" | room:number |
| "Finde ich" | "Employee Two" | "in" | "23-129" | "?" | room:number |
| "Finde ich" | "Employee One" | "in" | "23-232" | "?" | room:number |
| "Finde ich" | "Employee One" | "in" | "23-129" | "?" | room:number |
--------------------------------------------------------------------------------
上下文
嗨!
我有一个规范显示与另一个规范中的某些关系相关的问题。我的规范中的所有对象都有所谓的片段语言化(关系:hasFragmentVerbalisation)。
为了正确显示我的问题,我需要区分以下情况:我有一个“简单”的 Iri,我可以直接使用它的语言表达,或者它是否属于某种类型(在这种情况下,如果它是房间或员工的 iri)在哪些情况下我想 return 所述类型的所有资源的首选标签(所以基本上如果我的对象代表一个房间,我想 return 我数据库中的所有房间)。
我目前正在处理查询并尝试添加如下所示的语句部分:
OPTIONAL {
FILTER(isIRI(?object)).
?object relation:hasFragmentVerbalisation ?objectVerb .
}
OPTIONAL {
FILTER (?objectVerb= "Person"@en || ?objectVerb = "Teacher"@en)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?final ) .
}
OPTIONAL {
FILTER (?objectVerb= "room"@en || ?objectVerb = "lecture hall"@en)
?b room:prefLabel ?roomnumber .
BIND( ?roomnumber as ?final) .
FILTER (regex(?roomnumber, "20" ))
}
#OPTIONAL {
# FILTER (!BOUND(?final))
# BIND( IF ( isURI(?object), ?objectVerb, ?object) as ?final ) .
#}
我想在这里发生什么
我检索到了 ? 对象。我查询的主要结果是 ?final 对象。我现在想介绍三种可能的情况:
- 第一个可选语句:这里我只想检索片段语言。
- 第二个可选语句:如果我的 IRI 实际上指向一个员工,我想 return 我所有员工的首选标签为 ?final。基本上,我正在 return 列出我所有员工的名单。
- 第三个可选语句:如果我的 IRI 指向一个房间,我想 return 所有房间号为 ?final。正则表达式过滤器对我这里的问题并不重要。
- 第四条(取消注释)可选语句:如果第二条和第三条语句不适合,则不应绑定 ?final
问题
总的来说,除了出局的人都评论了一部作品。 但是,我在这里遇到两个问题:
- 对于第二个和第三个 Optionals 而不是将 ?objectVerb 与预定义字符串进行比较,我宁愿问(仅伪代码:)
Do this only if ?object rdf:type iri:for:person:or:room
。但是,我似乎无法做出这样的声明。 - “outcommented”可选调用(最后一个)不起作用
完全没有,我对为什么有点困惑。我在这里尝试的是:
- 如果我的 ?final 变量还没有被任何东西绑定,我想检查一下 如果 ?object 是 IRI,如果不是,我希望将先前检索到的 ?objectVerb-value 设置为 ?final 的值
这里有人能指出解决方案吗? 感谢您的帮助。
编辑: 完整查询:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
SELECT DISTINCT ?first ?second ?third ?fourth ?fourt4 ?fifth ?resulttype
WHERE {
?wording rdf:first ?first1 .
?wording rdf:rest/rdf:first ?second2 .
?wording rdf:rest/rdf:rest/rdf:first ?third3 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:first ?fourt4 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:rest/rdf:first ?fifth5 .
relation:hasBureau rdfs:range ?resulttype .
{
SELECT distinct ?wording (COUNT(?wording) AS ?sum)
WHERE {
relation:hasBureau relation:bigWord ?wording .
?wording rdf:rest*/rdf:first ?element .
}
GROUP BY ?wording
HAVING (?sum = 5)
}
OPTIONAL {
FILTER(isIRI(?first1)).
?first1 relation:fragmentWord ?firstVerb.
}
BIND( IF ( isURI(?first1), ?firstVerb , ?first1) as ?first ) .
FILTER(BOUND(?first)).
OPTIONAL {
FILTER(isIRI(?second2)).
?second2 relation:fragmentWord ?secondVerb.
}
OPTIONAL {
FILTER(isIRI(?third3)).
?third3 relation:fragmentWord ?thirdVerb.
}
BIND( IF ( isURI(?third3), ?thirdVerb , ?third3) as ?third ) .
FILTER(BOUND(?third)).
OPTIONAL {
FILTER(isIRI(?fourt4)).
?fourt4 relation:fragmentWord ?fourthVerb .
}
OPTIONAL {
FILTER(isIRI(?fifth5)).
?fifth5 relation:fragmentWord ?fifthVerb.
}
BIND( IF ( isURI(?fifth5), ?fifthVerb, ?fifth5) as ?fifth ) .
FILTER(BOUND(?fifth)).
OPTIONAL {
FILTER (?fourthVerb = "Person"@de || ?fourthVerb = "Dozent"@de || ?fourthVerb = "Lehrender"@de || ?fourthVerb = "Angestellter"@de)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?fourth ) .
}
OPTIONAL {
FILTER (?fourthVerb = "Hörsaal"@de || ?fourthVerb = "Zimmer"@de || ?fourthVerb = "Seminarraum"@de)
?b room:prefLabel ?roomnumber .
BIND( ?roomnumber as ?fourth ) .
}
FILTER(BOUND(?fourth)).
#OPTIONAL {
# FILTER (!BOUND(?fourth))
# BIND( IF ( isURI(?fourt4), ?fourthVerb, ?fourt4) as ?fourth ) .
#}
OPTIONAL {
FILTER (?secondVerb = "Büro"@de)
BIND( "Büro"@de as ?second ) .
}
OPTIONAL {
FILTER (?secondVerb = "Buero"@de)
BIND( "Buero"@de as ?second ) .
}
OPTIONAL {
FILTER (?secondVerb = "Person"@de || ?secondVerb = "Dozent"@de || ?secondVerb = "Lehrender"@de || ?secondVerb = "Angestellter"@de)
?a employee:prefLabel ?employeename .
BIND( ?employeename as ?second ) .
}
#OPTIONAL {
# FILTER (!BOUND(?second))
# BIND( IF ( isURI(?second2), ?secondVerb, ?second2) as ?second ) .
#}
}
还有一个极短的数据集 运行 它适用于它:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
<urn:xxx:fb5:employee#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Person"@de , "Dozent"@de, "Lehrender"@de, "Angestellter"@de .
<urn:yyy:assets:location:room#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Raum"@de , "Zimmer"@de, "Seminarraum"@de, "Hörsaal"@de .
relation:hasBureau
rdf:type rdf:Property ;
owl:minCardinality "1" ;
rdfs:domain employee:name ;
rdfs:range room:number ;
rdfs:label "hat ein Büro"@de, "has a bureau"@en ;
relation:fragmentWord "Büro"@de , "Buero"@de ;
relation:bigWord ("In welchem" relation:hasBureau "ist" <urn:xxx:fb5:employee#> "?") ;
relation:bigWord ("Finde ich" <urn:xxx:fb5:employee#> "in" <urn:yyy:assets:location:room#> "?") .
employee:PersonOne employee:prefLabel "Employee One".
employee:PersonOne relation:hasBureau room:23129 .
room:23129 room:prefLabel "23-129".
employee:PersonTwo employee:prefLabel "Employee Two".
employee:PersonTwo relation:hasBureau room:23232 .
room:23232 room:prefLabel "23-232".
不是要回答而是显示一些问题以获得反馈:
数据:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
<urn:xxx:fb5:employee#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Person"@de , "Dozent"@de, "Lehrender"@de, "Angestellter"@de .
<urn:yyy:assets:location:room#>
rdfs:subClassOf wording:fragment ;
relation:fragmentWord "Raum"@de , "Zimmer"@de, "Seminarraum"@de, "Hörsaal"@de .
relation:hasBureau
rdf:type rdf:Property ;
owl:minCardinality "1" ;
rdfs:domain employee:name ;
rdfs:range room:number ;
rdfs:label "hat ein Büro"@de, "has a bureau"@en ;
relation:fragmentWord "Büro"@de , "Buero"@de ;
relation:bigWord ("In welchem" relation:hasBureau "ist" <urn:xxx:fb5:employee#> "?") ;
relation:bigWord ("Finde ich" <urn:xxx:fb5:employee#> "in" <urn:yyy:assets:location:room#> "?") .
employee:PersonOne employee:prefLabel "Employee One".
employee:PersonOne relation:hasBureau room:23129 .
room:23129 room:prefLabel "23-129".
employee:PersonTwo employee:prefLabel "Employee Two".
employee:PersonTwo relation:hasBureau room:23232 .
room:23232 room:prefLabel "23-232".
查询:
PREFIX relation: <urn:xxx:beziehungen#>
PREFIX yyy: <urn:xxx#>
PREFIX employee: <urn:xxx:fb5:employee#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX room: <urn:yyy:assets:location:room#>
PREFIX label: <urn:xxx:assets:labels#>
PREFIX wording: <urn:xxx:assets:wording#>
SELECT DISTINCT ?first ?second ?third ?fourth ?fifth ?resulttype
WHERE {
?wording rdf:first ?first1 .
?wording rdf:rest/rdf:first ?second2 .
?wording rdf:rest/rdf:rest/rdf:first ?third3 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:first ?fourth4 .
?wording rdf:rest/rdf:rest/rdf:rest/rdf:rest/rdf:first ?fifth5 .
relation:hasBureau rdfs:range ?resulttype .
?a employee:prefLabel ?employeename .
?b room:prefLabel ?roomnumber .
{
SELECT ?wording (COUNT(?wording) AS ?sum)
WHERE {
relation:hasBureau relation:bigWord ?wording .
?wording rdf:rest*/rdf:first ?element .
}
GROUP BY ?wording
HAVING (?sum = 5)
}
OPTIONAL {
?first1 relation:fragmentWord ?firstVerb .
}
BIND( COALESCE(?firstVerb, ?first1) as ?first )
OPTIONAL {
?second2 relation:fragmentWord ?secondVerb .
}
BIND( IF(?second2 = <urn:xxx:fb5:employee#>, ?employeename, IF(?second2 = room:, ?roomnumber, COALESCE(?secondVerb, ?second2))) as ?second )
OPTIONAL {
?third3 relation:fragmentWord ?thirdVerb .
}
BIND( COALESCE(?thirdVerb, ?third3) as ?third )
OPTIONAL {
?fourth4 relation:fragmentWord ?fourthVerb .
}
BIND( IF(?fourth4 = <urn:xxx:fb5:employee#>, ?employeename, IF(?fourth4 = room:, ?roomnumber, COALESCE(?fourthVerb, ?fourth4))) as ?fourth )
OPTIONAL {
?fifth5 relation:fragmentWord ?fifthVerb .
}
BIND( COALESCE(?fifthVerb, ?fifth5) as ?fifth )
}
结果:
--------------------------------------------------------------------------------
| first | second | third | fourth | fifth | resulttype |
================================================================================
| "In welchem" | "Buero"@de | "ist" | "Employee Two" | "?" | room:number |
| "In welchem" | "Büro"@de | "ist" | "Employee Two" | "?" | room:number |
| "In welchem" | "Buero"@de | "ist" | "Employee One" | "?" | room:number |
| "In welchem" | "Büro"@de | "ist" | "Employee One" | "?" | room:number |
| "Finde ich" | "Employee Two" | "in" | "23-232" | "?" | room:number |
| "Finde ich" | "Employee Two" | "in" | "23-129" | "?" | room:number |
| "Finde ich" | "Employee One" | "in" | "23-232" | "?" | room:number |
| "Finde ich" | "Employee One" | "in" | "23-129" | "?" | room:number |
--------------------------------------------------------------------------------