GithubHelp home page GithubHelp logo

Comments (13)

harishbalachandran avatar harishbalachandran commented on July 29, 2024

@rtibbles @aronasorman can you put a ETA on this? Its a blocker for the MG channel.

from studio.

rtibbles avatar rtibbles commented on July 29, 2024

This should be achievable using a combination of https://github.com/transpect/mml2tex and then leveraging the xslt file in Python: http://stackoverflow.com/questions/16698935/how-to-transform-an-xml-file-using-xslt-in-python#answer-16699042

from studio.

jamalex avatar jamalex commented on July 29, 2024

The Perseus exercise renderer does not support MathML. Math formulas will need to be converted into latex format, and then inserted into the exercise text surrounded by $ symbols.

For example, if you put in $ f(x) = 2 ^ 3 $, it will be rendered as:
image

(the tools that @rtibbles mentiones above may be helpful for doing this in an automated way)

from studio.

yogeshmhaskule avatar yogeshmhaskule commented on July 29, 2024

@rtibbles @aronasorman @jamalex For more clarification, will this issue be handled in ricecooker or we need to handle it in our code (i.e sushi chef). I remember @aronasorman @jayoshih had taken care of the same issue before in ricecooker itself.

from studio.

jayoshih avatar jayoshih commented on July 29, 2024

@yogeshmhaskule See #222 You'll need to convert it to latex to bypass the html escaping using the tools @rtibbles mentioned

from studio.

yogeshmhaskule avatar yogeshmhaskule commented on July 29, 2024

@jayoshih @aronasorman If you provide sample example of convert mathml data to latex in "Sample program file". So we can take reference from it. It will helpful to us to move forward.

from studio.

jamalex avatar jamalex commented on July 29, 2024

Again, as this isn't something we support in the ricecooker, it's the responsibility of the sushi chef to convert into usable formats. You can use whatever tools you want to do the conversion, before passing it into the ricecooker.

Here's an example:

  • Install xsltproc (e.g., on Ubuntu, sudo apt-get install xsltproc)
  • Download and unzip these xslt specifications
  • Run a file with MathML in it through the converter:
> cat test.mml
<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>
    <mfrac>
      <mrow><mi>x</mi></mrow>
      <mrow><mi>y</mi></mrow>
    </mfrac>
  </mrow>
</math>

> xsltproc mmltex.xsl test.mml > test.tex

> cat test.tex
$ \frac{x}{y}$

You can either use a tool like that and run it from Python via subprocess, or you may be able to plug those xslt definitions into the tool @rtibbles linked to do it directly within Python.

from studio.

yogeshmhaskule avatar yogeshmhaskule commented on July 29, 2024

@jamalex @aronasorman I went through the xsltproc and it's working for me. But few of mathml questions are not rendering properly onto kolibri. This issue is specially to mathml which contains text. Latex conversion of same question is $ Convert the improper fraction into whole number.\phantom{\rule{0ex}{0ex}}\frac{12}{3}$. And same data shown on cc server. After importing the questions onto kolibri. It removes the white spaces between question text (Converttheimproperfractionintowholenumber.).

Screenshot of cc

screen shot 2017-05-02 at 7 36 15 pm

Screenshot of kolibri

witout space

from studio.

jamalex avatar jamalex commented on July 29, 2024

@yogeshmhaskule Can you post the full source HTML & MathML for that source question into the issue here? It seems as if the first sentence should be left outside the $, as it's not a math formula.

from studio.

yogeshmhaskule avatar yogeshmhaskule commented on July 29, 2024

@jamalex Below is the response of same question.

{
	'48113': {
		'success': True,
		'question': {
			'answer_type': 'number',
			'id': 48113,
			'topic_id': 2890,
			'unit': None,
			'difficulty_level': 1,
			'content': '<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>C</mi><mi>o</mi><mi>n</mi><mi>v</mi><mi>e</mi><mi>r</mi><mi>t</mi><mo>&#160;</mo><mi>t</mi><mi>h</mi><mi>e</mi><mo>&#160;</mo><mi>i</mi><mi>m</mi><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>e</mi><mi>r</mi><mo>&#160;</mo><mi>f</mi><mi>r</mi><mi>a</mi><mi>c</mi><mi>t</mi><mi>i</mi><mi>o</mi><mi>n</mi><mo>&#160;</mo><mi>i</mi><mi>n</mi><mi>t</mi><mi>o</mi><mo>&#160;</mo><mi>w</mi><mi>h</mi><mi>o</mi><mi>l</mi><mi>e</mi><mo>&#160;</mo><mi>n</mi><mi>u</mi><mi>m</mi><mi>b</mi><mi>e</mi><mi>r</mi><mo>.</mo><mspace linebreak="newline"/><mfrac><mn>12</mn><mn>3</mn></mfrac></math>'
		},
		'possible_answers': [{
			'question_id': 48113,
			'content': '4',
			'id': 114224,
			'is_correct': True
		}]
	}
}

Here is the another mathml question where xsltproc working properly also it shows the content properly onto kolibri.

{
	'100755': {
		'success': True,
		'question': {
			'answer_type': 'number',
			'id': 100755,
			'topic_id': 2890,
			'unit': None,
			'difficulty_level': 1,
			'content': 'Convert <math xmlns="http://www.w3.org/1998/Math/MathML"><mfrac><mn>30</mn><mn>3</mn></mfrac></math> into a whole number.'
		},
		'possible_answers': [{
			'question_id': 100755,
			'content': '10',
			'id': 192953,
			'is_correct': True
		}]
	}
}

Screenshot of working mathml conversion onto kolibri

first

from studio.

jamalex avatar jamalex commented on July 29, 2024

The MathML in the first example doesn't seem quite proper. It splits each letter of the non-math content into separate symbols. When I render it using an online MathML renderer, I get:

image

The format of the second example (which renders properly) looks correct -- non-math text is outside of the <math> block.

from studio.

harishbalachandran avatar harishbalachandran commented on July 29, 2024

@jamalex There are quite a few questions on MagoGenie front, that are of the first type (The entire question with the text declared as Math ML). Is there a way to work around for these set of questions.

For the second one, its not a problem since only the equations or the formulas are declared as MathML and we can import them without road block.

from studio.

jamalex avatar jamalex commented on July 29, 2024

It will probably require a pre-processing stage that detects and extracts the non-math text from the MathML block, before going through xsltproc. Depending on how consistently this content is marked up, it may be possible to do this with regular expressions, or else through parsing with an XML parser like lxml or maybe BeautifulSoup.

To more easily test final output and how it will look in Kolibri, you can use this tool:
http://khan.github.io/perseus/
(Put the output text in the Question box, and click "view rendered")

from studio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.