view src/org/qmul/eecs/c4dm/sia/SiaDimensionValueFactory.java @ 40:88a8c6a05b5f

removed unnecessary imports
author stevenh
date Thu, 28 Mar 2013 19:43:05 +0000
parents 88362f5eefa3
children 37ade31b7a29
line wrap: on
line source
package org.qmul.eecs.c4dm.sia;

import java.util.Vector;

import org.qmul.eecs.c4dm.sia.model.DimensionValue;

import com.hp.hpl.jena.ontology.OntModel;
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;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;

public class SiaDimensionValueFactory {

	public static Vector<DimensionValue> getDimensionValuesForResource(
			OntModel ontModel, Resource subject) {
		DimensionValue dimVal;
		StmtIterator dimValStmtIter;
		Property dimValProperty = ontModel.getOntProperty(DimensionValue.PROPERTY_URI);
		Property dimensionProperty = ontModel.getOntProperty(DimensionValue.DIMENSION_URI);
		Property valueProperty = ontModel.getOntProperty(DimensionValue.VALUE_URI);
		dimValStmtIter = ontModel.listStatements(subject, dimValProperty, (RDFNode)null);
		
		Vector<DimensionValue> dimValsList = new Vector<DimensionValue>();
		StmtIterator dimValDimensionStmtIter;
		StmtIterator dimValValueStmtIter;

		while (dimValStmtIter.hasNext())
		{
			Statement dimValStmt = dimValStmtIter.next();			
			Resource dimValResource = dimValStmt.getResource();
			
			dimValDimensionStmtIter = ontModel.listStatements(dimValResource, dimensionProperty, (RDFNode)null);
			dimValValueStmtIter = ontModel.listStatements(dimValResource, valueProperty, (RDFNode)null);
			dimVal = new DimensionValue();

			// There should only be one statment here - if not, application behaviour is undefined
			while (dimValDimensionStmtIter.hasNext())
			{
				Statement dimValDimensionStmt = dimValDimensionStmtIter.next();
				Literal dimension = dimValDimensionStmt.getLiteral();
				dimVal.setDimension(dimension.getInt());
			}

			// There should only be one statment here - if not, application behaviour is undefined
			while (dimValValueStmtIter.hasNext())
			{
				Statement dimValValueStmt = dimValValueStmtIter.next();	
				Literal value = dimValValueStmt.getLiteral();
				dimVal.setValue(value.getDouble());
			}
			
			dimValsList.add(dimVal);			
		}
		return dimValsList;
	}

}