Debian Codegraph @

extensions/Math/src/MathMLRdfBuilder.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Math;
4
5 use Wikibase\DataModel\Snak\PropertyValueSnak;
6 use Wikibase\Repo\Rdf\ValueSnakRdfBuilder;
7 use Wikimedia\Purtle\RdfWriter;
8
9 class MathMLRdfBuilder implements ValueSnakRdfBuilder {
10
11 /**
12 * Adds a value
13 *
14 * @param RdfWriter $writer
15 * @param string $propertyValueNamespace Property value relation namespace
16 * @param string $propertyValueLName Property value relation name
17 * @param string $dataType Property data type
18 * @param string $snakNamespace
19 * @param PropertyValueSnak $snak
20 */
21 public function addValue(
22 RdfWriter $writer,
23 $propertyValueNamespace,
24 $propertyValueLName,
25 $dataType,
26 $snakNamespace,
27 PropertyValueSnak $snak
28 ) {
29 $renderer = new MathMathML( $snak->getDataValue()->getValue() );
30 if ( $renderer->checkTeX() && $renderer->render() ) {
31 $mml = $renderer->getMathml();
32 } else {
33 $err = $renderer->getLastError();
34 $mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><merror>$err</merror></math>";
35 }
36 $writer->say( $propertyValueNamespace, $propertyValueLName )
37 ->value( $mml, 'http://www.w3.org/1998/Math/MathML' );
38 }
39 }