2

以下是我的 2 张桌子:

CREATE TABLE Tree (
    "id"            integer NOT NULL,   -- Primary key
    "tags"          varchar(500),
    "rootNode"      integer NOT NULL    -- Referes to Node table's "id"
);
CREATE TABLE Node (
    "id"            integer NOT NULL,   -- Primary key
    "parent"        integer NOT NULL,
    "owner"         varchar(500),
    "data"          varchar(500),
    "tags"          varchar(500)
);

我为这些创建的通用 RDF 文件如下:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:wp="http://example.com/dm#">
    <wp:WPS rdf:about="http://example.com/">
    <wp:node><rdf:Description>  <wp:id>0</wp:id><wp:parent>-1</wp:parent><wp:owner>Kumar</wp:owner><wp:data>--#ABCDEFGHIJKLMNOPQRSTUVWXYZ#--</wp:data><wp:tags>MyTag</wp:tags></rdf:Description></wp:node>
    .....
    <wp:tree><rdf:Description>  <wp:treeId>814</wp:treeId><wp:treeTags>Banking</wp:treeTags><wp:rootNode>19989</wp:rootNode></rdf:Description></wp:tree>
    .......
</wp:WPS></rdf:RDF>

这是为这两个表创建组合 rdf 文件的正确方法吗?


现在我想运行类似于以下 SQL 查询的 SPQRQL 查询:

select w.id, w.tags, w.owner from Node w, Tree t where t.id=100;

我尝试使用 FILTER 使用以下查询,但无法获得所需的结果。这样做的正确方法是什么?

    PREFIX wp: <http://example.com/dm#> 
              SELECT ?x ?id 
              WHERE { 
                ?x wp:id ?id .
                ?x wp:trailId ?trailId .
                ?x wp:rootWP ?rootWP .
                FILTER (?trailId = 100)
                FILTER (?rootWP = ?id)
              }
4

1 回答 1

2

一般来说,您不应该自己创建数据库表结构来存储 RDF 三元组。做对是一件复杂的事情,更难让它发挥作用。如果您只想创建一个持久的三元存储,请使用 RDF 平台的内置功能。在耶拿的情况下,这将是TDBSDB

或者,如果您需要将数据存储在关系模式中,但又希望将该数据视为 RDF 三元组,以便您可以使用 SPARQL 对其进行查询,那么您需要一个关系到 RDF 的映射工具这方面有标准化工作,还有开源实现,例如D2RQ

于 2012-06-21T09:26:04.383 回答