簡體   English   中英

DBpedia中的SPARQL子查詢

[英]SPARQL subquery in DBpedia

我想過濾查詢中用作“聯接”的資源。 例如,給定一個DBpedia資源,我需要返回由sameAs屬性鏈接的資源標簽,並且在其URI中具有“ pt”。 我正在使用以下查詢:

SELECT ?label
{ <http://dbpedia.org/resource/Category:Algorithms> owl:sameAs ?nomePT.
   ?nomePT rdfs:label ?label
    FILTER regex(str(?nomePT), "pt", "i") 
}

但是,它返回空值,因為變量“?NomePT”始終包含列表中的第一個資源。 看到:

SELECT ?nomePT
{ <http://dbpedia.org/resource/Category:Algorithms> owl:sameAs ?nomePT.
   ?nomePT rdfs:label ?label
}

但是資源具有幾個sameAs鏈接:

SELECT ?nomePT
{ <http://dbpedia.org/resource/Category:Algorithms> owl:sameAs ?nomePT.}

查詢中有什么問題?

提前致謝。

如果您編寫查詢:

SELECT distinct * {
    ?nomePT owl:sameAs category:Algorithms.
}

您將獲得所有owl:sameAs所有鏈接owl:sameAs您的資源category:Algorithms 但是,您已經在限制三元組的范圍。 因此,如果您要求:

SELECT distinct ?nomePT {
    ?nomePT owl:sameAs category:Algorithms.
    ?nomePT rdfs:label ?label
}

在此處輸入圖片說明

如果首先找到您的特定資源,然后僅尋找該資源的標簽。 但是,如果您一開始沒有綁定三元組,而只過濾資源,則會為您提供所需的所有鏈接:

SELECT distinct ?resource {
    ?nomePT owl:sameAs ?resource.
    ?nomePT rdfs:label ?label.
filter( ?nomePT=category:Algorithms )
}

在此處輸入圖片說明

因此,您應該首先找到所有資源,然后根據特定資源(例如category:Algorithms對它們進行過濾,並且由於sameAs是自反的:

SELECT distinct * {
    ?nomePT owl:sameAs ?resource.
    ?nomePT rdfs:label ?label.
filter( ?nomePT=category:Algorithms && regex(str(?resource), "pt", "i") )
}

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM