Category:MediaWiki extension Semantic MediaWiki | |
---|---|
Extension name | Semantic MediaWiki |
About this article / disclaimer | |
Logo | |
Screenshot | [[Image:|135px]] |
Location of the main author | Oxford, England |
Coordinates of the main authors | 51.752013, -1.25785 |
Developers | Markus Krötzsch, Denny Vrandecic, Jeroen De Dauw, others |
Licences | |
Description | Semantic MediaWiki is an extension for managing structured data in your wiki and for querying that data to create dynamic representations: tables, timelines, maps, lists, etc. |
Mediawiki requirements | [[Needs MediaWiki versions::Any recent version.
However, we suggest using MW 1.22 (dec 2013). This version includes support for Composer, a dependency manager that will ease installation.]] |
Dependencies | Validator, ParamProcessor |
Related extensions (documented here) | Semantic Drilldown, Semantic Forms, Semantic Forms Inputs, Semantic Maps, Semantic Result Formats |
Related extensions | |
Discussion | |
Language support | Many |
Status | stable |
First release date | 2005/01/01 |
Last release date (as of 2014/05/02!) | 2014/04/28 |
Last version number | 1.9.2 (40ea19e) |
Programming language | PHP |
Alternatives | |
Website | home page |
Publications | |
Support websites | web site |
Example websites | |
Last edited | 2014/05/02 |
“Semantic MediaWiki (SMW) is an extension of Mediawiki – the wiki application best known for powering Wikipedia – that helps to search, organise, tag, browse, evaluate, and share the wiki's content. While traditional wikis contain only text which computers can neither understand nor evaluate, SMW adds semantic annotations that allow a wiki to function as a collaborative database. Semantic MediaWiki was first released in 2005, and currently has over ten developers, and is in use on hundreds of sites. In addition, a large number of related extensions have been created that extend the ability to edit, display and browse through the data stored by SMW: the term "Semantic MediaWiki" is sometimes used to refer to this entire family of extensions. Semantic MediaWiki has been funded in part by projects of the Framework Programmes (FP) of the European Union, SEKT and ACTIVE and by project Halo.” (Introduction to Semantic MediaWiki, retrieved 14:31, 24 August 2011 (CEST))
According to Semantic MediaWiki, “is currently in active use in hundreds of sites, in many languages, around the world, including Fortune 500 companies, biomedical projects, government agencies and consumer directories”.
See also:
At the core of Semantic MediaWiki are so-called properties. Properties can be understood as "categories of information" and they are encoded in a way that a machine can understand. If you use a property + value in a given page, you implicitly create a so-called triplet.
For example, if we would like to add the information that Semantic MediaWiki is related to Semantic Forms we get the following triplet:
Semantic MediaWiki - Is related to - Semantic Forms (Subject) (predicate) (object)
In Semantic MediaWiki, we create triplets by adding code defining property/value pair to a page. Therefore, with respect to the above example:
The corresponding wiki code looks likes this:
[[Is related to::Semantic Forms]]
Similarities with RDF
In the Resource Description Framework RDF, a fragment like the following defines the same relationship.
<swivt:Subject rdf:about="http://edutechwiki.unige.ch/en/Special:URIResolver/Semantic_MediaWiki">
<property:Is_related_to rdf:resource="http://edutechwiki.unige.ch/en/Special:URIResolver/Semantic_Forms"/>
</swivt:Subject>
In some ways, Semantic MediaWiki is the Wiki equivalent of RDF. Semantic data of a page can be exported as RDF like this:
[http://edutechwiki.unige.ch/en/Special:ExportRDF/Semantic_MediaWiki RDF feed]
, e.g. click on RDF feedProperties in a Semantic MediaWikis define typed data, in a similar way as in object-oriented programming. Properties are used with the [[property_name::property_value]]
syntax. By default, the value of a property is a wiki page, i.e. default data type of a property is simply a wiki page.
MediaWiki [[is a:: Wiki]]
The following example shows a value that is an URL. However, this does not yet mean the data type of Has website
is an URL. Since default values for properties are wiki pages, we must explicitly create and edit the property page as explained further down.
[[Has website:: http://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki]]
The above code will be shown as http://www.semantic-mediawiki.org/wiki/Semantic MediaWiki
,i.e. the reader will see a clickable URL. Let's now look at property types.
Data types for property types
There exist several property types, for example:
Manual coding
[[property_name:: your_property_value]]
To define a property and its type there are three methods
(1a) Create a property instance with a value, then create/hand code the property page
[[property_name:: your_property_value]]
or use templates as explained in the Semantic Forms articleThis is a property of type [[Has type::URL]].
(1b) Use the Create with Form
(2) Use Special:CreateProperty
The easiest way to create a property (including its page and the type declaration) is to use the form in Special:CreateProperty "special" page.
The following screenshot shows a property page for property that is being used in page, but that is not defined yet. Do define it, either use method 1a or 1b as explained just above.
..............
(under construction ...)
The way a property will be displayed depends on its type and an additional parameter. By default, only the value will be shown, either as simple text or as a link.
Values that are not links
We defined a data type of property has accronym as string, therefore the value will not show as a wiki link (as per default data type): The following table shows what happens:
input | output | description |
---|---|---|
[[has acronym::SMW]] | SMW | Most typical use of properties |
[[has acronym::SMW::TheFuture::]] | SMW | Defining two values (shortcut) |
[[has acronym::SMW| ]] | Value will not be shown | |
[[has acronym::SMW|MWS]] | MWS | An alternative text will be shown |
[[:has acronym :: SMW]] | has acronym :: SMW | Creates a link instead of a property (useless) |
There are several options that could help finding properties.
Semantic Mediawiki includes a query language for semantic search. According to the manual (7/2013), it can be used in three contexts:
Most frequent use seem to be inline queries.
Queries usually define three things:
Inline queries dynamically include query results as in the examples below. This functionality is implemented with so-called parser functions.
One simple query would list all pages in a category. The following code:
{{#ask: [[Category: MediaWiki extension]]}}
produces a simple line:
By definition, various query clauses are combined with an AND operator
The following code selects all pages in the category software information and that include a property value Yaron Koren for the property Is developed by.
{{#ask: [[Category: MediaWiki extension]] [[Is developed by::Yaron Koren]]
| ?Has name
| format=ul
}}
It will produce this:
We also can use wildcards, e.g. if we wanted to list all pages that do include a property "Is developed by", we would use the following expression:
{{#ask: [[Category: MediaWiki extension]] [[Is developed by::+]]
| ?Has name
| format=ul
}}
It will produce this:
Roughly speaking, syntax of #ask:
is the following: It it includes three groups of information:
{{#ask
search_clause_1
search_clause_2
......
| ?Information_1 to display
| ?Information_2 to display
| ?......
| Result_format_parameter 1 = x
| Result_format_parameter 2 = y
|....
}}
By default, queries will return a list wiki pages (i.e. without telling which other information to show and whether the page itself should be skipped).
Search conditions (clauses) can include property/values (including wildcards and comparators), categories and some other stuff. In addition, you can use disjunctions (or's).
To search within a category and all subcategories, simply use the normal wiki syntax, e.g.
[[Category: MediaWiki extension]]
A query including just this condition would return all the pages in the MediaWiki extension'. For example, the query
{{#ask: [[Category: MediaWiki extension]]}}
produces this list: Maps (MediaWiki extension), Mediawiki collection extension installation, Page Forms, Semantic Drilldown, Semantic Forms Inputs, Semantic Maps, Semantic MediaWiki, Semantic Result Formats, VisualEditor
Notice: This makes me wonder what happens if you have circular category structures ...
Property conditions can take several forms, i.e. define a value, use a wildcard, or include comparators
Simple property value search
To search for a property with a given value, use the normal property syntax, e.g.
[[Developed with::MediaWiki software]]
The query {{#ask: [[Developed with::MediaWiki software]]}}
produces this list of pages: CS4CS, Transcribe Bentham
Wildcards
The query {{#ask: [[Supports languages::+]]}}
produces this list of pages: Maps (MediaWiki extension), Mediawiki, Mediawiki collection extension installation, Page Forms, Semantic Drilldown, Semantic MediaWiki, Some software
See also the ~
(like) operator below for string comparison.
Comparators
Comparators work with property values and they are placed after the ::
in property conditions.
The query {{#ask: [[Was last edited::>1 September 2013]]}}
produces this list of pages: Semantic MediaWiki, Semantic Result Formats, VisualEditor
The query {{#ask: [[Has field of science::~bio*]]}}
produces this list of pages: Budburst, Notes from Nature, Plankton Portal, Worm Watch Lab, i.e. it will return pages whose Has field of science
property includes at least one "bio". Below, a table that also lists the property values found
Has field of science | |
---|---|
Budburst | biology |
Notes from Nature | biology taxonomy biological classification |
Plankton Portal | biology biological oceanography planktology climatology |
Worm Watch Lab | biology genetics medicine neuroscience |
Some comparisons can be hairy, e.g. values that are rounded for display, coordinates and such.
<q> .... </q>
Examples:
Read the main article: Semantic Result Formats for more information about this topic, in particular if you are interested in visualizations made with JavaScript libraries.
By default, results that include more than one property to be shown are shown as a table. The following code selects the same pages as above, but also displays has last revision number values.
{{#ask: [[Category: MediaWiki extension]] [[Is developed by::Yaron Koren]]
| ?Has name
| ?has last revision number
| ?Is developed by
}}
produces this:
Has name | Has last revision number | Is developed by | |
---|---|---|---|
Page Forms | Semantic Forms | 2.6 (Dec 2013) | Yaron Koren Stephan Gambke others |
Semantic Drilldown | Semantic Drilldown | 1.2.5 (June 2013) | Yaron Koren David Loomer |
Semantic Forms Inputs | Semantic Forms Inputs | 0.7 | Stephan Gambke Yaron Koren Jeroen De Dauw Sanyam Goyal Yury Katkov others |
Semantic Result Formats | Semantic Result Formats | 1.9.1 alpha (9482833) | Jeroen De Dauw Frank Dengler Steren Giannini James Hong Kong Fabian Howahl Yaron Koren Markus Krötzsch David Loomer Joel Natividad Denny Vrandecic Nathan Yergler others |
Semantic Result Formats allows to produce graphics. The following displays all pages where Yaron Koren is defined as developer plus the participations of other developers.
{{#ask: [[Category: MediaWiki extension]] [[Is developed by::Yaron Koren]]
| ?Is developed by
| distribution=yes
| min=0
| format=jqplotchart
| mainlabel=-
}}
produces this:
Read more in Inline queries, Displaying information, Help:Semantic templates and Result formats (Semantic-Mediawiki.org)
SMW queries can include comparators and allows OR (disjunctions)
Use the debug option to test your #ask expression
{{#ask:[[Category:tutoriel]]
|?....
|format=debug
}}
Be aware that by default inline #ask only returns 50 results. Use the limit=..
parameter to change this. Alternatively reset the value of $smwgQDefaultLimit.
(needs to be completed ....)
Special properties are automatically generated by the system and have all sorts of functions. By default, these properties are not yet defined. In order to make use of them, we suggest the following procedure:
Good for debugging:
Understanding were you get your values from:
(this section needs to be written)
SMW has a page-based approach. This makes it difficult with data like "the teacher owns 3 bananas", i.e. he "has bananas" and "he has 3"
You either can use subobjects or semantic internal objects to deal with this problem. Both have the same syntax, but work differently.
{{#subobject:Owns row|Owns fruit=bananas |Has quantity=4}}
{{#set_internal:Is row in possions|Owns fruit=tomatoes|Has quantity=4}}
Most semantic MediaWiki sites make use of a whole range of extensions that are built on top of the basic Semantic MediaWiki infrastructure. For exemple, a popular extension is Semantic Forms.
Read official documentation & download information:
Notice:: Read this old version, if you have an older MediaWiki or if you prefer manual installs.
(Summer 2015 for MW 1.25, updated summer 2016 for MW 1.26 and 1.27)
composer require mediawiki/semantic-media-wiki "~2.4" composer require mediawiki/maps "*" composer require mediawiki/semantic-maps "*" composer require mediawiki/semantic-result-formats "*" php maintenance/update.php
.... "mediawiki/semantic-media-wiki": "~2.4", "mediawiki/maps": "*", "mediawiki/semantic-maps": "*", "mediawiki/semantic-result-formats": "*", "mediawiki/sub-page-list": "~1.2", "mediawiki/graph-viz": "^1.6", "mediawiki/image-map": "@dev" .....
Page Forms (formerly called Semantic Forms)
composer require mediawiki/semantic-forms composer require mediawiki/page-forms
// If needed, define a special namespace, can help if other custom extensions are used. Not necessary for fresh MediaWiki installs $smwgNamespaceIndex = 108; // Adjust to yours
// This seems to be still required in summer 2016 for MW 1.26.3 and SMW 2.4.1 enableSemantics('edutechwiki.unige.ch'); // adjust to yours
After mid-november 2013, you should learn how to use composer, a PHP dependency manager.
If your server doesn't meet these requirements (in particular a new 1.22 MediaWiki), you should stop reading and find another source of information.
If you run several wikis, it's probably best to install composer on system level:
cd /some/src curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
cd /your-mediawiki-install
rm -r extensions/SemanticMediaWiki rm -r extensions/Validator rm -r extensions/DataValues
rm -r extensions/Maps/ rm -r extensions/SemanticMaps/ rm -r extensions/SemanticResultFormats
Changes to Localsettings.php
(1) kill all the lines that load SMW and required extensions. You really have to start clean, for example kill
require_once( "$IP/extensions/DataValues/DataValues.php" ); require_once( "$IP/extensions/Validator/Validator.php" ); include_once("$IP/extensions/SemanticMediaWiki/SemanticMediaWiki.php")
(2) Keep the following:
$smwgNamespaceIndex = 108; // Adjust to yours, in case other custom extensions were use before. Not necessary for fresh mediawiki installs enableSemantics('edutechwiki.unige.ch'); // adjust to yours
$smwgNamespaceIndex = 108;
in our case) is the very first line of code that deals with SMW. E.g. if PHP sees the line enableSemantics(...)
first, it will start numbering SMW extensions at 104 or something and you won't see your properties, forms, etc. defined in your existing wiki. You then may panic and do weird stuff that won't help your wiki very much.(3) Comment out all other MediaWiki extensions
composer require mediawiki/semantic-media-wiki "~2.0"
composer require mediawiki/semantic-media-wiki "dev-master"
php maintenance/update.php
As you can see, it is better not to provide any version information. These extensions should know what version to use with what SMW version.
composer require mediawiki/maps "*" composer require mediawiki/semantic-maps "*" composer require mediawiki/semantic-result-formats "*"
cd extensions
// git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SemanticForms.git
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/PageForms
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SemanticFormsInputs.git
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SemanticDrilldown.git
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/AdminLinks.git
Of course, you then have to edit LocalSettings.php to include these files, for example it could look like this:
$smwgNamespaceIndex = 108;
enableSemantics('edutechwiki.unige.ch'); // adjust to yours
$smwgShowFactbox = SMW_FACTBOX_NONEMPTY;
// $smwgShowFactbox = SMW_FACTBOX_HIDDEN;
include_once("$IP/extensions/SemanticForms/SemanticForms.php");
# If one or more of your fields can contain internal links entered by users (e.g., "This is a [[cat]]")
$smwgLinksInValues = true;
# Semantic Drilldown. Needs yet another namespace
$sdgNamespaceIndex = 118;
include_once("$IP/extensions/SemanticDrilldown/SemanticDrilldown.php");
# Semantic Forms Inputs
# Is now available through composer (summer 2015)
# require_once("$IP/extensions/SemanticFormsInputs/SemanticFormsInputs.php");
# AdminLinks
include_once("$IP/extensions/AdminLinks/AdminLinks.php");
cd /your/mediawiki_installation_directory
composer self-update
For MW 1.22 or better ....
Typing the following won't work if you already have SMW installed
composer require mediawiki/semantic-media-wiki "~2.0"
In the root directory, edit file composer.json
and change the SMW line:
"mediawiki/semantic-media-wiki": "~2.0",
If you do the same for the various Semantic Mediawiki extension, the JSON section could look something like this (but extensions and version numbers may change). It is best to follow instructions on each extension page as shown on the packagist web site or the mediawiki extension page.
"require": {
"php": ">=5.3.2",
"psr/log": "1.0.0",
"mediawiki/semantic-media-wiki": "~2.0",
"mediawiki/semantic-result-formats": "*",
"mediawiki/sub-page-list": "~1.1",
"mediawiki/semantic-maps": "*",
"mediawiki/maps": "*"
"mediawiki/semantic-forms": "^3.4"
},
composer update
php maintenance/update.php
php extensions/SemanticMediaWiki/maintenance/SMW_refreshData.php -d 50 -v
From the Readme file:
It is required to set the environment variable MW_INSTALL_PATH to the root of your MediaWiki installation first. This is also required if you use a symbolic link from ./extensions/SemanticMediaWiki to the actual installation directory of SMW. Setting environment variables is different for different operating systems and shells, but can normally be done from the command line right before the php call. On Bash(Linux), e.g., one can use the following call to execute SMW_setup.php with different MW location.
export MW_INSTALL_PATH="/path/to/mediawiki" && php SMW_setup.php
If you work with GIT and use the (default) "master" (the development branch), really make sure that all your extensions are match, e.g. you could the "master" development versions.
cd extenstions/extension_X git pull origin master
It also may happen that you installed a new version that does not work using git pull
. In that case:
git tag -l | sort -V git checkout <tag name>
For example:
cd extensions/SemanticForms git tag -l git checkout 2.5.2
Otherwise, there are various support options:
If you get something like:
php maintenance/update.php MediaWiki 1.31.0 Updater
mediawiki/semantic-media-wiki: 2.5.8 installed, ~2.5 required. mediawiki/maps: 5.6.0 installed, ~5.1 required. mediawiki/semantic-result-formats: 2.5.6 installed, ~2.5 required. mediawiki/sub-page-list: 1.5.0 installed, ~1.5 required. mediawiki/graph-viz: 3.1.0 installed, * required. Error: your composer.lock file is not up to date. Run "composer update --no-dev" to install newer dependencies
try:
php maintenance/update.php --skip-external-dependencies
Frankly, this is riculous. I thought that composer would be able to handle minor variantgs. using the ~ syntax.
After each version upgrade, you should launch the maintenance script. A slower version also can be run by admins from the special pages. Finally, if you just run the global MW update script in the "normal" maintenance directory, it also will trigger running the SMW update script.
cd extensions/SemanticMediaWiki/maintenance php SMW_setup.php
Upgrading can go wrong, however since all SMW information (at least at our level of use) sits within wiki pages, you will not have to worry about messing up information that sits in semantic mediawiki database tables. If you made mistakes, e.g. killed lines defining namespaces index numbers in LocalSettings.php, simply rebuild all the SMW-related tables. SMW Database tables are just for performance, i.e. they are a secondary store. Just to make sure: Do never ever mess up other tables, we just talk about SMW tables here !
Furthermore, it cannot hurt to dump the whole database before you upgrade the MW software or just the SMW extensions. I usually do not do that, since I first upgrade a test server or a less critical production wiki. We also got daily backups if things really become bad. The main problem I had with MW/SMW upgrades is just that some less critical extensions stop working. I then usually try to find a fix and if I don't, I'll trash these minor extensions.
See the next point about rebuilding the SMW databases !
Disclaimer: If the following kills your wiki, erases your hard disk and burns down your office, do not blame me ! Read the documentation at the beginning of the script and evaluate the risks !
Let's assume that you created lots of useless parameters, that you created weird templates that produce illegal parameters etc. Time to clean up ! Although you could use the tools available in wiki's special pages, it maybe time to play with the maintenance scripts.
Read https://www.semantic-mediawiki.org/wiki/Help:RebuildData.php RebuildData.php
The rebuild data script will rebuild the database from SMW information found in pages.
The following script, if you use the -f option, will empty all semantic mediawiki tables and create the data again. Since all information is stored in both normal wiki pages and semantic MediaWiki namespaced pages, e.g. property:, the tables will be rebuilt by going through all wikipages in all namespaces. In other words, by erasing all the database tables, you should not loose any information.
cd SemanticMediaWiki/maintenance php rebuildData.php -f -d 100 -v
The script may choke on a page with a broken extension. E.g. in this wiki it was UML activity diagram. This page has ID=4219. If such a thing happens, just move on. Restart the script with the next page, e.g.
php rebuildData.php -d 100 -v -s 4220
Exemple, refreshing without killing anything, doing it a bit faster and without verbose output.
php rebuildData.php -d 50
The refreshData script is deprecated !!
You will notice that all bad properties are gone now if you look at special:properties
The SMW database should update each time a user does something.
To speed this, up you could run cronjobs.
Read Help:Maintenance
{{CURRENTUSER}}
that you could use for reporting/tracking applications.Read:
Code documentation:
Tutorials and examples:
See also: User manual, which includes additional links
See also: Semantic MediaWiki publications at semantic-mediawiki.org