info.sswap.impl.empire.model
Class RQGImpl

java.lang.Object
  extended by info.sswap.impl.empire.model.ModelImpl
      extended by info.sswap.impl.empire.model.SourceModelImpl
          extended by info.sswap.impl.empire.model.ProtocolImpl
              extended by info.sswap.impl.empire.model.RQGImpl
All Implemented Interfaces:
com.clarkparsia.empire.SupportsRdfId, RQG, SSWAPDocument, SSWAPModel, SSWAPProtocol, SourceModel

public abstract class RQGImpl
extends ProtocolImpl
implements RQG

Implementation of RQG interface

Author:
Blazej Bulka

Nested Class Summary
 
Nested classes/interfaces inherited from class info.sswap.impl.empire.model.ProtocolImpl
ProtocolImpl.DefaultMappingValidator<T extends SSWAPNode>, ProtocolImpl.MappingValidator<T>
 
Nested classes/interfaces inherited from interface com.clarkparsia.empire.SupportsRdfId
com.clarkparsia.empire.SupportsRdfId.BNodeKey, com.clarkparsia.empire.SupportsRdfId.RdfKey<T>, com.clarkparsia.empire.SupportsRdfId.URIKey
 
Field Summary
private static java.lang.String DEFAULT_DISCOVERY_SERVER
          The default URL of the discovery server that is used when the system property did not specify one.
private static java.lang.String DISCOVERY_SERVER_PROPERTY_NAME
          The name of the system property that is used to retrieve the URI of the discovery server.
private static int QUERY_INDENT
          The width of the indentation in the generated SPARQL query.
private  boolean resourceValidationEnabled
           
 
Fields inherited from class info.sswap.impl.empire.model.SourceModelImpl
SSWAP_ONTOLOGY_URI
 
Constructor Summary
RQGImpl()
           
 
Method Summary
 java.util.Collection<java.lang.String> executeQuery(com.hp.hpl.jena.rdf.model.Model... models)
          Creates and executes a SPARQL query that determines which RDGs match this RQG.
private  java.lang.String generateRegexRestriction(java.lang.String varName, int indent, java.lang.String propertyName, java.lang.String propertyValueVar, java.lang.Object propertyValueRestriction)
           
private  java.lang.String generateRestriction(java.lang.String varName, int indent, java.lang.String propertyName, java.lang.String propertyValueVar, java.lang.Object propertyValueRestriction)
           
private  java.lang.String generateSubClassRestriction(int indentLevel, java.lang.String var, SSWAPIndividual individual)
          Generates a restriction that the type of matched individuals is a subclass of the types of the specified individual
private  java.lang.String generateSubjectRestriction(int indentLevel, java.lang.String var, SSWAPSubject subject)
          Creates the part of the query that matches the RQG's subject with RDGs' subjects.
private  java.lang.String getDefaultDiscoveryServerURL()
           
 java.lang.String getGraphType()
          Gets the human readable name of the particular graph implementation (e.g., RDG, RQG, RIG, RRG) This method is mostly provided to generate meaningful messages in exceptions (rather than to include class name, which may not be familiar to most users)
protected  ProtocolImpl.MappingValidator<SSWAPObject> getObjectMappingValidator()
           
 java.lang.String getQuery()
          Gets a SPARQL query that can be executed over a model containing RDGs to determine which RDGs match this RQG.
protected  ProtocolImpl.MappingValidator<SSWAPResource> getResourceMappingValidator()
           
protected  ProtocolImpl.MappingValidator<SSWAPSubject> getSubjectMappingValidator()
           
private static java.lang.String indent(int level)
          Utility method that generates the desired inddentation level (consisting of spaces).
 java.util.Collection<RDG> invoke()
          Sends this RQG as a query to the default Discovery Server
 java.util.Collection<RDG> invoke(java.net.URI discoveryServerURIString)
          Sends this RQG as a query to the specified discovery server instance.
 boolean isResourceValidationEnabled()
           
protected  boolean needsClosedWorldForValidation()
           
 boolean needsDefaultParametersSet()
          Returns information whether this object needs default values of parameters set during validation against RDG (i.e., default values for sswap:Resource or sswap:Subject).
private  java.lang.String querySafe(java.lang.String value)
           
 boolean satisfiesResource(RDG rdg)
          Checks whether this RQG matches the given RDG
 void setResourceValidationEnabled(boolean resourceValidationEnabled)
           
 boolean validatesResourceURIMatch()
           
 
Methods inherited from class info.sswap.impl.empire.model.ProtocolImpl
anonymizeSSWAPNodes, closeWorld, createCopyObject, createGraph, createObject, createObject, createResource, createSubject, createSubject, dereference, doClosure, getGraph, getMappings, getObject, getObjectMappings, getPattern, getProvider, getResource, getResources, getSubject, getSubjectMappings, getTranslationMap, isMultiGraphs, isPattern, serialize, setMatchingGraphs, supportsTranslation, uncloseWorld, validate, validate, validateAgainstRDG, validatesObjects
 
