(** Module for handling phonological features and segments *) (* module Feature = struct *) (** Type representing a phonological feature value *) type feature_value = Plus | Minus | Zero (** Type representing a phonological feature *) type feature = | Syllabic | Sonorant | Consonantal | Continuant | DelayedRelease | Lateral | Nasal | Strident | Voiced | SpreadGlottis | ConstrictedGlottis | Anterior | Coronal | Distributed | Labial | High | Low | Back | Rounded | Velaric | Tense | Long | HighTone | HighReg (*high registry?*) type feature_spec = feature * feature_value (** Type representing a feature specification as a (value, feature) pair *) type segment = feature_spec list (** Convert a string feature value to the feature_value type *) let value_of_string = function | "+" -> Plus | "-" -> Minus | "0" -> Zero | s -> failwith (Printf.sprintf "Invalid feature value: %s" s) let string_of_feature = function | "syl" -> Syllabic | "son" -> Sonorant | "cons" -> Consonantal | "cont" -> Continuant | "delrel" -> DelayedRelease | "lat" -> Lateral | "nas" -> Nasal | "strid" -> Strident | "voi" -> Voiced | "sg" -> SpreadGlottis | "cg" -> ConstrictedGlottis | "ant" -> Anterior | "cor" -> Coronal | "distr" -> Distributed | "lab" -> Labial | "hi" -> High | "lo" -> Low | "back" -> Back | "round" -> Rounded | "velaric" -> Velaric | "tense" -> Tense | "long" -> Long | "hitone" -> HighTone | "hireg" -> HighReg | _ -> failwith "not a valid feature" (** Check if a segment has a specific feature with a given value *) let has_feature (value, feature_name) segment = List.exists (fun (v, f) -> v = value && f = feature_name) segment (** Create a feature test function for use in the decision tree *) let test feature_spec segment = has_feature feature_spec segment (* end *)