org.semwebcentral.sweetrules.sweetxsb
Class AbstractSweetXSBQueryAdapterTask

java.lang.Object
  extended byorg.semwebcentral.sweetrules.sweetxsb.AbstractSweetXSBQueryAdapterTask
Direct Known Subclasses:
SweetRuleMLQueryXSBAdapterTask, SweetXSBQueryXSBAdapterTask

public abstract class AbstractSweetXSBQueryAdapterTask
extends java.lang.Object

This class provides an abstraction of the XSBQuery. Mainly used for code sharing between different formats which need to do reasoning with XSB

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

Field Summary
protected static Logger logger
          This represents the logger object
protected  java.lang.String sweetDisambigDummyPredicatePrefix
          The predicate name used to disambiguate undefined answers in XSB
protected  java.lang.String sweetDummyPredicateName
          The predicate name for the dummy predicate used to generate the normal form
protected  SweetXSBEngine xsbEngine
          The SweetXSBEngine associated with this task
 
Constructor Summary
protected AbstractSweetXSBQueryAdapterTask(java.lang.String dummyPredicateName, java.lang.String disambigDummyPredicatePrefix, SweetXSBEngine engine)
          Constructor for the abstract task
 
Method Summary
protected abstract  java.lang.String[] applyAllSubstitutions(java.lang.String query, java.util.Vector varNameVector, java.util.Vector answerBindingMatrix)
          Provides an abstraction of applying substitutions
protected  void executeAbolishDummyPredicates(int arity)
          Function to clean up the dummy predicates
protected  void flattenAndDetectNonGroundTerms(TermModel termModel, java.util.Vector completeAnswerSetMatrix, java.util.Vector groundAnswerSetMatrix, java.util.Vector nonGroundAnswerSetMatrix)
          Method to convert the TermModel object to a matrix where each row represents a binding set.
protected abstract  java.lang.String[] generateBindingList(java.util.Vector varNameVector, java.util.Vector answerBindingMatrix)
          Provides the abstraction of generating the binding list
protected  ISweetQueryResult generateQueryResultForGroundQuery(java.lang.String query)
          Handles the execution of a ground query
protected  ISweetQueryResult generateQueryResultForNonGroundQuery(java.lang.String query, java.util.Vector varNameVector)
          Handles the case where the query has Non Ground terms
protected  TermModel[] generateTermModelAnswerSets(java.util.Vector varNameVector)
          Returns the results in the form of TermModels.
protected  java.util.Vector getEntailedAnswerSetMatrix(java.util.Vector allAnswerSetMatrix, java.util.Vector disambigAnswerSetMatrix, java.util.Vector groundAnswerSetMatrix, java.util.Vector nonGroundAnswerSetMatrix)
          Returns the entailedAnswerSetMatrix based on the presence/absence of the ground terms in the original answer set matrix
protected  boolean processSingleBinding(TermModel singleBindingTerm, java.util.Vector answerVector)
           
protected  java.util.Vector pruneAndgetUndefinedAnswerSetMatrix(java.util.Vector disambigAnswerSetMatrix, java.util.Vector allAnswerSetMatrix)
          This is a method with side effect of pruning the answer set from the undefined answer set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xsbEngine

protected SweetXSBEngine xsbEngine
The SweetXSBEngine associated with this task


sweetDummyPredicateName

protected java.lang.String sweetDummyPredicateName
The predicate name for the dummy predicate used to generate the normal form


sweetDisambigDummyPredicatePrefix

protected java.lang.String sweetDisambigDummyPredicatePrefix
The predicate name used to disambiguate undefined answers in XSB


logger

protected static Logger logger
This represents the logger object

Constructor Detail

AbstractSweetXSBQueryAdapterTask

protected AbstractSweetXSBQueryAdapterTask(java.lang.String dummyPredicateName,
                                           java.lang.String disambigDummyPredicatePrefix,
                                           SweetXSBEngine engine)
Constructor for the abstract task

Parameters:
dummyPredicateName - The dummy Predicate name
disambigDummyPredicatePrefix - The predicate which will be used to disambiguate the undefined Vs true queries
engine - The engine instance on which to execute the task
Method Detail

generateQueryResultForNonGroundQuery

protected ISweetQueryResult generateQueryResultForNonGroundQuery(java.lang.String query,
                                                                 java.util.Vector varNameVector)
                                                          throws SweetInferenceEngineException