Methods inherited from class info.sswap.impl.empire.model.SourceModelImpl
addDependentModel, addImport, checkProfile, createAnonymousDatatype, createAnonymousRestrictionType, createAnonymousType, createIndividual, createIndividual, createIntersectionOf, createList, createLiteral, createTypedLiteral, createUnionOf, dereference, dereference, dereference, equals, getClosedWorldModel, getClosureModel, getDatatype, getDependentModel, getDependentModel, getDependentModels, getEntityManager, getImports, getInferredABox, getInferredTBox, getIntersectionType, getMaxClosureBytes, getMaxClosureThreads, getMaxClosureTime, getModel, getModelResolver, getNsPrefixMap, getPredicate, getReasoningService, getType, hashCode, hasJenaModel, isClosureEnabled, isOwlDlRequired, isValueValidationEnabled, newIndividual, newIndividual, persist, refresh, removeDependentModel, removeImport, removeNsPrefix, resetReasoningService, serialize, setClosureEnabled, setClosureModel, setEntityManager, setMaxClosureBytes, setMaxClosureThreads, setMaxClosureTime, setModel, setNsPrefix, setOwlDlRequired, setValueValidationEnabled
 
Methods inherited from class info.sswap.impl.empire.model.ModelImpl
assertModel, assertSourceModel, getAllDependentObjects, getDependentObject, getDocument, getExpressivity, getInputStream, getSourceModel, getTypeSignature, getURI, hasSourceModel, hasSourceModelWithEntityManager, isDereferenced, rdfIdEquals, rdfIdHashCode, refreshSiblings, setDereferenced, setSourceModel, setURI
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface info.sswap.api.model.SSWAPProtocol
createGraph, createObject, createObject, createSubject, createSubject, getMappings, getProvider, getResource, isMultiGraphs, isPattern
 
Methods inherited from interface info.sswap.api.model.SSWAPDocument
createAnonymousDatatype, createAnonymousType, createIndividual, createIndividual, createIntersectionOf, createList, createLiteral, createTypedLiteral, createUnionOf, getDatatype, getPredicate, getType, newIndividual, newIndividual
 
Methods inherited from interface info.sswap.api.model.SSWAPModel
addImport, checkProfile, dereference, dereference, doClosure, getDocument, getImports, getInputStream, getNsPrefixMap, getReasoningService, getTypeSignature, getURI, isDereferenced, removeImport, removeNsPrefix, serialize, serialize, setNsPrefix, validate
 
Methods inherited from interface info.sswap.impl.empire.model.SourceModel
isDereferenced
 
Methods inherited from interface com.clarkparsia.empire.SupportsRdfId
getRdfId, setRdfId
 

Field Detail

DISCOVERY_SERVER_PROPERTY_NAME

private static final java.lang.String DISCOVERY_SERVER_PROPERTY_NAME
The name of the system property that is used to retrieve the URI of the discovery server.

See Also:
Constant Field Values

DEFAULT_DISCOVERY_SERVER

private static final java.lang.String DEFAULT_DISCOVERY_SERVER
The default URL of the discovery server that is used when the system property did not specify one.

See Also:
Constant Field Values

QUERY_INDENT

private static final int QUERY_INDENT
The width of the indentation in the generated SPARQL query.

See Also:
Constant Field Values

resourceValidationEnabled

private boolean resourceValidationEnabled
Constructor Detail

RQGImpl

public RQGImpl()
Method Detail

getQuery

public java.lang.String getQuery()
Description copied from interface: RQG
Gets a SPARQL query that can be executed over a model containing RDGs to determine which RDGs match this RQG. The model containing RDGs should contain inferred facts for these models (i.e., it should be either a model that contains previously computed inferences, or be backed by a reasoner to compute them dynamically; e.g., an OntModel). Additionally, the execution environment for the query should take into account the inferred facts for this RQG.

Specified by:
getQuery in interface RQG
Returns:
the SPARQL query.

querySafe

private java.lang.String querySafe(java.lang.String value)

generateRestriction

private java.lang.String generateRestriction(java.lang.String varName,
                                             int indent,
                                             java.lang.String propertyName,
                                             java.lang.String propertyValueVar,
                                             java.lang.Object propertyValueRestriction)

generateRegexRestriction

private java.lang.String generateRegexRestriction(java.lang.String varName,
                                                  int indent,
                                                  java.lang.String propertyName,
                                                  java.lang.String propertyValueVar,
                                                  java.lang.Object propertyValueRestriction)

executeQuery

public java.util.Collection<java.lang.String> executeQuery(com.hp.hpl.jena.rdf.model.Model... models)
Description copied from interface: RQG
Creates and executes a SPARQL query that determines which RDGs match this RQG. The query is executed over (potentially) multiple models that contain closures and inferred statements about the RDGs. The implementation of this method will also take into account the closure and inferred statements about this RQG when executiong the query.

Specified by:
executeQuery in interface RQG
Parameters:
models - models containing RDGs, their closures and inferred statements
Returns:
a collection of URIs of matching RDGs

indent

private static java.lang.String indent(int level)
Utility method that generates the desired inddentation level (consisting of spaces).

