0

语境

你好!
我有一个规范,显示与另一个规范中的某些关系相关的问题。我的规范中的所有对象都有所谓的片段语言化(relation:hasFragmentVerbalisation)。
为了正确显示我的问题,我需要区分我有一个“简单” Iri 的情况,我可以直接使用它的语言表达,或者它是否属于某种类型(在这种情况下,如果它是房间或员工的 iri)在哪些情况下我想返回所述类型的所有资源的首选标签(所以基本上如果我的对象代表一个房间,我想返回我在数据库中拥有的所有房间)。

我目前正在处理一个查询并尝试添加一个如下所示的语句部分:

    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 实际上指向一个员工,我想将我员工的所有首选标签返回为 ?final。基本上,我要返回我所有员工的名单。
  • 第三个可选语句:如果我的 IRI 指向一个房间,我想为 ?final 返回所有房间号。正则表达式过滤器对于我在这里的问题并不重要。
  • 第四个(已注释掉的)可选语句:如果第二个和第三个语句不合适, ?final 不应绑定

问题

一般来说,除了出局之外,所有人都评论了一部作品。但是,我在这里遇到两个问题:

  1. 对于第二个和第三个 Optionals 而不是将 ?objectVerb 与预定义的字符串进行比较,我宁愿问 (only pseudo-code:) Do this only if ?object rdf:type iri:for:person:or:room。但是,我似乎无法做出这样的声明。
  2. “注释掉的”可选调用(最后一个)根本不起作用,我对为什么有点困惑。我在这里尝试的是:
    • 如果我的 ?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".
4

1 回答 1

3

不打算作为答案,但显示一些查询以获得反馈:

数据:

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 |
--------------------------------------------------------------------------------
于 2021-02-19T15:24:26.520 回答