Extension:RDFa

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
RDFa

Release status: beta

Description Outputs semantic data of Mediawiki in the RDFa format.
Author(s) Jin Guang Zheng and Jie Bao
Latest version 0.0.3 (2010-02-10)
MediaWiki 1.9.* or greater
License The MIT License
Download See here

Translate the RDFa extension if possible

Check usage and version matrix; code metrics
This extension is most probably not functional with SMW 1.6+ as well as with MW 1.17+

What does this extension do?[edit | edit source]

This extension provides the functionality of outputting semantic data of Mediawiki pages in the RDFa format. The RDFa formatted data generated from a page will have the page itself as the subject. The properties and objects are retrieved from the semantic data of this page.

Besides the user defined properties, this extension is also able to recognize the following special properties:

  • Category
  • Has Type
  • Modification date
  • "Sub-Category" relation
  • Subproperty of

The corresponding properties in the RDFa format are as follows:

This extension does not generate any visible content for usual reading. You should use an RDFa-aware browser or tool to use the RDFa metadata.

The extension also provides the functionality that allows user to map the property of MediaWiki to other property. For example, instead of output property "has end date" from MediaWiki, user can ask the extension output property "vcal:dtend", where "vcal" is a prefix for "http://www.w3.org/2002/12/cal/icaltzd#".

RDFa -> Semantic MediaWiki Data

Another part of this extension provides the functionality to transform RDFa data to Semantic data in SMW. The extension first extracts the RDFa data of the source web page(Note: this extraction process requires ARC). Once we have all the triples from RDFa, the transformation process begins with creating a new helper wiki page(with hashed title) to hold each triple. Then the user can apply wiki template to generate Semantic data.

Download and installation[edit | edit source]

You can download the code at:

After you downloaded the code, place the code to the 'RDFa' directory within your MediaWiki 'extensions' directory. Then, add the following code to your LocalSetting.php after the line that installs Semantic MediaWiki.

Note: if you wants to use RDFa extraction part of the extension, you need download ARC2 lib, and put the code in RDFa_extractor directory.

require_once ("$IP/extensions/RDFa/rdfa.php");
require_once("$IP/extensions/RDFa_extractor/extract_rdfa.php");

You can browse the code at:

Dependencies[edit | edit source]

This extension requires Semantic MediaWiki. RDFa extraction part of the extension will be rely on ARC2 library

Functionalities and Usage (Semantic Data -> RDFa)[edit | edit source]

Basic Usage[edit | edit source]

[[capital of::Germany]]
[[locate in::Europe]]
[[has LatLong::52.5166667,13.4]]
[[Category:Location]]

Suppose there is a wiki page contains above structured data in wiki format. Further, lets assume the host address of the wiki is http://localhost/mediawiki. Then this extension will generate triples in the RDFa format as follows:

<div id='RDFa' about='http://localhost/mediawiki/index.php/Berlin' 
xmlns:wiki_1='http://localhost/mediawiki/index.php/' 
xmlns:wiki_1_property='http://localhost/mediawiki/index.php/Property:' 
xmlns:wiki_1_category='http://localhost/mediawiki/index.php/Category:' 
typeof='wiki_1_category:Location'>
<a href='wiki_1:Germany' rel='wiki_1_property:Capital_of'></a>
<div property='wiki_1_property:Has_LatLong' content='52.5166667,13.4'></div>
<a href='wiki_1:Europe' rel='wiki_1_property:Locate_in'></a>
<div property='wiki_1_property:Modification_date' content='3 September 2009 02:19:03'></div>
</div>

Notice that the extension use different html markup, <a> and <div>, to present the data. This is because the extension is able to regconize the type of the values of properties: the extension uses <a> to markup data if the value of property is another wiki page. Otherwise, the extension uses <div> markup. Also, the "typeof" property in the RDFa data is generated by the "Category" markup of wiki page.

These RDFa formatted data can be displayed as RDF triples:

<http://localhost/mediawiki/index.php/Berlin> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://localhost/mediawiki/index.php/Category:Location> .

<http://localhost/mediawiki/index.php/Berlin> <http://localhost/mediawiki/index.php/Property:Capital_of> <http://localhost/mediawiki/index.php/Germany> .

<http://localhost/mediawiki/index.php/Berlin> <http://localhost/mediawiki/index.php/Property:Has_LatLong> "52.5166667,13.4" .

<http://localhost/mediawiki/index.php/Berlin> <http://localhost/mediawiki/index.php/Property:Locate_in> <http://localhost/mediawiki/index.php/Europe> .

<http://localhost/mediawiki/index.php/Berlin> <http://localhost/mediawiki/index.php/Property:Modification_date> "3 September 2009 02:19:03" .

Mapping Properties[edit | edit source]

In some cases, the user may want to translate the property of MediaWiki to another property for certain purpose(so SearchMonkey of Yahoo! can display the enhanced search result). Parser function "rdfa_map" provides the functionality that maps one property of MediaWiki to other property.

We provides two ways for user to map between properties: 1. user can provide the title of a page which contains the mapping of properties(check Mapping Page Format for detail) at LocalSettings.php, 2. use parser function "rdfa_map"; Note: if bother ways are presented, extension will use the second one(parser function) to translate.

