se.kmr.scam.editor.util
Class QueryModel

java.lang.Object
  extended byse.kmr.scam.editor.util.QueryModel

public class QueryModel
extends Object

Helper for a RDF-model defined as a QueryModel .
In a QueryModel a set of variables are deified, the inter-relation between the varaibles describes an abstract path . The abstract path defines a path to a value in the ValueModel that the variable represents.

NOTE: A variable represents the value of a property in the ValueModel. For properties that is repeated (or properties with multiple values) the corresponding variable is repeated. This means that a variable can be bound to more than one value.

Version:
$Revision: 1.30 $
Author:
Jöran
Created:
den 30 juli 2002

Nested Class Summary
 class QueryModel.QueryNode
           
 class QueryModel.QueryStatement
          A simple container class for shipping queryStatements back and forth.
 
Field Summary
static int BNODE
           
static int LITERAL
           
protected static Hashtable modelToQueryModel
           
static int RESOURCE
           
 
Constructor Summary
QueryModel(Model queryModel)
          Constructor for the QueryModel object
QueryModel(String rdfXmlFilepath)
          Constructor for the QueryModel object
 
Method Summary
 QueryBinding bind(ValueModel value)
          Method bind.
 QueryBinding bind(ValueModel value, boolean createMissing)
          Description of the Method
 QueryBinding createNewBindingForVariable(QueryBinding pointOfAttachement, Resource variable)
          Creates new triples in the value model along a path between two variables in the query, the triple-path starts from a given point of attachement (a resource bound in a QueryBinding) for the first variable.
 QueryBinding getBinding()
          Gets the binding attribute of the QueryModel object
 Model getModel()
          Gets the model attribute of the QueryModel object
 Resource getParameterVariable()
          Gets a resource defined as a parameter varaible in the QueryModel .
 int getParseType(Resource variable)
          Diggs out the parsetype for a variable via it's constraints.
 TreeSet getPredefinedValues(Resource variable, boolean literalValue)
          Method fetches predefined values according to the constraints given in the query.
 int getShortestPathLength(Resource startVariable, Resource endVariable)
          Finds the shortestpath between two variables.
 void setExternalModel(Model model)
          Sets a model to be used for constraint checks for non anonymous resource if they fail to match in the value-model.
 void setExternalModel(String rdfXmlFilePath)
          As setExternalModel(Model).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modelToQueryModel

protected static Hashtable modelToQueryModel

BNODE

public static final int BNODE
See Also:
Constant Field Values

RESOURCE

public static final int RESOURCE
See Also:
Constant Field Values

LITERAL

public static final int LITERAL
See Also:
Constant Field Values
Constructor Detail

QueryModel

public QueryModel(String rdfXmlFilepath)
           throws RDFException
Constructor for the QueryModel object

Parameters:
rdfXmlFilepath - Description of the Parameter
Throws:
RDFException - Description of the Exception

QueryModel

public QueryModel(Model queryModel)
           throws RDFException
Constructor for the QueryModel object

Parameters:
queryModel - Description of the Parameter
Throws:
RDFException - Description of the Exception
Method Detail

setExternalModel

public void setExternalModel(Model model)
Sets a model to be used for constraint checks for non anonymous resource if they fail to match in the value-model.

Parameters:
model - the external Model.

setExternalModel

public void setExternalModel(String rdfXmlFilePath)
                      throws RDFException
As setExternalModel(Model).

Throws:
RDFException

bind

public QueryBinding bind(ValueModel value,
                         boolean createMissing)
                  throws RDFException
Description of the Method

Parameters:
value - a model containing the data that should be bound into a querybinding tree.
createMissing - wether we want placeholder triples (either dummy-resources or empty literals for objects) to be created to cover for variables with no matches.
Returns:
the resulting tree of querybindings reachable from the top querybinding
Throws:
RDFException - if stuff go wrong.

bind

public QueryBinding bind(ValueModel value)
                  throws RDFException
Method bind.

Parameters:
value -
Returns:
QueryBinding
Throws:
RDFException

getBinding

public QueryBinding getBinding()
Gets the binding attribute of the QueryModel object

Returns:
The binding value

getModel

public Model getModel()
Gets the model attribute of the QueryModel object

Returns:
The model value

getParameterVariable

public Resource getParameterVariable()
                              throws RDFException
Gets a resource defined as a parameter varaible in the QueryModel . If the QueryModel defines more than one variable as parameter it is udefined which is returned.

Returns:
a resource defined as a parameter variable
Throws:
RDFException - Description of the Exception

getShortestPathLength

public int getShortestPathLength(Resource startVariable,
                                 Resource endVariable)
Finds the shortestpath between two variables.

Parameters:
startVariable -
endVariable -
Returns:
an int n if there is n intermediate variables between the startvariable and endvariable, -1 if there isn't a path between these variables.

createNewBindingForVariable

public QueryBinding createNewBindingForVariable(QueryBinding pointOfAttachement,
                                                Resource variable)
Creates new triples in the value model along a path between two variables in the query, the triple-path starts from a given point of attachement (a resource bound in a QueryBinding) for the first variable. The triple path is bound (i.e. the query paths free variables are bound) in a branch of querybindings where the uppermost querybinding are attached to the pointofattachement-querybinding given as attribute.

Parameters:
pointOfAttachement - a QueryBinding constituting the start variable and a resource to be the first subject in the triple path.
variable - constitutes the end of the path to be created.
Returns:
QueryBinding that holdes the first variablebinding for the newly created triple path (branch).

getPredefinedValues

public TreeSet getPredefinedValues(Resource variable,
                                   boolean literalValue)
Method fetches predefined values according to the constraints given in the query. WARNING, currently only one model is searched if there is an external model that one is searched otherwise the value model is searched. If neither is set (i.e. when there is no external model and no bind has been performed) null is returned.

Parameters:
variable - to search predefined values for.
literalValue - tells wether literals is acceptable as predefined values.
Returns:
Collection of PredefinedObjects or null if no one where found.

getParseType

public int getParseType(Resource variable)
                 throws RDFException
Diggs out the parsetype for a variable via it's constraints. It's either Bnode, Resource or Literal. Literal is default.

Throws:
RDFException


Copyright © 2003 SCAM. All Rights Reserved.