Package stanfordlogic.knowledge

Examples of stanfordlogic.knowledge.KnowledgeBase


        }
       
        Iterable<GroundFact> newFacts = reasoner_.getAllAnswersIterable(QUERY_NEXT, currentContext_);
       
        // TODO: we should be creating the same kind of KB as currentState_ here
        KnowledgeBase newKb = new BasicKB();
       
        for(GroundFact newFact : newFacts)
            newKb.setTrue(trueProcessor_.processFact(newFact));
       
        currentState_ = newKb;
       
        if (stateLogger_.isLoggable(Level.FINE)) {
            stateLogger_.fine(gameId_ + "   -      New: " + currentState_.stateToGdl());
View Full Code Here


        // Get all next facts
        GroundFact does = GroundFact.fromExpression( parser_.parse("does xplayer noop") );
        GroundFact does2 = GroundFact.fromExpression( parser_.parse("does oplayer (mark 2 3)") );
        Fact question = VariableFact.fromExpression( parser_.parse("next ?x") );
       
        KnowledgeBase kb = new BasicKB();
       
        kb.setTrue(does);
        kb.setTrue(does2);
       
        ProofContext context = new ProofContext(kb, parser_);
       
        List<GroundFact> results = r.getAllAnswers( question, context );
       
View Full Code Here

   
    public void testTicTacToe() throws IOException
    {
        GameInformation info = MetaGdl.examineGame("game-defs/tictactoe.kif", parser_);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts(info.getAllGrounds());
       
        AbstractReasoner r = new BasicReasoner(staticKb, info.getIndexedRules(), parser_);
       
       
        Fact initQuestion = Fact.fromExpression(parser_.parse("init ?x"));
       
        // Compute the initial state
        List<GroundFact> inits = r.getAllAnswers(initQuestion);
       
        KnowledgeBase currentState = new BasicKB();
       
        RelationNameProcessor trueProcessor = new RelationNameProcessor(parser_.TOK_TRUE);
        for (GroundFact init: inits) {
            currentState.setTrue(trueProcessor.processFact(init));
        }
       
        assertEquals(10, currentState.getNumFacts());
       
        GroundFact [] moves;
       
        // Do some updates
        moves = new GroundFact [] {
                                   (GroundFact) makeFact("does xplayer (mark 1 1)"),
                                   (GroundFact) makeFact("does oplayer noop"),
        };
        currentState = updateKbWithMoves(r, currentState, moves);
        System.out.println(currentState.stateToGdl());
        assertEquals(10, currentState.getNumFacts());
       
        moves = new GroundFact [] {
                                   (GroundFact) makeFact("does xplayer noop"),
                                   (GroundFact) makeFact("does oplayer (mark 1 3)"),
        };
        currentState = updateKbWithMoves(r, currentState, moves);
        System.out.println(currentState.stateToGdl());
        assertEquals(10, currentState.getNumFacts());
    }
View Full Code Here

       
        ProofContext context = new ProofContext(kb, parser_);
       
        List<GroundFact> nexts = r.getAllAnswers(nextQuestion, context);
       
        KnowledgeBase newKb = new BasicKB();
       
        RelationNameProcessor trueProcessor = new RelationNameProcessor(parser_.TOK_TRUE);
       
        for (GroundFact next : nexts) {
            newKb.setTrue(trueProcessor.processFact(next));
        }
       
        return newKb;
       
    }
View Full Code Here

    public void testBigMinichess() throws IOException
    {
        // Load the rules for mini-chess
        GameInformation info = MetaGdl.examineGame("game-defs/minichess.kif", parser_);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts( info.getAllGrounds() );
       
        List<Implication> rules = info.getRules();
       
        KnowledgeBase volatileKb = new BasicKB();
       
        AbstractReasoner reasoner = new BasicReasoner(staticKb, rules, parser_);
       
        Fact question = VariableFact.fromList( parser_.parse("init ?x") );
       
        ProofContext context = new ProofContext(volatileKb, parser_);
       
        List<GroundFact> init = reasoner.getAllAnswers( question, context );
       
        // Make sure that we have a cache for all the initial truths
        assertEquals( 18, init.size() );
       
        RelationNameProcessor processor = new RelationNameProcessor(parser_.TOK_TRUE);
       
        for ( GroundFact f : init )
            volatileKb.setTrue ( processor.processFact(f) );
           
                // Find out how many legal moves there are
        List<GroundFact> legal = reasoner.getAllAnswers( makeFact( "legal white ?x" ),
                context );

        // Make sure there's the right amount of legal moves
        assertEquals( 7, legal.size() );

        // Is the game terminal?
        assertNull( reasoner.getAnAnswer( makeFact( "terminal" ), context ) );

        // Make some move
        GroundFact does1 = (GroundFact) makeFact( "does white (move wk c 1 c 2)" );
        GroundFact does2 = (GroundFact) makeFact( "does black noop" );

        volatileKb.setTrue( does1 );
        volatileKb.setTrue( does2 );

        // Find the next state.
        List<GroundFact> nextTruths = reasoner.getAllAnswers( makeFact( "next ?x" ),
                context );
View Full Code Here

    public void testChessLegalMoves()
    {
        // Load the rules for chess
        GameInformation info = MetaGdl.examineGame("game-defs/chess.kif", parser_);
       
        KnowledgeBase staticKb = new BasicKB();
        staticKb.loadWithFacts( info.getAllGrounds() );
       
        List<Implication> rules = info.getRules();
       
        KnowledgeBase volatileKb = new BasicKB();
       
        AbstractReasoner reasoner = new BasicReasoner(staticKb, rules, parser_);
       
        Fact question = VariableFact.fromList( parser_.parse("init ?x") );
       
        ProofContext context = new ProofContext(volatileKb, parser_);
       
        List<GroundFact> init = reasoner.getAllAnswers( question, context );
       
        assertEquals(66, init.size());
       
        RelationNameProcessor processor = new RelationNameProcessor(parser_.TOK_TRUE);
       
        for ( GroundFact f : init )
            volatileKb.setTrue ( processor.processFact(f) );
           
        // Find out how many legal moves there are
        List<GroundFact> legal = reasoner.getAllAnswers( makeFact( "legal white ?x" ),
                context );
View Full Code Here

TOP

Related Classes of stanfordlogic.knowledge.KnowledgeBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.