001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of LearnLib, http://www.learnlib.de/.
003 *
004 * LearnLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 *
008 * LearnLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 *
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with LearnLib; if not, see
015 * <http://www.gnu.de/documents/lgpl.en.html>.
016 */
017package de.learnlib.oracles;
018
019import net.automatalib.words.Word;
020import net.automatalib.words.WordBuilder;
021import de.learnlib.api.MembershipOracle.MealyMembershipOracle;
022import de.learnlib.api.SUL;
023
024/**
025 * A wrapper around a system under learning (SUL).
026 * 
027 * @author falkhowar
028 */
029public class SULOracle<I, O> extends AbstractSingleQueryOracle<I, Word<O>> implements MealyMembershipOracle<I,O> {
030
031        private final SUL<I, O> sul;
032
033        public SULOracle(SUL<I, O> sul) {
034                this.sul = sul;
035        }
036
037        @Override
038        public Word<O> answerQuery(Word<I> prefix, Word<I> suffix) {
039                sul.pre();
040                // Prefix: Execute symbols, don't record output
041                for(I sym : prefix)
042                        sul.step(sym);
043                
044                // Suffix: Execute symbols, outputs constitute output word
045                WordBuilder<O> wb = new WordBuilder<>(suffix.length());
046                for(I sym : suffix)
047                        wb.add(sul.step(sym));
048                
049                sul.post();
050                return wb.toWord();
051        }
052
053}