Eclipse JENA Java

Ipromise Source

i want to generate a graph of this in java with jenaenter image description here

Java don't recognize some prefix like "music" or "schema". It works in rdf.

The RDF code :

@prefix music: <> .

@prefix cerif: `<> .

@prefix rdf: <> .

@prefix l1: <http://www.TP1WS> .

@prefix schema: <>.

@prefix dbpedia-owl: <>.

@prefix foaf: <>.

l1:jupiter  music:Composer  l1:Wolfgang_A_Mozart.

l1:Wolfgang_A_Mozart  schema:birthPlace "Salzbourg";

                                     schema:birthDate "27 janvier 1756";

                                     schema:deathPlace "Vienne";

                                     schema:deathDate "5 décembre 1791";
                                     rdf:type  foaf:Person;

foaf:Person  rdf:type  foaf:Agent.

l1:jupiter   rdf:type   music:Oeuvre;

               l1:registrationDate  "1980"^^schema:integer;

               dbpedia-owl:genre  music:symphony .

music:symphony  rdf:type  rdf:List;

                         rdf:first  l1:Allegro_Vivace;

                         rdf:rest music:symphony.

music:symphony   rdf:first  l1:Andant_Cantabile;

                              rdf:type  rdf:List;

                              rdf:rest music:symphony.

music:symphony   rdf:first  l1:Menuetto;

                              rdf:type  rdf:List;

                              rdf:rest music:symphony.

music:symphony   rdf:first  l1:Molto_Allegro;

                             rdf:type  rdf:List;

                              rdf:rest rdf:nil.

The java code is

import org.apache.jena.rdf.model.; import org.apache.jena.vocabulary.;

public class JenaExample extends Object { public static void main (String args[]) {

    String oeuvre = "http://www.TP1WS/jupiter";

    //Description Mozart

    String mozartURI =  "http://www.TP1WS/Wolfgang_A_Mozart";
    String lieuMort = "Vienne";
    String lieuNaiss = "Salzbourg";
    String dateNaiss = "27 janvier 1756";
    String dateDeces = "5 decembre 1781";

    // Creation d'un modèle vide
    Model model = ModelFactory.createDefaultModel();

    Resource oeuvreJupiter 
    = model.createResource(oeuvre)
             .addProperty(RDF.type, "")
             .addProperty(l1.RegistrationDate, "1980")
                                                    .addProperty(RDF.type, ""))
                                    .addProperty(schema.birthPlace, lieuNaiss)
                                    .addProperty(schema.birthDate, dateNaiss)
                                    .addProperty(schema.deathPlace, lieuMort)
                                    .addProperty(schema.deatDate, dateDeces))               
                                 .addProperty(RDF.first, "http://www.TP1WS/Allegro_Vivace")
                                 .addProperty(RDF.type, RDF.List)
                                                        .addProperty(RDF.first, "http://www.TP1WS/Andant_Cantabile")
                                                        .addProperty(RDF.type, RDF.List)
                                                                                    .addProperty(RDF.first, "http://www.TP1WS/Menuetto")
                                                                                    .addProperty(RDF.type, RDF.List)
                                                                                                                .addProperty(RDF.first, "http://www.TP1WS/Molto_Allegro")
                                                                                                                .addProperty(RDF.type, RDF.List)
                                                                                                                .addProperty(, RDF.nil)))));    

    // list the statements in the graph
    StmtIterator iter = model.listStatements();

    // print out the predicate, subject and object of each statement
    while (iter.hasNext()) {
        Statement stmt      = iter.nextStatement();         // get next statement
        Resource  subject   = stmt.getSubject();   // get the subject
        Property  predicate = stmt.getPredicate(); // get the predicate
        RDFNode   object    = stmt.getObject();    // get the object

        System.out.print(" " + predicate.toString() + " ");
        if (object instanceof Resource) {
        } else {
            // object is a literal
            System.out.print(" \"" + object.toString() + "\"");
        System.out.println(" .");




comments powered by Disqus