简单的SPARQL查询不会提供乌龟文件的结果

时间:2019-02-07 11:30:01

标签: sparql

我有一个正在查询的ttl文件。这是我要查询的两个节点的示例:

<http://natarchives.com.mt/archivalresource/R494Vol1>
    a                       "http://data.archiveshub.ac.uk/def/ArchivalResource" ;
    locah:accessProvidedBy  "http://natarchives.com.mt/repository/MT01" ;
    locah:dateCreatedAccumulatedEnd
            "1497" ;
    locah:dateCreatedAccumulatedStart
            "1486" ;
    locah:dateCreatedAccumulatedString
            "1486-1497" ;
    locah:level             "http://data.archiveshub.ac.uk/page/level/file" ;
    <http://purl.org/dc/terms/creator>
            <http://natarchives.com.mt/author/R494Vol1_NotaryGiacomoZabbara> ;
    <http://purl.org/dc/terms/identifier>
            "R494Vol1" ;
    <http://purl.org/dc/terms/language>
            "la" ;
    <http://purl.org/dc/terms/type>
            "Register" ;

<http://natarchives.com.mt/deed/R494Vol1-D233>
    locah:accessProvidedBy  "http://natarchives.com.mt/repository/MT01" ;
    locah:associatedWith    "constituens" , "positum" , "annuam gabellam" , "juribus" , "melite" , "festo pasce ressureccionis dominice" , "moratorie" , "converso" , "bonam" , "ponderis" , "situm" , "nobilem" , "completis" , "procuratorem magnifici" , "precario" , "civitatis melite" , "jngabellacionem" , "territorium eiusdem magnifici" , "bona" , "pecunia" , "juravit" , "gabellam juxta usum melite" , "jngabellavit" , "personam" , "augustj" , "procurator magnifici" , "crastato" , "testibus testamur" ;
    locah:associatedWith    <http://natarchives.com.mt/person/person3617> , <http://natarchives.com.mt/place/place727> , <http://natarchives.com.mt/place/place191> , <http://natarchives.com.mt/person/person3612> , <http://natarchives.com.mt/person/person3616> , <http://natarchives.com.mt/place/place726> , <http://natarchives.com.mt/place/place190> , <http://natarchives.com.mt/person/person3619> , <http://natarchives.com.mt/person/person3611> , <http://natarchives.com.mt/person/person3615> , <http://natarchives.com.mt/person/person3614> , <http://natarchives.com.mt/person/person3618> , <http://natarchives.com.mt/place/place728> , <http://natarchives.com.mt/person/person3610> , <http://natarchives.com.mt/person/person3613> ;
    locah:level             "http://data.archiveshub.ac.uk/page/level/item" ;
    <http://purl.org/dc/terms/date>
            "8-8-1487" ;
    <http://purl.org/dc/terms/identifier>
            "R494Vol1-D233" ;
    <http://purl.org/dc/terms/isPartOf>
            "http://natarchives.com.mt/archivalresource/R494Vol1" ;
    <http://purl.org/dc/terms/type>
            "Cabella" .

这是我正在尝试的查询:

SELECT ?x ?reg ?regId
WHERE {
?x dcterms:date "8-8-1487".
?x dcterms:isPartOf ?reg.
?reg dcterms:identifier ?regId.
}

当我尝试获取regId时,查询没有给出任何结果,如果从turtle文件中可以明显看出存在regId。知道为什么吗?

1 个答案:

答案 0 :(得分:0)

问题在于,在您的数据中,isPartOf属性的值是字符串文字"http://natarchives.com.mt/archivalresource/R494Vol1"。字符串文字与URI不同。因此,查询的结果是?x<http://natarchives.com.mt/deed/R494Vol1-D233>匹配,?reg"http://natarchives.com.mt/archivalresource/R494Vol1"匹配,但是?regId与任何东西都不匹配,因为在数据中没有?reg的值作为主题的三元组(也没有,因为在RDF中主题不能是文字)。

要修复数据,您需要用正确的URI替换"http://natarchives.com.mt/archivalresource/R494Vol1",并用尖括号代替引号:<http://natarchives.com.mt/archivalresource/R494Vol1>

如果无法修复数据,则还可以通过使SPARQL将文字转换为IRI来查询数据,例如:

SELECT ?x ?regIri ?regId
WHERE {
  ?x dcterms:date "8-8-1487".
  ?x dcterms:isPartOf ?reg.
  BIND(IRI(?reg) as ?regIri) 
  ?regIri dcterms:identifier ?regId.
}