Automaton definitions and low-level access.
More...
#include <gfsmAlphabet.h>
#include <gfsmState.h>
#include <gfsmWeightMap.h>
#include <gfsmBitVector.h>
#include <gfsmAutomaton.hi>
Go to the source code of this file.
API: Automaton Properties |
Currently quite sketchy; better tracking and checking of automaton flags should be implemented.
|
#define | gfsm_automaton_is_transducer(fsm) ((fsm)->flags.is_transducer) |
#define | gfsm_automaton_is_weighted(fsm) ((fsm)->flags.is_weighted) |
#define | gfsm_automaton_sortmode(fsm) ((gfsmArcSortMode)(gfsm_acmask_nth((fsm)->flags.sort_mode,0))) |
#define | gfsm_automaton_is_acyclic(fsm) (!gfsm_automaton_is_cyclic(fsm)) |
guint | gfsm_automaton_n_arcs_full (gfsmAutomaton *fsm, guint *n_lo_epsilon, guint *n_hi_epsilon, guint *n_both_epsilon) |
gboolean | gfsm_automaton_is_cyclic_state (gfsmAutomaton *fsm, gfsmStateId qid, gfsmBitVector *visited, gfsmBitVector *completed) |
gboolean | gfsm_automaton_is_cyclic (gfsmAutomaton *fsm) |
gfsmAlphabet * | gfsm_automaton_get_alphabet (gfsmAutomaton *fsm, gfsmLabelSide which, gfsmAlphabet *alph) |
void | gfsm_automaton_renumber_states (gfsmAutomaton *fsm) |
void | gfsm_automaton_renumber_states_full (gfsmAutomaton *fsm, GArray *old2new, gfsmStateId n_new_states) |
void | gfsm_automaton_truncate_invalid_states (gfsmAutomaton *fsm) |
API: Automaton States |
#define | gfsm_automaton_is_final_state(fsm, qid) gfsm_automaton_state_is_final((fsm),(qid)) |
static gboolean | gfsm_automaton_has_state (gfsmAutomaton *fsm, gfsmStateId qid) |
static gfsmStateId | gfsm_automaton_add_state_full (gfsmAutomaton *fsm, gfsmStateId qid) |
static gfsmStateId | gfsm_automaton_ensure_state (gfsmAutomaton *fsm, gfsmStateId qid) |
static gfsmStateId | gfsm_automaton_add_state (gfsmAutomaton *fsm) |
static void | gfsm_automaton_remove_state (gfsmAutomaton *fsm, gfsmStateId qid) |
static gboolean | gfsm_automaton_lookup_final (gfsmAutomaton *fsm, gfsmStateId qid, gfsmWeight *wp) |
static gboolean | gfsm_automaton_state_is_final (gfsmAutomaton *fsm, gfsmStateId qid) |
static gfsmWeight | gfsm_automaton_get_final_weight (gfsmAutomaton *fsm, gfsmStateId qid) |
static void | gfsm_automaton_set_final_state_full (gfsmAutomaton *fsm, gfsmStateId qid, gboolean is_final, gfsmWeight final_weight) |
static void | gfsm_automaton_set_final_state (gfsmAutomaton *fsm, gfsmStateId qid, gboolean is_final) |
static guint | gfsm_automaton_out_degree (gfsmAutomaton *fsm, gfsmStateId qid) |
Accessors: Automaton Arcs |
#define | gfsm_automaton_arcsort_with_data(fsm, cmpfunc, data) gfsm_automaton_arcsort_full((fsm),(cmpfunc),(data)) |
static void | gfsm_automaton_add_arc (gfsmAutomaton *fsm, gfsmStateId qid1, gfsmStateId qid2, gfsmLabelId lo, gfsmLabelId hi, gfsmWeight w) |
static void | gfsm_automaton_add_arc_node (gfsmAutomaton *fsm, gfsmState *sp, gfsmArcList *node) |
static void | gfsm_automaton_remove_arc_ptr (gfsmAutomaton *fsm, gfsmArc *a) |
static void | gfsm_automaton_remove_arc_node (gfsmAutomaton *fsm, gfsmState *sp, gfsmArcList *node) |
static gfsmAutomaton * | gfsm_automaton_arcsort (gfsmAutomaton *fsm, gfsmArcCompMask mode) |
void | gfsm_automaton_arcsort_full (gfsmAutomaton *fsm, GCompareDataFunc cmpfunc, gpointer data) |
gfsmAutomaton * | gfsm_automaton_arcuniq (gfsmAutomaton *fsm) |
Detailed Description
Macro Definition Documentation
#define gfsm_automaton_is_transducer |
( |
|
fsm | ) |
((fsm)->flags.is_transducer) |
True iff automaton is a transducer
#define gfsm_automaton_is_weighted |
( |
|
fsm | ) |
((fsm)->flags.is_weighted) |
True iff automaton is weighted
Get current automaton arc-sort mode (primary sort)
Test whether automaton is acyclic
Function Documentation
Create and return a new gfsmAutomaton, using default flags, semiring type and size
Create a new gfsmAutomaton as a deep exact copy of fsm.
- Parameters
-
fsm | automaton to be cloned |
- Returns
- new deep copy of src
Assign non-structural contents (flags, semiring) of src to dst, without altering dst's topology.
- Parameters
-
dst | target automaton |
src | source automaton |
- Returns
- modified dst
- Warning
- Earlier versions of this function also set the root state of dst to that of src, but you should no longer rely on this being the case!
Assign the contents of fsm src to fsm dst
- Returns
- dst
Create a new gfsmAutomaton whose non-structural contents match those of fsm.
- Parameters
-
- Returns
- new automaton whose non-structural fields match those of fsm
Swap the contents of automata fsm1 and fsm2
Destroy an automaton: all associated states and arcs will be freed.
Get pointer to the semiring associated with this automaton
Set the semiring associated with this automaton
- Parameters
-
fsm | automaton to modify |
sr | semiring to be copied into fsm->sr |
- Returns
- pointer to the (new) semiring for fsm
- Note
- Implicitly frees the semiring previously associated with fsm, if any.
- Warning
- Prior to libgfsm-v0.0.9 this function returned the parameter sr itself
Set the semiring associated with this automaton by type.
- Parameters
-
fsm | automaton whose semiring is to be set |
srtype | type of new semiring |
- Note
- If fsm's semiring is already of type srtype, this function does nothing.
- If srtype is gfsmSRTUser, fsm's new semiring will be unitialized
- Implicitly frees the semiring previously associated with fsm, if any.
Reserve space for at least n_states states (may do nothing)
- Parameters
-
fsm | automaton to modify |
n_states | number of states to reserve, if supported by implementation |
static void gfsm_automaton_reserve_arcs |
( |
gfsmAutomaton * |
fsm, |
|
|
guint |
n_arcs |
|
) |
| |
|
inlinestatic |
Reserve space for at least n_arcs arcs
- Parameters
-
fsm | automaton to modify |
n_arcs | number of arcs to reserve |
- Note
- Currently does nothing.
Get the number of states in an automaton (modulo 'gaps' in state ID numbering).
- Parameters
-
- Returns
- The least gfsmStateId q such that for all r >= q, fsm has no state with ID r.
Get number of final states in fsm
Set ID of root state, creating state if necessary.
- Parameters
-
fsm | automaton whose root state is to be set |
new_root_id | ID of new root state
- If new_root_id is gfsmNoState, fsm is marked as 'unrooted'
- otherwise, a new state with ID new_root_id is implicitly created if none already existed
|
static void gfsm_automaton_finals_foreach |
( |
gfsmAutomaton * |
fsm, |
|
|
GTraverseFunc |
func, |
|
|
gpointer |
data |
|
) |
| |
|
inlinestatic |
Call a user-defined function \a func for each final state of \a fsm.
\param fsm automaton whose final states are to be traversed
\param func \c GTraverseFunc for final states, as for \c g_tree_foreach()
\param data user data for \a func
\warning
\a func may \e not directly alter any final weights of \a fsm.
See GLib documentaion of g_tree_foreach() for details and a workaround.
\note
\a func will be called as <tt>(*func)(gpointer final_stateid, gpointer final_weight, gpointer data)</tt>;
that is, both the ::gfsmStateId \a final_stateid and the final weight \a final_weight will be encoded
as (gpointers). They can be decoded with GPOINTER_TO_UINT() and gfsm_ptr2weight(), respectively, e.g.
gboolean my_final_func(gpointer id_p, gpointer fw_p, gpointer data) {
do_something_interesting();
return FALSE;
}
- See Also
- gfsm_automaton_finals_to_array()
Get a GArray of gfsmStateWeightPair values for final states of fsm.
- Parameters
-
fsm | automaton from which to extract final states |
array | array to be populated, or NULL to allocate a new array |
- Returns
- new array, or a newly allocated gfsmStateWeightPairArray
- Note
- Caller is responsible for freeing the array returned when it is no longer needed.
guint gfsm_automaton_n_arcs_full |
( |
gfsmAutomaton * |
fsm, |
|
|
guint * |
n_lo_epsilon, |
|
|
guint * |
n_hi_epsilon, |
|
|
guint * |
n_both_epsilon |
|
) |
| |
Get verbose summary arc information (linear time w/ number of arcs)
- Parameters
-
[in] | fsm | automaton to examine |
[out] | n_lo_epsilon | on return holds number of arcs with lower label gfsmEpsilon, or NULL |
[out] | n_hi_epsilon | on return holds number of arcs with upper label gfsmEpsilon, or NULL |
[out] | n_both_epsilon | on return holds number of arcs with both lower and upper labels gfsmEpsilon, or NULL |
- Returns
- total number of arcs
Test whether automaton is cyclic
Extract automaton-internal labels to alph. If alph is NULL, a new default alphabet will be created and returned (you will need to free it yourself).
The alphabet should be able to match literal label values to themselves (so don't pass a string alphabet)
- Parameters
-
[in] | fsm | automaton to examine |
[in] | which | determines which label side(s) to extract |
[out] | alph | alphabet to which labels are extracted, or NULL to create a new alphabet |
- Returns
- alph, or a newly allocated and populated alphabet
Renumber states of the automaton fsm. Destructively alters fsm
. On return, fsm should have no 'gaps' in its state enumeration function, and its root state should have the ID 0 (zero).
- Deprecated:
- prefer gfsm_statesort_aff()
Renumber states of an FSM using user-specified state-ID map old2new. Destructively alters fsm
.
- Parameters
-
fsm | Automaton whose states are to be renumbered |
old2new | GArray of gfsmStateId such that qid_new=old2new[qid_old] . qid_new may be gfsmNoState to ignore the corresponding qid_old |
n_new_states | Maximum qid_new gfsmStateId value in old2new, or 0 (zero) to auto-compute. |
- Deprecated:
- prefer gfsm_statemap_apply()
void gfsm_automaton_truncate_invalid_states |
( |
gfsmAutomaton * |
fsm | ) |
|
Truncate any invalid states off the end state vector: fast
Add a new state, specifying state ID.
- Parameters
-
fsm | automaton to modify |
qid | ID of new state, or gfsmNoState to use the first available state ID. |
- Returns
- Id of the (new) state
- Note
- Implicitly sets fsm's root state if fsm was previously unrooted.
- Does nothing if fsm already has a state with ID qid.
Add a new state to fsm. Really just an alias for
Remove the state with id qid, if any.
- Parameters
-
fsm | automaton from which to remove a state |
qid | ID of the state to be removed |
- Note
- Any incoming arcs for state qid are NOT removed, although any outgoing arcs are removed and freed.
Lookup final weight for state with ID qid in automaton fsm.
- Parameters
-
fsm | automaton to examine |
qid | ID of state to examine |
wp | output parameter for final weight |
- Returns
- TRUE if state qid is final, FALSE otherwise
Check whether the state with ID qid is final in fsm. Really just a wrapper for gfsm_automaton_lookup_final().
- Parameters
-
fsm | automaton to examine |
qid | ID of state to check for finality |
- Returns
- TRUE if qid is final in fsm, FALSE otherwise.
Get final weight.
- Returns
- final weight if state qid is final, else fsm->sr->zero
Set final-weight and/or final-states membership flag for state with ID qid in fsm.
- Parameters
-
fsm | automaton to modify |
qid | ID of state to modified |
is_final | whether state should be considered final |
final_weight | If is_final is true, final weight for state. Otherwise, final weight is implicitly fsm->sr->zero |
Get number of outgoing arcs from qid in fsm
Add an arc from state with ID qid1 to state with ID qid2 on labels (lo,hi) with weight w. Missing states should be implicitly created.
- Parameters
-
fsm | Automaton to modify |
qid1 | ID of source state |
qid2 | ID of target state |
lo | Lower label |
hi | Upper label |
w | Arc weight |
Remove an arc (pointer), without freeing it
Remove an arc node (without freeing it)
Sort all arcs in an automaton by one of the built-in comparison functions.
- Parameters
-
fsm | Automaton to modify |
mode | Specifies built-in arc comparison priorities |
- Returns
- modified fsm
- Note
-
void gfsm_automaton_arcsort_full |
( |
gfsmAutomaton * |
fsm, |
|
|
GCompareDataFunc |
cmpfunc, |
|
|
gpointer |
data |
|
) |
| |
Sort all arcs in an automaton by a user-specified comparison function.
- Parameters
-
fsm | Automaton to modify |
cmpfunc | 3-way comparison function, called as (*cmpfunc)(gfsmArc *a1, gfsmArc *a2, gpointer data) to compare arcs a1 and a2. |
data | User data for cmpfunc |
- Returns
- Modified fsm
Collect weights on adjacent otherwise identical arcs. Really only meaningful if automaton is arc-sorted e.g. by gfsmASMLower.
- Parameters
-
- Returns
- modified fsm
Variable Documentation
Default initial automaton size (number of states)
Default initial automaton flags
Default semiring for automaton arc weights