Provide page title[edit | edit source]

All you need to do is set variable $rdfa_map_page = "...page title..." in LocalSettings.php, and create the mapping at that page(check Mapping Page Format for detail). Exmaple:

$rdfa_map_page="property_map";

Parser function[edit | edit source]

Parser usage[edit | edit source]

{{#rdfa_map: property_map}}

The parser provided by the extension is associated with magic word "rdfa_map", and takes only one argument: title of the article which contains the mapping of two properties. For instance, in above example, the page contains the mapping of properties has title "property_map".

Mapping Page Format[edit | edit source]

Example: property_map

@prefix xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" <br />
@prefix xmlns:vcal="http://www.w3.org/2002/12/cal/icaltzd#" <br />
@prefix xmlns:dc="http://purl.org/dc/terms/" <br />
@prefix xmlns:vcard="http://www.w3.org/2006/vcard/ns#" <br />
@prefix xmlns:review="http://purl.org/stuff/rev#" <br />
@prefix xmlns:xsd="http://www.w3.org/2001/XMLSchema#" <br />
@prefix xmlns:commerce="http://search.yahoo.com/searchmonkey/commerce/" <br />
 
End_date       = vcal:dtend <br />
Location       = vcal:location <br />
Start_date     = vcal:dtstart <br />
Name           = dc:title <br />
Has_start_date = vcal:dtstart <br />
Has_end_date   = vcal:dtend <br />
Has_location   = vcal:location <br />
Has_label      = vcard:fn rdfs:label <br />
Comment        = rdfs:comment <br />
Latitude       = vcard:latitude <br />
Longitude      = vcard:longitude <br />
Longitude      = vcard:longitude <br />

The parser function recognizes the namespace declaration if "@prefix" provided. The format for namespace declaration is illustrated as above. Please note that there is a space between "@prefix" and the namespace, and a "<br />" after each declaration.

To map a property to a different property defined externally, we use "=" declare the mapping. In above example, property "End_date" in MediaWiki will be map to "vcal:dtend". Note: "vcal" is a namespace declared in the namespace declaration. Again, a "<br />" is needed after each mapping.

Functionalities and Usage (RDFa -> Semantic Data)[edit | edit source]

Parser Function[edit | edit source]

The extract part of the extension provides following parser:

{{#rdfa_extract: argument 1| argument 2}}

argument 1: (a html table<tb></tb>..

or wiki ask query) This argument should be a list of urls of web pages that contains rdfa data.

argument 2: a template that will be used to generate semantic annotation for the newly created wiki pages.

Example[edit | edit source]

Take the RDFa data in above section as an example, suppose we have RDFa data in a web page as below:

<div id='RDFa' about='http://localhost/mediawiki/index.php/Berlin' 
xmlns:wiki_1='http://localhost/mediawiki/index.php/' 
xmlns:wiki_1_property='http://localhost/mediawiki/index.php/Property:' 
xmlns:wiki_1_category='http://localhost/mediawiki/index.php/Category:' 
typeof='wiki_1_category:Location'>
<a href='wiki_1:Germany' rel='wiki_1_property:Capital_of'></a>
<div property='wiki_1_property:Has_LatLong' content='52.5166667,13.4'></div>
<a href='wiki_1:Europe' rel='wiki_1_property:Locate_in'></a>
<div property='wiki_1_property:Modification_date' content='3 September 2009 02:19:03'></div>
</div>

We can create a extract the rdfa data using the parser:

{{#rdfa_extract: <table><tr><tb>http://localhost/mediawiki/index.php/Berlin</tb></tr>| location_template}}

The RDFa extraction part of the extension will extract RDFa data at http://localhost/mediawiki/index.php/Berlin, and create 4 new wiki pages, each of these wiki page will hold one of these rdfa triples:

Example of newly created wiki page:

{{location_template|http://localhost/mediawiki/index.php/Berlin|http://localhost/mediawiki/index.php/Property:Has_LatLonge|52.5166667,13.4}}<br>

Then you can create a location_template to render this triple:

[[Subject::{{{1}}}]]
[[Property::{{{2}}}]]
[[Object::{{{3}}}]]

Done !!!!

Now you can use any of the parsing, rendering functionalities provided by Semantic MediaWiki to play with these triples.

Bugs, new feature request and contact information[edit | edit source]

Please reports bug, feature requests, or any feedback to zhengj3-at-rpi.edu

RDFa viewers[edit | edit source]

Please look at http://rdfa.info/wiki/Tools

Todo[edit | edit source]

  • an "action=rdfa" option to a page to render only rdfa data

Release Log[edit | edit source]

  • Date: 2009-09-11, version number:0.0.1, Version Description: initial version.
    • This version provides basic functionality of allowing people to output semantic data in RDFa format.
    • Download link: RDFa Extension (Version 1)

See also[edit | edit source]

However, there are issues with it (I've put your example from [1] as a standalone doc at [2]) - this stems from the fact that you're producing URIs (eg, in @typeof, @rel, @property) where only CURIEs are allowed [3]. Hence an RDFa processor (as in [2]) tries to interpret your URI as CURIE, for example: