Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/269473

Change subject: WIP: RDF Formatter for Math data type
......................................................................

WIP: RDF Formatter for Math data type

Change-Id: I15fbeec282868b4267a3e3d15740f2c3ff37ea48
---
A MathMLRdfBuilder.php
M MathWikidataHook.php
M extension.json
3 files changed, 53 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/73/269473/1

diff --git a/MathMLRdfBuilder.php b/MathMLRdfBuilder.php
new file mode 100644
index 0000000..ed7d790
--- /dev/null
+++ b/MathMLRdfBuilder.php
@@ -0,0 +1,37 @@
+<?php
+
+use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\Rdf\ValueSnakRdfBuilder;
+use Wikimedia\Purtle\RdfWriter;
+
+class MathMLRdfBuilder implements ValueSnakRdfBuilder{
+
+       /**
+        * Adds specific 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
+       ) {
+               /** @var \DataValues\StringValue $val */
+               $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 );
+       }
+}
\ No newline at end of file
diff --git a/MathWikidataHook.php b/MathWikidataHook.php
index 62183de..7d7a3a5 100644
--- a/MathWikidataHook.php
+++ b/MathWikidataHook.php
@@ -2,8 +2,13 @@
 
 use ValueFormatters\FormatterOptions;
 use ValueParsers\StringParser;
+use Wikibase\Rdf\DedupeBag;
+use Wikibase\Rdf\EntityMentionListener;
+use Wikibase\Rdf\RdfVocabulary;
+use Wikibase\Rdf\Values\MonolingualTextRdfBuilder;
 use Wikibase\Repo\Parsers\WikibaseStringValueNormalizer;
 use Wikibase\Repo\WikibaseRepo;
+use Wikimedia\Purtle\RdfWriter;
 
 class MathWikidataHook {
 
@@ -41,6 +46,15 @@
                                $wgOut->addModuleStyles( $styles );
                                return new MathFormatter( $format );
                        },
+                       'rdf-builder-factory-callback' => function (
+                               $mode,
+                               RdfVocabulary $vocab,
+                               RdfWriter $writer,
+                               EntityMentionListener $tracker,
+                               DedupeBag $dedupe
+                       ) {
+                               return new MathMLRdfBuilder();
+                       },
                );
        }
 
diff --git a/extension.json b/extension.json
index 9a00606..edc8732 100644
--- a/extension.json
+++ b/extension.json
@@ -28,7 +28,8 @@
                "SpecialMathStatus": "SpecialMathStatus.php",
                "MathValidator": "MathValidator.php",
                "MathFormatter": "MathFormatter.php",
-               "MathWikidataHook": "MathWikidataHook.php"
+               "MathWikidataHook": "MathWikidataHook.php",
+               "MathMLRdfBuilder": "MathMLRdfBuilder.php"
        },
        "DefaultUserOptions": {
                "math": "png"

-- 
To view, visit https://gerrit.wikimedia.org/r/269473
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15fbeec282868b4267a3e3d15740f2c3ff37ea48
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to