Question

I am quite new at Semantic Web. My question is: How can I use RDF Schema in Java program? I am NOT supposed to use Java Jena API for conversion. Is there any way for doing so? I have a list of names in Java program and would like to convert them into RDF Schema. Your help would be very much appreciated.

Was it helpful?

Solution

Based on some clarification in the comments, it appears that what's needed here is just he ability to represent some basic RDF. If you're going to write RDF by hand without using some supporting library, the easiest format to use will be N-Triples. You'll need to identify all resources by properties, and learn how to use literals (which may either be a plain string, a string with a language tag, or a string and a datatype). Here's a simple RDF document declaring two classes, Person and Animal, a property, hasPet, and containing the statement that FDR has (had?) a pet named 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> .

That's really all there is to it. Represent things with URIs, and write some sentences. It's much more common to use a library to generate RDF, since otherwise you'll have to worry about what characters are allowed in URIs and things like that, whereas a proper library would handle checking for those sorts of issues. At any rate, you can generate this however you would typically generate textual output in Java.

For reference, the same RDF graph in Turtle and RDF/XML follow. Turtle is more human readable, and not too hard to write by hand, but it's not as easy to write with a program as N-Triples is. RDF/XML shouldn't be written by hand at all.

@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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top