SimpleGraph-MediaWiki

From BITPlan Wiki
Jump to navigation Jump to search

SimpleGraph MediaWiki module

The SimpleGraph MediaWiki module makes MediaWiki site content accessible to Graph processing. It exposes the MediaWiki API using the mediawiki-japi Library by BITPlan.

Example

Goal

We'd like to get the pageContent of the MediaWiki article on Cologne

Result

...
{{Infobox German location
|name              = Cologne
|German_name       = ''Köln''
|type               = City
|image_photo       = Cologne montage.png
|imagesize         = 270px
|image_caption     = From top to bottom, left to right:<br />
[[Hohenzollern Bridge]] by night, [[Great St. Martin Church]], [[Colonius]] TV-tower, [[Cologne Cathedral]], ''[[Kranhaus]]'' buildings in [[Rheinauhafen]], [[MediaPark]]
|image_coa            =Großes Wappen von Köln.svg
|image_flag = Flagge Köln.svg
|image_plan = North rhine w K.svg
|plantext = Cologne within North Rhine-Westphalia
|coordinates       = {{coord|50|56|11|N|6|57|10|E|format=dms|display=inline,title}}
|state        = Nordrhein-Westfalen
|region  = [[Cologne (region)|Cologne]]
|district             = Urban districts of Germany
|elevation              = 37
|area            = 405.15
|population         = 1057327 <!--Technical, do not add dots, references or other, the table is automatically updated-->
|pop_metro   = 3573500
|Stand             = 2014/12/31
|postal_code               = 50441–51149
|PLZ-alt           = 5000
|area_code           = 0221, 02203 ([[Porz]])
|licence               = K
|Gemeindeschlüssel = 05 3 15 000
|LOCODE            = DE CGN
|mayor     = [[Henriette Reker]]
|Bürgermeistertitel = [[Lord Mayor]]
|website           = [http://www.stadt-koeln.de www.stadt-koeln.de]
|year              = 38 BC
}}
...

Explanation

JUnit TestCase

 @Test
  public void testGetPage() throws Exception {
    debug=true;
    MediaWikiSystem mws = new MediaWikiSystem();
    MediaWikiPageNode pageNode = (MediaWikiPageNode) mws
        .connect("https://en.wikipedia.org", "/w")
        .moveTo("Cologne");
    if (debug)
      pageNode.printNameValues(System.out);
    String pageContent=pageNode.getProperty("pageContent").toString();
    assertTrue(pageContent.contains("[[Category:Cities in North Rhine-Westphalia]]"));
  }