use std::collections::HashMap;
use anyhow::Result;
use crate::fst_properties::FstProperties;
use crate::fst_traits::{MutableFst, SerializableFst};
use crate::semirings::SerializableSemiring;
use crate::semirings::WeightQuantize;
use crate::tests_openfst::FstTestData;
pub fn parse_fst_properties(mapping: &HashMap<String, bool>) -> FstProperties {
let mut props = FstProperties::empty();
if mapping["acceptor"] {
props |= FstProperties::ACCEPTOR
}
if mapping["not_acceptor"] {
props |= FstProperties::NOT_ACCEPTOR
}
if mapping["i_deterministic"] {
props |= FstProperties::I_DETERMINISTIC
}
if mapping["not_i_deterministic"] {
props |= FstProperties::NOT_I_DETERMINISTIC
}
if mapping["o_deterministic"] {
props |= FstProperties::O_DETERMINISTIC
}
if mapping["not_o_deterministic"] {
props |= FstProperties::NOT_O_DETERMINISTIC
}
if mapping["epsilons"] {
props |= FstProperties::EPSILONS
}
if mapping["no_epsilons"] {
props |= FstProperties::NO_EPSILONS
}
if mapping["i_epsilons"] {
props |= FstProperties::I_EPSILONS
}
if mapping["no_i_epsilons"] {
props |= FstProperties::NO_I_EPSILONS
}
if mapping["o_epsilons"] {
props |= FstProperties::O_EPSILONS
}
if mapping["no_o_epsilons"] {
props |= FstProperties::NO_O_EPSILONS
}
if mapping["i_label_sorted"] {
props |= FstProperties::I_LABEL_SORTED
}
if mapping["not_i_label_sorted"] {
props |= FstProperties::NOT_I_LABEL_SORTED
}
if mapping["o_label_sorted"] {
props |= FstProperties::O_LABEL_SORTED
}
if mapping["not_o_label_sorted"] {
props |= FstProperties::NOT_O_LABEL_SORTED
}
if mapping["weighted"] {
props |= FstProperties::WEIGHTED
}
if mapping["unweighted"] {
props |= FstProperties::UNWEIGHTED
}
if mapping["cyclic"] {
props |= FstProperties::CYCLIC
}
if mapping["acyclic"] {
props |= FstProperties::ACYCLIC
}
if mapping["initial_cyclic"] {
props |= FstProperties::INITIAL_CYCLIC
}
if mapping["initial_acyclic"] {
props |= FstProperties::INITIAL_ACYCLIC
}
if mapping["top_sorted"] {
props |= FstProperties::TOP_SORTED
}
if mapping["not_top_sorted"] {
props |= FstProperties::NOT_TOP_SORTED
}
if mapping["accessible"] {
props |= FstProperties::ACCESSIBLE
}
if mapping["not_accessible"] {
props |= FstProperties::NOT_ACCESSIBLE
}
if mapping["coaccessible"] {
props |= FstProperties::COACCESSIBLE
}
if mapping["not_coaccessible"] {
props |= FstProperties::NOT_COACCESSIBLE
}
if mapping["string"] {
props |= FstProperties::STRING
}
if mapping["not_string"] {
props |= FstProperties::NOT_STRING
}
if mapping["weighted_cycles"] {
props |= FstProperties::WEIGHTED_CYCLES
}
if mapping["unweighted_cycles"] {
props |= FstProperties::UNWEIGHTED_CYCLES
}
props
}
pub fn test_fst_properties<W, F>(test_data: &FstTestData<W, F>) -> Result<()>
where
F: SerializableFst<W> + MutableFst<W>,
W: SerializableSemiring + WeightQuantize,
{
let ref_props = test_data.fst_properties;
let props = test_data.raw.properties();
assert_eq!(props, ref_props);
Ok(())
}