Parameters:
level - the indentation level
Returns:
the spaces to create the desired indentation level

generateSubjectRestriction

private java.lang.String generateSubjectRestriction(int indentLevel,
                                                    java.lang.String var,
                                                    SSWAPSubject subject)
Creates the part of the query that matches the RQG's subject with RDGs' subjects. The intention is that for any RDG matched, the subject's type of that RDG is a superclass of the RQG's subject's type. Since the query is executed against a model with inference results, for every instance you can obtain all of their types (including inferred types) by querying the model for the instance's rdf:type property. When this information is present, it is possible to rephrase the above matching rule (RDGs subject type must be a superclass of the RQGs subject type) as: the set of types for the RDG's subject instance must be a subset of the set of types for the RQG's subject. The query generated by this method takes advantage of that reformulated matching rule; that is, it tries to determine for a subject whether it contains any rdf:type statements that do not appear in the set of types for the RQG's subject. Next, it filters all the subjects that had any such rdf:type statements (i.e., the set of types for the RDG's subject is not a subset of the types of RQG's subject).

Parameters:
indentLevel - the base indentation level for the generated restriction (so that it lines up with other conditions on the same logical level)
var - the variable used to bind the subject in the encompassing query
subject - the SSWAPSubject for the RQG
Returns:
the part of the query that contains the restriction on the subject

generateSubClassRestriction

private java.lang.String generateSubClassRestriction(int indentLevel,
                                                     java.lang.String var,
                                                     SSWAPIndividual individual)
Generates a restriction that the type of matched individuals is a subclass of the types of the specified individual

Parameters:
indentLevel - the base indentation level of the generated restriction (so that it lines up with other parts of the query at the same logical level of nesting)
var - the variable used to match the individual
individual - the individual whose types should be included in the restriction
Returns:
the part of the query that contains the restriction

invoke

public java.util.Collection<RDG> invoke()
                                 throws java.io.IOException,
                                        DataAccessException
Description copied from interface: RQG
Sends this RQG as a query to the default Discovery Server

Specified by:
invoke in interface RQG
Returns:
the collection of RDGs matching the query
Throws:
java.io.IOException - if an I/O error should occur
DataAccessException - if there is a problem retrieving/reading RDGs for the services returned by the discovery server

invoke

public java.util.Collection<RDG> invoke(java.net.URI discoveryServerURIString)
                                 throws java.io.IOException,
                                        DataAccessException
Description copied from interface: RQG
Sends this RQG as a query to the specified discovery server instance.

Specified by:
invoke in interface RQG
Parameters:
discoveryServerURIString - the URI of the Discovery Server query end-point (may be null; in such a case, the default DS will be used)
Returns:
the collection of RDGs matching the query
Throws:
java.io.IOException - if an I/O error should occur
DataAccessException - if there is a problem retrieving/reading RDGs for the services returned by the discovery server

getDefaultDiscoveryServerURL

private java.lang.String getDefaultDiscoveryServerURL()

getGraphType

public java.lang.String getGraphType()
Description copied from class: ProtocolImpl
Gets the human readable name of the particular graph implementation (e.g., RDG, RQG, RIG, RRG) This method is mostly provided to generate meaningful messages in exceptions (rather than to include class name, which may not be familiar to most users)

Specified by:
getGraphType in class ProtocolImpl
Returns:
the name of this protocol graph implementation

needsClosedWorldForValidation

protected boolean needsClosedWorldForValidation()
Overrides:
needsClosedWorldForValidation in class ProtocolImpl

satisfiesResource

public boolean satisfiesResource(RDG rdg)
Description copied from interface: RQG
Checks whether this RQG matches the given RDG

Specified by:
satisfiesResource in interface RQG
Parameters:
rdg - the RDG
Returns:
true if this RQG matches the given RDG, false otherwise

validatesResourceURIMatch

public boolean validatesResourceURIMatch()
Overrides:
validatesResourceURIMatch in class ProtocolImpl

needsDefaultParametersSet

public boolean needsDefaultParametersSet()
Description copied from class: ProtocolImpl
Returns information whether this object needs default values of parameters set during validation against RDG (i.e., default values for sswap:Resource or sswap:Subject). Most protocol types require values of default parameters.

Overrides:
needsDefaultParametersSet in class ProtocolImpl
Returns:
true if this object requires default values of parameters

getResourceMappingValidator

protected ProtocolImpl.MappingValidator<SSWAPResource> getResourceMappingValidator()
Overrides:
getResourceMappingValidator in class ProtocolImpl

setResourceValidationEnabled

public void setResourceValidationEnabled(boolean resourceValidationEnabled)

isResourceValidationEnabled

public boolean isResourceValidationEnabled()

getSubjectMappingValidator

protected ProtocolImpl.MappingValidator<SSWAPSubject> getSubjectMappingValidator()
Overrides:
getSubjectMappingValidator in class ProtocolImpl

getObjectMappingValidator

protected ProtocolImpl.MappingValidator<SSWAPObject> getObjectMappingValidator()
Overrides:
getObjectMappingValidator in class ProtocolImpl


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.