Protégé-OWL 3.4

edu.stanford.smi.protegex.owl.swrl.sqwrl.impl
Class ResultImpl

java.lang.Object
  extended by edu.stanford.smi.protegex.owl.swrl.sqwrl.impl.ResultImpl
All Implemented Interfaces:
ResultGenerator, SQWRLResult, Serializable

public class ResultImpl
extends Object
implements ResultGenerator, SQWRLResult, Serializable

This class implements the interfaces SQWRLResult and ResultGenerator. It can be used to generate a result structure and populate it with data; it can also be used to retrieve those data from the result.

This class operates in three phases:

(1) Configuration Phase: In this phase the structure of the result is defined. This phase opened by a call to the configure() method (which will also clear any existing data). In this phase the columns are defined; aggregation or ordering is also specified in this phase. This phase is closed by a call to the configured() method.

(2) Preparation Phase: In this phase data are added to the result. This phase is implicitly opened by the call to the configured() method. It is closed by a call to the prepared() method.

The interface ResultGenerator defines the calls used in these two phases.

(3) Processing Phase: In this phase data may be retrieved from the result. This phase is implicitly opened by the call to the closed() method.

The interface Result defines the calls used in the processing phase.

An example configuration and data generation is:

ResultImpl result = new ResultImpl("TestResult");

result.addColumn("name");

result.addAggregateColumn("average", SQWRLNames.AvgAggregateFunction);

result.configured();<>p

result.openRow();

result.addData(new OWLFactory.createOWLIndividual("Fred"));

result.addData(new Literal(27));

result.closeRow();

result.openRow();

result.addData(new OWLFactory.createOWLIndividual("Joe"));

result.addData(new Literal(34));

result.closeRow();

result.openRow();

result.addData(new OWLFactory.createOWLIndividual("Joe"));

result.addData(new Literal(21));

result.closeRow();

result.prepared();

The result is now available for reading. The interface SQWRLResult defines the assessor methods. A row consists of a list of objects defined by the interface ResultValue. There are four possible types of values (1) DatatypeValue, representing literals; (2) ObjectValue, representing OWL individuals; (3) ClassValue, representing OWL classes; and (4) PropertyValue, representing OWL properties.

while (result.hasNext()) {

ObjectValue nameValue = result.getObjectValue("name");

DatatypeValue averageValue = result.getDatatypeValue("average");

System.out.println("Name: " + nameValue.getIndividualName());

System.out.println("Average: " + averageValue.getInt());

} // while

A convenience method addColumns that takes a list of column names is also supplied.

There is also a convenience method addRow, which takes a list of ResultValues. This method automatically does a row open and close. It is expecting the exact same number of list elements as there are columns in the result.

See Also:
Serialized Form

Constructor Summary
ResultImpl()
           
 
Method Summary
 void addAggregateColumn(String columnName, String aggregateFunctionName)
           
 void addColumn(String columnName)
           
 void addColumnDisplayName(String columnName)
           
 void addColumns(List<String> columnNames)
           
 void addOrderByColumn(int orderedColumnIndex, boolean ascending)
           
 void addRow(List<ResultValue> resultValues)
           
 void addRowData(ResultValue value)
           
 void closeRow()
           
 void configured()
           
 ClassValue getClassValue(int columnIndex)
           
 ClassValue getClassValue(String columnName)
           
 List<ResultValue> getColumn(int columnIndex)
           
 List<ResultValue> getColumn(String columnName)
           
 String getColumnName(int columnIndex)
           
 List<String> getColumnNames()
           
 DatatypeValue getDatatypeValue(int columnIndex)
           
 DatatypeValue getDatatypeValue(String columnName)
           
 int getNumberOfColumns()
           
 int getNumberOfRows()
           
 ObjectValue getObjectValue(int columnIndex)
           
 ObjectValue getObjectValue(String columnName)
           
 PropertyValue getPropertyValue(int columnIndex)
           
 PropertyValue getPropertyValue(String columnName)
           
 List<ResultValue> getRow()
           
 ResultValue getValue(int columnIndex)
           
 ResultValue getValue(int columnIndex, int rowIndex)
           
 ResultValue getValue(String columnName)
           
 boolean hasClassValue(int columnIndex)
           
 boolean hasClassValue(String columnName)
           
 boolean hasDatatypeValue(int columnIndex)
           
 boolean hasDatatypeValue(String columnName)
           
 boolean hasNext()
           
 boolean hasObjectValue(int columnIndex)
           
 boolean hasObjectValue(String columnName)
           
 boolean hasPropertyValue(int columnIndex)
           
 boolean hasPropertyValue(String columnName)
           
 void initialize()
           
 boolean isAscending()
           
 boolean isConfigured()
           
 boolean isDistinct()
           
 boolean isEmpty()
           
 boolean isOrdered()
           
 boolean isPrepared()
           
 boolean isRowOpen()
           
 void next()
           
 void openRow()
           
 void prepared()
           
 void reset()
           
 void setIsDistinct()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResultImpl

public ResultImpl()
Method Detail

isConfigured

public boolean isConfigured()
Specified by:
isConfigured in interface ResultGenerator

isRowOpen

public boolean isRowOpen()
Specified by:
isRowOpen in interface ResultGenerator

isDistinct

public boolean isDistinct()

isPrepared

public boolean isPrepared()
Specified by:
isPrepared in interface ResultGenerator

isOrdered

public boolean isOrdered()
Specified by:
isOrdered in interface ResultGenerator

isAscending

public boolean isAscending()
Specified by:
isAscending in interface ResultGenerator

initialize

public void initialize()
Specified by:
initialize in interface ResultGenerator

addColumns

public void addColumns(List<String> columnNames)
                throws SQWRLException
Specified by:
addColumns in interface ResultGenerator
Throws:
SQWRLException

addColumn

public void addColumn(String columnName)
               throws SQWRLException
Specified by:
addColumn in interface ResultGenerator
Throws:
SQWRLException

addAggregateColumn

public void addAggregateColumn(String columnName,
                               String aggregateFunctionName)
                        throws SQWRLException
Specified by:
addAggregateColumn in interface ResultGenerator
Throws:
SQWRLException

addOrderByColumn

public void addOrderByColumn(int orderedColumnIndex,
                             boolean ascending)
                      throws SQWRLException
Specified by:
addOrderByColumn in interface ResultGenerator
Throws:
SQWRLException

addColumnDisplayName

public void addColumnDisplayName(String columnName)
                          throws SQWRLException
Specified by:
addColumnDisplayName in interface ResultGenerator
Throws:
SQWRLException

configured

public void configured()
                throws SQWRLException
Specified by:
configured in interface ResultGenerator
Throws:
SQWRLException

setIsDistinct

public void setIsDistinct()
Specified by:
setIsDistinct in interface ResultGenerator

getNumberOfColumns

public int getNumberOfColumns()
                       throws SQWRLException
Specified by:
getNumberOfColumns in interface SQWRLResult
Throws:
SQWRLException

getColumnNames

public List<String> getColumnNames()
                            throws SQWRLException
Specified by:
getColumnNames in interface SQWRLResult
Throws:
SQWRLException

getColumnName

public String getColumnName(int columnIndex)
                     throws SQWRLException
Specified by:
getColumnName in interface SQWRLResult
Throws:
SQWRLException

addRow

public void addRow(List<ResultValue> resultValues)
            throws SQWRLException
Specified by:
addRow in interface ResultGenerator
Throws:
SQWRLException

openRow

public void openRow()
             throws SQWRLException
Specified by:
openRow in interface ResultGenerator
Throws:
SQWRLException

addRowData

public void addRowData(ResultValue value)
                throws SQWRLException
Specified by:
addRowData in interface ResultGenerator
Throws:
SQWRLException

closeRow

public void closeRow()
              throws SQWRLException
Specified by:
closeRow in interface ResultGenerator
Throws:
SQWRLException

prepared

public void prepared()
              throws SQWRLException
Specified by:
prepared in interface ResultGenerator
Throws:
SQWRLException

getNumberOfRows

public int getNumberOfRows()
                    throws SQWRLException
Specified by:
getNumberOfRows in interface SQWRLResult
Throws:
SQWRLException

isEmpty

public boolean isEmpty()
                throws SQWRLException
Specified by:
isEmpty in interface SQWRLResult
Throws:
SQWRLException

reset

public void reset()
           throws SQWRLException
Specified by:
reset in interface SQWRLResult
Throws:
SQWRLException

next

public void next()
          throws SQWRLException
Specified by:
next in interface SQWRLResult
Throws:
SQWRLException

hasNext

