mulgara - semantic store

skip navigation

SHOW SITE NAV
fixed
fluid
straight

Basic iTQL Operations

The types of basic operations you can perform using iTQLTM include:

Mulgara databases referenced in iTQL commands are identified by URLs that are made up of a:

For example, rmi://mysite.com/server1.

Fragment identifiers added to the URL of a Mulgara database, identifies RDF models stored on the database. For example, rmi://mysite.com/server1#model7.

 

Mulgara has a special server model reserved for use by the system. It contains statements about the models that currently exist on the system. Only Mulgara can modify server models directly. Users modify the server model indirectly by creating or dropping models. Server models have a fragment identifier of just #. For example rmi://mysite.com/server1#

The following iTQL select command lists all models on a newly created Mulgara database, rmi://mysite.com/server1#:

select $model from <rmi://mysite.com/server1#>
where $model <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://mulgara.org/mulgara#Model>;
1 columns: model (1 rows)
model=rmi://mysite.com/server1#

Note - Since it is a newly created Mulgara database, the query only lists the server model.

In the previous example, the where clause of the select command lists a fully qualified predicate and object. You can simplify your queries by using the alias command. The alias command allows you to define aliases to frequently accessed resources. For example:

alias <http://www.w3.org/1999/02/22-rdf-syntax-ns#> as rdf;
alias <http://mulgara.org/mulgara#> as mulgara;

You could then write the select command as follows:

select $model from <rmi://mysite.com/server1#>
where $model <rdf:type> <mulgara:Model>;

Note - The Mulgara shell automatically defines several aliases by default. These are:

alias <http://www.w3.org/1999/02/22-rdf-syntax-ns#> as rdf;
alias <http://www.w3.org/2000/01/rdf-schema#> as rdfs;
alias <http://www.w3.org/2002/07/owl#> as owl;
alias <http://mulgara.org/mulgara#> as mulgara;
alias <http://mulgara.org/owl/krule/#> as krule;

 

Creating New Models

You can create new models using the create command and remove them using the drop command . With create, you specify the new model name as the fragment identifier of the URL.

For example, to create a new model called model1:

create <rmi://mysite.com/server1#model1>;

Using the select command again to list all models, now displays two models.

select $model from <rmi://mysite.com/server1#>
where $model <rdf:type> <mulgara:Model>;
1 columns: model (2)

model=rmi://mysite.com/server1#
model=rmi://mysite.com/server1#model1

 

Inserting and Deleting Statements

Statements are inserted into a model using the insert command. Statements are specified by listing in order their subject, predicate and object.

For example, to insert into a model that John Smith is the creator of the Web page http://www.domain.net/~jsmith/home.html:

insert <http://www.domain.net/~jsmith/home.html> <dc:creator> 'John Smith'
into <rmi://mysite.com/server1#model1>;

Note - The semantics of creator are defined by the Dublin Core.

Using the select command to list all statements in a model:

select $subject $predicate $object from <rmi://mysite.com/server1#model1>
where $subject $predicate $object;
3 columns: subject predicate object (1 rows)
subject=http://www.domain.net/~jsmith/home.html
predicate=http://purl.org/dc/elements/1.1/creator
object="John Smith"

Note - The predicate, dc:creator, expands out to the longer URL of the Dublin Core creator element. The URI scheme dc: is automatically aliased to the URI prefix http://purl.org/dc/elements/1.1/ when the iTQL shell starts. For more information, see the alias command in the iTQL Command section.

Statements are deleted from a model using the delete command. For example, to delete the statement just inserted:

delete <http://www.domain.net/~jsmith/home.html> <dc:creator> 'John Smith'
from <rmi://mysite.com/server1#model1>;

Note - Inserting new statements to a model never deletes or changes any existing statements. In the example above, to change the author of the Web page from John Smith to Mary Jones requires that the original statement be deleted and a new statement inserted.

If the original statement is not deleted, then both statements are present in the model. Models act as mathematical sets, so inserting a statement more than once is permitted.

 

Loading Statements

It is usually not practical to insert statements into a model one at a time. The load command reads statements from a specified RDF/XML or N-Triple file and loads them into a model.

By default, the load command expects an XML/RDF file. To load an N-Triple file, the file must have one of the following file extensions: .n3, .nt, .n3.gz, .nt.gz, .n3.zip or .nt.zip. The load command also accepts zip and GNUzip (gzip) compressed file formats.

Also, when file: URLs are specified, the default load command assumes the file exists on the server. An optional parameter, local, streams the file from the client to the server, ready for loading.

For example:

load <file:/tmp/bookmarks.rdf> into <rmi://mysite.com/server1#model1>;
load <file:/tmp/ntriple.n3> into <rmi://mysite.com/server1#model1>;

See the load command in the iTQL Commands section for more details.

Note - In the above example, for systems running a Windows® operating system, the file specification would look something like <file:/C:/temp/bookmarks.rdf>.

 

Removing Models

Models are removed using the drop command. For example:

drop <rmi://mysite.com/server1#model1>;

A select command confirms that the model no longer exists:

