Mercurial > hg > semantic-sia
changeset 13:5a3a1c7fa3a8
organized imports
changed finalModelFileName to "src/rdf/finalSiaModel" (to distinguish from finalSiaTecModel)
removed select query
changed one of the sparql construct query filenames from construct_vector_table_bnodes to construct_sia_vector_table_bnodes
moved public static String SIA_NS_URI to the (new) "Namespaces" class
moved sparql-related methods to (new) class "SparqlWrapperMethods"
now use the newly-created "SiaVectorTableElementFactory.createV" method instead of the old "SiaVectorTableElementFactory.create" method for creating specifically the Vector Table V (as opposed to W) described in the paper
removed unnecessary code
moved display code to the "Display" class
author | stevenh |
---|---|
date | Tue, 08 Jan 2013 18:15:46 +0000 |
parents | 1e8f97ddaed3 |
children | eb086fc26803 |
files | src/org/qmul/eecs/c4dm/sia/SiaMain.java |
diffstat | 1 files changed, 21 insertions(+), 166 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/qmul/eecs/c4dm/sia/SiaMain.java Tue Jan 08 18:06:02 2013 +0000 +++ b/src/org/qmul/eecs/c4dm/sia/SiaMain.java Tue Jan 08 18:15:46 2013 +0000 @@ -1,11 +1,3 @@ -// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> -// This source code is available under the terms of the Affero General Public -// License v3. -// -// Please see LICENSE.txt for full license terms, including the availability of -// proprietary exceptions. -// Questions, comments, or requests for clarification: licensing@clarkparsia.com - package org.qmul.eecs.c4dm.sia; import java.io.File; @@ -16,31 +8,23 @@ import java.util.List; import org.mindswap.pellet.jena.PelletReasonerFactory; -import org.qmul.eecs.c4dm.sia.exceptions.DimensionException; import org.qmul.eecs.c4dm.sia.model.Datapoint; -import org.qmul.eecs.c4dm.sia.model.NDimensionalObject; +import org.qmul.eecs.c4dm.sia.model.VectorTable; import org.qmul.eecs.c4dm.sia.model.VectorTableElement; +import org.qmul.eecs.c4dm.sia.rdf.Namespaces; +import org.qmul.eecs.c4dm.sia.utilities.Display; +import org.qmul.eecs.c4dm.sparql.utilities.SparqlWrapperMethods; -import com.clarkparsia.pellet.sparqldl.jena.SparqlDLExecutionFactory; import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.Statement; -import com.hp.hpl.jena.rdf.model.StmtIterator; /** * <p> * Title: SiaMain * </p> * <p> - * Description: An RDF/OWL/Java implementation of the sia pattern discovery algorithm. + * Description: An RDF/OWL/Java implementation of the SIA pattern discovery algorithm. * </p> * * @author Steve Hargreaves, C4DM, Queen Mary University of London @@ -51,17 +35,18 @@ private static final String ontology = "file:src/rdf/siaDatapointOntology.n3"; // The final output file - private static final String finalModelFileName = "src/rdf/finalModel"; + private static final String finalModelFileName = "src/rdf/finalSiaModel"; // SPARQL queries private static final String[] selectQueries = new String[] { // A SPARQL-DL query + "file:src/sparql/select_all.sparql" }; // CONSTRUCT queries private static final String[] constructQueries = new String[] { // A SPARQL-DL CONSTRUCT query - "file:src/sparql/construct_vector_table_bnodes.sparql", + "file:src/sparql/construct_sia_vector_table_bnodes.sparql", "file:src/sparql/construct_vector_table_details.sparql" }; // ASK queries @@ -69,8 +54,6 @@ // A SPARQL-DL ASK query }; - public static String SIA_NS_URI = null; - public void run() { // First create a Jena ontology model backed by the Pellet reasoner @@ -83,34 +66,34 @@ // Set the value of SIA_NS_URI as the namespace for 'sia' found in // the ontology - SIA_NS_URI = ontModel.getNsPrefixURI("sia"); + Namespaces.SIA_NS_URI = ontModel.getNsPrefixURI("sia"); // Create custom sia Datapoint objects List<Datapoint> datapoints = SiaDatapointFactory.create(ontModel); - // Order the datapoints + // STEP 1 - Order the datapoints Collections.sort(datapoints); // Add datapoint order info to model SiaDatapointFactory.assertOrder(ontModel, datapoints); + // STEP 2 - Compute the vector table // Run all the CONSTRUCT queries for (int i = 0; i < constructQueries.length; i++) { String constructQuery = constructQueries[i]; - Model newModel = executeConstructQuery(constructQuery, ontModel); + Model newModel = SparqlWrapperMethods.executeConstructQuery(constructQuery, ontModel); // Add new triples to the current model ontModel.add(newModel); } // Create custom sia VectorTableElement objects - List<VectorTableElement> vteList = SiaVectorTableElementFactory.create(ontModel, datapoints); - Iterator<VectorTableElement> vteIter = vteList.iterator(); + VectorTable vectorTableV = SiaVectorTableElementFactory.createV(ontModel, datapoints); + List<VectorTableElement> vteList = vectorTableV.getVteList(); - // Order the VectorTableElement objects + // STEP 3 - Order the VectorTableElement objects Collections.sort(vteList); - vteIter = vteList.iterator(); // Add vector table element order info to model SiaVectorTableElementFactory.assertOrder(ontModel, vteList); @@ -119,7 +102,7 @@ for (int i = 0; i < selectQueries.length; i++) { String selectQuery = selectQueries[i]; - queryTheModel(selectQuery, ontModel); + SparqlWrapperMethods.queryTheModel(selectQuery, ontModel); } @@ -127,7 +110,7 @@ for (int i = 0; i < askQueries.length; i++) { String askQuery = askQueries[i]; - askTheModel(askQuery, ontModel); + SparqlWrapperMethods.askTheModel(askQuery, ontModel); } @@ -162,7 +145,7 @@ System.out.println("Model written to files: " + outFileRdf.getAbsolutePath() + " and " + outFileN3.getAbsolutePath()); - // Display the results + // STEP 4 - Display the results displaySiaResults(vteList); } @@ -179,15 +162,15 @@ while (i < m) { System.out.print("<"); - printVector(vteList.get(i)); + Display.printVector(vteList.get(i)); System.out.print(",{"); - printVector(vteList.get(i).getFromDatapoint()); + Display.printVector(vteList.get(i).getFromDatapoint()); int j = i + 1; while (j < m && (vteList.get(i).compareToIgnoreDatapoints(vteList.get(j)) == 0)) { System.out.print(","); - printVector(vteList.get(j).getFromDatapoint()); + Display.printVector(vteList.get(j).getFromDatapoint()); j++; } System.out.print("}>"); @@ -230,134 +213,6 @@ } /** - * @param vector - */ - private void printVector(NDimensionalObject vector) { - System.out.print("<"); - - int maxDimension = vector.getDimensionValues().size(); - - for (int dim = 1; dim <= maxDimension; dim++) - { - try { - double value = vector.getDimensionValue(dim); - System.out.print(value + (dim == maxDimension ? "" : ",")); - } catch (DimensionException e) { - e.printStackTrace(); - System.exit(1); - } - } - System.out.print(">"); - - } - - /** - * @param query - * @param m - * @return - */ - private Model executeConstructQuery(String query, Model m) { - - // Now read the query file into a query object - Query q = QueryFactory.read(query, Syntax.syntaxARQ); // only required - // if using - // (e.g.) LET in - // SPARQL - - QueryExecution qe = QueryExecutionFactory.create(q, m); - - // We want to execute a CONSTRUCT query, do it, and return the new - // triples - Model newModel = qe.execConstruct(); - - // Print the query for better understanding - System.out.println(q.toString()); - - // Print the new triples - StmtIterator iter = newModel.listStatements(); - printStmts(iter); - - return newModel; - } - - /** - * @param iter - */ - private void printStmts(StmtIterator iter) { - Statement statement; - - while (iter.hasNext()) { - statement = iter.nextStatement(); - System.out.println(" | <" + statement.getSubject() + "> | <" - + statement.getPredicate() + "> | <" - + statement.getObject() + "> | "); - } - - // And an empty line to make it pretty - System.out.println(); - } - - /** - * @param query - * @param m - */ - private void queryTheModel(String query, Model m) { - - // Now read the query file into a query object - Query q = QueryFactory.read(query, Syntax.syntaxARQ); // only required - // if using - // (e.g.) LET in - // SPARQL - - // Create a SPARQL-DL query execution for the given query and - // ontology model - QueryExecution qe = SparqlDLExecutionFactory.create(q, m); - - // We want to execute a SELECT query, do it, and return the result set - ResultSet rs = qe.execSelect(); - - // Print the query for better understanding - System.out.println(q.toString()); - - // There are different things we can do with the result set, for - // instance iterate over it and process the query solutions or, what we - // do here, just print out the results - ResultSetFormatter.out(rs); - - // And an empty line to make it pretty - System.out.println(); - } - - /** - * @param query - * @param m - */ - private void askTheModel(String query, Model m) { - - // Now read the query file into a query object - Query q = QueryFactory.read(query); - - // Create a SPARQL-DL query execution for the given query and - // ontology model - QueryExecution qe = SparqlDLExecutionFactory.create(q, m); - - // We want to execute a SELECT query, do it, and return the result set - boolean result = qe.execAsk(); - - // Print the query for better understanding - System.out.println(q.toString()); - - // Print the result - System.out.println("Result: " + result); - - // And an empty line to make it pretty - System.out.println(); - } - - /** - * @param args - */ - /** * @param args */ public static void main(String[] args) {