public boolean hasNext()
                throws SQWRLException
Specified by:
hasNext in interface SQWRLResult
Throws:
SQWRLException

getRow

public List<ResultValue> getRow()
                         throws SQWRLException
Specified by:
getRow in interface SQWRLResult
Throws:
SQWRLException

getValue

public ResultValue getValue(String columnName)
                     throws SQWRLException
Specified by:
getValue in interface SQWRLResult
Throws:
SQWRLException

getValue

public ResultValue getValue(int columnIndex)
                     throws SQWRLException
Specified by:
getValue in interface SQWRLResult
Throws:
SQWRLException

getValue

public ResultValue getValue(int columnIndex,
                            int rowIndex)
                     throws SQWRLException
Specified by:
getValue in interface SQWRLResult
Throws:
SQWRLException

getObjectValue

public ObjectValue getObjectValue(String columnName)
                           throws SQWRLException
Specified by:
getObjectValue in interface SQWRLResult
Throws:
SQWRLException

getObjectValue

public ObjectValue getObjectValue(int columnIndex)
                           throws SQWRLException
Specified by:
getObjectValue in interface SQWRLResult
Throws:
SQWRLException

getDatatypeValue

public DatatypeValue getDatatypeValue(String columnName)
                               throws SQWRLException
Specified by:
getDatatypeValue in interface SQWRLResult
Throws:
SQWRLException

getClassValue

public ClassValue getClassValue(String columnName)
                         throws SQWRLException
Specified by:
getClassValue in interface SQWRLResult
Throws:
SQWRLException

getClassValue

public ClassValue getClassValue(int columnIndex)
                         throws SQWRLException
Specified by:
getClassValue in interface SQWRLResult
Throws:
SQWRLException

getPropertyValue

public PropertyValue getPropertyValue(int columnIndex)
                               throws SQWRLException
Specified by:
getPropertyValue in interface SQWRLResult
Throws:
SQWRLException

getPropertyValue

public PropertyValue getPropertyValue(String columnName)
                               throws SQWRLException
Specified by:
getPropertyValue in interface SQWRLResult
Throws:
SQWRLException

getDatatypeValue

public DatatypeValue getDatatypeValue(int columnIndex)
                               throws SQWRLException
Specified by:
getDatatypeValue in interface SQWRLResult
Throws:
SQWRLException

getColumn

public List<ResultValue> getColumn(String columnName)
                            throws SQWRLException
Specified by:
getColumn in interface SQWRLResult
Throws:
SQWRLException

getColumn

public List<ResultValue> getColumn(int columnIndex)
                            throws SQWRLException
Specified by:
getColumn in interface SQWRLResult
Throws:
SQWRLException

hasObjectValue

public boolean hasObjectValue(String columnName)
                       throws SQWRLException
Specified by:
hasObjectValue in interface SQWRLResult
Throws:
SQWRLException

hasObjectValue

public boolean hasObjectValue(int columnIndex)
                       throws SQWRLException
Specified by:
hasObjectValue in interface SQWRLResult
Throws:
SQWRLException

hasDatatypeValue

public boolean hasDatatypeValue(String columnName)
                         throws SQWRLException
Specified by:
hasDatatypeValue in interface SQWRLResult
Throws:
SQWRLException

hasDatatypeValue

public boolean hasDatatypeValue(int columnIndex)
                         throws SQWRLException
Specified by:
hasDatatypeValue in interface SQWRLResult
Throws:
SQWRLException

hasClassValue

public boolean hasClassValue(String columnName)
                      throws SQWRLException
Specified by:
hasClassValue in interface SQWRLResult
Throws:
SQWRLException

hasClassValue

public boolean hasClassValue(int columnIndex)
                      throws SQWRLException
Specified by:
hasClassValue in interface SQWRLResult
Throws:
SQWRLException

hasPropertyValue

public boolean hasPropertyValue(String columnName)
                         throws SQWRLException
Specified by:
hasPropertyValue in interface SQWRLResult
Throws:
SQWRLException

hasPropertyValue

public boolean hasPropertyValue(int columnIndex)
                         throws SQWRLException
Specified by:
hasPropertyValue in interface SQWRLResult
Throws:
SQWRLException

toString

public String toString()
Overrides:
toString in class Object

Protégé-OWL 3.4

Submit a bug report or feature request
Copyright (c) 1998-2009 Stanford University.