autfilt: add new option --accept-word

Suggested by Matthias Heizmann. Fixes #109.

* NEWS: notify the new option
* THANKS: add Matthias Heizmann
* bin/autfilt.cc: add new option --accept-word=WORD which filters
automata that accept WORD
* doc/org/autfilt.org: add an example of the new option
* tests/Makefile.am: add core/acc_word.test to the list of test files
* tests/core/acc_word.test: test some uses of the new option
This commit is contained in:
Amaury Fauchille 2016-02-05 17:26:31 +01:00 committed by Alexandre Duret-Lutz
parent 1fd76ee918
commit 1c82444376
6 changed files with 82 additions and 20 deletions

View file

@ -69,6 +69,7 @@ Exit status:\n\
// Keep this list sorted
enum {
OPT_ACC_SETS = 256,
OPT_ACC_WORD,
OPT_AP_N,
OPT_ARE_ISOMORPHIC,
OPT_CLEAN_ACC,
@ -224,6 +225,8 @@ static const argp_option options[] =
"keep automata whose number of edges are in RANGE", 0 },
{ "acc-sets", OPT_ACC_SETS, "RANGE", 0,
"keep automata whose number of acceptance sets are in RANGE", 0 },
{ "accept-word", OPT_ACC_WORD, "WORD", 0,
"keep automata that recognize WORD", 0 },
RANGE_DOC_FULL,
{ nullptr, 0, nullptr, 0,
"If any option among --small, --deterministic, or --any is given, "
@ -293,6 +296,7 @@ static range opt_states = { 0, std::numeric_limits<int>::max() };
static range opt_edges = { 0, std::numeric_limits<int>::max() };
static range opt_accsets = { 0, std::numeric_limits<int>::max() };
static range opt_ap_n = { 0, std::numeric_limits<int>::max() };
static std::vector<std::string> opt_acc_words;
static int opt_max_count = -1;
static bool opt_destut = false;
static char opt_instut = 0;
@ -361,6 +365,9 @@ parse_opt(int key, char* arg, struct argp_state*)
case OPT_ACC_SETS:
opt_accsets = parse_range(arg, 0, std::numeric_limits<int>::max());
break;
case OPT_ACC_WORD:
opt_acc_words.push_back(arg);
break;
case OPT_ARE_ISOMORPHIC:
opt->are_isomorphic = read_automaton(arg, opt->dict);
break;
@ -652,6 +659,20 @@ namespace
matched &= spot::product(aut, opt->equivalent_neg)->is_empty()
&& spot::product(dtwa_complement(ensure_deterministic(aut)),
opt->equivalent_pos)->is_empty();
if (!opt_acc_words.empty())
{
auto word_aut = spot::parse_word(opt_acc_words[0],
opt->dict)->as_automaton();
for (size_t i = 1; i < opt_acc_words.size(); ++i)
{
// Compose each additionnanl word with the first one
word_aut = spot::product(word_aut,
spot::parse_word(opt_acc_words[i],
opt->dict)
->as_automaton());
}
matched &= !spot::product(aut, word_aut)->is_empty();
}
// Drop or keep matched automata depending on the --invert option
if (matched == opt_invert)
@ -812,6 +833,26 @@ main(int argc, char** argv)
if (processor.run())
return 2;
}
catch (const spot::parse_error& e)
{
auto is_several_lines =
[] (const char* err)
{
for (;;)
{
if (*err == '\0')
return false;
else if (*err == '\n')
return true;
++err;
}
};
auto err = e.what();
if (is_several_lines(err))
error(2, 0, "\n%s", err);
else
error(2, 0, "%s", err);
}
catch (const std::runtime_error& e)
{
error(2, 0, "%s", e.what());