Add Generator for ABox
This commit is contained in:
parent
950ead445d
commit
4080abfd7d
|
@ -46,6 +46,9 @@
|
|||
rdfs:domain :GameConsole ;
|
||||
rdfs:range foaf:Organization .
|
||||
|
||||
:hasPrice rdf:type rdf:Property ;
|
||||
rdfs:domain :GameConsole ;
|
||||
rdfs:range :PriceEur .
|
||||
|
||||
# rdfs:Datatype
|
||||
:PriceEur rdf:type rdfs:Datatype .
|
||||
|
|
|
@ -8,7 +8,8 @@ import hsh.ins_jena.model.Generator;
|
|||
*/
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Generating TBox ...");
|
||||
Generator.createTBox();
|
||||
System.out.print("Generating ... ");
|
||||
Generator.createTBoxAndABox();
|
||||
System.out.println("done.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,104 +20,176 @@ public class Generator {
|
|||
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();
|
||||
public static void createTBoxAndABox() {
|
||||
Model tboxModel = ModelFactory.createDefaultModel();
|
||||
|
||||
// Some boilerplate stuff
|
||||
Property rdfType = model.createProperty(rdfUri+"type");
|
||||
Resource rdfClass = model.createResource(rdfUri+"Class");
|
||||
Resource rdfProperty = model.createResource(rdfUri+"Property");
|
||||
Property rdfType = tboxModel.createProperty(rdfUri+"type");
|
||||
Resource rdfClass = tboxModel.createResource(rdfUri+"Class");
|
||||
Resource rdfProperty = tboxModel.createResource(rdfUri+"Property");
|
||||
|
||||
Property rdfsSubclassOf = model.createProperty(rdfsUri+"subclassOf");
|
||||
Property rdfsSubPropertyOf = model.createProperty(rdfsUri+"subPropertyOf");
|
||||
Property rdfsDomain = model.createProperty(rdfsUri+"domain");
|
||||
Property rdfsRange = model.createProperty(rdfsUri+"range");
|
||||
Property rdfsLabel = model.createProperty(rdfsUri+"label");
|
||||
Property rdfsDatatype = model.createProperty(rdfsUri+"Datatype");
|
||||
Property rdfsSubclassOf = tboxModel.createProperty(rdfsUri+"subclassOf");
|
||||
Property rdfsSubPropertyOf = tboxModel.createProperty(rdfsUri+"subPropertyOf");
|
||||
Property rdfsDomain = tboxModel.createProperty(rdfsUri+"domain");
|
||||
Property rdfsRange = tboxModel.createProperty(rdfsUri+"range");
|
||||
Property rdfsLabel = tboxModel.createProperty(rdfsUri+"label");
|
||||
Resource rdfsDatatype = tboxModel.createResource(rdfsUri+"Datatype");
|
||||
|
||||
|
||||
Resource foafPerson = model.createResource(foafUri+"Person");
|
||||
Resource foafOrganization = model.createResource(foafUri+"Organization");
|
||||
Resource foafPerson = tboxModel.createResource(foafUri+"Person");
|
||||
Resource foafOrganization = tboxModel.createResource(foafUri+"Organization");
|
||||
|
||||
Resource xsdInt = model.createResource(xsdUri+"int");
|
||||
Resource xsdBoolean = model.createResource(xsdUri+"boolean");
|
||||
Resource xsdString = model.createResource(xsdUri+"string");
|
||||
Resource xsdInt = tboxModel.createResource(xsdUri+"int");
|
||||
Resource xsdBoolean = tboxModel.createResource(xsdUri+"boolean");
|
||||
Resource xsdString = tboxModel.createResource(xsdUri+"string");
|
||||
|
||||
|
||||
// Own classes
|
||||
Resource gameConsole = model.createResource(ownUri+"GameConsole");
|
||||
Resource portableGameConsole = model.createResource(ownUri+"PortableGameConsole");
|
||||
Resource gameConsole = tboxModel.createResource(ownUri+"GameConsole");
|
||||
Resource portableGameConsole = tboxModel.createResource(ownUri+"PortableGameConsole");
|
||||
|
||||
// Add statements to the model
|
||||
model.add(model.createStatement(gameConsole, rdfType, rdfClass));
|
||||
model.add(model.createStatement(portableGameConsole, rdfType, rdfClass));
|
||||
model.add(model.createStatement(portableGameConsole, rdfsSubclassOf, gameConsole));
|
||||
tboxModel.add(tboxModel.createStatement(gameConsole, rdfType, rdfClass));
|
||||
tboxModel.add(tboxModel.createStatement(portableGameConsole, rdfType, rdfClass));
|
||||
tboxModel.add(tboxModel.createStatement(portableGameConsole, rdfsSubclassOf, gameConsole));
|
||||
|
||||
// Add properties to the model
|
||||
Resource ceo = model.createProperty(ownUri+"ceo");
|
||||
Property ceo = tboxModel.createProperty(ownUri+"ceo");
|
||||
ceo.addProperty(rdfType, rdfProperty);
|
||||
ceo.addProperty(rdfsDomain, foafOrganization);
|
||||
ceo.addProperty(rdfsRange, foafPerson);
|
||||
|
||||
Resource foundingYear = model.createProperty(ownUri+"foundingYear");
|
||||
Property foundingYear = tboxModel.createProperty(ownUri+"foundingYear");
|
||||
foundingYear.addProperty(rdfType, rdfProperty);
|
||||
foundingYear.addProperty(rdfsDomain, foafOrganization);
|
||||
foundingYear.addProperty(rdfsRange, xsdInt);
|
||||
|
||||
Resource internetEnabled = model.createProperty(ownUri+"internetEnabled");
|
||||
Property internetEnabled = tboxModel.createProperty(ownUri+"internetEnabled");
|
||||
internetEnabled.addProperty(rdfType, rdfProperty);
|
||||
internetEnabled.addProperty(rdfsDomain, gameConsole);
|
||||
internetEnabled.addProperty(rdfsRange, xsdBoolean);
|
||||
|
||||
Resource consoleName = model.createProperty(ownUri+"consoleName");
|
||||
Property consoleName = tboxModel.createProperty(ownUri+"consoleName");
|
||||
consoleName.addProperty(rdfType, rdfProperty);
|
||||
consoleName.addProperty(rdfsDomain, gameConsole);
|
||||
consoleName.addProperty(rdfsRange, xsdString);
|
||||
|
||||
Resource numOfSupportedControllers = model.createProperty(ownUri+"numOfSupportedControllers");
|
||||
Property numOfSupportedControllers = tboxModel.createProperty(ownUri+"numOfSupportedControllers");
|
||||
numOfSupportedControllers.addProperty(rdfType, rdfProperty);
|
||||
numOfSupportedControllers.addProperty(rdfsDomain, gameConsole);
|
||||
numOfSupportedControllers.addProperty(rdfsRange, xsdInt);
|
||||
|
||||
Resource predecessorOfConsole = model.createProperty(ownUri+"predecessorOfConsole");
|
||||
Property predecessorOfConsole = tboxModel.createProperty(ownUri+"predecessorOfConsole");
|
||||
predecessorOfConsole.addProperty(rdfType, rdfProperty);
|
||||
predecessorOfConsole.addProperty(rdfsDomain, gameConsole);
|
||||
predecessorOfConsole.addProperty(rdfsRange, gameConsole);
|
||||
|
||||
Resource successorOfConsole = model.createProperty(ownUri+"successorOfConsole");
|
||||
Property successorOfConsole = tboxModel.createProperty(ownUri+"successorOfConsole");
|
||||
successorOfConsole.addProperty(rdfType, rdfProperty);
|
||||
successorOfConsole.addProperty(rdfsDomain, gameConsole);
|
||||
successorOfConsole.addProperty(rdfsRange, gameConsole);
|
||||
|
||||
Resource relatedToConsole = model.createProperty(ownUri+"relatedToConsole");
|
||||
Property relatedToConsole = tboxModel.createProperty(ownUri+"relatedToConsole");
|
||||
relatedToConsole.addProperty(rdfType, rdfProperty);
|
||||
relatedToConsole.addProperty(rdfsDomain, gameConsole);
|
||||
relatedToConsole.addProperty(rdfsRange, gameConsole);
|
||||
|
||||
Resource releaseYear = model.createProperty(ownUri+"releaseYear");
|
||||
Property releaseYear = tboxModel.createProperty(ownUri+"releaseYear");
|
||||
releaseYear.addProperty(rdfType, rdfProperty);
|
||||
releaseYear.addProperty(rdfsDomain, gameConsole);
|
||||
releaseYear.addProperty(rdfsRange, xsdInt);
|
||||
|
||||
Resource madeBy = model.createProperty(ownUri+"madeBy");
|
||||
Property madeBy = tboxModel.createProperty(ownUri+"madeBy");
|
||||
madeBy.addProperty(rdfType, rdfProperty);
|
||||
madeBy.addProperty(rdfsDomain, gameConsole);
|
||||
madeBy.addProperty(rdfsRange, foafOrganization);
|
||||
|
||||
// Declare our datatype
|
||||
Resource priceEur = model.createResource(ownUri+"PriceEur");
|
||||
Resource priceEur = tboxModel.createResource(ownUri+"PriceEur");
|
||||
priceEur.addProperty(rdfType, rdfsDatatype);
|
||||
priceEur.addProperty(rdfsLabel, "Preis in Euro");
|
||||
|
||||
Property hasPrice = tboxModel.createProperty(ownUri+"hasPrice");
|
||||
hasPrice.addProperty(rdfType, rdfProperty);
|
||||
hasPrice.addProperty(rdfsDomain, gameConsole);
|
||||
hasPrice.addProperty(rdfsRange, priceEur);
|
||||
|
||||
// Use of subPropertyOf
|
||||
predecessorOfConsole.addProperty(rdfsSubPropertyOf, relatedToConsole);
|
||||
successorOfConsole.addProperty(rdfsSubPropertyOf, relatedToConsole);
|
||||
|
||||
// Store the model into a file
|
||||
Generator.writeModelToFile(model, "./output/tbox.ttl");
|
||||
Generator.writeModelToTurtleFile(tboxModel, "./output/tbox.ttl");
|
||||
Generator.writeModelToJsonFile(tboxModel, "./output/tbox.json");
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
// Now it's time to create the abox
|
||||
Model aboxModel = ModelFactory.createDefaultModel();
|
||||
|
||||
// Prepare some more properties for use within the ABox
|
||||
Property foafFamilyName = aboxModel.createProperty(foafUri+"familyName");
|
||||
Property foafGivenName = aboxModel.createProperty(foafUri+"givenName");
|
||||
Property foafName = aboxModel.createProperty(foafUri+"name");
|
||||
Property revHasReview = aboxModel.createProperty(revUri+"hasReview");
|
||||
Property revReviewer = aboxModel.createProperty(revUri+"reviewer");
|
||||
Property revText = aboxModel.createProperty(revUri+"text");
|
||||
|
||||
Resource revReview = aboxModel.createResource(revUri+"Review");
|
||||
|
||||
// Let's add stuff into the ABox
|
||||
Resource kimishima = aboxModel.createResource(ownUri+"Kimishima");
|
||||
kimishima.addProperty(rdfType, foafPerson);
|
||||
kimishima.addProperty(foafFamilyName, "Kimishima");
|
||||
kimishima.addProperty(foafGivenName, "Tatsumi");
|
||||
|
||||
Resource nintendo = aboxModel.createResource(ownUri+"Nintendo");
|
||||
nintendo.addProperty(rdfType, foafOrganization);
|
||||
nintendo.addProperty(foafName, "Nintendo Co., Ltd.");
|
||||
nintendo.addProperty(foundingYear, aboxModel.createTypedLiteral(1889));
|
||||
nintendo.addProperty(ceo, kimishima);
|
||||
|
||||
Resource wii = aboxModel.createResource(ownUri+"Wii");
|
||||
wii.addProperty(rdfType, gameConsole);
|
||||
wii.addProperty(madeBy, nintendo);
|
||||
|
||||
Resource wiiU = aboxModel.createResource(ownUri+"Wii_u");
|
||||
wiiU.addProperty(rdfType, gameConsole);
|
||||
wiiU.addProperty(internetEnabled, aboxModel.createTypedLiteral(true));
|
||||
wiiU.addProperty(consoleName, "Wii U");
|
||||
wiiU.addProperty(numOfSupportedControllers, aboxModel.createTypedLiteral(8));
|
||||
wiiU.addProperty(predecessorOfConsole, wii);
|
||||
wiiU.addProperty(releaseYear, aboxModel.createTypedLiteral(2012));
|
||||
wiiU.addProperty(madeBy, nintendo);
|
||||
|
||||
Resource cSwitch = aboxModel.createResource(ownUri+"Switch");
|
||||
wiiU.addProperty(successorOfConsole, cSwitch);
|
||||
cSwitch.addProperty(rdfType, portableGameConsole);
|
||||
cSwitch.addProperty(madeBy, nintendo);
|
||||
|
||||
Resource jpt = aboxModel.createResource(ownUri+"JPT");
|
||||
jpt.addProperty(rdfType, foafPerson);
|
||||
jpt.addProperty(foafName, "Jan Philipp Timme");
|
||||
|
||||
Resource maschell = aboxModel.createResource(ownUri+"Maschell");
|
||||
maschell.addProperty(rdfType, foafPerson);
|
||||
maschell.addProperty(foafName, "Marcel Felix");
|
||||
|
||||
Resource switchReviewByJPT = aboxModel.createResource(ownUri+"SwitchReviewByJPT");
|
||||
switchReviewByJPT.addProperty(rdfType, revReview);
|
||||
switchReviewByJPT.addProperty(revReviewer, jpt);
|
||||
switchReviewByJPT.addProperty(revText, "Yet another gaming console. I lost a tetris game once. Meh.");
|
||||
|
||||
cSwitch.addProperty(revHasReview, switchReviewByJPT);
|
||||
|
||||
cSwitch.addProperty(hasPrice, "329,00€");
|
||||
|
||||
// Store the model into a file
|
||||
Generator.writeModelToTurtleFile(aboxModel, "./output/abox.ttl");
|
||||
Generator.writeModelToJsonFile(aboxModel, "./output/abox.json");
|
||||
}
|
||||
|
||||
private static void writeModelToFile(Model model, String path) {
|
||||
private static void writeModelToTurtleFile(Model model, String path) {
|
||||
FileOutputStream outfile = null;
|
||||
try {
|
||||
outfile = new FileOutputStream(path);
|
||||
|
@ -127,4 +199,14 @@ public class Generator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void writeModelToJsonFile(Model model, String path) {
|
||||
FileOutputStream outfile = null;
|
||||
try {
|
||||
outfile = new FileOutputStream(path);
|
||||
model.write(outfile, "JSON-LD");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue