Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly use it in Python -- Translation errors, Math meaning errors, and how to set simple output #103

Open
WinterStraw opened this issue Jul 26, 2024 · 0 comments

Comments

@WinterStraw
Copy link

WinterStraw commented Jul 26, 2024

#97
I am following this issue to explore further.
I found several problems

  1. I successfully set analyze_math_meaning to True to get more meaningful output But some of the mathematical logic is still wrong. For example, f^{-1}(x) should be the inverse function of f x, but the Chinese result is f superscript negative 1 x.
    ############
    Output: [['标记'], [['f']], ['上标'], [[['负']], [['1']]], ['结束标记']], [['左小括']], [['x']], [['右小括']]
    Literal translation result: [[' tags'], [[' f ']], [' superscript '], [[[' negative ']], [[' 1 ']]], [' end tag]], [[' left small enclosed]], [[' x ']], [[' right small enclosed]]
    ############

  2. The output still has a description similar to the left/right parentheses
    ############
    The example in the first question already demonstrates this problem
    ############

  3. Some symbols are not translated
    ############
    [[''], [[''], [['c']], ['的平方']], [['等于']], [[''], [['a']], ['的平方']], [['加']], [[''], [['b']], ['的平方']], [['减']], [['2']], [['a']], [['b']], [], [['c']], [['d']], [['o']], [['t']], [], [['c']], [['o']], [['s']], [['左小括']], [], [['g']], [['a']], [['m']], [['m']], [['a']], [['右小括']], ['']]
    the 'cos' and 'gamma' are good, but cdot should be translated as '点乘‘ [dot product]
    ############

My code:
‘’‘
import latex2mathml.converter
from A8M_PM import MathContent, initialize
import config

try:
Access8MathConfig = config.conf["Access8Math"]
except AttributeError:
Access8MathConfig = {
"settings": {
"analyze_math_meaning": True,
"language": "zh_CN",
"LaTeX_delimiter": 'bracket',
"Nemeth_delimiter": "at",
"auto_generate": False,
"dictionary_generate": True,
"no_move_beep": True,
"command_mode": False,
"navigate_mode": False,
"shortcut_mode": False,
"writeNavAudioIndication": True,
"writeNavAcrossLine": True,
"LaTeX_delimiter": "bracket",
"Nemeth_delimiter": "at",
"speech_source": "Access8Math",
"braille_source": "Access8Math",
"interact_source": "Access8Math"
},
"rules": {
"SingleMsubsupType": True,
"SingleMsubType": True,
"SingleMsupType": True,
"SingleMunderoverType": True,
"SingleMunderType": True,
"SingleMoverType": True,
"SingleFractionType": True,
"SingleSqrtType": True,
"PowerType": True,
"SquarePowerType": True,
"CubePowerType": True,
"SetType": True,
"AbsoluteType": True,
"MatrixType": True,
"DeterminantType": True,
"AddIntegerFractionType": True,
}
}

initialize(Access8MathConfig)

def get_output(latex):
print('*' * 80)
mathMl = latex2mathml.converter.convert(latex)
mathcontent = MathContent("zh_CN", mathMl)
print(mathcontent.pointer.serialized())

if name == "main":
print('*' * 80)

latex_list = []

latex_list.append( r"(a + b)^2 = a^2 + 2ab + b^2" )

latex_list.append( r"x = \frac{{-b \pm \sqrt{{b^2 - 4ac}}}}{{2a}}")

latex_list.append(r"\frac{a}{\sin A} = \frac{b}{\sin B} = \frac{c}{\sin C}")

latex_list.append(r"f^{-1}(x) = \frac{1}{f'(f^{-1}(x))}")

latex_list.append(r"c^2 = a^2 + b^2 - 2ab \\cdot \\cos(\\gamma)")

for latex in latex_list:
    get_output(latex)

‘’‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant