NSoiffer / MathCAT

MathCAT: Math Capable Assistive Technology for generating speech, braille, and navigation.
MIT License
60 stars 35 forks source link

Unexpected braille Ok result and gibberish braille output when expecting an error #39

Closed brichwin closed 2 years ago

brichwin commented 2 years ago

For fun, I fed some content MathML to MathCat 0.1.23 and got an expected error from get_spoken_text() but received an Ok result and gibberish braille instead of an expected error from get_braille("".to_string()):

u⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tapplyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼teqe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tciu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixrowe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tcie⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tciu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixrowe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tcie⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tci

The MathML was:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>
    <mi>A</mi>
    <mo>=</mo>
    <mfenced open="[" close="]">
      <mtable>
        <mtr>
          <mtd>
            <mi>x</mi>
          </mtd>
          <mtd>
            <mi>y</mi>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mi>z</mi>
          </mtd>
          <mtd>
            <mi>w</mi>
          </mtd>
        </mtr>
      </mtable>
    </mfenced>
  </mrow>
</math>
NSoiffer commented 2 years ago

I think you made a mistake pasting in the MathML. It's not content MathML and when I try it, there is no problem in either https://nsoiffer.github.io/MathCATDemo/ (which is V0.1.22) or on my current version of MathCAT.

I'm not surprised that MathCAT would do poorly with content MathML. On my todo list is to do something about illegal MathML (wrong elements).

Can you retry with the content MathML you used.

Thanks,

Neil

On Wed, Jun 8, 2022 at 1:12 PM Brian Richwine @.***> wrote:

For fun, I fed some content MathML to MathCat 0.1.23 and got an expected error from get_spoken_text() but received an Ok result and gibberish braille instead of an expected error from get_braille("".to_string()):

u⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tapplyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼teqe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tciu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixrowe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tcie⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tciu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼t⠐atrixrowe⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tcie⠐ptyu⠼k⠼ow⠼⠐ath⠐lele⠐e⠼tci

The MathML was:

A = x y z w

— Reply to this email directly, view it on GitHub https://github.com/NSoiffer/MathCAT/issues/39, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALZM3GMPCRR3KW6NTR7HSTVOD5D7ANCNFSM5YHXSZZQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

brichwin commented 2 years ago

Oh, yes. Sorry - That is the wrong MathML. Here is what I had used:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>
    <apply>
      <eq />
      <ci>A</ci>
      <matrix>
        <matrixrow>
          <ci>x</ci>
          <ci>y</ci>
        </matrixrow>
        <matrixrow>
          <ci>z</ci>
          <ci>w</ci>
        </matrixrow>
      </matrix>
    </apply>
  </mrow>
</math>
brichwin commented 2 years ago

For my testing, I modified the main.rs included in the repo so I could pass MathML as an argument and then get a JSON result back. I then called the mathcat.exe file from node.js. It's inefficient, but was a quick way for me to do testing. In case it matters, the main.rs I used was:

// *** MathCAT doesn't normally want to build a binary ***
// *** This file is here because it is useful for trying out things ***

fn main() {
  use libmathcat::interface::*;
  use std::env;

  let args: Vec<String> = env::args().collect();
  let expr = &args[1];

  let rules_dir = std::env::current_exe().unwrap().parent().unwrap().join("./Rules");
  let rules_dir = rules_dir.as_os_str().to_str().unwrap().to_string();
  if let Err(e) = set_rules_dir(rules_dir) {
    panic!("Error: exiting -- {}", errors_to_string(&e));  }
  if let Err(e) = set_mathml(expr.to_string()) {
    panic!("Error: exiting -- {}", errors_to_string(&e));
  };

  // println!("Version = '{}'", get_version());
  set_preference("TTS".to_string(), "none".to_string()).unwrap();
  // set_preference("Bookmark".to_string(), "true".to_string()).unwrap();
  set_preference("SpeechStyle".to_string(), "ClearSpeak".to_string()).unwrap();

  let mut json_string = String::new();

  json_string.push_str("{ clearspeak:'");

  match get_spoken_text() {
    Ok(speech) => json_string.push_str(&speech),
    Err(e) => json_string.push_str("ERROR"),
  }

  json_string.push_str("', braille:'");

  set_preference("BrailleCode".to_string(), "Nemeth".to_string()).unwrap();
  match get_braille("".to_string()) {
    Ok(braille) => json_string.push_str(&braille),
    Err(e) => json_string.push_str("ERROR"),
  }
  json_string.push_str("'}");
  println!("{}", json_string);
}
NSoiffer commented 2 years ago

I'm wavering back and forth between:

  1. generating an error when I get non-presentation MathML elements
  2. ignoring them and plowing on
  3. replacing them with some error speech and/or braille such as "unknown mathml tag xxx with children ..."

Any preference?

'1' is unfriendly to users but better in many cases (I think) for programs that call MathCAT. '2' might result in somewhat bizarre, but '3' is pretty disruptive.

NSoiffer commented 2 years ago

I went with '1' (an error if not valid presentation MathML)