From 935263862ece33233951e5dcc74bfe66d716efe6 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Thu, 11 Aug 2016 20:54:08 +0200 Subject: [PATCH] [TASK] Enhance Main.java for static knowledge. --- src/main/java/lu/jpt/csparqltest/Main.java | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index ef8400f..7198265 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -6,6 +6,7 @@ import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import eu.larkc.csparql.common.utils.CsparqlUtils; import eu.larkc.csparql.core.engine.ConsoleFormatter; import eu.larkc.csparql.core.engine.CsparqlEngine; import eu.larkc.csparql.core.engine.CsparqlEngineImpl; @@ -31,7 +32,22 @@ public class Main { // Instantiate and initialize engine CsparqlEngine engine = new CsparqlEngineImpl(); engine.initialize(true); - + + // Add static knowledge into local graph from file + try { + //engine.putStaticNamedModel("http://streamreasoning.org/roomConnection", CsparqlUtils.serializeRDFFile("examples_files/roomConnection.rdf")); + } catch (Exception e) { + logger.error(e.toString()); + logger.error(e.getStackTrace().toString()); + } + + /* Use a SPARQL Query to update the local knowledge from code instead of using CONSTRUCT within the engine. + String updateQuery = "PREFIX : " + + "INSERT DATA " + + "{ GRAPH { :room :isConnectedTo :room2 } }"; + engine.execUpdateQueryOverDatasource(updateQuery); + */ + // Debugging: Needed to verify which engine is being used //logger.debug("CWD: " + System.getProperty("user.dir")); //logger.debug("Engine from: " + engine.getClass().getProtectionDomain().getCodeSource()); @@ -52,9 +68,9 @@ public class Main { CsparqlQueryResultProxy resultProxy = null; try { resultProxy = engine.registerQuery(query, true); - } catch (ParseException e1) { - logger.error(e1.toString()); - logger.error(e1.getStackTrace().toString()); + } catch (ParseException e) { + logger.error(e.toString()); + logger.error(e.getStackTrace().toString()); } // Add ConsoleFormatter as observer so it gets notified of every query result resultProxy.addObserver(new ConsoleFormatter());