RDF in Semantic Mediawiki: Difference between revisions

From artserver wiki
No edit summary
m (Text replacement - "Code_Notes" to "Code Notes")
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{#set: Section:Code Notes
|Date:2020
}}


=Notes on importing ontologies to SMW=


==Import ontology==
'''Notes on importing ontologies to SMW
'''


at page <nowiki>MediaWiki:Smw_import_dcterm</nowiki>
=How to importing ontology?=
The documentation on importing existing ontologies to SMW in its Manual Section [https://www.semantic-mediawiki.org/wiki/Help:Import_vocabulary Help:Import_vocabulary]
 
==MediaWiki:Smw_import==
To import existing Semantic Web ontologies SMW uses the <nowiki>MediaWiki:Smw_import_ONTOGOLOGYNAME</nowiki> pages, such as [[MediaWiki:Smw_import_foaf]] for the Friend Of A Friend ontology.
 
SMW manual mentions the following ontologies, some of which are already present in SMW instances, others need to be create from the examples provided by the SMW manual:
 
* [[MediaWiki:Smw_import_foaf|foaf]] Friend Of A Friend [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_foaf Smw_import_foaf example]
* [[MediaWiki:Smw_import_rdfs|rdfs]] RDF Schema [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_rdfs Smw_import_rdfs example]
* [[MediaWiki:Smw_import_owl|owl]] Web Ontology Language (OWL) [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_owl Smw_import_owl example]
* [[MediaWiki:Smw_import_skos|SKOS]] Simple Knowledge Organization System (SKOS) [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_skos Smw_import_skos example]
* [[MediaWiki:Smw_import_dc|dc]] Dublin Core Metadata [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_dc Smw_import_dc example]
* [[MediaWiki:Smw_import_dcterms|dcterms]] DCMI Metadata Terms [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_dcterms Smw_import_dcterms example]
* [[MediaWiki:Smw_import_bibo|bibo]] Bibliographic Ontology [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_bibo Smw_import_bibo example]
* [[MediaWiki:Smw_import_frbr|frbr]] Functional Requirements for Bibliographic Records [https://www.semantic-mediawiki.org/wiki/MediaWiki:Smw_import_frbr Smw_import_frbr example]
 
I will be adding and making use of in this wiki of the [[MediaWiki:Smw_import_foaf|foaf]] ontology.




==Property pages==
==Property pages==
Each one of the properties listed in the MediaWiki:Smw_import_XYZ page has to be created with the following template
<pre>
* [[Imported from::ONTOLOGYNAME:PROPERTY]]
* [[Has property description::DESCRIPTION OF PROPERTY.@langcode]]
[[Category:Imported vocabulary]]{{DISPLAYTITLE:ONTOLOGYNAME:PROPERTY}}
</pre>


Create Property pages for each one of the ontology properties
As for instance the [[Property:foaf:name]]:


Following the template:
<pre>
...
* [[Imported from::foaf:name]]
* [[Has property description::A name for some thing or agent.@en]]


==Classes==
[[Category:Imported vocabulary]]{{DISPLAYTITLE:foaf:name}}
Create category pages for the properties containing the '''Datatype Category'''
</pre>


Containing the Property::value pair
Note in that [[Property:foaf:name| Property page]] that the '''Property Type''' is not declared on this page, but its assignment is done at the [[MediaWiki:Smw_import_foaf|ontology import page]]


<nowiki>[[Imported from::foaf:Person]]</nowiki>
Because it can be quite tedious to create all those Property pages manually we can resort to scripts which create wiki pages, by interaction with the Mediawiki API <ref>See some Python the scripts for this at https://gitlab.com/Castro0o/wikitools </ref>


After the Properties have been created ensure to run MW's scripts:
* <code>maintenance/runJobs.php</code> to run pending jpbs
* <code>maintenance/update.php</code> since we made change to Property types


== Desambiguation==


===Classes in RDF and SMW===
The created Properties should be visible in [[Special:Properties]]
 
==Classes <nowiki>==</nowiki> Categories==
As it is visible in [[MediaWiki:Smw_import_foaf]] the entries '''Person''' and '''Organization'''  both have'''Category as their type''', which makes them not a Property but a Category. And as a result they do not have property pages but category pages: [[:Category:Person]], [[:Category:Organization]].
 
 
In the category page, you have to inform SWM that this is an imported class from an external vocabulary. This is done via the ''[[Help:Special property Imported from|Imported from]]'' [[Help:Special properties|special property]] declaration: <pre>[[Imported from::foaf:Person]]</pre>
 
 
'''Why Categories?'''
 
The reason they are Categories is because '''SMW uses categories to state that something is an element of a ''class'', as categories are mapped internally as rdf:type.'''. In Semantic Web ontologies classes create semantic classification groupings. And according to the RDF Schema" "rdf:type is an instance of rdf:Property that is used to state that a resource is an instance of a class." <ref>https://www.w3.org/TR/rdf-schema/#ch_type</ref>
 


<blockquote>
<blockquote>
An RDF class is defined as the set of its instances. Consider the class of abstract ideas. Members – instances – of that set include love, honour, duty, pi, evolution, etc. This view of a class is a mathematical concept, so the set of abstract ideas is both an idea and quite abstract, so therefore is itself an instance, or member, of the class abstract ideas. More prosaically, if a class is a set of things, then RDFS classes both denote sets of things, and are themselves instances of the set of all classes, aka rdfs:Class.<ref>https://stackoverflow.com/questions/6472043/instances-vs-classes-in-rdfs</ref>
A class in OWL is a classification of individuals into groups which share common characteristics. If an individual is a member of a class, it tells a machine reader that it falls under the semantic classification given by the OWL class.<ref>http://www.linkeddatatools.com/introducing-rdfs-owl</ref></blockquote>
</blockquote>
 
The FOAF specification<ref>http://xmlns.com/foaf/spec/#sec-crossref</ref> stipulates the following classes: <code>Agent | Document | Group | Image | LabelProperty | OnlineAccount | OnlineChatAccount | OnlineEcommerceAccount | OnlineGamingAccount | Organization | Person | PersonalProfileDocument | Project
</code> out of which the [[MediaWiki:Smw_import_foaf]] uses Person and Organization.
 
 
 
== Annotating ==
 
As an example of semantic annotations, which use and imported vocabulary I will use the pages [[Rana Hamadeh - The Ten Murders of Josephine]], [[Rana Hamadeh]] and [[Witte de With Center for Contemporary Art]]
 
In [[Rana Hamadeh - The Ten Murders of Josephine]] belongs to Class [[:Category:Project]]
<pre>
* '''Location:''' [[Foaf:maker::Witte de With Center for Contemporary Art]], Rotterdam
* '''Author:''' [[Foaf:maker::Rana Hamadeh]]
 
[[Category:Project]]
</pre>
 


In SMW a class is page It is  a thing.
[[Rana Hamadeh]] belongs to the Class [[:Category:Person]] with the FOAF descriptors:
<pre>
{{#set: Foaf:name=Rana Hamadeh
|Foaf:homepage=http://ranahamadeh.com/
|Foaf:depiction=https://dutchartinstitute.eu/image/2014/5/12/r_hamadeh_self_portrait_2.jpg
|Foaf:knows=User:Andre|Jorg Schellekens
|Foaf:made=Rana Hamadeh - The Ten Murders of Josephine
}}
[[Category:Person]]
</pre>


[[Witte de With Center for Contemporary Art]] belongs to the Class [[:Category:Organization]]
<pre>{{#set: foaf:website=http://www.wdw.nl/en/
|foaf:knows=Rana Hamadeh
|foaf:made=Rana Hamadeh - The Ten Murders of Josephine
}}</pre>


=== Inverse Properties: not supported by SMW ===
It is worth noting that both [[Rana Hamadeh]] and [[Witte de With Center for Contemporary Art]] use the [[Property:foaf:made]] which is the inverse of [[Property:foaf:maker]].
In a normal situation, since they are inverse we would not need to also define the [[Property:foaf:made]] in [[Rana Hamadeh]] and [[Witte de With Center for Contemporary Art]]. However '''SMW Semantic MediaWiki does not internally support inverse relationships'''. So  a bit of redundancy is necessary


=== Ask ===
We can ask who '''made''' something
<pre>
{{#ask: [[Foaf:made::+]]
|?Foaf:made
|format=broadtable
|limit=50
|offset=0
|link=all
|sort=
|order=asc
|headers=show
|mainlabel=Foaf:maker
|searchlabel=... further results
|class=sortable wikitable smwtable
}}
</pre>
{{#ask: [[Foaf:made::+]]
|?Foaf:made
|format=broadtable
|limit=50
|offset=0
|link=all
|sort=
|order=asc
|headers=show
|mainlabel=Foaf:maker
|searchlabel=... further results
|class=sortable wikitable smwtable
}}
Or What entities know other entities and what aretheir classes.  In  other words  Who '''knows''' Who
<pre>
{{#ask: [[Foaf:knows::+]]
|?Category=Class
|?Foaf:knows
|format=broadtable
|limit=50
|offset=0
|link=all
|sort=
|order=asc
|headers=show
|mainlabel=Entity
|searchlabel=... further results
|class=sortable wikitable smwtable
}}
</pre>
{{#ask: [[Foaf:knows::+]]
|?Category=Class
|?Foaf:knows
|format=broadtable
|limit=50
|offset=0
|link=all
|sort=
|order=asc
|headers=show
|mainlabel=Entity
|searchlabel=... further results
|class=sortable wikitable smwtable
}}
== RDF export ==


----
----
[[Section::Code Notes]]
[[Date::2020]]

Latest revision as of 13:53, 25 August 2022


Notes on importing ontologies to SMW

How to importing ontology?

The documentation on importing existing ontologies to SMW in its Manual Section Help:Import_vocabulary

MediaWiki:Smw_import

To import existing Semantic Web ontologies SMW uses the MediaWiki:Smw_import_ONTOGOLOGYNAME pages, such as MediaWiki:Smw_import_foaf for the Friend Of A Friend ontology.

SMW manual mentions the following ontologies, some of which are already present in SMW instances, others need to be create from the examples provided by the SMW manual:

I will be adding and making use of in this wiki of the foaf ontology.


Property pages

Each one of the properties listed in the MediaWiki:Smw_import_XYZ page has to be created with the following template

* [[Imported from::ONTOLOGYNAME:PROPERTY]] 
* [[Has property description::DESCRIPTION OF PROPERTY.@langcode]] 

[[Category:Imported vocabulary]]{{DISPLAYTITLE:ONTOLOGYNAME:PROPERTY}}


As for instance the Property:foaf:name:

* [[Imported from::foaf:name]] 
* [[Has property description::A name for some thing or agent.@en]] 

[[Category:Imported vocabulary]]{{DISPLAYTITLE:foaf:name}}

Note in that Property page that the Property Type is not declared on this page, but its assignment is done at the ontology import page

Because it can be quite tedious to create all those Property pages manually we can resort to scripts which create wiki pages, by interaction with the Mediawiki API [1]

After the Properties have been created ensure to run MW's scripts:

  • maintenance/runJobs.php to run pending jpbs
  • maintenance/update.php since we made change to Property types


The created Properties should be visible in Special:Properties

Classes == Categories

As it is visible in MediaWiki:Smw_import_foaf the entries Person and Organization both haveCategory as their type, which makes them not a Property but a Category. And as a result they do not have property pages but category pages: Category:Person, Category:Organization.


In the category page, you have to inform SWM that this is an imported class from an external vocabulary. This is done via the Imported from special property declaration:

[[Imported from::foaf:Person]]


Why Categories?

The reason they are Categories is because SMW uses categories to state that something is an element of a class, as categories are mapped internally as rdf:type.. In Semantic Web ontologies classes create semantic classification groupings. And according to the RDF Schema" "rdf:type is an instance of rdf:Property that is used to state that a resource is an instance of a class." [2]


A class in OWL is a classification of individuals into groups which share common characteristics. If an individual is a member of a class, it tells a machine reader that it falls under the semantic classification given by the OWL class.[3]

The FOAF specification[4] stipulates the following classes: Agent | Document | Group | Image | LabelProperty | OnlineAccount | OnlineChatAccount | OnlineEcommerceAccount | OnlineGamingAccount | Organization | Person | PersonalProfileDocument | Project out of which the MediaWiki:Smw_import_foaf uses Person and Organization.


Annotating

As an example of semantic annotations, which use and imported vocabulary I will use the pages Rana Hamadeh - The Ten Murders of Josephine, Rana Hamadeh and Witte de With Center for Contemporary Art

In Rana Hamadeh - The Ten Murders of Josephine belongs to Class Category:Project

* '''Location:''' [[Foaf:maker::Witte de With Center for Contemporary Art]], Rotterdam
* '''Author:''' [[Foaf:maker::Rana Hamadeh]]

[[Category:Project]]


Rana Hamadeh belongs to the Class Category:Person with the FOAF descriptors:

{{#set: Foaf:name=Rana Hamadeh
|Foaf:homepage=http://ranahamadeh.com/
|Foaf:depiction=https://dutchartinstitute.eu/image/2014/5/12/r_hamadeh_self_portrait_2.jpg
|Foaf:knows=User:Andre|Jorg Schellekens
|Foaf:made=Rana Hamadeh - The Ten Murders of Josephine
}}
[[Category:Person]]

Witte de With Center for Contemporary Art belongs to the Class Category:Organization

{{#set: foaf:website=http://www.wdw.nl/en/
|foaf:knows=Rana Hamadeh
|foaf:made=Rana Hamadeh - The Ten Murders of Josephine
}}

Inverse Properties: not supported by SMW

It is worth noting that both Rana Hamadeh and Witte de With Center for Contemporary Art use the Property:foaf:made which is the inverse of Property:foaf:maker. In a normal situation, since they are inverse we would not need to also define the Property:foaf:made in Rana Hamadeh and Witte de With Center for Contemporary Art. However SMW Semantic MediaWiki does not internally support inverse relationships. So a bit of redundancy is necessary

Ask

We can ask who made something

{{#ask: [[Foaf:made::+]]
 |?Foaf:made
 |format=broadtable
 |limit=50
 |offset=0
 |link=all
 |sort=
 |order=asc
 |headers=show
 |mainlabel=Foaf:maker
 |searchlabel=... further results
 |class=sortable wikitable smwtable
}}
Foaf:makerFoaf:made
Witte de With Center for Contemporary ArtRana Hamadeh - The Ten Murders of Josephine


Or What entities know other entities and what aretheir classes. In other words Who knows Who

{{#ask: [[Foaf:knows::+]]
 |?Category=Class
 |?Foaf:knows
 |format=broadtable
 |limit=50
 |offset=0
 |link=all
 |sort=
 |order=asc
 |headers=show
 |mainlabel=Entity
 |searchlabel=... further results
 |class=sortable wikitable smwtable
}}
EntityClassFoaf:knows
Femke SneltingPersonAndre
Renée Turner
Cristina Cochior
Rana HamadehPersonAndre
Jorg Schellekens
Renée TurnerPersonAndre
Cristina Cochior
Femke Snelting
Witte de With Center for Contemporary ArtOrganizationRana Hamadeh

RDF export


Code Notes 2020

... more about "RDF in Semantic Mediawiki"
Code Notes +
Date"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2020 +