Properties and Semantic Triples
At the core of SMW are properties, which represent typed relationships between entities. When a property and its value are added to a page, they form a triple: subject → predicate → object.
For example, annotating a page titled "Semantic MediaWiki" with the property "Is related to" and the value "Semantic Forms" creates the triple:
- Subject: Semantic MediaWiki
- Predicate: Is related to
- Object: Sementic Forms
This is expressed in wiki syntax as:
[[Is related to::Semantic Forms]]
These triples mirror the structure of RDF (Resource Description Framework). SMW can export this data as RDF via a dedicated endpoint:
http://edutechwiki.unige.ch/en/Special:ExportRDF/Semantic_MediaWiki
Property Types
Properties in SMW are strongly typed, similar to object-oriented data models. By default, a property’s value is interpreted as a link to another wiki page. How ever, other data types—such as text, number, date, URL, or geocoordinates—can be explicitly defined.
For instance, to store a website URL:
[[Has website::http://www.semantic-mediawiki.org]]
Although the value appears as a URL, SMW treats it as a page link unless the property’s type is explicitly declared. To define a property’s type, you must edit its corresponding property page (e.g., Property:Has website) and add:
This is a property of type [[Has type::URL]].
There are three primary methods to create and define properties:
- Manual creation: Use the property syntax on any page, then navigate to the property page and assign a type.
- Create with Form: Use a form interface to select the data type from a dropdown, reducing manual errors.
- Special:CreateProperty: The most streamlined method—access a dedicated form to define the property name, type, and description in one step.
Displaying Property Values
How a property’s value is rendered depends on its type. Text and number values appear as plain text. Page-type properties render as internal links. URL-type properties may display as clickable links, depending on configuration.
For example, if "Has acronym" is defined as a string type:
[[Has acronym::SMW]]
It will display simply as "SMW", not as a link.
Searching for Properties
To discover all defined properties, use Special:Properties. This page lists all properties, their types, and usage counts. Red links indicate undeclared properties—clicking them allows you to define their type.
Inline Queries
SMW provides a query language accessible via parser functions. The two primary functions are #ask and #show.
#askperforms a search and returns results formatted according to specified parameters.#showretrieves a single property value from a specified page (a shortcut for simple lookups).
A basic query to list all pages in a category:
{{#ask: [[Category:MediaWiki extension]]}}
Outputs: a bulleted list of all pages tagged with that category.
Query Syntax and Filters
Queries follow this structure:
{{#ask: [search conditions] | [display options] | [format options] }}
Search conditions can include:
- Categories:
[[Category:MediaWiki extension]] - Properties:
[[Developed with::MediaWiki software]] - Wildcards:
[[Supports languages::+]](matches any value) - Comparators:
[[Was last edited::>1 September 2013]] - Partial matches:
[[Has field of science::~bio*]](matches values starting with "bio")
Multiple conditions are combined with logical AND. For OR logic, use the pipe symbol:
{{#ask: [[Category:Extension]] || [[Category:Tool]] }}
Querying Across Categories
By default, category queries include subcategories. For example:
{{#ask: [[Category:MediaWiki extension]]}}
Returns all pages in "MediaWiki extension" and its child categories like "Semantic MediaWiki extensions".
Displaying Multiple Properties
When multiple properties are requested, results appear in a table by default:
{{#ask:
[[Category:MediaWiki extension]]
| ?Has developer
| ?Last edited
| ?Has website
}}
This displays a table with the extension name, its developer, last edit date, and website link.
Visualization
SMW supports visual output formats via result formats. For instance, to generate a chart of developers:
{{#ask:
[[Has developer::Yaron Koren]]
| ?Has developer
| ?Has name
| format=category
}}
Can render as a tag cloud or graph, depending on installed extensions like Semantic Result Formats.
Query Limits and Debugging
By default, #ask limits results to 50 entries. Override this with the limit parameter:
{{#ask: ... | limit=100 }}
To debug queries, enable the debug parameter to see the underlying SPARQL-like query structure.
Special Properties and Composite Data
SMW includes built-in special properties, such as:
Has page languageWas last editedPage namespace
These are automatically populated and can be viewed and configured via Special:Properties. To enable them, click the red link and assign a type (e.g., text, date).
Handling Complex Data with Subobjects
SMW’s page-centric model struggles with compound data like "Teacher has three bananas." To represent such relationships, use semantic subobjects:
{{#subobject:banana1
| has quantity=3
| has color=yellow
}}
Subobjects allow nested data structures within a single page, enabling modeling of real-world relationships without requiring separate pages for each component.