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

Function find_arg

src/infer_intent.rs:384–419  ·  view source on GitHub ↗

look for @arg=name in mathml if 'check_intent', then look at an @intent for this element (typically false for non-recursive calls)

(rules_with_context: &'r mut SpeechRulesWithContext<'c,'s,'m>, name: &str, mathml: Element<'c>, skip_self: bool, no_check_inside: bool)

Source from the content-addressed store, hash-verified

382/// look for @arg=name in mathml
383/// if 'check_intent', then look at an @intent for this element (typically false for non-recursive calls)
384fn find_arg<'r, 'c, 's:'c, 'm:'c>(rules_with_context: &'r mut SpeechRulesWithContext<'c,'s,'m>, name: &str, mathml: Element<'c>, skip_self: bool, no_check_inside: bool) -> Result<Option<Element<'m>>> {
385 // debug!("Looking for '{}' in\n{}", name, mml_to_string(&mathml));
386 if !skip_self {
387 if let Some(arg_val) = mathml.attribute_value("arg") {
388 // debug!("looking for '{}', found arg='{}'", name, arg_val);
389 if name == arg_val {
390 // check to see if this mathml has an intent value -- if so the value is the value of its intent value
391 if let Some(intent_str) = mathml.attribute_value("intent") {
392 let mut lex_state = LexState::init(intent_str.trim())?;
393 return Ok( Some( build_intent(rules_with_context, &mut lex_state, mathml)? ) );
394 } else {
395 return Ok( Some( rules_with_context.match_pattern::<Element<'m>>(mathml)? ) );
396 }
397 } else if no_check_inside {
398 return Ok(None); // don't look inside 'arg'
399 }
400 }
401 }
402
403 if no_check_inside && mathml.attribute_value("intent").is_some() {
404 return Ok(None); // don't look inside 'intent'
405 }
406
407 if is_leaf(mathml) {
408 return Ok(None);
409 }
410
411 for child in mathml.children() {
412 let child = as_element(child);
413 if let Some(element) = find_arg(rules_with_context, name, child, false, true)? {
414 return Ok( Some(element) );
415 }
416 }
417
418 return Ok(None); // not present
419}
420
421#[cfg(test)]
422mod tests {

Callers 1

build_intentFunction · 0.85

Calls 3

build_intentFunction · 0.85
is_leafFunction · 0.85
as_elementFunction · 0.85

Tested by

no test coverage detected