Skip to content

andrecastro0o/ontology2smw

Repository files navigation

ontology2smw build pytest

Ontology to SMW

Automating an RDF ontology import into Semantic Mediawiki

Semantic Mediawiki(SMW) allows external ontologies to be imported into a Mediawiki (MW) instance. External ontology's properties and classes can be used inside the MW instance, and produce a RDF exports of the wiki pages, which point to IRIs of the imported ontology(s).

The process of importing is simple, but time consuming. Hence making it a perfect candidate for an automated process, which can be run at anytime a new version of the ontology is published, hence this python script.

Watch the ontology2smw presentation at SMWCon 2020.

ontology2smw import workflow

Supports:

  • python3.6, python3.7, python3.8

Install:

Manually

git clone https://github.com/TIBHannover/ontology2smw.git
cd ontology2smw
# ---- (optional) create and activate a virtual-environment
python -m venv venv
source venv/bin/activate
# ---- virtual environment created
pip install --upgrade setuptools
python setup.py install

Run:

Run:

Using a remote ontology:
ontology2smw --format ttl --ontology https://raw.githubusercontent.com/tibonto/aeon/master/aeon.ttl

Writing to wiki pages:
ontology2smw --format ttl --ontology https://raw.githubusercontent.com/tibonto/aeon/master/aeon.ttl --write

Asking for help:
ontology2smw --help

usage: ontology2smw [-h] [-w] [-o ONTOLOGY] [-f {rdf,ttl}] [-v] [-r]


                   ___    
                 { . . } 
--------------o00---'----00o--
              ontology2SMW  
-----------------------------

optional arguments:
  -h, --help            show this help message and exit
  -w, --write           writes the output to wiki or file. Default: False (dry-run).
  -o ONTOLOGY, --ontology ONTOLOGY
                        Ontology file or URI. Default: https://raw.githubusercontent.com/tibonto/aeon/master/aeon.ttl 
  -f {rdf,ttl}, --format {rdf,ttl}
                        Ontology format. Default value: ttl
  -v, --verbose         Verbose output. Default: False.
  -r, --report          Save report in file report.txt Default: False.

To write wiki pages

wikidetails.yml & wiki write access

  • Ensure user your wiki user account belongs to bot group: see wiki page Special:UserRights
  • Create a bot password in wiki page: Special:BotPasswords
  • copy wikidetails.template.yml as wikidetails.yml and fill in bot name and password:
  • give the bot appropriate rights: basic, editinterface, editpage, editprotected, createeditmovepage, highvolume

The local test VM, mentioned in the following section, sets a bot account for the Admin user, so that once the VM is created you can just run the script against it. Details for that wiki, VM, bot username and password are set in wikidetails.yml

Try on local Virtual Machine

In order to test ontology2smw in action in a isolated virtual environment, the repository includes a Ansible playbook which creates a VM with Mediawiki installed, and also creates a Bot account for wiki user Admin.

The playbook sets Mediawiki with:

  • URL: https://192.168.100.100/w
  • SemanticMediawiki extension
  • bot account for Admin, with details (in wikidetail.yml):
    • wiki user: Admin
    • wiki user password: adminpassword
    • wiki bot: Admin@ontology2smwbot
    • wiki bot password: botpasswordbotpasswordbotpassword

Requirements:

Create VM:

cd vm
vagrant up
ansible-playbook playbook_mw.yml

Once tests are done you can either,

  • suspend the VM: vagrant suspend so it can be reused from the state it was left in with vagrant up
  • destroy it: vagrant destroy

Develop

git clone https://github.com/TIBHannover/ontology2smw.git
cd ontology2smw
# (optional) create and activate a virtual-environment
pip install -r requirements.txt
python -m ontology2smw

Test

Tox: automated testing on py36, py37, py38 tox -p all -v

  • pytest
  • flake8s
  • test coverage report

pytest

  • without running target VM running Mediawiki + SMW pytest -m "not smw"
  • with VM running Mediawiki + SMW pytest for all the tests