<< Prev | - Up - | Next >> |
Hint: In newer versions of SWI-Prolog (at least) you can use the built-in predicate
atom_chars/2
to convert an atom into a list of one-character atoms. For instance callingatom_chars(hallo, X).
yields:
X = [h, a, l, l, o]
Hint: In newer versions of SWI-Prolog (at least) you can use the built-in predicate atom_chars/2
to convert an atom into a list of one-character atoms. For instance calling
atom_chars(hallo, X).
yields:
X = [h, a, l, l, o]
So you can use atom_chars/2
to prepare the input for your FSA like this:
atom_chars('haha!', X), test(a1,X).
Note that if the word you want to split in single letter contains an exclamation mark, you have to enclose the whole word in single quotes (as seen in the example).
Now, let's see if our program for manipulating FSAs really works as it should.
Have a look at hahuho.pl
. This file contains two automata, named hahu
and haho
. They recognize different kinds of laughter. For hahu
, the laughter can be any sequence of ``ha'' and ``hu'', ended by an exclamation mark. For haho
it has to consist of ``ha'' and ``ho'' and also end in an exclamation mark. These are the automata we will test our new program on, so make sure you understand them.
Start Prolog and consult recognize.pl
, hahuho.pl
and operations.pl
. (You may see some warnings. Don't mind...) Use test/2
to test hahu
and haho
on some laughter of your choice.
Think about how to characterize the language that the union-automaton of hahu
and haho
should accept.
Build and test the automaton. First request our program to build the union-automaton of hahu
and haho
(indicated by ;
) and then save it under the name u
(using cp
), as follows: scan(cp((hahu;haho), u)).
Now you can use test/2
to test u
on any input that you think should or shouldn't be accepted. For instance try test(u, [h,a,h,u,!]).
, test(u, [h,a,h,o,!]).
, and test(u, [h,u,h,o,!]).
.
Describe (for yourself...) the language that the intersection-automaton of hahu
and haho
should accept.
Build the intersection-automaton (using ,
) and save it under the name s
. Then test s
on several inputs that it should or shouldn't accept.
Finally, use generate/2
to generate with hahu
, haho
, s
and u
(if you don't remember how to do this, look it up in Section 1.4.2). What do you see? Have a look at the code to explain your observations.
<< Prev | - Up - | Next >> |