As an ... I want to ... in order to ...
Problem:
Currently, we only export the MathML representation of a formula to RDF/Wikidata Query Service, not the original TeX string (T126349). This makes it impossible to efficiently query for statements with a certain math value – you have to use REGEX (CONTAINS is not enough, because the TeX annotation embedded in the MathML is not identical to the original TeX string). It also means that any external application that wants to use the TeX string based on the RDF export must use an XML parser to analyze the MathML and extract the TeX annotation.
Example:
Current JSON of Pythagorean theorem:
{ "mainsnak": { "snaktype": "value", "property": "P2534", "datavalue": { "value": "c^2=a^2 b^2", "type": "string" }, "datatype": "math" }, "type": "statement", "id": "Q11518$fe4a5b31-4f7e-29a3-06da-25f0186d9a42", "rank": "normal" }
Current TTL of the same item:
wd:Q11518 wdt:P2534 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"{\\displaystyle c^{2}=a^{2} b^{2}}\">\n <semantics>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n <msup>\n <mi>c</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n <mo>=</mo>\n <msup>\n <mi>a</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n <mo> </mo>\n <msup>\n <mi>b</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n </mstyle>\n </mrow>\n <annotation encoding=\"application/x-tex\">{\\displaystyle c^{2}=a^{2} b^{2}}</annotation>\n </semantics>\n</math>"^^<http://www.w3.org/1998/Math/MathML> . wd:Q11518 p:P2534 s:Q11518-fe4a5b31-4f7e-29a3-06da-25f0186d9a42 . s:Q11518-fe4a5b31-4f7e-29a3-06da-25f0186d9a42 a wikibase:Statement, wikibase:BestRank ; wikibase:rank wikibase:NormalRank ; ps:P2534 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"{\\displaystyle c^{2}=a^{2} b^{2}}\">\n <semantics>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n <msup>\n <mi>c</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n <mo>=</mo>\n <msup>\n <mi>a</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n <mo> </mo>\n <msup>\n <mi>b</mi>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mn>2</mn>\n </mrow>\n </msup>\n </mstyle>\n </mrow>\n <annotation encoding=\"application/x-tex\">{\\displaystyle c^{2}=a^{2} b^{2}}</annotation>\n </semantics>\n</math>"^^<http://www.w3.org/1998/Math/MathML> .
Screenshots/mockups:
BDD
GIVEN
AND
WHEN
AND
THEN
AND
Acceptance criteria:
Open questions:
Notes:
See T126349#2014848 for more information.
Side note: the “math” datatype currently seems to be missing completely from the RDF Dump Format page – once we’ve implemented this, we should rectify that.
See also the discussion on the request a query page and contact the development team.
Note from Lucas: I think we should add full value nodes for math values, with a structure a bit like this:
wd:Q4115189 a wikibase:Item; # ... wdt:P2534 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"{\\displaystyle a}\">\n <semantics>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n <mi>a</mi>\n </mstyle>\n </mrow>\n <annotation encoding=\"application/x-tex\">{\\displaystyle a}</annotation>\n </semantics>\n</math>"^^<http://www.w3.org/1998/Math/MathML>. wd:Q4115189 p:P2534 wds:Q4115189-af122b69-484b-2edd-1af8-f0a691b05039. wds:Q4115189-af122b69-484b-2edd-1af8-f0a691b05039 a wikibase:Statement; ps:P2534 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"{\\displaystyle a}\">\n <semantics>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n <mi>a</mi>\n </mstyle>\n </mrow>\n <annotation encoding=\"application/x-tex\">{\\displaystyle a}</annotation>\n </semantics>\n</math>"^^<http://www.w3.org/1998/Math/MathML>; psv:P2534 wdv:d961720c22709f7991be5be0ddf51c88. wdv:d961720c22709f7991be5be0ddf51c88 a wikibase:MathValue; wikibase:mathML "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\" alttext=\"{\\displaystyle a}\">\n <semantics>\n <mrow class=\"MJX-TeXAtom-ORD\">\n <mstyle displaystyle=\"true\" scriptlevel=\"0\">\n <mi>a</mi>\n </mstyle>\n </mrow>\n <annotation encoding=\"application/x-tex\">{\\displaystyle a}</annotation>\n </semantics>\n</math>"^^<http://www.w3.org/1998/Math/MathML>; wikibase:mathTeX "a"^^<http://latex.example/TODO>.