Search Engine, Semantic Web, RDF, Resource Description Framework, Semantic Web Search, RDF Search, RSS, FOAF, RDFS, OWL, RSS Search, FOAF Search

Semantic Web Search A Search Engine for the Semantic Web (BETA) Powered by Intellidimension RDF Gateway

SWS Library

The SWS Library contains the core functionality for developing agents that use Semantic Web Search to locate information on the Semantic Web. The SWS Library makes it easy for you, as an agent developer, to querying our service to find important information and quickly process it with very few lines of code. The SWS Library is a RDF Gateway library package that can only be used by agents running on RDF Gateway. The SWS Library can be downloaded and installed from this site (click here).

Objects

The SWS Library provides RDF Gateway agent developers with a simple object model for accessing the features of Semantic Web Search. The table below provides an overview of the objects in the SWS Library. To use any of these objects in your scripts you must import the file /sws/webapi.rql .

ObjectDescription
SWSQuery This object is used to query our service for documents and resource description we've indexed on the Semantic Web.
SWSDocument Zero or more SWSDocument objects are returned as the result of querying our service. A SWSDocument object can also be used to submit a URL to our service so it can be added to our Semantic Web Index.
 

SWSQuery Object

The SWSQuery object is used to query our service for documents on the Internet that contain the information specified in the query. This object allows you define all of the parameters for the query, execute it, and iterate over the resulting documents (see SWSDocument). Results are returned from our service one page at a time (see pageSize property). This object encapsulates the logic for fetching query results that are contained in multiple pages.

Contructors
SWSQuery( condition )
condtion
Specifies the condition for the query.
Properties
condition
This string property specifies the condition for the query. This property must be set to valid query condition.
query.condition = "{?p ?s ?o} AND ?o LIKE 'class'";
document
This property specifies the URL of document document to be queried. If this value is null then all documents are searched. By default this property is null.
query.document = "http://www.w3.org/1999/02/22-rdf-syntax-ns";
domain
This property specifies the domain that a document must be located in. This value can be a single string or an array of strings to specify multiple domains. If this value is null then all domains are searched. By default this property is null.
// Single domain
query.domain = "www.intellidimension.com";

// Multiple domains
query.domain = new Array("www.intellidimension.com", "www.w3.org");
format
This property specifies the content format of documents to be included in the query. It is specified using one of the following predefined values.
SWS_FORMAT_RDFXML
SWS_FORMAT_N3
SWS_FORMAT_NTRIPLES	
SWS_FORMAT_HTML	
If this value is null then all formats are searched. By default this property is null.
query.format = SWS_FORMAT_RDFXML; // Only search for RDF/XML documents
minDate
Only documents modified after this date property are included in the search. If this property is set to null it will not effect the search;
query.minDate = new Date(2004, 0, 1); // modified after January 1, 2004
maxDate
Only documents modified before this date property are included in the search. If this property is set to null it will not effect the search;
query.minDate = new Date(2004, 1, 15); // modified before February 15, 2004
pageSize
This property specifies the maximum number of documents that are returned in a single web service request. If the number of documents that are matched in a query exceeds the page size then the query results are split into multiple pages. Only a single page of results are returned from Semantic Web Search at a time so that each page must be individually fetched to obtain the all of the query results. If this property value is null then the default page size of 10 is used.
subject
This property must be set to a non-null value if you want the concise bounded description for the resources matched by the query to be returned in the resulting documents (see SWSDocument.descriptions). The value of this property can be set to either the URI of resource or a name of a variable used in the query condition. If a URI is specified then only the description of that resource is returned with each document. If a variable name is specified then the descriptions of all of the resources matching the URI of bound value of the variable are returned with each document.
// Get the description for rdf:subject
q.document = new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns");
q.subject = new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject ");


// Get the description of all classes
q.condition = "{[rdf:type]} ?s [rdfs:Class]}";
q.domain = "www.w3.org";
q.subject = "?s";
Methods
current ( )
Returns the current SWSDocument object from the current page of query results. If there are no more documents in the current page this method will return null.
first ( )
Returns the first SWSDocument object from the current page of query results. If there are no documents in the current page this method will return null.
next ( [auto_page] )
Returns the next SWSDocument object from the query results. If there are no more are documents in the query results this method will return null.
auto_page
(optional) If this value is set to true then next page of query results will be fetched from Semantic Web Search when the end of the current page is reached. If no more pages are available then this method will return null. If this argument is not specified or set to false this method will return null when the end of the current page is reached.
run ( )
Executes the query using Semantic Web Search and returns true if there are results.

Example

In this example we implement an agent that uses Semantic Web Search to gather all the RDF schemas at the W3C site. To implement this we use the SWSQuery object to execute a Semantic Web Search query for documents that are located in the domain www.w3.org and contain resources of type rdf:Class. We set the subject property to the variable "?s" that is used in the query condition. When the query is executed this variable is bound to the URI of each RDF Class found. The returned SWSDocument objects will contain concise bounded descriptions for each RDF Class in the document. All of resource descriptions are inserted into a database table. The agent reports on all of the RDF classes it found by selecting the URI and name of each RDF class that are in its database table.

import "/sws/webapi.rql"; // Create an in-memory table to hold all of our agent data CREATE TABLE agent_data AS TEMP; var agentData = new DataSource("agent_data"); // Create a Semantic Web Search query and run it. var q = new SWSQuery("{[rdf:type] ?s [rdfs:Class]}"); q.domain = "www.w3.org"; q.subject = "?s"; q.run(); // Iterate over all of the matching documents for (var doc = q.next(); doc != null; doc = q.next()) { if (doc.descriptions != null) { // Iterate over all matching resources and add // their statements to our table for (var i = 0; i < doc.descriptions.length; i++) agentData.insert(doc.descriptions[i].datasource); } } // Select out all the classes along with their names SELECT ?class ?name USING agent_data WHERE {[rdf:type] ?class [rdfs:Class]} AND {[rdfs:label] ?class ?name};
 

SWSDocument Object

A SWSDocument object is returned as the result of a Semantic Web Search query that is performed using the SWSQuery object. Its properties include the URL and format of the document that can be used to download and parse the document contents from the Web. The SWSDocument object can be used to submit a URL of a RDF document to be added to the Semantic Web Search index.

Contructors
SWSDocument( url )
url
The URL of the document.
Properties
bytes
The count of bytes in the document. (read-only)
descriptions
An array of RDFNode objects each containing a concise bounded description for a resource in the document that was matched by the query. This property is set to null is no descriptions were returned by the query. Descriptions are only returned if the subject property is set on the SWSQuery object. (read-only)
rank
The numeric Semantic Web Search Relevancy Ranking of the document. The higher the number the more references there are on the Semantic Web to the document.
scanDate
The date the document was last indexed. (read-only)
triples
The count of RDF triples in the document. (read-only)
url
This string property specifies the URL of the document. This property must be set to valid URL.
Methods
submit ( )
Submits the URL of the document to Semantic Web Search be added to the index.

Example

In this example we implement a simple agent that uses the SWSDocument object to submit the URL of RSS document to Semantic Web Search so that it will indexed.

import "/sws/webapi.rql"; var doc = new SWSDocument("http://www.semanticwebsearch.com/news/news.rdf"); doc.submit();
Copyright 2004-2007 Intellidimension  -  Report a Problem  -  Terms of Service