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

test file
author stevenh
date Mon, 29 Dec 2014 15:16:22 +0000
parents 7f3a6cf478bc
children
rev   line source
steve@0 1 package org.qmul.eecs.c4dm.sia;
steve@0 2
steve@0 3 import java.util.Vector;
steve@0 4
stevenh@89 5 import org.qmul.eecs.c4dm.sia.exceptions.DimensionException;
stevenh@89 6 import org.qmul.eecs.c4dm.sia.model.Datapoint;
steve@0 7 import org.qmul.eecs.c4dm.sia.model.DimensionValue;
stevenh@89 8 import org.qmul.eecs.c4dm.sia.model.VectorTableElement;
steve@0 9
steve@0 10 import com.hp.hpl.jena.ontology.OntModel;
steve@0 11 import com.hp.hpl.jena.rdf.model.Literal;
steve@0 12 import com.hp.hpl.jena.rdf.model.Property;
steve@0 13 import com.hp.hpl.jena.rdf.model.RDFNode;
steve@0 14 import com.hp.hpl.jena.rdf.model.Resource;
steve@0 15 import com.hp.hpl.jena.rdf.model.Statement;
steve@0 16 import com.hp.hpl.jena.rdf.model.StmtIterator;
steve@0 17
steve@0 18 public class SiaDimensionValueFactory {
steve@0 19
stevenh@89 20 public static Vector<DimensionValue> getDimensionValuesForVectorTableElement(VectorTableElement vte) throws DimensionException
stevenh@89 21 {
stevenh@89 22 Datapoint fromDatapoint = vte.getFromDatapoint();
stevenh@89 23 Datapoint toDatapoint = vte.getToDatapoint();
stevenh@89 24
stevenh@89 25 int dimensionality = fromDatapoint.getDimensionValues().size();
stevenh@89 26 Vector<DimensionValue> dimVals = new Vector<DimensionValue>();
stevenh@89 27
stevenh@89 28 for (int dim = 1; dim <= dimensionality; dim++)
stevenh@89 29 {
stevenh@89 30 double val = toDatapoint.getDimensionValue(dim) - fromDatapoint.getDimensionValue(dim);
stevenh@89 31 DimensionValue dimVal = new DimensionValue();
stevenh@89 32 dimVal.setDimension(dim);
stevenh@89 33 dimVal.setValue(val);
stevenh@89 34 dimVals.add(dimVal);
stevenh@89 35 }
stevenh@89 36
stevenh@89 37 return dimVals;
stevenh@89 38 }
stevenh@89 39
steve@0 40 public static Vector<DimensionValue> getDimensionValuesForResource(
steve@0 41 OntModel ontModel, Resource subject) {
steve@0 42 DimensionValue dimVal;
steve@0 43 StmtIterator dimValStmtIter;
steve@0 44 Property dimValProperty = ontModel.getOntProperty(DimensionValue.PROPERTY_URI);
steve@0 45 Property dimensionProperty = ontModel.getOntProperty(DimensionValue.DIMENSION_URI);
steve@0 46 Property valueProperty = ontModel.getOntProperty(DimensionValue.VALUE_URI);
steve@0 47 dimValStmtIter = ontModel.listStatements(subject, dimValProperty, (RDFNode)null);
steve@0 48
steve@0 49 Vector<DimensionValue> dimValsList = new Vector<DimensionValue>();
steve@0 50 StmtIterator dimValDimensionStmtIter;
steve@0 51 StmtIterator dimValValueStmtIter;
steve@0 52
steve@0 53 while (dimValStmtIter.hasNext())
steve@0 54 {
stevenh@12 55 Statement dimValStmt = dimValStmtIter.next();
steve@0 56 Resource dimValResource = dimValStmt.getResource();
steve@0 57
steve@0 58 dimValDimensionStmtIter = ontModel.listStatements(dimValResource, dimensionProperty, (RDFNode)null);
steve@0 59 dimValValueStmtIter = ontModel.listStatements(dimValResource, valueProperty, (RDFNode)null);
steve@0 60 dimVal = new DimensionValue();
stevenh@66 61 dimVal.setResource(dimValResource);
steve@0 62
stevenh@39 63 // There should only be one statment here - if not, application behaviour is undefined
stevenh@39 64 while (dimValDimensionStmtIter.hasNext())
stevenh@39 65 {
stevenh@39 66 Statement dimValDimensionStmt = dimValDimensionStmtIter.next();
stevenh@39 67 Literal dimension = dimValDimensionStmt.getLiteral();
stevenh@39 68 dimVal.setDimension(dimension.getInt());
stevenh@39 69 }
steve@0 70
stevenh@39 71 // There should only be one statment here - if not, application behaviour is undefined
stevenh@39 72 while (dimValValueStmtIter.hasNext())
stevenh@39 73 {
stevenh@39 74 Statement dimValValueStmt = dimValValueStmtIter.next();
stevenh@39 75 Literal value = dimValValueStmt.getLiteral();
stevenh@39 76 dimVal.setValue(value.getDouble());
stevenh@39 77 }
steve@0 78
stevenh@12 79 dimValsList.add(dimVal);
steve@0 80 }
steve@0 81 return dimValsList;
steve@0 82 }
steve@0 83
steve@0 84 }