From 3762eead8c4c203724fd3223660abec1b53e35a0 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 20 Nov 2017 19:21:38 +0100 Subject: [PATCH] Add very first code to verify jena is working --- .classpath | 4 ++-- .gitignore | 13 +++++++++++++ pom.xml | 16 ++++++++++++++- src/main/java/hsh/ins_jena/App.java | 30 +++++++++++++++++++++++++++++ target/classes/.gitignore | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/.classpath b/.classpath index 0a1dadd..40303b7 100644 --- a/.classpath +++ b/.classpath @@ -12,12 +12,12 @@ - + - + diff --git a/.gitignore b/.gitignore index 9e87eff..c9ca779 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,16 @@ +# Eclipse stuff .settings +# Compile artifacts *.class +*.jar + +# Target stuff +target/classes/META-INF/ +target/maven-archiver/ +target/maven-status/ +target/surefire-reports/ + +# Own files +test.ttl + diff --git a/pom.xml b/pom.xml index b50c53e..7c06f02 100644 --- a/pom.xml +++ b/pom.xml @@ -21,11 +21,25 @@ 3.8.1 test + + + org.apache.jena + apache-jena + 3.5.0 + pom + + + + org.apache.jena + jena-core + 3.5.0 + + org.apache.jena apache-jena-libs - pom 3.5.0 + pom diff --git a/src/main/java/hsh/ins_jena/App.java b/src/main/java/hsh/ins_jena/App.java index 0bff19a..035727e 100644 --- a/src/main/java/hsh/ins_jena/App.java +++ b/src/main/java/hsh/ins_jena/App.java @@ -1,5 +1,14 @@ package hsh.ins_jena; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.Statement; + /** * Hello world! * @@ -7,5 +16,26 @@ package hsh.ins_jena; public class App { public static void main(String[] args) { System.out.println("Hello World!"); + String familyUri = "http://family/"; + String relationshipUri = "http://purl.org/vocab/relationship/"; + + Model model = ModelFactory.createDefaultModel(); + Resource donald = model.createResource(familyUri + "donald"); + Resource tick = model.createResource(familyUri + "tick"); + + Property childOf = model.createProperty(relationshipUri, "childOf"); + Property knows = model.createProperty(relationshipUri, "knows"); + tick.addProperty(childOf, donald); + + Statement st1 = model.createStatement(donald, knows, tick); + model.add(st1); + FileOutputStream outfile; + try { + outfile = new FileOutputStream("./test.ttl"); + model.write(outfile, "TURTLE"); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } diff --git a/target/classes/.gitignore b/target/classes/.gitignore index 3385916..43da863 100644 --- a/target/classes/.gitignore +++ b/target/classes/.gitignore @@ -1 +1 @@ -/META-INF/ +/hsh/