Begin creating TBox programmatically
This commit is contained in:
parent
06e26d7753
commit
730b45057d
|
@ -14,3 +14,4 @@ target/surefire-reports/
|
||||||
# Own files
|
# Own files
|
||||||
test.ttl
|
test.ttl
|
||||||
|
|
||||||
|
output/*
|
||||||
|
|
|
@ -5,6 +5,13 @@
|
||||||
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
||||||
@prefix rev: <http://purl.org/stuff/rev#> .
|
@prefix rev: <http://purl.org/stuff/rev#> .
|
||||||
|
|
||||||
|
# Our classes
|
||||||
|
:GameConsole rdf:type rdf:Class .
|
||||||
|
|
||||||
|
:PortableGameConsole rdf:type rdf:Class ;
|
||||||
|
rdfs:subclassOf :GameConsole .
|
||||||
|
|
||||||
|
|
||||||
# Our own properties
|
# Our own properties
|
||||||
:ceo rdf:type rdf:Property ;
|
:ceo rdf:type rdf:Property ;
|
||||||
rdfs:domain foaf:Organization ;
|
rdfs:domain foaf:Organization ;
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package hsh.examplecode;
|
||||||
|
|
||||||
|
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!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SampleCode {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,6 @@
|
||||||
package hsh.ins_jena;
|
package hsh.ins_jena;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import hsh.ins_jena.model.Generator;
|
||||||
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!
|
* Hello world!
|
||||||
|
@ -15,27 +8,7 @@ import org.apache.jena.rdf.model.Statement;
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello World!");
|
System.out.println("Generating TBox ...");
|
||||||
String familyUri = "http://family/";
|
Generator.createTBox();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package hsh.ins_jena.model;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class Generator {
|
||||||
|
|
||||||
|
// Our own namespace uri
|
||||||
|
private static String ownUri = "http://example.com/ins_uebung/#";
|
||||||
|
|
||||||
|
// Uris for other vocabularies we use
|
||||||
|
private static String rdfUri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||||
|
private static String rdfsUri = "http://www.w3.org/2000/01/rdf-schema#";
|
||||||
|
private static String xsdUri = "http://www.w3.org/2001/XMLSchema#";
|
||||||
|
private static String foafUri = "http://xmlns.com/foaf/0.1/";
|
||||||
|
private static String revUri = "http://purl.org/stuff/rev#";
|
||||||
|
|
||||||
|
public static void createTBox() {
|
||||||
|
Model model = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
// Some boilerplate stuff
|
||||||
|
Property rdfType = model.createProperty(rdfUri+"type");
|
||||||
|
Resource rdfClass = model.createResource(rdfUri+"Class");
|
||||||
|
|
||||||
|
Property rdfsSubclassOf = model.createProperty(rdfsUri+"subclassOf");
|
||||||
|
|
||||||
|
Resource gameConsole = model.createResource(ownUri+"GameConsole");
|
||||||
|
Resource portableGameConsole = model.createResource(ownUri+"PortableGameConsole");
|
||||||
|
|
||||||
|
model.add(model.createStatement(gameConsole, rdfType, rdfClass));
|
||||||
|
model.add(model.createStatement(portableGameConsole, rdfType, rdfClass));
|
||||||
|
model.add(model.createStatement(portableGameConsole, rdfsSubclassOf, gameConsole));
|
||||||
|
|
||||||
|
/*
|
||||||
|
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);
|
||||||
|
*/
|
||||||
|
|
||||||
|
Generator.writeModelToFile(model, "./tbox.ttl");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeModelToFile(Model model, String path) {
|
||||||
|
FileOutputStream outfile = null;
|
||||||
|
try {
|
||||||
|
outfile = new FileOutputStream(path);
|
||||||
|
model.write(outfile, "TURTLE");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue