Jump to content

Extension:Semantic Compound Queries: Difference between revisions

From mediawiki.org
Content deleted Content added
chg
m Reverted edits by Roger2027 (talk) to last version by Wooze
Tag: Rollback
(61 intermediate revisions by 20 users not shown)
Line 1: Line 1:
<languages/>
{{TNT|Extension
{{Extension
|name = Semantic Compound Queries
|name = Semantic Compound Queries
|status = stable
|status = stable
|type1 = parser function
|type1 = parser function
|author = [[User:Yaron Koren|Yaron Koren]] <yaron57@gmail.com>
|author = [[User:Yaron Koren|Yaron Koren]] and others
|maintainer = [[semantic-mw:Help:SMW Project|SMW Project]]
|image =
|image =
|version = 0.4
|version = 2.2.0
|update = May 2014
|update = 2022-01-20
|mediawiki = 1.16.* or greater
|mediawiki = 1.31+
|license = GPL
|license = GPL-2.0-or-later
|php = 7.3+
|download = [[#Download|See here]] or<br>{{TNT|WikimediaDownload|SemanticCompoundQueries}}
|download = {{GithubDownload|SemanticMediaWiki|SemanticCompoundQueries|translatewiki=1}}
|composer = mediawiki/semantic-compound-queries
|needs-updatephp = No
|needs-updatephp = No
|changelog =
|changelog =
|description = Defines a parser function, #compound_query, that can make multiple Semantic MediaWiki queries at the same time
|description = Defines a parser function, <code>#compound_query</code>, that can make multiple Semantic MediaWiki queries at the same time
|readme = [https://github.com/SemanticMediaWiki/SemanticCompoundQueries/blob/master/RELEASE-NOTES.md RELEASE NOTES]
|parameters =
|parameters =
|translate = mwgithub-semanticcompoundqueries
|rights =
|rights =
|compatibility = '''Compatibility'''
|example = [http://smw.referata.com/wiki/Main_Page#Community A map showing people, organizations and events, with a different icon for each]
* Semantic MediaWiki 3.0 and later
|example = [https://www.epsa-projects.eu/index.php?title=EPSA-Projects.eu A Google Map showing two different kinds of points, with a different marker for each]
|CheckUsageNameOverride=SemanticCompoundQueries
}}
}}


The '''Semantic Compound Queries''' extension is meant to work with [[Extension:Semantic MediaWiki|Semantic MediaWiki]] and allows for the display of more than one SMW inline query in one results display set. It uses its own parser function, #compound_query, that takes inputs similar to that of #ask but can take in an unlimited number of queries, instead of just one.
The '''Semantic Compound Queries''' extension is meant to work with [[Extension:Semantic MediaWiki|Semantic MediaWiki]] and allows for the display of more than one SMW inline query in one results display set.
It uses its own parser function, #compound_query, which takes inputs similar to that of #ask but can take in an unlimited number of queries, instead of just one.


==Installation==
Semantic MediaWiki version 1.6 or later is required for this extension to work.


The recommended way to install Semantic Compound Queries is by using Composer with an entry in MediaWiki's "composer.local.json" file:
==Download==
<syntaxhighlight lang="json">
You can download the Semantic Compound Queries code, in .zip format, [https://git.wikimedia.org/zip/?r=mediawiki/extensions/SemanticCompoundQueries&h=ae8f8250b1a7df0e8f623816087aef741c680064&format=zip here].
{
"require": {
"mediawiki/semantic-compound-queries": "~2.2"
}
}
</syntaxhighlight>


Now run the following in the shell:
You can also download the code directly via Git from the MediaWiki source code repository. From a command line, you can call the following:
<syntaxhighlight lang="bash">
php composer.phar update --no-dev --prefer-source
</syntaxhighlight>


To invoke the extension add the following line to the bottom of your "LocalSettings.php" file:
<syntaxhighlight lang="bash">git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SemanticCompoundQueries.git</syntaxhighlight>
<syntaxhighlight lang="php">
wfLoadExtension( 'SemanticCompoundQueries' );
</syntaxhighlight>


==Usage==
To view the code online, including version history for each file, go [https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FSemanticCompoundQueries here].


=== Normal queries ===
{{SB Extension}}
A normal inline query, using the #ask parser function, takes in arguments of three types:


# a ''filter'' that determines the results
==Installation==
# the names of ''properties'' to be ''displayed''
To install this extension, create a 'SemanticCompoundQueries' directory (either by extracting a compressed file or downloading via Git), and place this directory within the main MediaWiki 'extensions' directory. Then, in the file 'LocalSettings.php', somewhere below the inclusion of Semantic MediaWiki (both the main 'include_once' line and the 'enableSemantics' line), add the following line:
# arguments that determine the ''format'' and other aspects of the display


Here is an example of a regular ask query:
<source lang="php">require_once( "$IP/extensions/SemanticCompoundQueries/SemanticCompoundQueries.php" );</source>


<syntaxhighlight lang="wikitext">
==Usage==
{{#ask: [[Category:Stores]] [[Has type::Clothing]] |?Has country=Country |format=table }}
A normal inline query, using the #ask parser function, takes in arguments of three types: (1) a filter that determines the results, (2) the names of properties to be displayed, and (3) arguments that determine the format and other aspects of the display. Here is an example of a normal inline query:
</syntaxhighlight>

<pre><nowiki>{{#ask:[[Category:Stores]][[Has type::Clothing]]|?Has country=Country|format=table}}</nowiki></pre>


In this query there are three arguments separated by pipes and they belong to argument types 1, 2 and 3, respectively.
In this query there are three arguments separated by pipes and they belong to argument types 1, 2 and 3, respectively.


=== Compound queries ===
For compound queries the first two types of argument are unique to each sub-query and are separated from each other by semicolons instead of pipes; pipes are used to separate one sub-query from the rest. The third type of argument, setting the display of the results, is common across all sub-queries. Here is an example of a call to #compound_query that shows both clothing stores and fast-food restaurants in a table:
For compound queries the first two types of argument are unique to each sub-query and are separated from each other by semicolons (;) instead of pipes (|); pipes are used to separate one sub-query from the rest.


The third type of argument, setting the display of the results, is common across all sub-queries.
<pre><nowiki>{{#compound_query:[[Category:Stores]][[Has type::Clothing]];?Has country=Country
|[[Category:Restaurants]][[Has cuisine::Fast food]];?Has country=Country
|format=table}}</nowiki></pre>


Here is an example of a call to #compound_query that shows both clothing stores and fast-food restaurants in a table:
One important exception to this rule is the <tt>limit=</tt> parameter, which sets the maximum number of results displayed: it must be used '''per sub-query''', not for the overall compound query.
<syntaxhighlight lang="text">
{{#compound_query:
[[Category:Stores]] [[Has type::Clothing]] ;?Has country=Country
|[[Category:Restaurants]][[Has cuisine::Fast food]] ;?Has country=Country
|format=table
}}
</syntaxhighlight>

One important exception to this rule is the <kbd>limit=</kbd> parameter, which sets the maximum number of results displayed: it must be used '''per sub-query''', not for the overall compound query.


===Maps===
===Maps===
To make things more interesting, we can place all these results on a map, using the [[Extension:Semantic Maps|Semantic Maps]] extension. Here is the same set of results, using SM's 'googlemaps' format, and a different property displayed for both sets of points to set their geographical coordinates:


To make things more interesting, we can place all these results on a map, using the [[Extension:Maps|Maps]] extension. Here is the same set of results, using Maps 'googlemaps' format, and a different property displayed for both sets of points to set their geographical coordinates:
<pre><nowiki>{{#compound_query: [[Category:Stores]] [[Has type::Clothing]]; ?Has coordinates
<syntaxhighlight lang="text">
| [[Category:Restaurants]] [[Has cuisine::Fast food]]; ?Has coordinates
{{#compound_query:
| format=googlemaps}}</nowiki></pre>
[[Category:Stores]] [[Has type::Clothing]] ;?Has coordinates
|[[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates
|format=googlemaps
}}
</syntaxhighlight>


We can set a different icon to appear for each location type in the map, by using the "icon" parameter, which Semantic Maps understands (note that this feature only works with MediaWiki 1.13 or higher). Assuming your wiki contains uploaded images by the name of "Shirt.png" and "Hamburger.png", you could call the following:
We can set a different icon to appear for each location type in the map, by using the "icon" parameter, which Maps understands.Assuming your wiki contains uploaded images by the name of "Shirt.png" and "Hamburger.png", you could call the following:
<syntaxhighlight lang="text">

<pre><nowiki>{{#compound_query: [[Category:Stores]] [[Has type::Clothing]]; ?Has coordinates; icon=Shirt.png
{{#compound_query:
[[Category:Stores]] [[Has type::Clothing]] ;?Has coordinates ;icon=Shirt.png
| [[Category:Restaurants]] [[Has cuisine::Fast food]]; ?Has coordinates; icon=Hamburger.png
|[[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates ;icon=Hamburger.png
| format=googlemaps|height=400|width=600}}</nowiki></pre>
|format=googlemaps |height=400 |width=600
}}
</syntaxhighlight>


This query also sets the height and width of the map - additional arguments of the third type.
This query also sets the height and width of the map - additional arguments of the third type.


<nowiki>#compound_query</nowiki> avoids displaying the same page more than once, so if a page gets returned by more than sub-query, it's displayed only for the first one. In this way, a compound query can have specific sub-queries, and then a general catch-all sub-query at the end:
<code><nowiki>#compound_query</nowiki></code> avoids displaying the same page more than once, so if a page gets returned by more than sub-query, it's displayed only for the first one.
In this way, a compound query can have specific sub-queries, and then a general catch-all sub-query at the end:


<syntaxhighlight lang="text">
<pre><nowiki>{{#compound_query:[[Category:Restaurants]][[Has cuisine::Fast food]];?Has coordinates;icon=Hamburger.png
{{#compound_query:
|[[Category:Restaurants]][[Has cuisine::Italian]];?Has coordinates;icon=Spaghetti.png
|[[Category:Restaurants]];?Has coordinates;icon=Fork.png
[[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates ;icon=Hamburger.png
|[[Category:Restaurants]] [[Has cuisine::Italian]] ;?Has coordinates ;icon=Spaghetti.png
|format=googlemaps}}</nowiki></pre>
|[[Category:Restaurants]] ;?Has coordinates ;icon=Fork.png

|format=googlemaps
[[Extension:Semantic Maps|Semantic Maps]] displaying the result of a compound query with Google Maps:
}}
[[File:Sm-qp-gmaps-referata.jpg|400px]]
</syntaxhighlight>


===Calendars===
===Calendars===
There's also special handling for the [[Extension:Semantic Result Formats/calendar format|'calendar' format, defined in Semantic Result Formats]] - if you display a calendar, you can set a different color for each set of events displayed. Here is an example:


There's also special handling for the [[Extension:Semantic Result Formats/calendar format|'calendar' format, defined in Semantic Result Formats]] - if you display a calendar, you can set a different color for each set of events displayed.
<pre><nowiki>{{#compound_query:[[Category:Events]][[Has priority::High]];?Has date;color=red

|[[Category:Events]][[Has priority::Low]];?Has date;color=#99cc99
Here is an example:
|[[Category:Events]];?Has date
<syntaxhighlight lang="text">
|format=calendar}}</nowiki></pre>
{{#compound_query:
[[Category:Events]] [[Has priority::High]] ;?Has date ;color=red
|[[Category:Events]] [[Has priority::Low]] ;?Has date ;color=#99cc99
|[[Category:Events]] ;?Has date
|format=calendar
}}
</syntaxhighlight>

===API===

Starting with version 1.0 this extension provides an API module called "compoundquery".
The documentation is available [[semantic-mw:Help:CompoundQuery|semantic-mediawiki.org]]


===Limitations===
===Limitations===

* Unlike regular #ask queries, #compound_query does not display a "further results" link if the number of results exceeds the limit. For this reason, the <tt>searchlabel</tt> parameter available for regular #ask queries cannot be used.
Unlike regular #ask queries, #compound_query does not display a "further results" link if the number of results exceeds the limit. For this reason, the <kbd>searchlabel</kbd> parameter available for regular #ask queries cannot be used.


==Authors==
==Authors==
Semantic Compound Queries was mostly written by [[User:Yaron Koren|Yaron Koren]], reachable at yaron57 -at- gmail.com. Important contributions were made by Jeroen De Dauw.


Semantic Compound Queries was funded initially by the [http://www.kdz.or.at/english.html KDZ - Centre for Public Administration Research] in Vienna, Austria.
Semantic Compound Queries was mostly written by [[User:Yaron Koren|Yaron Koren]]. Important contributions were made by James Hong Kong, Jeroen De Dauw and Peter Grassberger.

Semantic Compound Queries was funded initially by the [https://kdz.eu/de/node/1791 KDZ - Centre for Public Administration Research] in Vienna, Austria.


==Version history==
==Version history==

Semantic Compound Queries is currently at version 0.4. See the entire [[Extension:Semantic Compound Queries/Version history|version history]].
Semantic Compound Queries is currently at version 2.2.0. See the entire [[Extension:Semantic Compound Queries/Version history|version history]].


==Bugs and feature requests==
==Bugs and feature requests==
You should use the Semantic MediaWiki mailing list, [https://lists.sourceforge.net/lists/listinfo/semediawiki-user semediawiki-user], for any questions, suggestions or bug reports about Semantic Compound Queries. If possible, please add "[SCQ]" at the beginning of the subject line, to clarify the subject matter.


You should use the Semantic MediaWiki mailing list, [https://lists.sourceforge.net/lists/listinfo/semediawiki-user semediawiki-user], for any questions, suggestions or bug reports about Semantic Compound Queries.
You can also send specific code patches to Yaron Koren, at yaron57 -at- gmail.com.

If possible, please add "[SCQ]" at the beginning of the subject line, to clarify the subject matter.

{{Used by}}


[[Category:Semantic MediaWiki extensions]]
[[Category:Semantic Bundle extensions{{#translation:}}]]
[[Category:Semantic MediaWiki extensions{{#translation:}}]]

Revision as of 22:42, 21 July 2024

MediaWiki extensions manual
Semantic Compound Queries
Release status: stable
Implementation Parser function
Description Defines a parser function, #compound_query, that can make multiple Semantic MediaWiki queries at the same time
Author(s) Yaron Koren and others
Maintainer(s) SMW Project
Latest version 2.2.0 (2022-01-20)
MediaWiki 1.31+
PHP 7.3+
Database changes No
Composer mediawiki/semantic-compound-queries
License GNU General Public License 2.0 or later
Download
RELEASE NOTES
Example A Google Map showing two different kinds of points, with a different marker for each

Compatibility

  • Semantic MediaWiki 3.0 and later
Translate the Semantic Compound Queries extension

The Semantic Compound Queries extension is meant to work with Semantic MediaWiki and allows for the display of more than one SMW inline query in one results display set. It uses its own parser function, #compound_query, which takes inputs similar to that of #ask but can take in an unlimited number of queries, instead of just one.

Installation

The recommended way to install Semantic Compound Queries is by using Composer with an entry in MediaWiki's "composer.local.json" file:

{
    "require": {
        "mediawiki/semantic-compound-queries": "~2.2"
    }
}

Now run the following in the shell:

php composer.phar update --no-dev --prefer-source

To invoke the extension add the following line to the bottom of your "LocalSettings.php" file:

wfLoadExtension( 'SemanticCompoundQueries' );

Usage

Normal queries

A normal inline query, using the #ask parser function, takes in arguments of three types:

  1. a filter that determines the results
  2. the names of properties to be displayed
  3. arguments that determine the format and other aspects of the display

Here is an example of a regular ask query:

{{#ask: [[Category:Stores]] [[Has type::Clothing]] |?Has country=Country |format=table }}

In this query there are three arguments separated by pipes and they belong to argument types 1, 2 and 3, respectively.

Compound queries

For compound queries the first two types of argument are unique to each sub-query and are separated from each other by semicolons (;) instead of pipes (|); pipes are used to separate one sub-query from the rest.

The third type of argument, setting the display of the results, is common across all sub-queries.

Here is an example of a call to #compound_query that shows both clothing stores and fast-food restaurants in a table:

{{#compound_query:
 [[Category:Stores]] [[Has type::Clothing]] ;?Has country=Country
 |[[Category:Restaurants]][[Has cuisine::Fast food]] ;?Has country=Country
 |format=table
}}

One important exception to this rule is the limit= parameter, which sets the maximum number of results displayed: it must be used per sub-query, not for the overall compound query.

Maps

To make things more interesting, we can place all these results on a map, using the Maps extension. Here is the same set of results, using Maps 'googlemaps' format, and a different property displayed for both sets of points to set their geographical coordinates:

{{#compound_query:
 [[Category:Stores]] [[Has type::Clothing]] ;?Has coordinates
 |[[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates
 |format=googlemaps
}}

We can set a different icon to appear for each location type in the map, by using the "icon" parameter, which Maps understands.Assuming your wiki contains uploaded images by the name of "Shirt.png" and "Hamburger.png", you could call the following:

{{#compound_query:
 [[Category:Stores]] [[Has type::Clothing]] ;?Has coordinates ;icon=Shirt.png
 |[[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates ;icon=Hamburger.png
 |format=googlemaps |height=400 |width=600
}}

This query also sets the height and width of the map - additional arguments of the third type.

#compound_query avoids displaying the same page more than once, so if a page gets returned by more than sub-query, it's displayed only for the first one. In this way, a compound query can have specific sub-queries, and then a general catch-all sub-query at the end:

{{#compound_query:
 [[Category:Restaurants]] [[Has cuisine::Fast food]] ;?Has coordinates ;icon=Hamburger.png
 |[[Category:Restaurants]] [[Has cuisine::Italian]] ;?Has coordinates ;icon=Spaghetti.png
 |[[Category:Restaurants]] ;?Has coordinates ;icon=Fork.png
 |format=googlemaps
}}

Calendars

There's also special handling for the 'calendar' format, defined in Semantic Result Formats - if you display a calendar, you can set a different color for each set of events displayed.

Here is an example:

{{#compound_query:
 [[Category:Events]] [[Has priority::High]] ;?Has date ;color=red
 |[[Category:Events]] [[Has priority::Low]] ;?Has date ;color=#99cc99
 |[[Category:Events]] ;?Has date
 |format=calendar
}}

API

Starting with version 1.0 this extension provides an API module called "compoundquery". The documentation is available semantic-mediawiki.org

Limitations

Unlike regular #ask queries, #compound_query does not display a "further results" link if the number of results exceeds the limit. For this reason, the searchlabel parameter available for regular #ask queries cannot be used.

Authors

Semantic Compound Queries was mostly written by Yaron Koren. Important contributions were made by James Hong Kong, Jeroen De Dauw and Peter Grassberger.

Semantic Compound Queries was funded initially by the KDZ - Centre for Public Administration Research in Vienna, Austria.

Version history

Semantic Compound Queries is currently at version 2.2.0. See the entire version history.

Bugs and feature requests

You should use the Semantic MediaWiki mailing list, semediawiki-user, for any questions, suggestions or bug reports about Semantic Compound Queries.

If possible, please add "[SCQ]" at the beginning of the subject line, to clarify the subject matter.