steve@0: package org.qmul.eecs.c4dm.sia; steve@0: steve@0: import java.util.ArrayList; steve@0: import java.util.List; steve@0: import java.util.Vector; steve@0: steve@0: import org.qmul.eecs.c4dm.sia.model.Datapoint; steve@0: import org.qmul.eecs.c4dm.sia.model.DimensionValue; stevenh@68: import org.qmul.eecs.c4dm.sia.model.SiaVector; steve@0: steve@0: import com.hp.hpl.jena.ontology.OntClass; steve@0: import com.hp.hpl.jena.ontology.OntModel; stevenh@38: import com.hp.hpl.jena.ontology.OntResource; steve@0: import com.hp.hpl.jena.rdf.model.Property; stevenh@68: import com.hp.hpl.jena.rdf.model.Statement; steve@0: import com.hp.hpl.jena.util.iterator.ExtendedIterator; steve@0: steve@0: public class SiaDatapointFactory { steve@0: stevenh@38: /** stevenh@38: * @param ontModel stevenh@38: * @return List stevenh@38: */ steve@0: public static List create(OntModel ontModel) { steve@0: stevenh@42: List datapointsList = new ArrayList(); stevenh@42: Datapoint datapoint; steve@0: OntClass datapointClass = ontModel.getOntClass(Datapoint.RESOURCE_URI); stevenh@38: stevenh@42: ExtendedIterator datapointIter; stevenh@42: try stevenh@42: { stevenh@42: datapointIter = datapointClass.listInstances(); stevenh@42: } stevenh@42: catch (NullPointerException npe) stevenh@42: { stevenh@42: return datapointsList; stevenh@42: } steve@0: steve@0: // Find all rdf datapoints stevenh@38: OntResource datapointIndividual; steve@0: while (datapointIter.hasNext()) steve@0: { steve@0: datapointIndividual = datapointIter.next(); steve@0: datapoint = new Datapoint(); steve@0: datapoint.setResource(datapointIndividual); stevenh@68: Property vectorProperty = ontModel.getOntProperty(SiaVector.PROPERTY_URI); stevenh@68: Statement vector = datapointIndividual.getProperty(vectorProperty); stevenh@38: steve@0: Vector dimValsList = SiaDimensionValueFactory.getDimensionValuesForResource( stevenh@68: ontModel, vector.getResource()); steve@0: steve@0: datapoint.setDimensionValues(dimValsList); steve@0: datapointsList.add(datapoint); steve@0: steve@0: } steve@0: return datapointsList; steve@0: } steve@0: stevenh@38: /** stevenh@38: * @param datapoints stevenh@38: */ stevenh@88: public static void assertOrder(List datapoints) { steve@0: steve@0: int numDatapoints = datapoints.size(); steve@0: steve@0: Datapoint datapoint; steve@0: steve@0: for (int orderedIndex = 0; orderedIndex < numDatapoints; orderedIndex++) steve@0: { steve@0: datapoint = datapoints.get(orderedIndex); stevenh@11: datapoint.setOrderedIndex(orderedIndex + 1); steve@0: } steve@0: } steve@0: steve@0: }