Extension:SemanticQueryRDFS++

What This Extension Does
The SemanticQueryPlus extension ("SMW-QL+")  is an extension of the Semantic MediaWiki extension. It extends the modeling (SMW-ML) and query language (SMW-QL) of SMW with
 * negation and cardinality in query
 * inverse property in query and modeling
 * transitive, functional, inverse functional, symmetric properties in modeling
 * domain and range inference for properties in modeling

It is based on a theoretical work described in

''Jie Bao, Li Ding, James A. Hendler. Knowledge Representation and Query in Semantic MediaWiki: A Formal Study, In Tetherless World Constellation (RPI) Technical Report, pp. TW-2008-42, 2008 http://tw.rpi.edu/wiki/TW-2008-42''

How It Works
The extension translates both the SMW semantic markup ("the modeling language") and the query language into logic programs (LP), and uses a LP solver as the reasoner. For this implementation, we used dlv as the reasoner, but other LP solvers may be used as well.

It has two work modes
 * file-based mode: first, the administrator need to build a dump of the wiki semantic data using "php QLPlus_dump.php". In this mode, no real-time change will be captured in queries.
 * database-based mode: the wiki semantic data may also be dumped to a shadow database via ODBC. Real-time changes of instance data will be updated, but ontological changes (i.e. the ones about categories and properties, or the introduction of new category/property) won't. See DLV ODBC setup for setup.

Scalability
Tested on a machine with configuration: 2 * Xeon 5365 Quad 3.0GHz 1333MHz /16G / 2 * 1TB

A dump of part of DBLP data is used, with about 10k pages and 100k triples.

For the file-based mode, most of queries is answered <1.5s.

For the database-based mode, most of queries is answered <2.5s. In general, db-mode takes 50% more time than the file-base mode.

The execution time is linear to the size of the wiki, and almost constant for most of queries (due to the nature of modeling building strategies used in lp solvers).

Caching
If caching is turned on ($wgQLPlus_UseCache = true), then a query is only executed for the first visit, following page visits will be loaded from a cache. The cache may be refreshed by the "refresh" (purge) action.

Semantic Query Plus Syntax
Use the "askplus" hook function: e.g.

The syntax is an extension of SMW-QL, so you can use most of SMW-QL features here (some limitations apply)

Features inherited from SMW
From SMW-ML
 * category instantiation e.g. [[Category:C]]
 * property instantiation e.g. Property:P
 * subclass, e.g. [[Category:C]] (on a category page)
 * subclass, e.g. Subpropety of:Property:P (on a property page)

From SMW-QL
 * conjunction: e.g.,
 * disjunction: e.g.,, B or |w
 * property chain: e.g., P.Q::v
 * property wildcat: e.g., P::+
 * subquery: e.g., [[P::
 * inverse property e.g., -P::v

Negation
Use '<>' before a category or property's name

Example

Instances of D which are not instances of C.

Instances C that have no attribute value of P

It's always a good idea to not use a negated query condition alone (e.g., ), because it may lead to a VERY large result set.

Cardinality
Unqualified cardinality queries:

Find instances with at least 3 attribute values of P

Qualified cardinality queries:

Find instances with less than 3 attribute values of P, which are instances of D

Domain and Range
On a property page. e.g. Property:P, add

Domain:Category:C Range:Category:D means that for every instance P::y on page x, then x is an instance of C, y is an instance of D.

The "Category:" prefix may be omitted. Thus, the following script has the same effect.

Domain:C Range:D

Property Types
On Property:P, one may declare

Type::Transitive Type::Symmetric Type::Functional Type::InverseFunctional

For properties of Functional or InverseFunctional types, "SameAs" relations maybe inferred. For instance, for a functional property P, with " P::v1P::v2 " on the same page, then SameAs(v1,v2) is inferred (i.e., equivalent to adding SameAs::v2 to page v1).

While it is possible to add those markup to any properties, to ensure correct inference, it's better only add them to properties of "Page" datatypes, i.e. the ones with Has type::Type:Page (this is default type of a property)

Configuration
To be added. See QLPlus_Setting.php for details.

Demo and Examples
To be setup

Model Integrity Constraint
The SMW-QL+ language maybe used to state integrity constraints. For instance, if we require every person to have a name, the following query will find all instances violating this constraint

Combining this with templates, it's easy to show integrity constraint warnings on a category page, or on individual pages that violates the constraint.

Installation
Download the zip, unzip to /extension/SemanticQueryPlus. Add to LocalSetting.php one line

require_once("$IP/extensions/SemanticQueryPlus/QLPlus_AskQueryExtension.php");

Make sure executables under /bin have the right permissions (e.g., 755)

Limitations
Not all printing features of the "ask" function are supported, e.g. counting, soting or multi-page viewing. [To be extended]

Change Log
the latest SemanticHistory has been tested on MediaWiki versions 1.16 and Semantic MediaWiki version 1.5.4.

History:
 * Dec 22, 2010 version 0.1 -first release