查询多个 TDB 数据集

Fab*_*ian 5 sparql jena dbpedia fuseki tdb

使用:jena-fuseki-1.1.0, apache-jena-2.12.0

我想要达到的目标和我目前的状态:

我正在尝试使用从 wiki.dbpedia.org/Downloads2014 作为 .nt 文件下载的 dbpedia Persondata(英语和德语)、跨语言链接、图像和维基百科文章链接来设置本地 jena-fuseki 服务器。我想对它们运行下面的 SPAQRL-Query 并获得与 dbpedia.org/sparql 相同的结果。这个查询应该给我所有在德国斯图加特出生的人,包括他们的姓名、生日、英语和德语描述文本、维基百科链接、图片链接和简短描述。

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT ?name ?birth ?description_en ?description_de ?wiki ?description ?pic
WHERE {
   ?person dbo:birthPlace :Stuttgart .
   ?person dbo:birthDate ?birth .
   ?person foaf:name ?name .
   OPTIONAL{
      ?person dc:description ?description .
      FILTER (LANG(?description) = 'en') .
   }
   OPTIONAL{
      ?person foaf:isPrimaryTopicOf ?wiki .
   }
   FILTER NOT EXISTS{
      ?person dbo:deathDate ?death .
   }
   OPTIONAL {
      ?person rdfs:comment ?description_en .
      FILTER (LANG(?description_en) = 'en') .
   }
   OPTIONAL {
      ?person rdfs:comment ?description_de .
      FILTER (LANG(?description_de) = 'de') .
   }
   OPTIONAL {
      ?person dbo:thumbnail ?pic
   }
}
ORDER BY ?name
Run Code Online (Sandbox Code Playgroud)

我在 dbpedia.org/sparql 上得到了什么:

第一排:

"Abdulsamed Akin"@en 1991-07-17+02:00 "Abdulsamed Akin (born July 17, 1991) is a Turkish-German footballer who plays for Stuttgarter Kickers."@en "Abdulsamed Akin (* 17. Juli 1991 in Stuttgart) ist ein deutscher Fußballspieler türkischer Abstammung."@de http://en.wikipedia.org/wiki/Abdulsamed_Akin "Footballer"@en http://commons.wikimedia.org/wiki/Special:FilePath/Abdulsamed_Akin.jpg?width=300

我在我的 fuseki 上得到了什么:

第一排:

"Abdulsamed Akin"@en "1991-07-17"^^<http://www.w3.org/2001/XMLSchema#date> [empty] [empty] [empty] [empty] "Footballer"@en [empty]

如您所见,我的本地查询中缺少描述文本以及维基百科和图片的链接。

不同的属性在不同的 TDB-Datasets 中,因为来自 DBpedia 的 .nt-Files 是分开的。?name、?birth 和?description 来自“Persondata”的TDB、“Links to Wikipedia Articel”中的?wiki 和“Images”中的?pic。

所以我需要跨不同的 TDB 数据源进行查询或将它们组合起来。

到目前为止我做了什么:

下载 .nt 文件并在其上使用 tdbloader 后,我得到了五个 tdb 文件夹,将它们放入我的本地 fuseki 中。然后我将这两个配置放在一起,目的是组合 tdb-datasets,所以我可以进行上述查询,但它们都不起作用:

第一的:

@prefix :        <#> .
@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .

[] rdf:type fuseki:Server ;
   fuseki:services (
     <#service1>
   ) .

# TDB
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

<#service1> rdf:type fuseki:Service ;
    # URI of the dataset -- http://localhost:3030/ds
    fuseki:name                        "ds" ; 
    fuseki:serviceQuery                "sparql" ;   
    fuseki:serviceReadGraphStore       "data" ;
    fuseki:serviceReadGraphStore       "get" ;
    fuseki:dataset                     <#dataset> ;
    .

