Added file loading and first SPARQL query.

This commit is contained in:
Marcel 2017-11-21 17:54:21 +01:00
parent 9fd0d256b5
commit 4b64764b82
3 changed files with 191 additions and 122 deletions

80
pom.xml
View File

@ -1,45 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>hsh</groupId> <groupId>hsh</groupId>
<artifactId>ins-jena</artifactId> <artifactId>ins-jena</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ins-jena</name> <name>ins-jena</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena --> <!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena -->
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>apache-jena</artifactId> <artifactId>apache-jena</artifactId>
<version>3.5.0</version> <version>3.5.0</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jena/jena-core --> <!-- https://mvnrepository.com/artifact/org.apache.jena/jena-core -->
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId> <artifactId>jena-core</artifactId>
<version>3.5.0</version> <version>3.5.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena-libs --> <!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena-libs -->
<dependency> <dependency>
<groupId>org.apache.jena</groupId> <groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId> <artifactId>apache-jena-libs</artifactId>
<version>3.5.0</version> <version>3.5.0</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,11 +1,69 @@
package hsh.ins_jena; package hsh.ins_jena;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import hsh.ins_jena.model.Generator; import hsh.ins_jena.model.Generator;
public class App { public class App {
public static String OUTPUT_PATH = "./output";
public static void main(String[] args) { public static void main(String[] args) {
generateFiles(OUTPUT_PATH);
readAndHandleFiles(OUTPUT_PATH);
}
private static void readAndHandleFiles(String inputPath) {
Model tboxModel = ModelFactory.createDefaultModel();
Model aboxModel = ModelFactory.createDefaultModel();
InputStream inT, inA;
try {
inT = new FileInputStream(new File(inputPath + "/" + Generator.T_BOX_FILENAME_XML));
inA = new FileInputStream(new File(inputPath + "/" + Generator.A_BOX_FILENAME_XML));
tboxModel.read(inT, "");
aboxModel.read(inA, "");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println(tboxModel);
System.out.println(aboxModel);
Query query = QueryFactory.create("" + "PREFIX : <" + Generator.OWN_URI + ">" + "" + "SELECT ?console\n"
+ "WHERE {\n" + " ?console :madeBy :Nintendo .\n" + " ?console :releaseYear ?releaseYear . \n"
+ " FILTER(?releaseYear > 2015)\n" + "}");
// Query query = QueryFactory
// .create("PREFIX : <" + Generator.OWN_URI + ">" + " " + " SELECT ?s ?p ?p WHERE {" + "?s ?p ?o .}");
QueryExecution queryExec = QueryExecutionFactory.create(query, aboxModel);
ResultSet rs = queryExec.execSelect();
if (rs.hasNext()) {
rs.forEachRemaining(qs -> {
System.out.println(qs);
});
}
}
private static void generateFiles(String outputhPath) {
new File(OUTPUT_PATH).mkdirs();
System.out.print("Generating ... "); System.out.print("Generating ... ");
Generator.createTBoxAndABox(); Generator.createTBoxAndABox(OUTPUT_PATH);
System.out.println("done."); System.out.println("done.");
} }
} }

View File

@ -10,43 +10,57 @@ import org.apache.jena.rdf.model.Resource;
public class Generator { public class Generator {
public static final String T_BOX_FILENAME_TTL = "tbox.ttl";
public static final String T_BOX_FILENAME_JSON = "tbox.json";
public static final String T_BOX_FILENAME_XML = "tbox.xml";
public static final String A_BOX_FILENAME_TTL = "abox.ttl";
public static final String A_BOX_FILENAME_JSON = "abox.json";
public static final String A_BOX_FILENAME_XML = "abox.xml";
// Our own namespace uri // Our own namespace uri
private static String ownUri = "http://example.com/ins_uebung/#"; public static final String OWN_URI = "http://example.com/ins_uebung/#";
// Uris for other vocabularies we use // Uris for other vocabularies we use
private static String rdfUri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; public static final String RDF_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
private static String rdfsUri = "http://www.w3.org/2000/01/rdf-schema#"; public static final String RDFS_URI = "http://www.w3.org/2000/01/rdf-schema#";
private static String xsdUri = "http://www.w3.org/2001/XMLSchema#"; public static final String XSD_URI = "http://www.w3.org/2001/XMLSchema#";
private static String foafUri = "http://xmlns.com/foaf/0.1/"; public static final String FOAF_URI = "http://xmlns.com/foaf/0.1/";
private static String revUri = "http://purl.org/stuff/rev#"; public static final String REV_URI = "http://purl.org/stuff/rev#";
public static final String MODEL_TURTLE = "TURTLE";
public static final String MODEL_JSON = "JSON-LD";
public static final String MODEL_RDF_XML = "RDF/XML";
public static void createTBoxAndABox() { public static void createTBoxAndABox() {
createTBoxAndABox(".");
}
public static void createTBoxAndABox(String outputPath) {
Model tboxModel = ModelFactory.createDefaultModel(); Model tboxModel = ModelFactory.createDefaultModel();
// Some boilerplate stuff // Some boilerplate stuff
Property rdfType = tboxModel.createProperty(rdfUri+"type"); Property rdfType = tboxModel.createProperty(RDF_URI + "type");
Resource rdfClass = tboxModel.createResource(rdfUri+"Class"); Resource rdfClass = tboxModel.createResource(RDF_URI + "Class");
Resource rdfProperty = tboxModel.createResource(rdfUri+"Property"); Resource rdfProperty = tboxModel.createResource(RDF_URI + "Property");
Property rdfsSubclassOf = tboxModel.createProperty(rdfsUri+"subclassOf"); Property rdfsSubclassOf = tboxModel.createProperty(RDFS_URI + "subclassOf");
Property rdfsSubPropertyOf = tboxModel.createProperty(rdfsUri+"subPropertyOf"); Property rdfsSubPropertyOf = tboxModel.createProperty(RDFS_URI + "subPropertyOf");
Property rdfsDomain = tboxModel.createProperty(rdfsUri+"domain"); Property rdfsDomain = tboxModel.createProperty(RDFS_URI + "domain");
Property rdfsRange = tboxModel.createProperty(rdfsUri+"range"); Property rdfsRange = tboxModel.createProperty(RDFS_URI + "range");
Property rdfsLabel = tboxModel.createProperty(rdfsUri+"label"); Property rdfsLabel = tboxModel.createProperty(RDFS_URI + "label");
Resource rdfsDatatype = tboxModel.createResource(rdfsUri+"Datatype"); Resource rdfsDatatype = tboxModel.createResource(RDFS_URI + "Datatype");
Resource foafPerson = tboxModel.createResource(FOAF_URI + "Person");
Resource foafOrganization = tboxModel.createResource(FOAF_URI + "Organization");
Resource foafPerson = tboxModel.createResource(foafUri+"Person"); Resource xsdInt = tboxModel.createResource(XSD_URI + "int");
Resource foafOrganization = tboxModel.createResource(foafUri+"Organization"); Resource xsdBoolean = tboxModel.createResource(XSD_URI + "boolean");
Resource xsdString = tboxModel.createResource(XSD_URI + "string");
Resource xsdInt = tboxModel.createResource(xsdUri+"int");
Resource xsdBoolean = tboxModel.createResource(xsdUri+"boolean");
Resource xsdString = tboxModel.createResource(xsdUri+"string");
// Own classes // Own classes
Resource gameConsole = tboxModel.createResource(ownUri+"GameConsole"); Resource gameConsole = tboxModel.createResource(OWN_URI + "GameConsole");
Resource portableGameConsole = tboxModel.createResource(ownUri+"PortableGameConsole"); Resource portableGameConsole = tboxModel.createResource(OWN_URI + "PortableGameConsole");
// Add statements to the model // Add statements to the model
tboxModel.add(tboxModel.createStatement(gameConsole, rdfType, rdfClass)); tboxModel.add(tboxModel.createStatement(gameConsole, rdfType, rdfClass));
@ -54,62 +68,62 @@ public class Generator {
tboxModel.add(tboxModel.createStatement(portableGameConsole, rdfsSubclassOf, gameConsole)); tboxModel.add(tboxModel.createStatement(portableGameConsole, rdfsSubclassOf, gameConsole));
// Add properties to the model // Add properties to the model
Property ceo = tboxModel.createProperty(ownUri+"ceo"); Property ceo = tboxModel.createProperty(OWN_URI + "ceo");
ceo.addProperty(rdfType, rdfProperty); ceo.addProperty(rdfType, rdfProperty);
ceo.addProperty(rdfsDomain, foafOrganization); ceo.addProperty(rdfsDomain, foafOrganization);
ceo.addProperty(rdfsRange, foafPerson); ceo.addProperty(rdfsRange, foafPerson);
Property foundingYear = tboxModel.createProperty(ownUri+"foundingYear"); Property foundingYear = tboxModel.createProperty(OWN_URI + "foundingYear");
foundingYear.addProperty(rdfType, rdfProperty); foundingYear.addProperty(rdfType, rdfProperty);
foundingYear.addProperty(rdfsDomain, foafOrganization); foundingYear.addProperty(rdfsDomain, foafOrganization);
foundingYear.addProperty(rdfsRange, xsdInt); foundingYear.addProperty(rdfsRange, xsdInt);
Property internetEnabled = tboxModel.createProperty(ownUri+"internetEnabled"); Property internetEnabled = tboxModel.createProperty(OWN_URI + "internetEnabled");
internetEnabled.addProperty(rdfType, rdfProperty); internetEnabled.addProperty(rdfType, rdfProperty);
internetEnabled.addProperty(rdfsDomain, gameConsole); internetEnabled.addProperty(rdfsDomain, gameConsole);
internetEnabled.addProperty(rdfsRange, xsdBoolean); internetEnabled.addProperty(rdfsRange, xsdBoolean);
Property consoleName = tboxModel.createProperty(ownUri+"consoleName"); Property consoleName = tboxModel.createProperty(OWN_URI + "consoleName");
consoleName.addProperty(rdfType, rdfProperty); consoleName.addProperty(rdfType, rdfProperty);
consoleName.addProperty(rdfsDomain, gameConsole); consoleName.addProperty(rdfsDomain, gameConsole);
consoleName.addProperty(rdfsRange, xsdString); consoleName.addProperty(rdfsRange, xsdString);
Property numOfSupportedControllers = tboxModel.createProperty(ownUri+"numOfSupportedControllers"); Property numOfSupportedControllers = tboxModel.createProperty(OWN_URI + "numOfSupportedControllers");
numOfSupportedControllers.addProperty(rdfType, rdfProperty); numOfSupportedControllers.addProperty(rdfType, rdfProperty);
numOfSupportedControllers.addProperty(rdfsDomain, gameConsole); numOfSupportedControllers.addProperty(rdfsDomain, gameConsole);
numOfSupportedControllers.addProperty(rdfsRange, xsdInt); numOfSupportedControllers.addProperty(rdfsRange, xsdInt);
Property predecessorOfConsole = tboxModel.createProperty(ownUri+"predecessorOfConsole"); Property predecessorOfConsole = tboxModel.createProperty(OWN_URI + "predecessorOfConsole");
predecessorOfConsole.addProperty(rdfType, rdfProperty); predecessorOfConsole.addProperty(rdfType, rdfProperty);
predecessorOfConsole.addProperty(rdfsDomain, gameConsole); predecessorOfConsole.addProperty(rdfsDomain, gameConsole);
predecessorOfConsole.addProperty(rdfsRange, gameConsole); predecessorOfConsole.addProperty(rdfsRange, gameConsole);
Property successorOfConsole = tboxModel.createProperty(ownUri+"successorOfConsole"); Property successorOfConsole = tboxModel.createProperty(OWN_URI + "successorOfConsole");
successorOfConsole.addProperty(rdfType, rdfProperty); successorOfConsole.addProperty(rdfType, rdfProperty);
successorOfConsole.addProperty(rdfsDomain, gameConsole); successorOfConsole.addProperty(rdfsDomain, gameConsole);
successorOfConsole.addProperty(rdfsRange, gameConsole); successorOfConsole.addProperty(rdfsRange, gameConsole);
Property relatedToConsole = tboxModel.createProperty(ownUri+"relatedToConsole"); Property relatedToConsole = tboxModel.createProperty(OWN_URI + "relatedToConsole");
relatedToConsole.addProperty(rdfType, rdfProperty); relatedToConsole.addProperty(rdfType, rdfProperty);
relatedToConsole.addProperty(rdfsDomain, gameConsole); relatedToConsole.addProperty(rdfsDomain, gameConsole);
relatedToConsole.addProperty(rdfsRange, gameConsole); relatedToConsole.addProperty(rdfsRange, gameConsole);
Property releaseYear = tboxModel.createProperty(ownUri+"releaseYear"); Property releaseYear = tboxModel.createProperty(OWN_URI + "releaseYear");
releaseYear.addProperty(rdfType, rdfProperty); releaseYear.addProperty(rdfType, rdfProperty);
releaseYear.addProperty(rdfsDomain, gameConsole); releaseYear.addProperty(rdfsDomain, gameConsole);
releaseYear.addProperty(rdfsRange, xsdInt); releaseYear.addProperty(rdfsRange, xsdInt);
Property madeBy = tboxModel.createProperty(ownUri+"madeBy"); Property madeBy = tboxModel.createProperty(OWN_URI + "madeBy");
madeBy.addProperty(rdfType, rdfProperty); madeBy.addProperty(rdfType, rdfProperty);
madeBy.addProperty(rdfsDomain, gameConsole); madeBy.addProperty(rdfsDomain, gameConsole);
madeBy.addProperty(rdfsRange, foafOrganization); madeBy.addProperty(rdfsRange, foafOrganization);
// Declare our datatype // Declare our datatype
Resource priceEur = tboxModel.createResource(ownUri+"PriceEur"); Resource priceEur = tboxModel.createResource(OWN_URI + "PriceEur");
priceEur.addProperty(rdfType, rdfsDatatype); priceEur.addProperty(rdfType, rdfsDatatype);
priceEur.addProperty(rdfsLabel, "Preis in Euro"); priceEur.addProperty(rdfsLabel, "Preis in Euro");
Property hasPrice = tboxModel.createProperty(ownUri+"hasPrice"); Property hasPrice = tboxModel.createProperty(OWN_URI + "hasPrice");
hasPrice.addProperty(rdfType, rdfProperty); hasPrice.addProperty(rdfType, rdfProperty);
hasPrice.addProperty(rdfsDomain, gameConsole); hasPrice.addProperty(rdfsDomain, gameConsole);
hasPrice.addProperty(rdfsRange, priceEur); hasPrice.addProperty(rdfsRange, priceEur);
@ -119,8 +133,10 @@ public class Generator {
successorOfConsole.addProperty(rdfsSubPropertyOf, relatedToConsole); successorOfConsole.addProperty(rdfsSubPropertyOf, relatedToConsole);
// Store the model into a file // Store the model into a file
Generator.writeModelToTurtleFile(tboxModel, "./output/tbox.ttl");
Generator.writeModelToJsonFile(tboxModel, "./output/tbox.json"); Generator.writeModelFile(tboxModel, outputPath, T_BOX_FILENAME_TTL, MODEL_TURTLE);
Generator.writeModelFile(tboxModel, outputPath, T_BOX_FILENAME_JSON, MODEL_JSON);
Generator.writeModelFile(tboxModel, outputPath, T_BOX_FILENAME_XML, MODEL_RDF_XML);
/******************************************************************/ /******************************************************************/
@ -128,32 +144,32 @@ public class Generator {
Model aboxModel = ModelFactory.createDefaultModel(); Model aboxModel = ModelFactory.createDefaultModel();
// Prepare some more properties for use within the ABox // Prepare some more properties for use within the ABox
Property foafFamilyName = aboxModel.createProperty(foafUri+"familyName"); Property foafFamilyName = aboxModel.createProperty(FOAF_URI + "familyName");
Property foafGivenName = aboxModel.createProperty(foafUri+"givenName"); Property foafGivenName = aboxModel.createProperty(FOAF_URI + "givenName");
Property foafName = aboxModel.createProperty(foafUri+"name"); Property foafName = aboxModel.createProperty(FOAF_URI + "name");
Property revHasReview = aboxModel.createProperty(revUri+"hasReview"); Property revHasReview = aboxModel.createProperty(REV_URI + "hasReview");
Property revReviewer = aboxModel.createProperty(revUri+"reviewer"); Property revReviewer = aboxModel.createProperty(REV_URI + "reviewer");
Property revText = aboxModel.createProperty(revUri+"text"); Property revText = aboxModel.createProperty(REV_URI + "text");
Resource revReview = aboxModel.createResource(revUri+"Review"); Resource revReview = aboxModel.createResource(REV_URI + "Review");
// Let's add stuff into the ABox // Let's add stuff into the ABox
Resource kimishima = aboxModel.createResource(ownUri+"Kimishima"); Resource kimishima = aboxModel.createResource(OWN_URI + "Kimishima");
kimishima.addProperty(rdfType, foafPerson); kimishima.addProperty(rdfType, foafPerson);
kimishima.addProperty(foafFamilyName, "Kimishima"); kimishima.addProperty(foafFamilyName, "Kimishima");
kimishima.addProperty(foafGivenName, "Tatsumi"); kimishima.addProperty(foafGivenName, "Tatsumi");
Resource nintendo = aboxModel.createResource(ownUri+"Nintendo"); Resource nintendo = aboxModel.createResource(OWN_URI + "Nintendo");
nintendo.addProperty(rdfType, foafOrganization); nintendo.addProperty(rdfType, foafOrganization);
nintendo.addProperty(foafName, "Nintendo Co., Ltd."); nintendo.addProperty(foafName, "Nintendo Co., Ltd.");
nintendo.addProperty(foundingYear, aboxModel.createTypedLiteral(1889)); nintendo.addProperty(foundingYear, aboxModel.createTypedLiteral(1889));
nintendo.addProperty(ceo, kimishima); nintendo.addProperty(ceo, kimishima);
Resource wii = aboxModel.createResource(ownUri+"Wii"); Resource wii = aboxModel.createResource(OWN_URI + "Wii");
wii.addProperty(rdfType, gameConsole); wii.addProperty(rdfType, gameConsole);
wii.addProperty(madeBy, nintendo); wii.addProperty(madeBy, nintendo);
Resource wiiU = aboxModel.createResource(ownUri+"Wii_u"); Resource wiiU = aboxModel.createResource(OWN_URI + "Wii_u");
wiiU.addProperty(rdfType, gameConsole); wiiU.addProperty(rdfType, gameConsole);
wiiU.addProperty(internetEnabled, aboxModel.createTypedLiteral(true)); wiiU.addProperty(internetEnabled, aboxModel.createTypedLiteral(true));
wiiU.addProperty(consoleName, "Wii U"); wiiU.addProperty(consoleName, "Wii U");
@ -162,20 +178,21 @@ public class Generator {
wiiU.addProperty(releaseYear, aboxModel.createTypedLiteral(2012)); wiiU.addProperty(releaseYear, aboxModel.createTypedLiteral(2012));
wiiU.addProperty(madeBy, nintendo); wiiU.addProperty(madeBy, nintendo);
Resource cSwitch = aboxModel.createResource(ownUri+"Switch"); Resource cSwitch = aboxModel.createResource(OWN_URI + "Switch");
wiiU.addProperty(successorOfConsole, cSwitch); wiiU.addProperty(successorOfConsole, cSwitch);
cSwitch.addProperty(rdfType, portableGameConsole); cSwitch.addProperty(rdfType, portableGameConsole);
cSwitch.addProperty(releaseYear, aboxModel.createTypedLiteral(2017));
cSwitch.addProperty(madeBy, nintendo); cSwitch.addProperty(madeBy, nintendo);
Resource jpt = aboxModel.createResource(ownUri+"JPT"); Resource jpt = aboxModel.createResource(OWN_URI + "JPT");
jpt.addProperty(rdfType, foafPerson); jpt.addProperty(rdfType, foafPerson);
jpt.addProperty(foafName, "Jan Philipp Timme"); jpt.addProperty(foafName, "Jan Philipp Timme");
Resource maschell = aboxModel.createResource(ownUri+"Maschell"); Resource maschell = aboxModel.createResource(OWN_URI + "Maschell");
maschell.addProperty(rdfType, foafPerson); maschell.addProperty(rdfType, foafPerson);
maschell.addProperty(foafName, "Marcel Felix"); maschell.addProperty(foafName, "Marcel Felix");
Resource switchReviewByJPT = aboxModel.createResource(ownUri+"SwitchReviewByJPT"); Resource switchReviewByJPT = aboxModel.createResource(OWN_URI + "SwitchReviewByJPT");
switchReviewByJPT.addProperty(rdfType, revReview); switchReviewByJPT.addProperty(rdfType, revReview);
switchReviewByJPT.addProperty(revReviewer, jpt); switchReviewByJPT.addProperty(revReviewer, jpt);
switchReviewByJPT.addProperty(revText, "Yet another gaming console. I lost a tetris game once. Meh."); switchReviewByJPT.addProperty(revText, "Yet another gaming console. I lost a tetris game once. Meh.");
@ -185,25 +202,17 @@ public class Generator {
cSwitch.addProperty(hasPrice, "329,00€"); cSwitch.addProperty(hasPrice, "329,00€");
// Store the model into a file // Store the model into a file
Generator.writeModelToTurtleFile(aboxModel, "./output/abox.ttl");
Generator.writeModelToJsonFile(aboxModel, "./output/abox.json"); Generator.writeModelFile(aboxModel, outputPath, A_BOX_FILENAME_TTL, MODEL_TURTLE);
Generator.writeModelFile(aboxModel, outputPath, A_BOX_FILENAME_JSON, MODEL_JSON);
Generator.writeModelFile(aboxModel, outputPath, A_BOX_FILENAME_XML, MODEL_RDF_XML);
} }
private static void writeModelToTurtleFile(Model model, String path) { private static void writeModelFile(Model model, String path, String filename, String format) {
FileOutputStream outfile = null; FileOutputStream outfile = null;
try { try {
outfile = new FileOutputStream(path); outfile = new FileOutputStream(path + "/" + filename);
model.write(outfile, "TURTLE"); model.write(outfile, format);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static void writeModelToJsonFile(Model model, String path) {
FileOutputStream outfile = null;
try {
outfile = new FileOutputStream(path);
model.write(outfile, "JSON-LD");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }