de.learnlib.mealy.SymbolOracleWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of learnlib-core Show documentation
Show all versions of learnlib-core Show documentation
Infrastructure and core functionalities of LearnLib
/* Copyright (C) 2013 TU Dortmund
* This file is part of LearnLib, http://www.learnlib.de/.
*
* LearnLib is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 3.0 as published by the Free Software Foundation.
*
* LearnLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with LearnLib; if not, see
* .
*/
package de.learnlib.mealy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.automatalib.words.Word;
import de.learnlib.api.MembershipOracle;
import de.learnlib.api.Query;
/**
* Word-to-Symbol-Oracle adapter.
*
* Wraps an oracle which uses {@link Word}s as its output to an oracle which only
* yields the last symbol of each output.
*
* @author Malte Isberner
*
* @param input symbol class
* @param output symbol class
*/
final class SymbolOracleWrapper implements MembershipOracle {
private static final class LastSymbolQuery extends Query> {
private final Query originalQuery;
public LastSymbolQuery(Query originalQuery) {
this.originalQuery = originalQuery;
}
@Override
public Word getPrefix() {
return originalQuery.getPrefix();
}
@Override
public Word getSuffix() {
return originalQuery.getSuffix();
}
@Override
public void answer(Word output) {
originalQuery.answer(output.isEmpty() ? null : output.lastSymbol());
}
}
private final MembershipOracle> wordOracle;
/**
* Constructor.
* @param wordOracle the {@link MembershipOracle} returning output words.
*/
public SymbolOracleWrapper(MembershipOracle> wordOracle) {
this.wordOracle = wordOracle;
}
/*
* (non-Javadoc)
* @see de.learnlib.api.MembershipOracle#processQueries(java.util.Collection)
*/
@Override
public void processQueries(Collection extends Query> queries) {
List> lsQueries = new ArrayList>(queries.size());
for(Query qry : queries)
lsQueries.add(new LastSymbolQuery(qry));
wordOracle.processQueries(lsQueries);
}
}