Commit fa0869d6 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Add the pair-to-fmp command to TAF-Kit.

* taf-kit/src/Makefile.am (vcsn_char_fmp_b_LDADD,
vcsn_char_fmp_z_LDADD, vcsn_int_fmp_b_LDADD,
vcsn_int_fmp_z_LDADD): Add the corresponding pair automaton
library.
* taf-kit/src/fmp_commands.cc (pair_to_fmp): New command.
* taf-kit/src/getters.hxx (get_pair_aut): New function.
* taf-kit/src/pipe_getters.hh, taf-kit/src/pipe_getters.hxx
(pair_automaton_getter): New class.
* taf-kit/tests/vcsn-char-fmp-b.test,
taf-kit/tests/vcsn-int-fmp-z.test: Add more tests for ltl-to-pair
and pair-to-fmp.
parent ba19db3e
2009-06-05 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Add the pair-to-fmp command to TAF-Kit.
* taf-kit/src/Makefile.am (vcsn_char_fmp_b_LDADD,
vcsn_char_fmp_z_LDADD, vcsn_int_fmp_b_LDADD,
vcsn_int_fmp_z_LDADD): Add the corresponding pair automaton
library.
* taf-kit/src/fmp_commands.cc (pair_to_fmp): New command.
* taf-kit/src/getters.hxx (get_pair_aut): New function.
* taf-kit/src/pipe_getters.hh, taf-kit/src/pipe_getters.hxx
(pair_automaton_getter): New class.
* taf-kit/tests/vcsn-char-fmp-b.test,
taf-kit/tests/vcsn-int-fmp-z.test: Add more tests for ltl-to-pair
and pair-to-fmp.
2009-06-05 Alexandre Duret-Lutz <adl@lrde.epita.fr>
 
