本文整理汇总了Java中gnu.prolog.vm.PrologException类的典型用法代码示例。如果您正苦于以下问题:Java PrologException类的具体用法?Java PrologException怎么用?Java PrologException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrologException类属于gnu.prolog.vm包,在下文中一共展示了PrologException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
RuleEvent re = getRuleEvent(args[0]);
if (!(re instanceof BasicEvent)) {
PrologException.domainError(RULEEVENT_ATOM, args[0]);
}
BasicEvent spo = (BasicEvent) re;
if (!(args[1] instanceof JavaObjectTerm)) {
PrologException.instantiationError();
}
Object arg1 = ((JavaObjectTerm) args[1]).value;
Object arg1Transposed = null;
if (arg1 instanceof Node) {
arg1Transposed = spo.getAnchorMap().getNode((RuleNode) arg1);
} else if (arg1 instanceof Edge) {
arg1Transposed = spo.getAnchorMap().getEdge((RuleEdge) arg1);
} else {
PrologException.domainError(AtomTerm.get("node_edge"), args[1]);
}
if (arg1Transposed == null) {
return FAIL;
}
Term res = new JavaObjectTerm(arg1Transposed);
return interpreter.unify(args[2], res);
}
示例2: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
if (backtrackMode) {
PrologCollectionIterator bi =
(PrologCollectionIterator) interpreter.popBacktrackInfo();
interpreter.undo(bi.getUndoPosition());
return bi.nextSolution(interpreter);
} else {
if (!(interpreter.getEnvironment() instanceof GrooveEnvironment)) {
GrooveEnvironment.invalidEnvironment();
}
GTS lts =
((GrooveEnvironment) interpreter.getEnvironment()).getGrooveState().getGts();
if (lts == null) {
return FAIL;
}
PrologCollectionIterator it =
new PrologCollectionIterator(lts.getFinalStates(), args[0],
interpreter.getUndoPosition());
return it.nextSolution(interpreter);
}
}
示例3: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
if (backtrackMode) {
PrologCollectionIterator bi =
(PrologCollectionIterator) interpreter.popBacktrackInfo();
interpreter.undo(bi.getUndoPosition());
return bi.nextSolution(interpreter);
} else {
GraphState graphState = getGraphState(args[0]);
Collection<GraphState> nextStateSet = new ArrayList<>();
for (GraphTransition trans : graphState.getTransitions()) {
nextStateSet.add(trans.target());
}
PrologCollectionIterator it =
new PrologCollectionIterator(nextStateSet, args[1],
interpreter.getUndoPosition());
return it.nextSolution(interpreter);
}
}
示例4: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
if (backtrackMode) {
PrologCollectionIterator bi =
(PrologCollectionIterator) interpreter.popBacktrackInfo();
interpreter.undo(bi.getUndoPosition());
return bi.nextSolution(interpreter);
} else {
GraphState graphState = getGraphState(args[0]);
PrologCollectionIterator it =
new PrologCollectionIterator(graphState.getTransitions(),
args[1], interpreter.getUndoPosition());
return it.nextSolution(interpreter);
}
}
示例5: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode, Term[] args)
throws PrologException {
if (!(interpreter.getEnvironment() instanceof GrooveEnvironment)) {
GrooveEnvironment.invalidEnvironment();
}
TypeGraph typeGraph =
((GrooveEnvironment) interpreter.getEnvironment()).getGrooveState().getGraphGrammar().getTypeGraph();
if (typeGraph == null) {
return FAIL;
}
Term nodeTerm = new JavaObjectTerm(typeGraph);
return interpreter.unify(args[0], nodeTerm);
}
示例6: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode, Term[] args)
throws PrologException {
if (!(interpreter.getEnvironment() instanceof GrooveEnvironment)) {
GrooveEnvironment.invalidEnvironment();
}
Graph startGraph =
((GrooveEnvironment) interpreter.getEnvironment()).getGrooveState().getGraphGrammar().getStartGraph();
if (startGraph == null) {
return FAIL;
}
return interpreter.unify(args[0], new JavaObjectTerm(startGraph));
}
示例7: getGraph
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
/**
* Get a graph from a term representing a graph
* @param term A term representing a graph
* @return A graph
*/
public static final Graph getGraph(Term term) throws PrologException {
if (term instanceof JavaObjectTerm) {
JavaObjectTerm jot = (JavaObjectTerm) term;
if (jot.value instanceof GraphState) {
return ((GraphState) jot.value).getGraph();
}
if (jot.value instanceof Graph) {
return (Graph) jot.value;
}
PrologException.domainError(GraphPrologCode.GRAPH_ATOM, term);
} else {
PrologException.typeError(GraphPrologCode.GRAPH_ATOM, term);
}
return null;
}
示例8: getHostGraph
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
/**
* Get a host graph from a term representing a host graph
* @param term A term representing a host graph
* @return A host graph
*/
public static final HostGraph getHostGraph(Term term)
throws PrologException {
if (term instanceof JavaObjectTerm) {
JavaObjectTerm jot = (JavaObjectTerm) term;
if (jot.value instanceof GraphState) {
return ((GraphState) jot.value).getGraph();
}
if (jot.value instanceof HostGraph) {
return (HostGraph) jot.value;
}
PrologException.domainError(GraphPrologCode.GRAPH_ATOM, term);
} else {
PrologException.typeError(GraphPrologCode.GRAPH_ATOM, term);
}
return null;
}
示例9: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode, Term[] args)
throws PrologException {
if (!(interpreter.getEnvironment() instanceof GrooveEnvironment)) {
GrooveEnvironment.invalidEnvironment();
}
String startGraphName =
((GrooveEnvironment) interpreter.getEnvironment()).getGrooveState().getGraphGrammar().getStartGraph().getName();
if (startGraphName == null) {
return FAIL;
}
Term value = AtomTerm.get(startGraphName);
return interpreter.unify(args[0], value);
}
示例10: next
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
/**
* Get the next results
*
* @return Null if there is no next result
* @throws PrologException if there was an error during execution
*/
public QueryResult next() throws PrologException {
if (this.currentResult == null) {
return null;
}
if (this.currentResult.isLastResult()) {
// no more results
return null;
}
long startTime = System.nanoTime();
int rc;
rc = this.interpreter.execute(this.currentResult.goal);
long stopTime = System.nanoTime();
if (this.currentResult.getReturnValue() != QueryReturnValue.NOT_RUN) {
this.currentResult = new InternalQueryResult(this.currentResult);
}
this.currentResult.setReturnValue(QueryReturnValue.fromInt(rc));
this.currentResult.setExecutionTime(stopTime - startTime);
if (this.currentResult.getReturnValue() != QueryReturnValue.FAIL
&& this.currentResult.getReturnValue() != QueryReturnValue.HALT) {
this.currentResult.setVariables(TermConverter.convert(this.currentResult.rawVars));
}
return this.currentResult;
}
示例11: handlePrologException
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
/**
* Handler for the exceptions thrown by the prolog environment
*/
private void handlePrologException(Throwable e) {
try {
getUserOutput().flush();
} catch (IOException e1) {
// ignore
}
if (e.getCause() instanceof PrologException) {
PrologException pe = (PrologException) e.getCause();
if (pe.getCause() == null) {
getResultsArea().append(e.getCause().getMessage());
return;
} else {
e = pe;
}
}
// StringWriter sw = new StringWriter();
// e.printStackTrace(new PrintWriter(sw));
// this.results.append(sw.toString());
getResultsArea().append(e.getMessage());
}
示例12: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
if (args[0] instanceof JavaObjectTerm) {
if (((JavaObjectTerm) args[0]).value instanceof ValueNode) {
return SUCCESS_LAST;
}
}
return FAIL;
}
示例13: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
try {
ValueNode node = getValueNode(args[0]);
Term result;
Algebra<?> alg = node.getAlgebra();
Object value = alg.toJavaValue(node.getValue());
switch (alg.getSort()) {
case BOOL:
result = new JavaObjectTerm(value);
break;
case INT:
result = IntegerTerm.get((Integer) value);
break;
case REAL:
result = new FloatTerm((Double) value);
break;
case STRING:
result = AtomTerm.get((String) value);
break;
default:
result = null;
assert false;
}
return interpreter.unify(args[1], result);
} catch (Exception e) {
return FAIL;
}
}
示例14: getValueNode
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
/**
* Gets a valuenode from a term
* @param term A term representing a valuenode
* @return A valuenode
*/
public static final ValueNode getValueNode(Term term)
throws PrologException {
if (term instanceof JavaObjectTerm) {
JavaObjectTerm jot = (JavaObjectTerm) term;
if (!(jot.value instanceof ValueNode)) {
PrologException.domainError(VALUENODE_ATOM, term);
}
return (ValueNode) jot.value;
} else {
PrologException.typeError(VALUENODE_ATOM, term);
}
return null;
}
示例15: execute
import gnu.prolog.vm.PrologException; //导入依赖的package包/类
@Override
public int execute(Interpreter interpreter, boolean backtrackMode,
Term[] args) throws PrologException {
if (args[0] instanceof JavaObjectTerm) {
if (((JavaObjectTerm) args[0]).value instanceof Rule) {
return SUCCESS_LAST;
}
}
return FAIL;
}