MCPcopy Create free account
hub / github.com/daisy/MathCAT / intent_rules

Function intent_rules

src/speech.rs:82–98  ·  view source on GitHub ↗
(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, doc: Document<'m>, mathml: Element, nav_node_id: &'m str)

Source from the content-addressed store, hash-verified

80
81
82fn intent_rules<'m>(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, doc: Document<'m>, mathml: Element, nav_node_id: &'m str) -> Result<Element<'m>> {
83 SpeechRules::update()?;
84 rules.with(|rules| {
85 rules.borrow_mut().read_files()?;
86 let rules = rules.borrow();
87 // debug!("speak_rules:\n{}", mml_to_string(&mathml));
88 let mut rules_with_context = SpeechRulesWithContext::new(&rules, doc, nav_node_id);
89 let intent = rules_with_context.match_pattern::<Element<'m>>(mathml)
90 .chain_err(|| "Pattern match/replacement failure!")?;
91 if name(&intent) == "TEMP_NAME" { // unneeded extra layer
92 assert_eq!(intent.children().len(), 1);
93 return Ok( as_element(intent.children()[0]) );
94 } else {
95 return Ok(intent);
96 }
97 })
98}
99
100/// Speak the MathML
101/// If 'nav_node_id' is not an empty string, then the element with that id will have [[...]] around it

Callers 1

intent_from_mathmlFunction · 0.85

Calls 3

nameFunction · 0.85
as_elementFunction · 0.85
read_filesMethod · 0.80

Tested by

no test coverage detected