Mercurial > hg > semantic-sia
changeset 16:6863887e1b70
organized imports
added new "createV" and "createW" methods so that we can specifically create Vector Tables V or W as described in the paper
removed unnecessary code
added try/catch blocks where necessary
author | stevenh |
---|---|
date | Tue, 08 Jan 2013 18:30:14 +0000 |
parents | b43260af3de6 |
children | f21eb0fddba2 |
files | src/org/qmul/eecs/c4dm/sia/SiaVectorTableElementFactory.java |
diffstat | 1 files changed, 57 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/qmul/eecs/c4dm/sia/SiaVectorTableElementFactory.java Tue Jan 08 18:22:26 2013 +0000 +++ b/src/org/qmul/eecs/c4dm/sia/SiaVectorTableElementFactory.java Tue Jan 08 18:30:14 2013 +0000 @@ -5,6 +5,7 @@ import java.util.List; import java.util.Vector; +import org.qmul.eecs.c4dm.sia.exceptions.DimensionException; import org.qmul.eecs.c4dm.sia.model.Datapoint; import org.qmul.eecs.c4dm.sia.model.DimensionValue; import org.qmul.eecs.c4dm.sia.model.DirectlyFollows; @@ -13,13 +14,13 @@ import org.qmul.eecs.c4dm.sia.model.OrderedIndex; import org.qmul.eecs.c4dm.sia.model.OrderedSet; import org.qmul.eecs.c4dm.sia.model.ToDatapoint; +import org.qmul.eecs.c4dm.sia.model.VectorTable; import org.qmul.eecs.c4dm.sia.model.VectorTableElement; import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.AnonId; -import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.Resource; @@ -30,42 +31,54 @@ public class SiaVectorTableElementFactory { - public static List<VectorTableElement> create(OntModel ontModel, List<Datapoint> datapoints) { + /** + * @param ontModel + * @param datapoints + * @return + */ + public static VectorTable createV(OntModel ontModel, List<Datapoint> datapoints) { + return create(ontModel, datapoints, false); + } + + /** + * @param ontModel + * @param datapoints + * @return + */ + public static VectorTable createW(OntModel ontModel, List<Datapoint> datapoints) { + return create(ontModel, datapoints, true); + } + + /** + * @param ontModel + * @param datapoints + * @param returnWResults + * @return + */ + public static VectorTable create(OntModel ontModel, List<Datapoint> datapoints, boolean returnWResults) { OntClass vteClass = ontModel.getOntClass(VectorTableElement.RESOURCE_URI); Resource vteResource = ontModel.getOntResource(vteClass); ExtendedIterator<Individual> vteIter = ontModel.listIndividuals(vteResource); - Property dimValProperty = ontModel.getOntProperty(DimensionValue.PROPERTY_URI); - Property dimensionProperty = ontModel.getOntProperty(DimensionValue.DIMENSION_URI); - Property valueProperty = ontModel.getOntProperty(DimensionValue.VALUE_URI); Property fromDatapointProperty = ontModel.getOntProperty(FromDatapoint.PROPERTY_URI); Property toDatapointProperty = ontModel.getOntProperty(ToDatapoint.PROPERTY_URI); List<VectorTableElement> vteList = new ArrayList<VectorTableElement>(); VectorTableElement vte; - DimensionValue dimVal; - Individual vteIndividual; - StmtIterator dimValStmtIter; StmtIterator fromDPStmtIter; StmtIterator toDPStmtIter; - StmtIterator dimValDimensionStmtIter; - StmtIterator dimValValueStmtIter; Statement fromDatapointStmt; Statement toDatapointStmt; - Resource dimValResource; - Statement dimValDimensionStmt; - Statement dimValValueStmt; - Literal dimension; - Literal value; - + + VectorTable vectorTable = new VectorTable(); + // Find all rdf VectorTableElements while (vteIter.hasNext()) { vteIndividual = vteIter.next(); - System.out.println(vteIndividual.toString()); vte = new VectorTableElement(); vte.setResource(vteIndividual); @@ -73,33 +86,51 @@ fromDPStmtIter = ontModel.listStatements(vteIndividual, fromDatapointProperty, (RDFNode)null); fromDatapointStmt = fromDPStmtIter.next(); Datapoint fromDatapoint = findDatapoint(ontModel, datapoints, fromDatapointStmt.getResource()); - vte.setFromDatapoint(fromDatapoint); + try { + vte.setFromDatapoint(fromDatapoint); + } catch (DimensionException e) { + e.printStackTrace(); + System.exit(1); + } // Find the 'toDatapoint' for this VectorTableElement toDPStmtIter = ontModel.listStatements(vteIndividual, toDatapointProperty, (RDFNode)null); toDatapointStmt = toDPStmtIter.next(); Datapoint toDatapoint = findDatapoint(ontModel, datapoints, toDatapointStmt.getResource()); - vte.setToDatapoint(toDatapoint); + try { + vte.setToDatapoint(toDatapoint); + } catch (DimensionException e) { + e.printStackTrace(); + System.exit(1); + } - // Find all dimensionValues for this VectorTableElement - Vector<DimensionValue> dimensionValues = SiaDimensionValueFactory.getDimensionValuesForResource(ontModel, vteIndividual); - vte.setDimensionValues(dimensionValues); - - vteList.add(vte); - + // Only add VectorTableElements whose 'from' ordered index is less than the 'to' ordered index + if (returnWResults || vte.getFromDatapoint().getOrderedIndex() < vte.getToDatapoint().getOrderedIndex()) + { + // Find all dimensionValues for this VectorTableElement + Vector<DimensionValue> dimensionValues = SiaDimensionValueFactory.getDimensionValuesForResource(ontModel, vteIndividual); + vte.setDimensionValues(dimensionValues); + + vteList.add(vte); + } } - return vteList; + + vectorTable.setVteList(vteList); + vectorTable.setNumDatapoints(datapoints.size()); + return vectorTable; } public static Datapoint findDatapoint(OntModel ontModel, List<Datapoint> datapoints, Resource resource) { Iterator<Datapoint> datapointsIter = datapoints.iterator(); Datapoint datapoint; + while (datapointsIter.hasNext()) { datapoint = datapointsIter.next(); if (datapoint.getResource().getLocalName().equals(resource.getLocalName())) return datapoint; } + datapoint = new Datapoint(); datapoint.setResource(resource); Vector<DimensionValue> dimensionValues = SiaDimensionValueFactory.getDimensionValuesForResource(ontModel, resource);