首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查询多个TDB数据集

查询多个TDB数据集
EN

Stack Overflow用户
提问于 2014-09-30 13:21:53
回答 2查看 2.6K关注 0票数 5

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

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

我正在尝试建立一个本地的jena-fuseki服务器,其中包含dbpedia Persondata (英语和德语)、跨语言链接、图片和维基百科文章的链接,从wiki.dbpara.org/ downloaded 2014下载为.nt文件。我想对它们运行下面的SPAQRL-查询,并获得与dbparia.org/sparql相同的结果。这个查询应该给我所有出生在德国斯图加特的活人,他们的名字,生日,英语和德语描述文本,链接到维基百科,链接到一张图片和一个简短的描述。

代码语言:javascript
复制
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

我在dbpara.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

我在我的婚礼上得到了什么:

第一行:

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

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

由于从DBpedia中分离出..nt文件,所以不同的属性在不同的TDB-数据集中。名称、出生和描述在TDB中,分别来自"Persondata“、”链接到维基百科文章“中的”wiki“和”图片“中的图片。

因此,我需要查询不同的或如何组合它们。

到目前为止我所做的:

下载了..nt文件并在其上使用tdbloader之后,我得到了五个tdb文件夹,我将这些文件夹放在本地的fuseki中。然后,我将这两个信任集合放在一起,目的是将tdb-数据集组合起来,这样我就可以进行上面的查询,但它们都没有工作:

第一:

代码语言:javascript
复制
@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 ;
    .

第二:

代码语言:javascript
复制
@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 ;
    .

那么,为什么本地查询缺少属性呢?我是否配置或查询了fuseki错误?他们的东西在查询中丢失了吗?还有别的方法来实现我想要的吗?

我希望能清楚地传达我所需要的东西,如果没有的话,请随便问!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-01 08:52:24

没有必要将每个单独的文件加载到一个单独的TDB数据集中,除非您出于某种原因实际希望将数据保持独立。

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

至于为什么当前的设置不能工作,这是因为您只将服务连接到一个TDB数据集。

票数 2
EN

Stack Overflow用户

发布于 2015-02-18 03:08:44

我曾经在joseki工作过,但是fuseki因为某种原因给我带来了悲伤。

1-有多个TDB数据集

代码语言:javascript
复制
:ds1 a tdb:DatasetTDB ; tdb:location "dir1" .
:ds2 a tdb:DatasetTDB ; tdb:location "dir2" .

2-生成多个图

代码语言:javascript
复制
:g1 a tdb:GraphTDB ; tdb:dataset :ds1 ; tdb:graphName foo:the-dataset .
:g2 a tdb:GraphTDB ; tdb:dataset :ds2 ; tdb:graphName bar:the-dataset .

3-绘制一个联合图

代码语言:javascript
复制
:g a ja:UnionModel
  ; ja:subModel :g1
  ; ja:subModel :g2

4-在您的数据集中,使用此联合图作为默认图。

代码语言:javascript
复制
:dataset a ja:RDFDataset
 ; ja:defaultGraph :g
 ; ja:namedGraph [ ja:graphName foo:the-graph ; ja:graph :g1 ]
 ; ja:namedGraph [ ja:graphName bar:the-graph ; ja:graph :g2 ]
]

您的查询运行在默认情况下,但您也可以使用sparql子句对任意一个图进行专门的查询。

代码语言:javascript
复制
WHERE { GRAPH foo:the-graph { ?S ?p ?o } }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26121947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档