select $model from <rmi://mysite.com/server1#>
where $model <rdfns:type> <mulgarans:Model>;
1 columns: model (2 rows)

model=rmi://mysite.com/server1#

Note - The above example assumes prior execution of the following alias commands:

alias <http://www.w3.org/1999/02/22-rdf-syntax-ns#> as rdfns;
alias <http://mulgara.org/mulgara#> as mulgarans;

 

Queries

As shown in the previous sections, the select command performs queries against a model.

In its simplest form, a select command has three clauses:

  1. select

    Specifies the variables to solve for and the order in which they should appear in the result.

  2. from

    Specifies the model to be queried.

  3. where

    Specifies the constraints for the query. It must always specify the subject, predicate and object sequence of an RDF statement.

For example, the following query is not valid as there are only two elements in the where clause, a subject and an object.

select $x from <rmi://mysite.com/server1#MyModel> where $x 'Title';

The following query is valid. It finds the subjects and predicates of all statements where the object of the statement is the literal 'Title'.

select $x $y from <rmi://mysite.com/server1#MyModel> where $x $y 'Title';

Variables can be any name you specify. In the above query for example, $x and $y could be replaced with something more meaningful:

select $subject $predicate from <rmi://mysite.com/server1#MyModel>
where $subject $predicate 'Title';

This is the same query as before, but returns columns named subject and predicate, rather than x and y.

The following command shows everything about the Dublin Core title element:

select $obj $pred from <http://purl.org/dc/elements/1.1/>
where <http://purl.org/dc/elements/1.1/title> $pred $obj;
2 columns: obj pred (8 rows)
obj=http://dublincore.org/usage/documents/principles/#element
pred=http://purl.org/dc/elements/1.1/type
obj=http://dublincore.org/usage/terms/history/#title-004
pred=http://purl.org/dc/terms/hasVersion
obj=http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
pred=http://www.w3.org/1999/02/22-rdf-syntax-ns#type
obj=1999-07-02
pred=http://purl.org/dc/terms/issued
obj=2002-10-04
pred=http://purl.org/dc/terms/modified
obj="A name given to the resource."
pred=http://www.w3.org/2000/01/rdf-schema#comment
obj="Title"
pred=http://www.w3.org/2000/01/rdf-schema#label
obj="Typically, a Title will be a name by which the resource is formally known."
pred=http://purl.org/dc/elements/1.1/description

The following commands show the current headlines on Slashdot:

alias <http://purl.org/rss/1.0/> as rss;
select $title from <http://slashdot.org/slashdot.rss> where $url <rss:title> $title;
1 columns: title (14 rows)
title="A Motherboard That Doesn't Require An OS"
title="Beagle 2 Failure Theories"
title="Building Social Skills in Gifted Youths?"
title="DARPA Grand Challenge Kicks Off March 13th"
title="How The Web Ruined The Encyclopedia Business"
title="Is Windows Worth $45?"
title="PayPal Settles NY Probe, But Faces Others"
title="RMS & FSF Directors To Meet With FSF Members"
title="Search Slashdot"
title="Sandia Builds Micromechanical 'Device Driver'"
title="Measuring The Distance From Earth To Moon"
title="Slashdot"
title="The Implications Of Software Commodity?"
title="Viacom and DishNetwork Battle On Air Over Contract"

Note - The above titles are current as at the date of the query.

The following command shows not only the titles, but also their corresponding URLs:

alias <http://purl.org/rss/1.0/> as rss;
select $title $url from <http://slashdot.org/slashdot.rss>
where $url <rss:title> $title;
2 columns: title url (13 rows)
title="A Motherboard That Doesn't Require An OS"
url=http://slashdot.org/article.pl?sid=04/03/08/2319215
title="Beagle 2 Failure Theories"
url=http://slashdot.org/article.pl?sid=04/03/08/2340206
title="Building Social Skills in Gifted Youths?"
url=http://slashdot.org/article.pl?sid=04/03/09/013254
title="DARPA Grand Challenge Kicks Off March 13th"
url=http://slashdot.org/article.pl?sid=04/03/09/0356227
title="How The Web Ruined The Encyclopedia Business"
url=http://slashdot.org/article.pl?sid=04/03/08/2014231
title="Is Windows Worth $45?"
url=http://slashdot.org/article.pl?sid=04/03/09/0032257
title="PayPal Settles NY Probe, But Faces Others"
url=http://slashdot.org/article.pl?sid=04/03/08/2357225
title="RMS & FSF Directors To Meet With FSF Members"
url=http://slashdot.org/article.pl?sid=04/03/08/1926222
title="Search Slashdot"
url=http://slashdot.org/search.pl
title="Slashdot"
url=http://images.slashdot.org/topics/topicslashdot.gif
title="Slashdot"
url=http://images.slashdot.org/topics/topicslashdot.gif
title="The Implications Of Software Commodity?"
url=http://slashdot.org/article.pl?sid=04/03/08/2010215
title="Viacom and DishNetwork Battle On Air Over Contract"
url=http://slashdot.org/article.pl?sid=04/03/08/1915243

Valid XHTML 1.0 TransitionalValid CSS 3.0!