org.semwebcentral.sweetrules.sweetxsb
Class SweetXSBQueryXSBAdapterTask

java.lang.Object
  extended byorg.semwebcentral.sweetrules.sweetxsb.AbstractSweetXSBQueryAdapterTask
      extended byorg.semwebcentral.sweetrules.sweetxsb.SweetXSBQueryXSBAdapterTask
All Implemented Interfaces:
ISweetInferenceEngineTask

public class SweetXSBQueryXSBAdapterTask
extends AbstractSweetXSBQueryAdapterTask
implements ISweetInferenceEngineTask

XSB query adapter task

Author:
Shashidhara K Ganjugunte, Dr. Benjamin Grosof, Dr. Said Tabet, Chitravanu Neogy

Field Summary
private static Logger logger
          Logger object for this class
private  java.lang.String queryString
          The queryString to be executed
 
Fields inherited from class org.semwebcentral.sweetrules.sweetxsb.AbstractSweetXSBQueryAdapterTask
sweetDisambigDummyPredicatePrefix, sweetDummyPredicateName, xsbEngine
 
Constructor Summary
SweetXSBQueryXSBAdapterTask(java.lang.String xsbQuery, java.lang.String dummyPredicateName, java.lang.String disambigDummyPredicatePrefix, SweetXSBEngine engine)
          Constructor for the XSB adapter
 
Method Summary
protected  java.lang.String[] applyAllSubstitutions(java.lang.String query, java.util.Vector varNameVector, java.util.Vector answerBindingMatrix)
          Provides an abstraction of applying substitutions
private  ISweetQueryResult createGoalAndExecuteQuery(java.lang.String xsbQuery, java.util.Vector varNameVector)
          Creates the goal in the XSB form and executes the query
 java.lang.Object execute()
          Implementation of execute method
protected  java.lang.String[] generateBindingList(java.util.Vector varNameVector, java.util.Vector answerBindingMatrix)
          Provides the abstraction of generating the binding list
private  java.lang.String generateCanonicalXSBQuery(java.lang.String xsbQuery, java.util.Vector emptyVariableNameVector)
          Generates a canonical XSB query in the form of dummyPredicate (...) :- actualQuery(...)
private  void loadQuery(java.lang.String canonicalXSBQuery, java.util.Vector variableNameVector)
          Loads the query into XSB
 
Methods inherited from class org.semwebcentral.sweetrules.sweetxsb.AbstractSweetXSBQueryAdapterTask
executeAbolishDummyPredicates, flattenAndDetectNonGroundTerms, generateQueryResultForGroundQuery, generateQueryResultForNonGroundQuery, generateTermModelAnswerSets, getEntailedAnswerSetMatrix, processSingleBinding, pruneAndgetUndefinedAnswerSetMatrix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queryString

private java.lang.String queryString
The queryString to be executed


logger

private static Logger logger
Logger object for this class

Constructor Detail

SweetXSBQueryXSBAdapterTask

public SweetXSBQueryXSBAdapterTask(java.lang.String xsbQuery,
                                   java.lang.String dummyPredicateName,
                                   java.lang.String disambigDummyPredicatePrefix,
                                   SweetXSBEngine engine)
Constructor for the XSB adapter

Parameters:
xsbQuery - The xsb query to be executed
dummyPredicateName - The name of the dummy predicate
disambigDummyPredicatePrefix - The prefix for the dummy predicate to be used while disambiguating the undefined value
engine - The xsb engine instance
Method Detail

execute

public java.lang.Object execute()
                         throws SweetInferenceEngineException
Implementation of execute method

Specified by:
execute in interface ISweetInferenceEngineTask
Returns:
The result of query execution
Throws:
SweetInferenceEngineException

generateCanonicalXSBQuery

private java.lang.String generateCanonicalXSBQuery(java.lang.String xsbQuery,
                                                   java.util.Vector emptyVariableNameVector)
Generates a canonical XSB query in the form of dummyPredicate (...) :- actualQuery(...) Note that the arguments to the dummyPredicate are just variables in the actual query. If there are no variables in the actual query it will be of the form: dummyPredicate :- actualQuery(...)

Parameters:
xsbQuery - The actual xsb query
emptyVariableNameVector - An instance of Vector class into which the variable names will be stored
Returns:
The canonical query (sideeffect is to fill the emptyVariableNameVector).

loadQuery

private void loadQuery(java.lang.String canonicalXSBQuery,
                       java.util.Vector variableNameVector)
                throws SweetInferenceEngineException
Loads the query into XSB

Parameters:
canonicalXSBQuery - The canonical XSB query
variableNameVector - The variable name vector
Throws:
SweetInferenceEngineException - if an error occurs

createGoalAndExecuteQuery

private ISweetQueryResult createGoalAndExecuteQuery(java.lang.String xsbQuery,
                                                    java.util.Vector varNameVector)
                                             throws SweetInferenceEngineException
Creates the goal in the XSB form and executes the query

Parameters:
xsbQuery - The xsb query
varNameVector - The vector of variables
Returns:
The answer set to the query
Throws:
SweetInferenceEngineException - if an error occurs

applyAllSubstitutions

protected java.lang.String[] applyAllSubstitutions(java.lang.String query,
                                                   java.util.Vector varNameVector,
                                                   java.util.Vector answerBindingMatrix)
                                            throws SweetInferenceEngineException
Provides an abstraction of applying substitutions

Specified by:
applyAllSubstitutions in class AbstractSweetXSBQueryAdapterTask
Parameters:
query - The query on which substitutions need to be applied
varNameVector - The vector of the variables
answerBindingMatrix - The matrix having the bindings of the variables
Returns:
An array of strings after applying all substitutions
Throws:
SweetInferenceEngineException - if an error occurs

generateBindingList

protected java.lang.String[] generateBindingList(java.util.Vector varNameVector,
                                                 java.util.Vector answerBindingMatrix)
                                          throws SweetInferenceEngineException
Provides the abstraction of generating the binding list

Specified by:
generateBindingList in class AbstractSweetXSBQueryAdapterTask
Parameters:
varNameVector - The vector of variables
answerBindingMatrix - The values of the variables in the form of an answer binding list
Returns:
An array of Strings having the result of the application of bindings
Throws:
SweetInferenceEngineException