77
88
99import os
10- import libmathcat
10+ import sys
11+ import libmathcat_py as libmathcat # type: ignore
1112
1213# import shutil
1314# if os.path.exists("libmathcat_py.pyd"):
1415# os.remove("libmathcat_py.pyd")
1516# shutil.copy("..\\target\\i686-pc-windows-msvc\\release\\libmathcat_py.dll", "libmathcat.pyd")
1617
1718
18- def SetMathCATPreferences ():
19+ def setMathCATPreferences ():
1920 try :
2021 libmathcat .SetRulesDir (
2122 # this assumes the Rules dir is in the same dir a the library. Modify as needed
2223 os .path .join (os .path .dirname (os .path .abspath (__file__ )), "Rules" )
2324 )
2425 except Exception as e :
25- print ( "problem with finding the MathCAT rules" , e )
26+ sys . exit ( f "problem with finding the MathCAT rules: { e } " )
2627
2728 try :
2829 libmathcat .SetPreference ("TTS" , "none" )
2930 libmathcat .SetPreference ("Language" , "en" ) # Also "id" and "vi"
3031 libmathcat .SetPreference ("SpeechStyle" , "SimpleSpeak" ) # Also "ClearSpeak"
3132 libmathcat .SetPreference ("Verbosity" , "Verbose" ) # also terse "Terse"/"Medium"
3233 libmathcat .SetPreference ("CapitalLetters_UseWord" , "true" ) # if "true", X => "cap x"
34+ libmathcat .SetPreference ("BrailleCode" , "Nemeth" );
3335 except Exception as e :
34- print ( "problem with setting a preference" , e )
36+ sys . exit ( f "problem with setting a preference: { e } " )
3537
3638
37- def SetMathMLForMathCAT (mathml : str ):
39+ def setMathMLForMathCAT (mathml : str ):
3840 try :
3941 libmathcat .SetMathML (mathml )
4042 except Exception as e :
41- print ( "problem with SetMathML" , e )
43+ sys . exit ( f "problem with setMathML: { e } " )
4244
4345
44- def GetSpeech ():
46+ def getSpeech ():
4547 try :
4648 return libmathcat .GetSpokenText ()
4749 except Exception as e :
48- return "problem with getting speech for MathML" , e
50+ sys . exit ( f "problem with getting speech for MathML: { e } " )
4951
5052
51- SetMathCATPreferences () # you only need to this once
53+ def getBraille ():
54+ try :
55+ return libmathcat .GetBraille ("" )
56+ except Exception as e :
57+ sys .exit (f"problem with getting braille for MathML: { e } " )
58+
59+
60+ def test ():
61+ setMathCATPreferences () # you only need to this once
62+ print ("Using MathCAT version '{}'" .format (libmathcat .GetVersion ()))
63+
64+ mathml = "<math><mfrac> <mn>1</mn> <mi>X</mi> </mfrac> </math>"
65+ setMathMLForMathCAT (mathml )
66+ speech = getSpeech ()
67+ if speech != '1 over cap x,' :
68+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
69+ braille = getBraille ()
70+ if braille != '⠹⠂⠌⠠⠭⠼' :
71+ sys .exit (f"MathML: { mathml } \n Braille: '{ braille } '" )
72+
73+ mathml = "<math display='block'><mi>x</mi><mo>⨯</mo><mi>y</mi></math>"
74+ setMathMLForMathCAT (mathml )
75+ speech = getSpeech ()
76+ if speech != 'x cross product y' :
77+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
78+
79+ mathml = "<math><msup> <mi>x</mi> <mn>3</mn> </msup> </math>"
80+ setMathMLForMathCAT (mathml )
81+ speech = getSpeech ()
82+ if speech != 'x cubed' :
83+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
84+
5285
53- print ("Using MathCAT version '{}'" .format (libmathcat .GetVersion ()))
86+ mathml = "<math><msup intent='transpose:postfix($x)'> <mi arg='x'>x</mi> <mi>T</mi> </msup> </math>"
87+ setMathMLForMathCAT (mathml )
88+ speech = getSpeech ()
89+ if speech != ', x transpose' :
90+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
5491
55- mathml = "<math><mfrac> <mn>1</mn> <mi>X</mi> </mfrac> </math>"
56- SetMathMLForMathCAT (mathml )
57- print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
5892
59- mathml = "<math display='block'><mi>x</mi><mo>⨯</mo><mi>y</mi></math>"
60- SetMathMLForMathCAT (mathml )
61- print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
93+ mathml = "<math><mrow intent='_(x, $op)'><mo arg='op'>!</mo></mrow></math>"
94+ setMathMLForMathCAT (mathml )
95+ speech = getSpeech ()
96+ if speech != 'x factorial' :
97+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
6298
63- mathml = "<math><msup> <mi>x</mi> <mn>3</mn> </msup> </math>"
64- SetMathMLForMathCAT (mathml )
65- print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
99+ mathml = "<math intent=':structure'><mrow><mo>\
100+ (</mo><mfrac linethickness='0'><mn arg='n'>7</mn><mn arg='m'>3</mn></mfrac><mo>)</mo></mrow></math>"
101+ setMathMLForMathCAT (mathml )
102+ speech = getSpeech ()
103+ if speech != '7 choose 3' :
104+ sys .exit (f"MathML: { mathml } \n Speech: '{ speech } '" )
66105
67- mathml = "<math><msup intent='transpose:postfix($x)'> <mi arg='x'>x</mi> <mi>T</mi> </msup> </math>"
68- SetMathMLForMathCAT (mathml )
69- print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
106+ print ("Test was successful!" )
70107
71- mathml = "<math><mrow intent='_(x, $op)'><mo arg='op'>!</mo></mrow></math>"
72- SetMathMLForMathCAT (mathml )
73- print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
74108
75- mathml = "<math intent=':structure'><mrow><mo>\
76- (</mo><mfrac linethickness='0'><mn arg='n'>7</mn><mn arg='m'>3</mn></mfrac><mo>)</mo></mrow></math>"
77- SetMathMLForMathCAT (mathml )
78- print ("MathML: {}\n Speech (no inference): '{}'" .format (mathml , GetSpeech ()))
109+ test ()
110+ sys .exit (0 )
0 commit comments