将名称列表转换为RDF架构(RDFS)

时间:2013-10-09 19:07:50

标签: java rdf semantic-web owl rdfs

我在语义网上很新。我的问题是:如何在Java程序中使用RDF Schema?我不应该使用Java Jena API进行转换。有没有办法这样做?我在Java程序中有一个名称列表,并希望将它们转换为RDF Schema。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

根据评论中的一些澄清,似乎这里需要的只是他能够代表一些基本的RDF。如果您要在不使用某些支持库的情况下手动编写RDF,最简单的格式是N-Triples。您需要按属性标识所有资源,并学习如何使用文字(可以是普通字符串,带有语言标记的字符串,字符串和数据类型)。这是一个简单的RDF文档,声明了两个类,Person和Animal,一个属性,hasPet,并包含FDR(有?)一个名为Fala的宠物的声明。

<http://example.org/Fala> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Animal> .
<http://example.org/Animal> <http://www.w3.org/2000/01/rdf-schema#label> "Animal"@en .
<http://example.org/Animal> <http://www.w3.org/2000/01/rdf-schema#comment> "The class of (non-human) animals"@en .
<http://example.org/Animal> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://example.org/Person> <http://www.w3.org/2000/01/rdf-schema#label> "Person"@en .
<http://example.org/Person> <http://www.w3.org/2000/01/rdf-schema#comment> "The class of people." .
<http://example.org/Person> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://dbpedia.org/resource/Franklin_D._Roosevelt> <http://example.org/hasPet> <http://example.org/Fala> .
<http://dbpedia.org/resource/Franklin_D._Roosevelt> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
<http://example.org/hasPet> <http://www.w3.org/2000/01/rdf-schema#comment> "used to indicate that the object is a pet of the subject"@en .
<http://example.org/hasPet> <http://www.w3.org/2000/01/rdf-schema#label> "has pet"@en .
<http://example.org/hasPet> <http://www.w3.org/2000/01/rdf-schema#range> <http://example.org/Animal> .
<http://example.org/hasPet> <http://www.w3.org/2000/01/rdf-schema#domain> <http://example.org/Person> .
<http://example.org/hasPet> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .

这就是它的全部内容。用URI表示事物,并写一些句子。使用库来生成RDF更为常见,因为否则你将不得不担心URI和类似的东西中允许哪些字符,而正确的库会处理这些问题的检查。无论如何,你可以生成这个,但是你通常会用Java生成文本输出。

作为参考,后面是Turtle和RDF / XML中的相同RDF图。 Turtle更具人性化,并且不易手工编写,但用N-Triples编写程序并不容易。 RDF / XML不应该手工编写。

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex:      <http://example.org/> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix dbpedia:  <http://dbpedia.org/resource/> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

ex:Animal
      a       rdfs:Class ;
      rdfs:comment "The class of (non-human) animals"@en ;
      rdfs:label "Animal"@en .

ex:Fala
      a       ex:Animal .

ex:hasPet
      a       rdf:Property ;
      rdfs:comment "used to indicate that the object is a pet of the subject"@en ;
      rdfs:domain ex:Person ;
      rdfs:label "has pet"@en ;
      rdfs:range ex:Animal .

<http://dbpedia.org/resource/Franklin_D._Roosevelt>
      a       ex:Person ;
      ex:hasPet ex:Fala .

ex:Person
      a       rdfs:Class ;
      rdfs:comment "The class of people." ;
      rdfs:label "Person"@en .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:ex="http://example.org/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:dbpedia="http://dbpedia.org/resource/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <rdfs:Class rdf:about="http://example.org/Animal">
    <rdfs:label xml:lang="en">Animal</rdfs:label>
    <rdfs:comment xml:lang="en">The class of (non-human) animals</rdfs:comment>
  </rdfs:Class>
  <rdfs:Class rdf:about="http://example.org/Person">
    <rdfs:label xml:lang="en">Person</rdfs:label>
    <rdfs:comment>The class of people.</rdfs:comment>
  </rdfs:Class>
  <rdf:Property rdf:about="http://example.org/hasPet">
    <rdfs:comment xml:lang="en">used to indicate that the object is a pet of the subject</rdfs:comment>
    <rdfs:label xml:lang="en">has pet</rdfs:label>
    <rdfs:range rdf:resource="http://example.org/Animal"/>
    <rdfs:domain rdf:resource="http://example.org/Person"/>
  </rdf:Property>
  <ex:Person rdf:about="http://dbpedia.org/resource/Franklin_D._Roosevelt">
    <ex:hasPet>
      <ex:Animal rdf:about="http://example.org/Fala"/>
    </ex:hasPet>
  </ex:Person>
</rdf:RDF>