Handles the case where the query has Non Ground terms

Parameters:
query - Query to be handled
varNameVector - The variables in the query
Returns:
The result of executing the query
Throws:
SweetInferenceEngineException - if an error occurs

generateQueryResultForGroundQuery

protected ISweetQueryResult generateQueryResultForGroundQuery(java.lang.String query)
Handles the execution of a ground query

Parameters:
query - Query to be processed
Returns:
The result of processing the query

generateTermModelAnswerSets

protected TermModel[] generateTermModelAnswerSets(java.util.Vector varNameVector)
                                           throws SweetInferenceEngineException
Returns the results in the form of TermModels. This is specific to XSB

Parameters:
varNameVector - The vector of the variables in the query
Returns:
A 2-element array of term models. The first one having the answers to the query alone and the second one having the answer to the query and it's negation together. The second part is used to disambiguate the undefined case
Throws:
SweetInferenceEngineException

applyAllSubstitutions

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

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 abstract java.lang.String[] generateBindingList(java.util.Vector varNameVector,
                                                          java.util.Vector answerBindingMatrix)
                                                   throws SweetInferenceEngineException
Provides the abstraction of generating the binding list

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

pruneAndgetUndefinedAnswerSetMatrix

protected java.util.Vector pruneAndgetUndefinedAnswerSetMatrix(java.util.Vector disambigAnswerSetMatrix,
                                                               java.util.Vector allAnswerSetMatrix)
This is a method with side effect of pruning the answer set from the undefined answer set. The residual allAnswerSet will have only the entailed answers.

Parameters:
disambigAnswerSetMatrix - The pruning is based on the contents of this matrix which has the "yes" answer for a query and it's negation
allAnswerSetMatrix - The matrix having both defined && undefined answers. It will be pruned to have only defined answers
Returns:
The undefined (pruned) answers

getEntailedAnswerSetMatrix

protected java.util.Vector getEntailedAnswerSetMatrix(java.util.Vector allAnswerSetMatrix,
                                                      java.util.Vector disambigAnswerSetMatrix,
                                                      java.util.Vector groundAnswerSetMatrix,
                                                      java.util.Vector nonGroundAnswerSetMatrix)
Returns the entailedAnswerSetMatrix based on the presence/absence of the ground terms in the original answer set matrix

Parameters:
allAnswerSetMatrix - The complete answer set matrix
disambigAnswerSetMatrix - The answer set having "yes" answers to the query and it's negation
groundAnswerSetMatrix - The answer set with only ground answers
nonGroundAnswerSetMatrix - The answer set with non-ground answers
Returns:
A vector with only the entailed answers based on contract in ISweetQueryResult

flattenAndDetectNonGroundTerms

protected void flattenAndDetectNonGroundTerms(TermModel termModel,
                                              java.util.Vector completeAnswerSetMatrix,
                                              java.util.Vector groundAnswerSetMatrix,
                                              java.util.Vector nonGroundAnswerSetMatrix)
Method to convert the TermModel object to a matrix where each row represents a binding set. It flattens the list structure of the TermModel. The binding list contained in TermModel (based on my observations) is of the form if there is more than 1 variable in the query [[BINDINGLIST1], [LIST OF REST OF THE BINDINGLIST]] if there is only 1 variable in the query [BINDING1, [LIST OF OTHER BINDINGS]] For e.g. if the answer to the query predicate(X,Y) is {{X/abc,Y/def}, {X/abc1, Y/def1}, {X/abc2, Y/def2}} The term model returned will be [[abc def], [[abc1 def] [abc2 def2]] But if the query predicate is predicate(X) with answer set {{X/abc}, {X/abc1}, {X/abc2}} [abc, [abc1, abc2]] It follows the car and cdr paradigms in LISP

Parameters:
termModel - The TermModel object to flatten
completeAnswerSetMatrix - The output matrix with both the non-ground and ground results
groundAnswerSetMatrix - The output matrix with only the ground answers
nonGroundAnswerSetMatrix - The output matrix which has the non-ground answers

processSingleBinding

protected boolean processSingleBinding(TermModel singleBindingTerm,
                                       java.util.Vector answerVector)

executeAbolishDummyPredicates

protected void executeAbolishDummyPredicates(int arity)
                                      throws SweetInferenceEngineException
Function to clean up the dummy predicates

Parameters:
arity - The arity of the dummy predicates
Throws:
SweetInferenceEngineException - if an error occurs