Ask Function
Community knoodl / wiki / Wikitext

The {{ASK ...}} is a wikifunction that defines a SPARQL query such that when users view the page, a SPARQL query is executed and the results are embedded in the page.

Contents

There are actually several different forms of the "ask" wikifunction:

Function Name

Explanation

ask

Performs a search and places the results into a table. The SPARQL query language is used. If no query is specified, a default query is used that searches for all relationship with the resource represented by the current page as the subject.

ask:table

Same as {{ask}}.

ask:rows

Same as {{ask:table}}, except only rows are generated. This function is designed to be embedded in other wikitext tables, and allows for customizing the appearance and headers of the table.

ask:list

Same as {{ask}}, except results are placed into a bullet, numbered or other wiki list. The characters that precede each line can be specified, allowing different list types (including sublists) to be generated; the default is "*" (for a bullet list).

ask:line

Same as {{ask}}, except results are written out as simple line using a supplied delimiter. The default delimiter is ", " to generate a comma-separated list. This is most useful when the query contains a single variable result.

ask:rdf

Performs a SPARQL describe query and displays the raw RDF result. If no query is specified, a default query is used to describe the resource represented by the current page.

ask:show

Displays the default or supplied SPARQL query, without executing the query or displaying the results.

Parameters

This function has several parameters. If the parameter has a default value, then the parameter is optional.

Option

Allowed Values

Default Value

Explanation

type

table
rows
list
line

table

Specifies how the results should be shown on the page. The default is table, which produces an full HTML table (including headers). If you want to control the content of the header cell or want to add your own rows, use rows. Using list will cause the results to be displayed as a bulleted list, numbered list, or even definition list (see the start option). And line puts all of the results onto a single line (convenient for embedding the results of a query into a paragraph).

caption

any string

empty

If type=table (or {{ask:table}} or {{ask}}), then caption specifies the text to use as the table caption. If not used, no table caption is left off of the table.

begin

*
#
:
;
or combinations

"*"

If type=list (or {{asklist}}), then begin specifies the text that begins each item in the list. Note that the text should be a combination of one or more wikitext table prefixes.

 The default is to show as a bullet list.

delim

any string

", "

If type=line (or {{ask:line}}), then delim specifies the text that separates each row in the results when written to a single line. The default is a comma followed by a single space.

links

yes
no

yes

Specifies whether references to other pages in the results should be shown as hyperlinks.

rdf

yes
no

yes

Specifies whether the RDF results should be included.

show

yes
no

yes

Specifies whether the RDF results should be included.

Specifying the Query

The "ask" wiki function allows you to execute a SPARQL query against the current vocabulary and have the results embedded on the page. And the query is run every time the page is viewed, making sure that the page shows the latest and greatest information.

SPARQL is a powerful query language for RDF. Since vocabularies are represented in Knoodl as RDF, SPARQL can be used to query vocabularies. But SPARQL can be complicated, so the "ask" wikifunction simplifies things a bit, yet still gives you the power to build exactly the query you want.

Examples

Here are just a few examples that show how you can dynamically embed information into the pages of your vocabularies.

Ask about this resource

This version is the simplest to use, and it basically returns a table showing all of the known facts about the resource that the current page is associated with.

{{ask}}

Note that this will include the actual RDF data at the bottom of the table. If you don't like the RDF, simply say that you don't want it:

{{ask|rdf=no}}

Ask for the RDF of this resource

This returns just the known facts about the current resource in the form of RDF.

{{ask:rdf}}

Ask for all resources that have a property value

This example shows how to find all of the resources (which are given the variable ?subject) and their value of the vs:term_status property. The results are returned in ascending order, first by status value and then by subject. Note that 'DISTINCT' removes duplicate rows (if there are any).

{{ask:table|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
      } 
ORDER BY ASC(?status) ASC(?subject)
}}

This is a similar query, except that only those resources with a status value of 'stable' are returned, and that the results are returned in ascending order of status and decending order of subject.

{{ask:table|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
        FILTER ( ?status = 'stable' )
      } 
ORDER BY ASC(?status) DESC(?subject)
}}

By simply changing the type of the query (by changing "ask:table" to "ask:list"), the same query is run but the results are shown as a bullet list. Each line is of the form "firstValue (secondValue, thirdValue, ...)", or in this case "subject (status)".

{{ask:list|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
        FILTER ( ?status = 'stable' )
      } 
ORDER BY ASC(?status) DESC(?subject)
}}

or, as a numbered list:

{{ask:list|begin=#|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
        FILTER ( ?status = 'stable' )
      } 
ORDER BY ASC(?status) DESC(?subject)
}}

Embed results into text

It is also possible to render the results directly within text.

Shown as a data embedded in text: {{ask:line|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
      } 
ORDER BY ASC(?status) ASC(?subject)
}}.

Show the SPARQL query but do not execute

This example shows how to display the SPARQL query without actually running the query:

{{ask:show|
SELECT DISTINCT ?subject ?status 
WHERE { ?subject vs:term_status ?status.
      } 
ORDER BY ASC(?status) ASC(?subject)
}}

About the content on this page:

Copyright © 2006-2007 Revelytix, Inc. All rights reserved.