Extension:Rdf

From MediaWiki.org
(Redirected from Extension:RDF)
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
RDF

Release status: unknown

Implementation Tag, Special page
Description Flexible framework that goes beyond the ability of the code described at RDF metadata
Author(s) Evan Prodromou
MediaWiki 1.6, 1.17
License No license specified
Download http://svn.wikimedia.org/svnroot/mediawiki/tags/REL1_17_2/extensions/Rdf/
Example WikiTravel:Wikitravel:RDF
Parameters

$wgRdfModelFunctions
$wgRdfDefaultModels
$wgRdfOutputFunctions
$wgRdfNamespaces
$wgRdfCacheExpiry

Hooks used
ArticleSave

ArticleSaveComplete
TitleMoveComplete
ArticleDeleteComplete

Translate the Rdf extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

This page is about an effort to provide an extensive RDF interface for MediaWiki. The idea is to create a flexible framework that goes beyond the ability of the code described at RDF metadata. There's an implementation by Evan Prodromou (see infobox), which is in production on Wikitravel (see WikiTravel:Wikitravel:RDF). The design arose from some discussions in 2005, mainly between Evan Prodromou and User:Duesentrieb.

Installation[edit | edit source]

  1. Download the files from SVN
  2. Place the downloaded files under extensions folder in your MediaWiki installation
  3. Add
    require_once("$IP/extensions/RDF/Rdf.php");
    into your wiki's LocalSettings.php
  4. The extension should be active now.

NOTE: Below is a copy of the original conceptual draft, it may not accurately describe the actual implementation by Evan!

Scope[edit | edit source]

The idea is to provide a way to query different kinds of information about a wiki page in RDF format. This may include

  • basic metadata as defined by the Dublin Core standard and/or the Creative Commons project.
  • List of all authors
  • List of all links to and from a page
  • List of keywords (Categories for a page)
  • List of members of a category
  • ...and a plugin interface for more.

Also, the RDF could be delivered in different notations, like

  • RDF/XML
  • N-Triple
  • Turtle
  • ..and maybe others.

This will probably implemented as an extension that provides a special page which, wehn called without parameters, would present a form where the user can specify what data is wanted in what format.

Another possible feature would be to allow users to add custom RDF information on any page, in Turtle format, in a <rdf>...</rdf> block

Implementation[edit | edit source]

The implementation will probably be based on the RAP framework [1].

core[edit | edit source]

The core function will take a list of "models", i.e. datasets wanted, and return a RAP model which can then be serialized to create the actual output.

Here is the code for that function, as suggested by Evan:

 function getRdf($article, $modelNames=$wgDefaultModelNames) {
   global $wgModelFunctions;
 
   #empty model

   $fullModel = new RAP::Model();
 
   for ($modelNames as $modelName) {
        $modelFunction = $wgModelFunctions[$modelName];
        if ($modelFunction == null) {
             #print error
             continue;
        }
        $model = $modelFunction($article);
        $fullModel->merge($model);
   }
 
   return $fullModel;
 }

$wgModelFunctions may be changed to contain a human readable description of the data set in addition to the function name. This would be displayed on the query form where the user can choose the data sets.

some example functions[edit | edit source]

Here's an example function for creating Dublin Core base data (code suggested by Evan):

 function DublinCoreModel($article) {
    global $DC_creator, $DC_date; # available from RAP system

    $model = new Model();
 
    $resource = getArticleResource($article); # Gets a RAP resource for the article; we'll have some utilities like this
    $user = getUserResource($article->getUser()); # another utility

    $model->add(new Statement($resource, $DC_creator, $user));
    $model->add(new Statement($resource, $DC_date, new Literal($article->getDate()));
 
    # etc.

    return $model;
 }

Example function for listing all links from a page (also suggested by User:Evan):

 function LinkingModel($article) {
 
    global $DCMES, $DCTERM, $DCMI_types;
 
    $model = new Model();
 
    $resource = getArticleResource($article); # here's that utility again
 
    $linkFromTitles = $article->links(); # actually, I'm pretty sure this doesn't exist, but it should. B-)
 
    for ($linkFromTitles as $linkFromTitle) {
        $model->add(new Statement($resource, $DCTERM['References'], titleToResource($linkFromTitle));
    }
 
    $linkToTitles = $article->whatLinksHere(); # another function that never was
 
    for ($linkToTitles as $linkToTitle) {
        $model->add(new Statement($resource, $DCTERM['isReferencedBy'], titleToResource($linkToTitle));
    }
 
    # ... more for Image links, etc.
 
    return $model;
 }

It may however be better to have a more generic function that allows to build such a list directly from an SQL query. This would make it very easy to add new datasets.

custom RDF[edit | edit source]

Function for building a model from custum RDF stuff on the wiki page:

 function InTextTurtleModel($article) {
 
    $text = $article->getText();
 
    $turtleBits = preg_match("<rdf>.*?</rdf>"); # Get stuff between <rdf> tags

    $turtle = string_join($turtleBits); # ...and join it into one big string

    $turtleParser = new N3Parser(); # RAP's "N3" parser is really a Turtle parser

    $model = $turtleParser->parse2model($turtle); # FIXME: handle errors here

    return $model; #  # That's it!
 }

the code on the wiki page would use Turtle notation. The example below says that some of the text of the page was copied from another Wikipedia article, and that another part of the page was copied from some other random URL.

 <rdf>
    <> dc:source <http://www.example.com/some/upstream/document.txt>, Wikipedia:AnotherArticle .
 
    <http://www.example.com/some/upstream/document.txt>
      a cc:Work;
      dc:creator "Anne Example-Person", "Anne Uther-Person";
      dc:contributor "Yadda Nudda Person";
      dc:dateCopyrighted "14 Mar 2005";
      cc:License cc:by-sa-1.0.
 </rdf>

Links[edit | edit source]

See also[edit | edit source]