W3C AnnoteaDocumentation

Algae2 HOWTO

Algae Specification | Perl Libraries | Downloading | Documentation

This document describes how to use the W3C-Perllib algae interface. See the Algae specification for more details.

Algae2 is a constraint-based query interface based on algernon and then algae. Aside from syntax, the pricipal difference between algae and algernon was that algae is not tied to an accessor (algernon assumes triples are accessed by subject only). Algae2 abandoned the s-expression syntax and adopted an n3 syntax for queries and assertions.

If you are looking for the interface to W3C::Rdf::bin::algae, please see the RdfApp HOWTO.

Table of Contents

Queries

Queries select a result set with an query string and collect the results with an collect string:

query ::
"ask" S* "(" S* contstraintStr+ ")"
 S* "collect" S* (" S* variable+ ")" S* ")"

where the constrinatStr is a set of notation 3 statements

For example, the following query looksfor all annotations annotated by Joe. The :collect part of the query defines what the query returns, in this case all the annotations that were found and the documents they annotate.

ask (
  ?annot <http://...#type> <http://...#Annotation> .
  ?annot <http://...#creator> "Joe" .
  ?annot <http://...#Annotates> ?doc)
collect (?annot ?doc)

You may also take advanage of Notation 3 shortcuts like namespace prefixes:

ns rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
ns d1=<http://purl.org/dc/elements/1.1/>
ns a=<http://www.w3.org/2000/10/annotation-ns#>
ask (
  ?annot rdf:type <http://...#Annotation> .
  ?annot dc:creator "Joe" .
  ?annot a:annotates ?doc)
collect (?annot ?doc)

or repeated properties on the same subject:

ns rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
ns d1=<http://purl.org/dc/elements/1.1/>
ns a=<http://www.w3.org/2000/10/annotation-ns#>
ask (
  ?annot rdf:type <http://...#Annotation> ;
         dc:creator "Joe" ;
         a:annotates ?doc)
collect (?annot ?doc)

The algae2 engine returns a set of solutions and the statements that support each statement. This enables an applications to provide a "prove it" button which is helpful for many reasons:

data checking
user confidence
refining criteria
...

SolutionSets

It may be usefull to introduce the algae2 query term by drawing an analogy to SQL query. An SQL query looks something like:

SELECT places.description,things.description FROM places,things WHERE places.name = things.name

This query consists of the desired result set (places.description,things.description) and the query constraints (places.name = things.name).

combinatorial solution set
yields every combination that matches query:

Example: SQL Rolodex

Friend
id name
586 Dick
14 Jane
703 Spot
Address
id street
586 218 12th Street West
14 6219 6th Avenue
586 123 Elmstraas
SELECT Friend.name,Address.street
FROM Friend,Address
WHERE Friend.id=Address.id
query results
name street
Dick 218 12th Street West
Jane 6219 6th Avenue
Dick 123 Elmstraas

Example: RDF Rolodex

predicate subject object
rdf:type myFriends:Dick Rolodex:Friend
Rolodex:Address myFriends:Dick [anoymous node 23]
Rolodex:Street [anoymous node 23] 218 12th Street West
Rolodex:Address myFriends:Dick [anoymous node 614]
Rolodex:Street [anoymous node 614] 123 Elmstraas
rdf:type myFriends:Jane Rolodex:Friend
Rolodex:Address myFriends:Jane [anoymous node 218]
Rolodex:Street [anoymous node 218] 6219 6th Avenue
rdf:type myFriends:Spot Rolodex:Friend
ask (?friend rdf:type Rolodex:Friend .
       ?friend Rolodex:Address ?addrNode .
       ?addrNode Rolodex:Street ?street)
collect (?friend ?street)
query results
?friend ?street
myFriends:Dick 218 12th Street West
myFriends:Dick 123 Elmstraas
myFriends:Jane 6219 6th Avenue

Eric Prud'hommeaux,
@(#) $Id: Algae-HOWTO.html,v 1.27 2004/06/19 03:34:54 eric Exp $ Valid HTML 4.0!