A query condition is an expression syntax used by your software agents to precisely describe the information needed when performing a query. To quickly put things in perspective, if your agents were accessing information from a relational database then a query condition would be expressed in the WHERE clause of a SQL SELECT statement. The Semantic Web can be thought of as a slightly different type database in which information is stored on Internet using an open standard called the Resource Description Framework (RDF). Querying for information on the Semantic Web requires an expression syntax that works with RDF data and a language called RDFQL offers just that.
The query commands in RDFQL are very similar to those in SQL. So it makes sense that when your agents query for information on the Semantic Web a query condition is expressed using the WHERE clause syntax of a RDFQL SELECT statement. This document will introduce you to the subset RDFQL that can be used by your agents to query the Semantic Web through our service.
Your agents submit queries to our service that specify a query condition describing the information you need. Our service will return to your agent the URLs of the documents on the Internet that contain the exact information described by the query condition. It is important to keep in mind, we return the URLs of the documents that contain the information and not the actual information. It is up to your agents to gather the information you need from the documents.
When our service receives a query from one of your agents, we apply the query condition to each document in our index. Only the URLs for those documents that contain RDF data that satisfies the query condition are returned to your agent. An agent query should be thought of as a document search of the Internet and not a federated query of all the RDF data on the Internet.
We will define a RDF document as a set of one or more RDF statements that exist at a URL on the Internet. A RDF statement is often referred to as a triple because it is made up of three components called the predicate, subject and object. A triple is used to represent a single fact about some resource (person, place, or thing). For example if you wanted to assert the fact "The color of the ball is red" you would need to create a triple with the values color, ball, and red for the predicate, subject and object respectively. The triple is the fundemental building block for all data models represented using RDF.
Since the triple is fundemental to all RDF data models it should follow that the triple is also fundemental in querying RDF documents. All query conditions describe the information to be searched for as a logical expression containing one or more triples.
In RDFQL the syntax for representing a triple is three terms separated by a space and enclosed in a pair of curly braces. The first, second and third term denote the predicate, subject and object respectively.
The table below describes the terms that can be placed inside of a RDFQL triple.
| Term | Syntax | Description |
| Resource | [rdf:type] |
A RDF resource is expressed as a URI enclosed by a pair of square braces. The predicate of a statement must
always be a resource and in general refers to a property in a schema. The subject must
also be a resource that defines the person, place, or thing the statement is about. The object can be
a resource if the statement refers to another resource.
The RDFQL resource syntax supports XML namespaces to allow for a shorthand notation of lenghty URIs. However Semantic Web Search only reconizes certain namespace abbreviations (see Namespace Reference). |
| Literal |
"hello world"
|
A RDF literal is expressed as a string of characters delimited by a pair of double quote marks. If the character
string contains a newline, double quote, or backslash then the character must be escaped with a backslash
as shown respectively: \n \" \\ .
A language identifier may be specified by adding an at-sign followed by the 2 or 3 letter code for the language (IETF RFC 1766) immediately after the literal value. |
| Typed Literal |
Literal ^^< XML-Datatype > |
A RDF typed literal is expressed using the literal syntax followed by two carets and a XML datatype
enclosed between a pair of angle brackets.
Example: "10"^^<http://www.w3.org/2001/XMLSchema#int>
|
| Variable | ?x, ?author, ?doc_url |
A variable is denoted by a single question mark followed by a name. The name must start
with a letter and contain only letters, numbers, and underscores. When a variable is placed
in a RDFQL triple it is bound to its coresponding value in any RDF triple found in data
being queried that matches the other two terms in the RDFQL triple. For example, if all three
terms in a RDFQL triple are different variables then all RDF triples in the queried data are matched and
the variables are correspondingly bound to the predicate, subject and object values of the matched triples.
In their most basic use, variables allow wildcard searches of one or more terms in a triple. You can use a unique variable name when you don't care about the value of a particular term. In more complex queries variables allow you to link triples together by using the same variable in two or more triples. For example, using the same variable in the subject of a RDFQL triple will link together multiple statements about the same resource. Variables can also be used to perform functional and comparison operations on individual terms in a triple. For example, checking if the object value of a triple is a literal that contains a certain phrase. |
As we defined earlier, query condition is a logical expression that describes the information you need. In its simplest form a logical expression can be a single triple that defines a RDF statement that you are searching for. However some queries require multiple triples with functional and comparisons operations on the various terms of the triples. RDFQL Operators allow you create simple expressions that assign and compare variables and logically join expressions to create a more complex expressions.
The examples below shows two expressions. The first matches all statements that have a rdf:value
equal to the literal constant "Banana" using a single triple. The second matches all statements that have
a rdf:value that contains the literal constant "Banana". In the second expression
two simpler expressions {[rdf:value] ?s ?value} and ?value LIKE "Banana" are
joined together by the variable ?value using the AND operator.
|
|
A simple triple expression |
|
|
A logical join of multiple expressions |
Expressions are evaluated according to the precedence of the operators. Operators of equal precedence are evaluated from left to right. Parenthesis can be used to control the order of evaluation by forcing expressions within the inner most parenthesis to be evaluated first. The table below describes the RDFQL operators supported by Semantic Web Search.
| Type | Syntax | Description |
| Logical | AND, OR |
Logical operators are used to join the intersection (AND) or union (OR) of the results of two expressions.
Logical operators have the lowest precendence of all operators with the AND operator having a higher precendence
than the OR operator.
A common use of the AND operator is to join together multiple statements about the same resource by using a common variable in the subject of each RDFQL triple. The OR operator is used to test that at least one of multiple expressions is true. {[rdf:type] ?s [rdfs:Class]} AND {[rdfs:label] ?s ?class_name} AND
When joining together multiple expressions it is important to note that varibles are bound to values in the same order that the expression is evaluated. |
| Comparison | =, !=, <, <=, >, >=, LIKE |
A comparison operator is used to compare two values such as bound variables, constants, and return
values from functions. All comparison operators have the same precedence.
{[rdf:value] ?s ?value} AND strcmpi(?value, "K") >= 0 AND strcmpi(?value, "N") < 0
|
| Assignment | = |
The assignment operator is used to set the value of an unbound variable. Only an unbound variable can be assigned
a value. If the variable is currently bound in an expression then the assignment operator behaves the same as the
equality operator (=). Varibles are bound to values in the order that the expression is evaluated.
The assignment operator has the same precedence as the equality operator.
{[rdf:value] ?s ?value} AND ?x = trim(value) AND strcmpi(?x, "Red") = 0
|
RDFQL Functions are used within an expression to perform an intrinsic operations such as math, date, string, URI, and data type conversion operations. All functions return a value that can be compared to another value, assigned to an unbound variable or used as an argument to another function. A function call is specified in an expression using its name followed by a pair of parenthesis that contain zero or more comma separated agruments. An argument to a function can be a bound variable, a constant, or as stated earlier a return value from another function.
Semantic Web Search supports a subset of the RDFQL intrinsic functions. The links below refer you to the RDFQL on-line documentation for more details on their use.
Data Type Conversion Functions 
URI Functions