当前位置: 首页>>代码示例>>Java>>正文


Java PrologException类代码示例

本文整理汇总了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);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:27,代码来源:Predicate_ruleevent_transpose.java

示例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);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:24,代码来源:Predicate_final_state.java

示例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);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:21,代码来源:Predicate_state_next.java

示例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);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:17,代码来源:Predicate_state_transition.java

示例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);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:19,代码来源:Predicate_composite_type_graph.java

示例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));
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:17,代码来源:Predicate_start_graph.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:21,代码来源:GraphPrologCode.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:22,代码来源:GraphPrologCode.java

示例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);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:18,代码来源:Predicate_start_graph_name.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:31,代码来源:PrologEngine.java

示例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());
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:24,代码来源:PrologDisplay.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:11,代码来源:Predicate_is_valuenode.java

示例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;
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:32,代码来源:Predicate_convert_valuenode.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:19,代码来源:AlgebraPrologCode.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:11,代码来源:Predicate_is_rule.java


注:本文中的gnu.prolog.vm.PrologException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。