org.topbraid.spin.util
Class SPINUtil

java.lang.Object
  extended by org.topbraid.spin.util.SPINUtil

public class SPINUtil
extends java.lang.Object

Some static util methods for SPIN that don't fit anywhere else.

Author:
Holger Knublauch

Field Summary
static java.lang.String TYPE_CLASS_VAR_NAME
          The name of the variable that will be used in type binding triple patterns (?this rdf:type ?TYPE_CLASS)
 
Constructor Summary
SPINUtil()
           
 
Method Summary
static void addQueryOrTemplateCalls(Resource cls, Property predicate, java.util.List<QueryOrTemplateCall> results)
          Collects all queries or template calls at a given class.
static java.lang.String addThisTypeClause(java.lang.StringBuilder sb)
          Inserts a statement ?this a ?TYPE_CLASS .
static void applyBindings(java.util.Map<Property,RDFNode> map, java.util.Map<java.lang.String,RDFNode> bindings)
          Applies variable bindings, replacing the values of one map with the values from a given variables map.
static void bindThis(QueryExecution qexec, RDFNode value)
          Binds the variable ?this with a given value.
static boolean containsThis(Query query)
          Checks whether a given query mentions the variable ?this anywhere.
static java.lang.String getQueryString(RDFNode node, boolean usePrefixes)
          Attempts to convert a given RDFNode to a String so that it can be parsed into a Jena query object.
static java.util.Set<java.lang.String> getQueryStrings(Resource subject, Property property)
          Gets a Collection of all query strings defined as values of a given property.
static java.util.Set<Resource> getURIResources(Query query)
           
static java.util.Map<java.lang.String,RDFNode> mapProperty2VarNames(java.util.Map<Property,RDFNode> map)
          Converts a map from Properties to RDFNode values to a Map from variable names (Strings) to those values, for quicker look up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_CLASS_VAR_NAME

public static final java.lang.String TYPE_CLASS_VAR_NAME
The name of the variable that will be used in type binding triple patterns (?this rdf:type ?TYPE_CLASS)

See Also:
Constant Field Values
Constructor Detail

SPINUtil

public SPINUtil()
Method Detail

addQueryOrTemplateCalls

public static void addQueryOrTemplateCalls(Resource cls,
                                           Property predicate,
                                           java.util.List<QueryOrTemplateCall> results)
Collects all queries or template calls at a given class.

Parameters:
cls - the class to get the queries at
predicate - the predicate such as spin:rule
results - the List to add the results to

addThisTypeClause

public static java.lang.String addThisTypeClause(java.lang.StringBuilder sb)
Inserts a statement ?this a ?TYPE_CLASS . after the WHERE { keyword.

Parameters:
sb - the StringBuilder to manipulate
Returns:
the variable name of the ?TYPE_CLASS variable

applyBindings

public static void applyBindings(java.util.Map<Property,RDFNode> map,
                                 java.util.Map<java.lang.String,RDFNode> bindings)
Applies variable bindings, replacing the values of one map with the values from a given variables map.

Parameters:
map - the Map to modify
bindings - the current variable bindings

bindThis

public static void bindThis(QueryExecution qexec,
                            RDFNode value)
Binds the variable ?this with a given value.

Parameters:
qexec - the QueryExecution to modify
value - the value to bind ?this with

containsThis

public static boolean containsThis(Query query)
Checks whether a given query mentions the variable ?this anywhere. This can be used to check whether ?this needs to be bound before execution, etc.

Parameters:
query - the query to test
Returns:
true if query mentions ?this

getQueryString

public static java.lang.String getQueryString(RDFNode node,
                                              boolean usePrefixes)
Attempts to convert a given RDFNode to a String so that it can be parsed into a Jena query object. The node must be either a string Literal, or a sp:Query node or a template call. If it's a template call then the resulting query string will have additional LET statements to "hard-bind" the template variables.

Parameters:
node - the RDFNode to convert
usePrefixes - true to use qname abbreviations
Returns:
the String representation of node
Throws:
java.lang.IllegalArgumentException - if the node is not a valid SPIN Query or a String

getQueryStrings

public static java.util.Set<java.lang.String> getQueryStrings(Resource subject,
                                                              Property property)
Gets a Collection of all query strings defined as values of a given property. This will accept strings or SPIN expressions (including template calls). The query model is the subject's getModel(). All sub-properties of property from the query model will also be queried.

Parameters:
subject - the subject to get the values of
property - the property to query
Returns:
a Set of query strings

getURIResources

public static java.util.Set<Resource> getURIResources(Query query)

mapProperty2VarNames

public static java.util.Map<java.lang.String,RDFNode> mapProperty2VarNames(java.util.Map<Property,RDFNode> map)
Converts a map from Properties to RDFNode values to a Map from variable names (Strings) to those values, for quicker look up.

Parameters:
map - the old Map
Returns:
the new Map