Package org.projog.api
Class QueryResult
- java.lang.Object
-
- org.projog.api.QueryResult
-
public final class QueryResult extends java.lang.ObjectRepresents an executing query.
-
-
Constructor Summary
Constructors Constructor Description QueryResult(PredicateFactory predicateFactory, Term query, java.util.Map<java.lang.String,Variable> variables)Evaluates a query.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanevaluate()java.lang.StringgetAtomName(java.lang.String variableId)Returns the name of the atom instantiated to the variable with the specified id.doublegetDouble(java.lang.String variableId)Returns thedoublevalue instantiated to the variable with the specified id.longgetLong(java.lang.String variableId)Returns thelongvalue instantiated to the variable with the specified id.TermgetTerm(java.lang.String variableId)Returns the term instantiated to the variable with the specified id.java.util.Set<java.lang.String>getVariableIds()Returns id's of all variables defined in the query this object represents.booleanisExhausted()Returnstrueif it is known that all possible solutions have been found, elsefalse.booleannext()Attempts to evaluate the query this object represents.
-
-
-
Constructor Detail
-
QueryResult
QueryResult(PredicateFactory predicateFactory, Term query, java.util.Map<java.lang.String,Variable> variables)
Evaluates a query.- Parameters:
PredicateFactory- thePredicateFactorythat will be used to evaluate the queryquery- represents the query statement being evaluatedvariables- collection of variables contained in the query (keyed by variable id)- See Also:
QueryStatement.executeQuery()
-
-
Method Detail
-
next
public boolean next()
Attempts to evaluate the query this object represents.Subsequent calls of the
next()method attempt to reevaluate the query, and because it returnsfalsewhen the are no more results, it can be used in awhileloop to iterate through all the results.- Returns:
trueif the query was (re)evaluated successfully orfalseif there are no more results. Oncefalsehas been returned bynext()thenext()method should no longer be called on that object.- Throws:
ProjogException- if an error occurs while evaluating the query
-
evaluate
private boolean evaluate()
-
isExhausted
public boolean isExhausted()
Returnstrueif it is known that all possible solutions have been found, elsefalse.- Returns:
trueif it is known that all possible solutions have been found, elsefalse.- See Also:
Predicate.couldReevaluationSucceed()
-
getAtomName
public java.lang.String getAtomName(java.lang.String variableId)
Returns the name of the atom instantiated to the variable with the specified id.- Parameters:
variableId- the id of the variable from which to return the instantiated term- Returns:
- the name of the atom instantiated to the variable with the specified id
- Throws:
ProjogException- if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not an atom- See Also:
getTerm(String)
-
getDouble
public double getDouble(java.lang.String variableId)
Returns thedoublevalue instantiated to the variable with the specified id.- Parameters:
variableId- the id of the variable from which to return the instantiated term- Returns:
- the name of the atom instantiated to the variable with the specified id
- Throws:
ProjogException- if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not a number- See Also:
getTerm(String)
-
getLong
public long getLong(java.lang.String variableId)
Returns thelongvalue instantiated to the variable with the specified id.- Parameters:
variableId- the id of the variable from which to return the instantiated term- Returns:
- the value instantiated to the variable with the specified id
- Throws:
ProjogException- if no variable with the specified id exists in the query this object represents, or if the term instantiated to the variable is not a number- See Also:
getTerm(String)
-
getTerm
public Term getTerm(java.lang.String variableId)
Returns the term instantiated to the variable with the specified id.next()must be called before this method.- Parameters:
variableId- the id of the variable from which to return the instantiated term- Returns:
- the term instantiated to the variable with the specified id (or the
Variableof representing the variable if it is uninstantiated) - Throws:
ProjogException- if no variable with the specified id exists in the query this object represents- See Also:
getAtomName(String),getDouble(String),getLong(String)
-
getVariableIds
public java.util.Set<java.lang.String> getVariableIds()
Returns id's of all variables defined in the query this object represents.- Returns:
- id's of all variables defined in the query this object represents
-
-