0

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.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Mod
  • 5,091
  • 7
  • 28
  • 47
  • Are you trying to use RDFS properties and types inside a Java program? Could you post a code snippet to explain better your problem? – loopasam Oct 09 '13 at 20:26
  • Yes. This is exactly what I have been trying to do. My program would not really help you. I extracted all my friends list from Facebook using restFB and should use RDFS in this list. How can I use RDFS at this point? I mean where should I start from? – Mod Oct 09 '13 at 20:51
  • What is it you're trying to do? RDFS is just an RDF vocabulary. It's a set of URIs that, by convention, have some meaning. You use these URIs when _describe_ some resources (RDF is the Resource Description Framework). It doesn't make sense to say that you want to convert a list of names into RDFS, but it might make sense to say that you want to describe it using RDFS. What are you trying to describe, and what do you want to say about it? – Joshua Taylor Oct 09 '13 at 20:55
  • OK. Let's put it that way. Forget about the list I just mentioned. It is right when you said that RDFS is for describing resources. What I want to do is how to technically apply RDFS in Java program? Jena could be very useful but I am not supposed to use it in this case. Is there any simple example you can help me out with so I can have a look?! – Mod Oct 09 '13 at 21:04
  • It's not clear how you want to use it. RDF is a data representation format, based on statements, aka triples each having the form [subject, predicate (or property), object]. E.g., you might have [user:1281433 hasUsername "Joshua Taylor"]. RDFS is just a set of IRIs, some of which have conventional meanings when used as properties and objects. What are you trying to do with them? Output RDF? Reason about some statements? Something else entirely? As it stands now, it's sort of like asking, "I just a got a dictionary that has some words and their definitions, how can I use them in Java?" – Joshua Taylor Oct 09 '13 at 21:32
  • Thanks for the explanation. Yes, At this point, I would like to get an RDF output. How can I do this in a very simple Java program? I did this using Jena API. But I am not supposed to use it. Could you please help me with this? Your support would be very much appreciated. – Mod Oct 09 '13 at 21:37
  • This getting to be a bit more managable, but it's still a little too broad. Let's see if we can narrow it down a bit. The RDFS vocabulary is for describing simple classes and properties. If you can clarify you question to include informal descriptions of what you want to express in RDF (e.g., "hasBestFriend is a property, and its domain and range are Person, which is a class. hasPet is a property and its domain is Person and its range is Animal, which is also a class."), we might be able to make some progress. – Joshua Taylor Oct 09 '13 at 21:42
  • You are legend. Thanks for that. Yes, please. How can I represent this? For example, how can I represent: user2864315 hasBestFriend Joshua Taylor? I am very much thankful to you. – Mod Oct 09 '13 at 21:54

1 Answers1

0

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>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thank you very much indeed for this. One more question please? What library or editor can I use to apply this example? I would like to try it and see the result. Once again, thank you very much for your assistance and patience. – Mod Oct 10 '13 at 10:58
  • @user2864315 Well, to be honest, I wrote some Jena code to generate the ontology, and then wrote it out in a few different formats. You said you didn't want to use Jena though, so I'm afraid I don't have any particularly useful recommendations. When I write Turtle by hand, I typically use [tag:Emacs]. – Joshua Taylor Oct 10 '13 at 15:06
  • @user2864315 Also, if this answered your question, you can [accept an answer](http://meta.stackexchange.com/q/5234/225437) to let other users know that it worked for you, and to reduce the number of questions without an accepted answer. It also gives you and the answerer some reputation points. – Joshua Taylor Oct 10 '13 at 15:08
  • I am trying with Java RIO (Writing RDF with RIO). Have you ever tried it? The problem is I am not supposed to use Jena. Any idea? Thank you very much for all your answers. – Mod Oct 10 '13 at 16:02
  • @user2864315 I have not used it. Note that "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." While questions about finding libraries are important questions, they don't happen to be a kind of question that's a great fit for Stack Overflow. There are lots of RDF libraries out there. For the most part, you'll do the same thing with them: create a model, add statements, and serialize the model. – Joshua Taylor Oct 10 '13 at 16:11