## ----------------------------------
## dataset for default graph
<#dataset> rdf:type      ja:RDFDataset ;
     ja:defaultGraph <#dbenGraph> ;
     #ja:namedGraph
     #   [ ja:graphName      <http://localhost:3030/dbenGraph> ;
     #     ja:graph          <#dbenGraph> ] ;
     ja:namedGraph
        [ ja:graphName       <http://localhost:3030/dbdeGraph> ;
          ja:graph           <#dbdeGraph> ] ;
     ja:namedGraph
        [ ja:graphName       <http://localhost:3030/dbinterGraph> ;
          ja:graph           <#dbinterGraph> ] ;
     ja:namedGraph
        [ ja:graphName       <http://localhost:3030/dbpicGraph> ;
          ja:graph           <#dbpicGraph> ] ;
     ja:namedGraph
        [ ja:graphName       <http://localhost:3030/dbwikiGraph> ;
          ja:graph           <#dbwikiGraph> ] ;
     .

## ----------------------------------
## the graph's  
<#dbenGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_en> ;
    tdb:unionDefaultGraph   true ;
    .

<#dbdeGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_de> ;
    tdb:unionDefaultGraph   true ;
    .

<#dbinterGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_inter> ;
    tdb:unionDefaultGraph   true ;
    .

<#dbpicGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_wiki> ;
    tdb:unionDefaultGraph   true ;
    .

<#dbwikiGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_inter> ;
    tdb:unionDefaultGraph   true ;
    .

## DB of persons in Englisch
<#dbpedia_en> rdf:type      tdb:DatasetTDB ;
    tdb:location            "db" ;
    tdb:unionDefaultGraph   true ;
    .

## DB of persons in German
<#dbpedia_de> rdf:type      tdb:DatasetTDB ;
    tdb:location            "dbde" ;
    tdb:unionDefaultGraph   true ;
    .

## DB of persons inter-language-link
<#dbpedia_inter> rdf:type      tdb:DatasetTDB ;
    tdb:location               "dbinter" ;
    tdb:unionDefaultGraph      true ;
    .

## DB of image-links
<#dbpedia_pic> rdf:type      tdb:DatasetTDB ;
    tdb:location "dbpic" ;
    tdb:unionDefaultGraph true ;
    .

## DB of wiki-links
<#dbpedia_wiki> rdf:type      tdb:DatasetTDB ;
    tdb:location "dbwiki" ;
    tdb:unionDefaultGraph true ;
    .
Run Code Online (Sandbox Code Playgroud)

第二:

@prefix :        <#> .
@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .

[] rdf:type fuseki:Server ;

   fuseki:services (
     <#service1>
   ) .

# TDB
[] ja:loadClass "com.hp.hpl.jena.tdb.TDB" .
tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
tdb:GraphTDB    rdfs:subClassOf  ja:Model .

## ---------------------------------------------------------------
## Services.

<#service1> rdf:type fuseki:Service ;
    # URI of the dataset -- http://localhost:3030/ds
    fuseki:name                        "ds" ; 
    fuseki:serviceQuery                "sparql" ;   
    fuseki:serviceReadGraphStore       "data" ;
    fuseki:serviceReadGraphStore       "get" ;
    fuseki:dataset                     <#dataset> ;
    .

<#dataset> rdf:type       ja:RDFDataset ;
    ja:defaultGraph       <#model_inf> ;
    .

<#model_inf> a ja:InfModel ;
    ja:baseModel <#dbenGraph> ;
    ja:reasoner [
        ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLMicroFBRuleReasoner>
    ] 
    .

<#dbenGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#dbpedia_en> ;
    tdb:unionDefaultGraph   true ;
    .   

## DB of Persons in Englisch
<#dbpedia_en> rdf:type      tdb:DatasetTDB ;
    tdb:location            "db" ;
    tdb:unionDefaultGraph   true ;
    .

## DB of Persons in German
<#dbpedia_de> rdf:type      tdb:DatasetTDB ;
    tdb:location            "dbde" ;
    tdb:unionDefaultGraph   true ;
    .

## DB of Persons inter-language-link
<#dbpedia_inter> rdf:type      tdb:DatasetTDB ;
    tdb:location               "dbinter" ;
    tdb:unionDefaultGraph      true ;
    .

## DB von Resource auf Image
<#dbpedia_pic> rdf:type      tdb:DatasetTDB ;
    tdb:location "dbpic" ;
    tdb:unionDefaultGraph true ;
    .

## DB von Resource auf Wiki
<#dbpedia_wiki> rdf:type      tdb:DatasetTDB ;
    tdb:location "dbwiki" ;
    tdb:unionDefaultGraph true ;
    .
Run Code Online (Sandbox Code Playgroud)

那么为什么本地 Query 缺少 Attributes 呢?我是否配置或查询了 fuseki 错误?查询中是否缺少他们的某些内容?有没有另一种方法来实现我想要的?

我希望清楚地传达我的需要,如果没有随时问!

Rob*_*obV 2

绝对没有必要将每个单独的文件加载到单独的 TDB 数据集中,除非您确实出于某种原因想要将数据分开。

从您的问题描述来看,您似乎希望将所有数据组合在一起,因此最好只创建一个 TDB 数据集并对其进行查询。 tdbloader将非常高兴地允许您将多个文件加载到单个 TDB 数据库中。

至于为什么您当前的设置不起作用,是因为您仅将服务连接到单个 TDB 数据集。