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: <https://www.kanzaki.com/ns/music#> .

@prefix cerif: `<https://www.eurocris.org/ontologies/cerif/1.3/#> .

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

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

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

@prefix dbpedia-owl: <http://dbpedia.org/ontology/>.

@prefix foaf: <http://xmlns.com/foaf/0.1/>.


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, "https://www.kanzaki.com/ns/music#Oeuvre")
             .addProperty(l1.RegistrationDate, "1980")
             .addProperty(music.Composer, 
                            model.createResource(mozartURI)
                                    .addProperty(RDF.type, 
                                            model.createResource("http://xmlns.com/foaf/0.1/Person")
                                                    .addProperty(RDF.type, "http://xmlns.com/foaf/0.1/Agent"))
                                    .addProperty(schema.birthPlace, lieuNaiss)
                                    .addProperty(schema.birthDate, dateNaiss)
                                    .addProperty(schema.deathPlace, lieuMort)
                                    .addProperty(schema.deatDate, dateDeces))               
             .addProperty(dbpedia-owl.genre, 
                          model.createResource("https://www.kanzaki.com/ns/music#symphony")
                                 .addProperty(RDF.first, "http://www.TP1WS/Allegro_Vivace")
                                 .addProperty(RDF.type, RDF.List)
                                 .addProperty(RDF.rest, 
                                                model.createResource("https://www.kanzaki.com/ns/music#symphony")
                                                        .addProperty(RDF.first, "http://www.TP1WS/Andant_Cantabile")
                                                        .addProperty(RDF.type, RDF.List)
                                                        .addProperty(RDF.rest, 
                                                                            model.createResource("https://www.kanzaki.com/ns/music#symphony")
                                                                                    .addProperty(RDF.first, "http://www.TP1WS/Menuetto")
                                                                                    .addProperty(RDF.type, RDF.List)
                                                                                    .addProperty(RDF.rest, 
                                                                                                        model.createResource("https://www.kanzaki.com/ns/music#symphony")
                                                                                                                .addProperty(RDF.first, "http://www.TP1WS/Molto_Allegro")
                                                                                                                .addProperty(RDF.type, RDF.List)
                                                                                                                .addProperty(RDF.rest, 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(subject.toString());
        System.out.print(" " + predicate.toString() + " ");
        if (object instanceof Resource) {
            System.out.print(object.toString());
        } else {
            // object is a literal
            System.out.print(" \"" + object.toString() + "\"");
        }
        System.out.println(" .");
    }
}

}

javardfjena

Answers

comments powered by Disqus