forked from wikimedia/mediawiki-extensions-Math
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathMLRdfBuilder.php
35 lines (32 loc) · 1.01 KB
/
MathMLRdfBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\Rdf\ValueSnakRdfBuilder;
use Wikimedia\Purtle\RdfWriter;
class MathMLRdfBuilder implements ValueSnakRdfBuilder {
/**
* Adds a value
*
* @param RdfWriter $writer
* @param string $propertyValueNamespace Property value relation namespace
* @param string $propertyValueLName Property value relation name
* @param string $dataType Property data type
* @param PropertyValueSnak $snak
*/
public function addValue(
RdfWriter $writer,
$propertyValueNamespace,
$propertyValueLName,
$dataType,
PropertyValueSnak $snak
) {
$renderer = new MathMathML( $snak->getDataValue()->getValue() );
if ( $renderer->checkTeX() && $renderer->render() ) {
$mml = $renderer->getMathml();
} else {
$err = $renderer->getLastError();
$mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><merror>$err</merror></math>";
}
$writer->say( $propertyValueNamespace, $propertyValueLName )
->value( $mml, 'http://www.w3.org/1998/Math/MathML' );
}
}