annotate src/org/qmul/eecs/c4dm/sia/SiaDatapointFactory.java @ 94:fedf516f6a78 tip

test file
author stevenh
date Mon, 29 Dec 2014 15:16:22 +0000
parents affdfe375b41
children
rev   line source
steve@0 1 package org.qmul.eecs.c4dm.sia;
steve@0 2
steve@0 3 import java.util.ArrayList;
steve@0 4 import java.util.List;
steve@0 5 import java.util.Vector;
steve@0 6
steve@0 7 import org.qmul.eecs.c4dm.sia.model.Datapoint;
steve@0 8 import org.qmul.eecs.c4dm.sia.model.DimensionValue;
stevenh@68 9 import org.qmul.eecs.c4dm.sia.model.SiaVector;
steve@0 10
steve@0 11 import com.hp.hpl.jena.ontology.OntClass;
steve@0 12 import com.hp.hpl.jena.ontology.OntModel;
stevenh@38 13 import com.hp.hpl.jena.ontology.OntResource;
steve@0 14 import com.hp.hpl.jena.rdf.model.Property;
stevenh@68 15 import com.hp.hpl.jena.rdf.model.Statement;
steve@0 16 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
steve@0 17
steve@0 18 public class SiaDatapointFactory {
steve@0 19
stevenh@38 20 /**
stevenh@38 21 * @param ontModel
stevenh@38 22 * @return List<Datapoint>
stevenh@38 23 */
steve@0 24 public static List<Datapoint> create(OntModel ontModel) {
steve@0 25
stevenh@42 26 List<Datapoint> datapointsList = new ArrayList<Datapoint>();
stevenh@42 27 Datapoint datapoint;
steve@0 28 OntClass datapointClass = ontModel.getOntClass(Datapoint.RESOURCE_URI);
stevenh@38 29
stevenh@42 30 ExtendedIterator<? extends OntResource> datapointIter;
stevenh@42 31 try
stevenh@42 32 {
stevenh@42 33 datapointIter = datapointClass.listInstances();
stevenh@42 34 }
stevenh@42 35 catch (NullPointerException npe)
stevenh@42 36 {
stevenh@42 37 return datapointsList;
stevenh@42 38 }
steve@0 39
steve@0 40 // Find all rdf datapoints
stevenh@38 41 OntResource datapointIndividual;
steve@0 42 while (datapointIter.hasNext())
steve@0 43 {
steve@0 44 datapointIndividual = datapointIter.next();
steve@0 45 datapoint = new Datapoint();
steve@0 46 datapoint.setResource(datapointIndividual);
stevenh@68 47 Property vectorProperty = ontModel.getOntProperty(SiaVector.PROPERTY_URI);
stevenh@68 48 Statement vector = datapointIndividual.getProperty(vectorProperty);
stevenh@38 49
steve@0 50 Vector<DimensionValue> dimValsList = SiaDimensionValueFactory.getDimensionValuesForResource(
stevenh@68 51 ontModel, vector.getResource());
steve@0 52
steve@0 53 datapoint.setDimensionValues(dimValsList);
steve@0 54 datapointsList.add(datapoint);
steve@0 55
steve@0 56 }
steve@0 57 return datapointsList;
steve@0 58 }
steve@0 59
stevenh@38 60 /**
stevenh@38 61 * @param datapoints
stevenh@38 62 */
stevenh@88 63 public static void assertOrder(List<Datapoint> datapoints) {
steve@0 64
steve@0 65 int numDatapoints = datapoints.size();
steve@0 66
steve@0 67 Datapoint datapoint;
steve@0 68
steve@0 69 for (int orderedIndex = 0; orderedIndex < numDatapoints; orderedIndex++)
steve@0 70 {
steve@0 71 datapoint = datapoints.get(orderedIndex);
stevenh@11 72 datapoint.setOrderedIndex(orderedIndex + 1);
steve@0 73 }
steve@0 74 }
steve@0 75
steve@0 76 }