1

我为图形编写了以下 XML,例如:

 `Person ------> Organization`
 `Person ------> name`

并且组织进一步在节点上

 `Organization----->Title`
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:foaf="http://www.example.org/terms/">

  <rdf:Description rdf:about="person">
  <foaf:name>Usman</foaf:name>
  </rdf:Description>

但我不知道在哪里添加organization节点及其子节点作为标题?

4

1 回答 1

2

手工编写 RDF/XML 非常容易出错,我最强烈的建议是以不同的格式编写,然后将其转换为 RDF/XML。RDF/XML 并非设计为人类可读的,相同的 RDF 图可以以多种不同的方式在 RDF/XML 中表示。

我将从编写以下 Turtle 文档开始(作为示例):

@prefix : <http://example.org/>

:john a :Person .
:john :hasName "John" .
:john :belongsTo :company42 .

:company42 a :Company .
:company42 :hasName "The Company" .

然后,如果您需要 RDF/XML,您可以使用几乎任何 RDF 库对其进行转换,以获得:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://example.org/">
  <Person rdf:about="http://example.org/john">
    <hasName>John</hasName>
    <belongsTo>
      <Company rdf:about="http://example.org/company42">
        <hasName>The Company</hasName>
      </Company>
    </belongsTo>
  </Person>
</rdf:RDF>

为了突出 RDF/XML 可能性的变化,下面是同一个 RDF 图,仍然是 RDF/XML:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://example.org/" > 
  <rdf:Description rdf:about="http://example.org/john">
    <rdf:type rdf:resource="http://example.org/Person"/>
    <hasName>John</hasName>
    <belongsTo rdf:resource="http://example.org/company42"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/company42">
    <rdf:type rdf:resource="http://example.org/Company"/>
    <hasName>The Company</hasName>
  </rdf:Description>
</rdf:RDF>

使用人类可读和人类可写的形式要容易得多,比如 Turtle。随着您对 Turtle 的经验越来越丰富,您可以使用它所允许的方便的速记。例如,上面的图表也可以这样写,这样可以节省一些输入:

@prefix : <http://example.org/>

:john a :Person ;
      :hasName "John" ;
      :belongsTo :company42 .

:company42 a :Company ;
           :hasName "The Company" .
于 2016-05-24T15:47:50.280 回答