Make pair_to_fmp() available in FMP contexts.
......
......@@ -81,7 +81,8 @@ vcsn_char_fmp_b_CPPFLAGS = $(AM_CPPFLAGS) \
-DRW_CONTEXT=boolean_transducer -DVCSN_USE_LIB
vcsn_char_fmp_b_LDADD = $(LDADD) \
$(top_builddir)/lib/libvcsn-fmp-tdc.la \
$(top_builddir)/lib/libvcsn-b.la
$(top_builddir)/lib/libvcsn-b.la \
$(top_builddir)/lib/libvcsn-char-char-b.la
vcsn_char_fmp_z_SOURCES = $(COMMON_SOURCES) \
fmp_commands.cc
......@@ -93,7 +94,8 @@ vcsn_char_fmp_z_CPPFLAGS = $(AM_CPPFLAGS) \
-DWITH_WEIGHTS
vcsn_char_fmp_z_LDADD = $(LDADD) \
$(top_builddir)/lib/libvcsn-z-fmp-tdc.la \
$(top_builddir)/lib/libvcsn-z.la
$(top_builddir)/lib/libvcsn-z.la \
$(top_builddir)/lib/libvcsn-char-char-z.la
vcsn_int_b_SOURCES = $(COMMON_SOURCES) \
ratexp_commands.hh \
......@@ -121,7 +123,8 @@ vcsn_int_fmp_b_CPPFLAGS = $(AM_CPPFLAGS) -DCONTEXT=int_fmp_transducer \
-DRW_CONTEXT=int_boolean_transducer -DVCSN_USE_LIB
vcsn_int_fmp_b_LDADD = $(LDADD) \
$(top_builddir)/lib/libvcsn-int-b.la \
$(top_builddir)/lib/libvcsn-int-fmp-tdc.la
$(top_builddir)/lib/libvcsn-int-fmp-tdc.la \
$(top_builddir)/lib/libvcsn-int-int-b.la
vcsn_int_fmp_z_SOURCES = $(COMMON_SOURCES) \
fmp_commands.cc
......@@ -133,7 +136,8 @@ vcsn_int_fmp_z_CPPFLAGS = $(AM_CPPFLAGS) -DCONTEXT=int_z_fmp_transducer \
-DVCSN_USE_LIB
vcsn_int_fmp_z_LDADD = $(LDADD) \
$(top_builddir)/lib/libvcsn-int-z.la \
$(top_builddir)/lib/libvcsn-int-z-fmp-tdc.la
$(top_builddir)/lib/libvcsn-int-z-fmp-tdc.la \
$(top_builddir)/lib/libvcsn-int-int-z.la
vcsn_char_char_b_SOURCES = $(COMMON_SOURCES) \
ratexp_commands.hh \
......
......@@ -82,6 +82,14 @@ DEFINE_COMMAND(NAME(ltl_to_pair)
KEEP(dst)
RETURNVALUE(0));
DEFINE_COMMAND(NAME(pair_to_fmp)
CODE(
vcsn::mute_ltl_to_pair_t::ret src = get_pair_aut(args, 1);
automaton_t dst = pair_to_fmp(src);
set_writing_data(dst, args))
KEEP(dst)
RETURNVALUE(0));
DEFINE_COMMAND (NAME(evaluation)
CODE(automaton_t src = get_aut(args, 1))
OUTPUT(
......@@ -214,7 +222,9 @@ const command_t command_map[] =
"Evaluate the language described by the\n\t"
IOAUT_NAME " automaton `aut2' on the transducer `aut1'."),
COMMAND_ENTRY(ltl_to_pair, Aut,
"Give an automaton defined over a pair letter alphabet same as `aut'."),
"Convert `Aut' into an automaton defined over a pair letter alphabet."),
COMMAND_ENTRY(pair_to_fmp, Aut,
"Convert an automata `Aut' using pair letters into an FMP."),
COMMAND_ENTRY(image, Aut,
"Give an automaton that accepts all output produced by `aut'."),
COMMAND_ENTRY(transpose, Aut,
......
......@@ -332,6 +332,66 @@ static IOAUT_CONTEXT::automaton_t get_boolean_aut(const arguments_t& args, const
exit(1);
}
}
static
mute_ltl_to_pair<automaton_t::set_t, automaton_t::value_t>::ret
get_pair_aut(const arguments_t& args, const int& n)
{
const std::string& s = args.args[n];
if (s == "-")
{
mute_ltl_to_pair<automaton_t::set_t, automaton_t::value_t>::ret a =
boost::apply_visitor(pair_automaton_getter
(global_result.name, global_result.input_aut_type),
global_result.output);
// We don't set the writing data before return because the
// pair automaton will be passed to pair_to_fmp and we will
// force the writing data on the resulting fmp.
return a;
}
std::istream* is (s == "-" ? &std::cin : new std::ifstream (s.c_str()));
if (not is->fail())
{
using namespace vcsn::tools;
using namespace vcsn::xml;
mute_ltl_to_pair<automaton_t::set_t, automaton_t::value_t>::ret a =
mute_ltl_to_pair<automaton_t::set_t, automaton_t::value_t>::
make_automaton(mute_ltl_to_pair<automaton_t::set_t,
automaton_t::value_t>::ret_alphabet_t());
switch (global_result.input_aut_type)
{
case INPUT_TYPE_XML:
*is >> automaton_loader(a, string_out (), XML ());
break;
case INPUT_TYPE_FSM:
fsm_load(*is, a);
break;
default:
std::cerr << "FATAL: Could not load automaton." << std::endl;
exit(1);
}
if (s != "-")
delete is;
// We don't set the writing data before return because the
// pair automaton will be passed to pair_to_fmp and we will
// force the writing data on the resulting fmp.
return a;
}
else
{
std::cerr << "FATAL: Could not load automaton." << std::endl;
exit(1);
}
}
#endif // !WITH_TWO_ALPHABETS
// Set the representations provided on the command line.
......
......@@ -94,6 +94,31 @@ public:
std::string command;
input_format_t f;
};
class pair_automaton_getter
: public boost::static_visitor<mute_ltl_to_pair<automaton_t::set_t,
automaton_t::value_t>::ret>
{
public:
typedef mute_ltl_to_pair<automaton_t::set_t, automaton_t::value_t> trait;
typedef trait::ret pair_t;
pair_automaton_getter (std::string& command, input_format_t);
pair_t
operator() (pair_t& a) const;
pair_t
operator() (std::string& str) const;
pair_t operator() (command_output_status& i) const;
template<typename T>
pair_t operator() (T&) const;
std::string command;
input_format_t f;
};
# endif // !WITH_TWO_ALPHABETS
#endif /* !PIPE_GETTERS_HH */
......@@ -296,6 +296,85 @@ boolean_automaton_getter::operator() (T&) const
<< std::endl;
exit (1);
}
pair_automaton_getter::pair_automaton_getter (std::string& cmd,
input_format_t fmt)
: command (cmd),
f (fmt)
{
}
pair_automaton_getter::pair_t
pair_automaton_getter::operator() (pair_automaton_getter::pair_t& a) const
{
return a;
}
pair_automaton_getter::pair_t
pair_automaton_getter::operator() (std::string& str) const
{
std::istringstream is (str);
// Representations will be build by the automaton loader.
pair_automaton_getter::pair_t a =
pair_automaton_getter::trait::make_automaton(trait::ret_alphabet_t());
switch (f)
{
case INPUT_TYPE_XML:
is >> automaton_loader(a, string_out (), XML ());
break;
case INPUT_TYPE_FSM:
fsm_load(is, a);
break;
default:
std::cerr << "FATAL: Could not load automaton." << std::endl;
exit(1);
}
return a;
}
pair_automaton_getter::pair_t
pair_automaton_getter::operator() (command_output_status& i) const
{
if (i != PIPE_GET_FROM_STDIN)
{
std::cerr << command
<< ": Incorrect input type"
<< std::endl;
exit (1);
}
// Representations will be build by the automaton loader.
pair_automaton_getter::pair_t a =
pair_automaton_getter::trait::make_automaton(trait::ret_alphabet_t());
switch (f)
{
case INPUT_TYPE_XML:
std::cin >> automaton_loader(a, string_out (), XML ());
break;
case INPUT_TYPE_FSM:
fsm_load(std::cin, a);
break;
default:
std::cerr << "FATAL: Could not load automaton." << std::endl;
exit(1);
}
return a;
}
template<typename T>
pair_automaton_getter::pair_t
pair_automaton_getter::operator() (T&) const
{
std::cerr << command
<< ": Incorrect input type"
<< std::endl;
exit (1);
}
# endif // !WITH_TWO_ALPHABETS
#endif /* !PIPE_GETTERS_HXX */
......@@ -323,6 +323,12 @@ x
EOF
$VCSN is-ltl ltl.xml
$VCSN ltl-to-pair ltl.xml > ltl-pair.xml
$VCSN pair-to-fmp ltl-pair.xml > ltl2.xml
$VCSN is-ltl ltl2.xml
# We should use are-isomorphic here
$VCSN info ltl.xml > ltl.info
$VCSN info ltl2.xml > ltl2.info
diff ltl.info ltl2.info
# Now we will check with first_projection and second_projection
# on one side (pair), and image and domain on the other side (FMP).
......
......@@ -58,8 +58,6 @@ sed '/^#/d' <<EOF | $VCSN --alphabet1=10,11,12 --alphabet2=20,21,22 edit-automat
10
EOF
# The evaluation of a word on FMP transducers internally uses
# aut-to-exp which may produce different results depending on the
# order used to remove the states of the automaton. The following
......@@ -82,6 +80,73 @@ res=`$VCSN image x.xml | vcsn-int-z aut-to-exp -`
res=`vcsn-int-z expand --alphabet=22,20 "$res"`
test "x$res" = "x{30} (({5} 22#22#20)*.22)"
fail1 $VCSN is-ltl x.xml
fail1 $VCSN sub-normalize x.xml \| is-ltl -
sed '/^#/d' <<EOF | $VCSN --alphabet1=10,11,12 --alphabet2=20,21,22 edit-automaton y.xml
# Add states
1
# Add two states
3
# Set a state to be initial.
5
# Which state
0
# Weight?
2
# Set a state to be final.
7
# Which state
2
# Weight
3
# Add transition
3
# From and to
0
1
# Label (word,word,weight)
10#11
22#20
5
# Add transition
3
# From and to
1
2
# Label
11#12
22#20
1
# Add transition
3
# From and to
2
1
# Label
e
e
1
# Exit.
10
EOF
fail1 $VCSN is-ltl y.xml
fail1 $VCSN sub-normalize y.xml \| is-ltl -
fail1 $VCSN eps-removal y.xml \| is-ltl -
$VCSN sub-normalize y.xml \| eps-removal - \| is-ltl -
$VCSN eps-removal y.xml \| sub-normalize - > yl.xml
$VCSN is-ltl yl.xml
$VCSN ltl-to-pair yl.xml > yp.xml
$VCSN pair-to-fmp yp.xml > yl2.xml
$VCSN info yl.xml > yl.info
$VCSN info yl2.xml > yl2.info
diff yl.info yl2.info
## --------------------------- ##
## Test writing data handling. ##
## --------------------------- ##
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment