Class jQuery.rdf
A jQuery.rdf object represents the results of a query over its jQuery.rdf#databank. The results of a query are a sequence of objects which represent the bindings of values to the variables used in filter expressions specified using jQuery.rdf#where or jQuery.rdf#optional. Each of the objects in this sequence has associated with it a set of triples that are the sources for the variable bindings, which you can get at using jQuery.rdf#sources.
The jQuery.rdf object itself is a lot like a jQuery object. It has a jQuery.rdf#length and the individual matches can be accessed using [n]
, but you can also iterate through the matches using jQuery.rdf#map or jQuery.rdf#each.
jQuery.rdf is designed to mirror the functionality of SPARQL while providing an interface that's familiar and easy to use for jQuery programmers.
Defined in: jquery.rdf.js.
Constructor Attributes | Constructor Name and Description |
---|---|
jQuery.rdf(options)
Creates a new jQuery.rdf object.
|
Field Attributes | Field Name and Description |
---|---|
The databank over which this query operates.
|
|
<static> <constant> |
jQuery.rdf.first
A jQuery.rdf.resource for rdf:first
|
<static> <constant> |
jQuery.rdf.label
A jQuery.rdf.resource for rdfs:label
|
The number of matches represented by the jQuery.rdf object.
|
|
<static> <constant> |
jQuery.rdf.nil
A jQuery.rdf.resource for rdf:nil
|
<static> <constant> |
jQuery.rdf.object
A jQuery.rdf.resource for rdf:object
|
<static> <constant> |
jQuery.rdf.property
A jQuery.rdf.resource for rdf:property
|
The version of rdfQuery.
|
|
<static> <constant> |
jQuery.rdf.rest
A jQuery.rdf.resource for rdf:rest
|
<static> <constant> |
jQuery.rdf.subject
A jQuery.rdf.resource for rdf:subject
|
<static> <constant> |
jQuery.rdf.type
A jQuery.rdf.resource for rdf:type
|
Method Attributes | Method Name and Description |
---|---|
about(resource, options)
Creates a new jQuery.rdf object whose set of bindings include
property and value for every triple that is about the specified resource. |
|
add(triple, options)
Adds a triple to the jQuery.rdf#databank or another jQuery.rdf object to create a union.
|
|
base(base)
Sets or returns the base URI of the jQuery.rdf#databank.
|
|
describe(bindings)
Provides simple concise bounded descriptions of the resources or bindings that are passed in the argument.
|
|
dump(options)
Dumps the triples that form the basis of the variable bindings that are the primary product of jQuery.rdf into a format that can be shown to the user or sent to a server.
|
|
<static> |
jQuery.rdf.dump(triples, options)
Dumps the triples passed as the first argument into a format that can be shown to the user or sent to a server.
|
each(callback)
Iterates over the matches held by the jQuery.rdf object and performs a function on each of them.
|
|
end()
Returns the parent jQuery.rdf object, which is equivalent to undoing the most recent filtering operation (such as jQuery.rdf#where or jQuery.rdf#filter).
|
|
eq(n)
Returns a new jQuery.rdf object that contains only one set of variable bindings.
|
|
except(query)
Creates a new jQuery.rdf object whose databank contains all the triples in this object's databank except for those in the argument's databank.
|
|
filter(property, condition)
Creates a new jQuery.rdf object whose set of bindings include only those that satisfy some arbitrary condition.
|
|
get(num)
Either returns the item specified by the argument or turns the jQuery.rdf object into an array.
|
|
jquery()
Returns a jQuery object that wraps this jQuery.rdf object.
|
|
load(data, options)
Loads some data into the jQuery.rdf#databank
|
|
map(callback)
Iterates over the matches held by the jQuery.rdf object and creates a new jQuery object that holds the result of applying the passed function to each one.
|
|
optional(filter, options)
Creates a new jQuery.rdf object whose set of bindings might optionally include those based on the filter pattern.
|
|
prefix(prefix, namespace)
Sets or returns a namespace binding on the jQuery.rdf#databank.
|
|
reason(rules, options)
Reasons over the jQuery.rdf#databank associated with this jQuery.rdf object using the jQuery.rdf.rule or jQuery.rdf.ruleset given as the first argument.
|
|
remove(triple, options)
Removes a triple or several triples from the jQuery.rdf#databank.
|
|
reset()
Returns a jQuery.rdf object that includes no filtering (and therefore has no matches) over the jQuery.rdf#databank.
|
|
select(bindings)
Filters the variable bindings held by this jQuery.rdf object down to those listed in the bindings parameter.
|
|
size()
Returns the number of matches in this jQuery.rdf object (equivalent to jQuery.rdf#length).
|
|
sources()
Gets the triples that form the basis of the variable bindings that are the primary product of jQuery.rdf.
|
|
where(filter, options)
Creates a new jQuery.rdf object that is the result of filtering the matches on this jQuery.rdf object based on the filter that's passed into it.
|
Creates a new jQuery.rdf object. This should be invoked as a method rather than constructed using new; indeed you will usually want to generate these objects using a method such as jQuery#rdf or jQuery.rdf#where.
rdf = jQuery.rdf();
- Parameters:
- {Object} options Optional
- {jQuery.rdf.databank} options.databank Optional
- The databank that this query should operate over.
- {jQuery.rdf.triple[]} options.triples Optional
- A set of triples over which the query operates; this is only used if options.databank isn't specified, in which case a new databank with these triples is generated.
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings. Rather than passing this in when you construct the jQuery.rdf instance, you will usually want to use the jQuery.rdf#prefix method.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret any relative URIs used within the query.
- Returns:
- {jQuery.rdf}
- See:
- jQuery#rdf
property
and value
for every triple that is about the specified resource.
var rdf = $.rdf() .prefix('dc', ns.dc) .prefix('foaf', ns.foaf) .add('<photo1.jpg> dc:creator <http://www.blogger.com/profile/1109404> .') .add('<http://www.blogger.com/profile/1109404> foaf:img <photo1.jpg> .') .add('<photo2.jpg> dc:creator <http://www.blogger.com/profile/1109404> .') .add('<http://www.blogger.com/profile/1109404> foaf:img <photo2.jpg> .') .about('<http://www.blogger.com/profile/1109404>');
- Parameters:
- {String|jQuery.rdf.resource} resource
- The subject of the matching triples.
- {Object} options Optional
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings used to interpret the resource if it's a CURIE. Defaults to the namespace bindings defined on the jQuery.rdf#databank.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret the resource if it's a relative URI (wrapped in
<
and>
). Defaults to the base URI defined on the jQuery.rdf#databank.
- Returns:
- {jQuery.rdf} A new jQuery.rdf object whose jQuery.rdf#parent is this jQuery.rdf.
var rdf = $.rdf() .prefix('dc', ns.dc) .prefix('foaf', ns.foaf) .add('<photo1.jpg> dc:creator <http://www.blogger.com/profile/1109404> .') .add('<http://www.blogger.com/profile/1109404> foaf:img <photo1.jpg> .');
var rdfA = $.rdf() .prefix('dc', ns.dc) .add('<photo1.jpg> dc:creator "Jane"'); var rdfB = $.rdf() .prefix('foaf', ns.foaf) .add('<photo1.jpg> foaf:depicts "Jane"'); var rdf = rdfA.add(rdfB);
- Parameters:
- {String|jQuery.rdf.triple|jQuery.rdf.pattern|jQuery.rdf} triple
- The triple, jQuery.rdf.pattern or jQuery.rdf object to be added to this one. If the triple is a jQuery.rdf object, the two queries are unioned together. If the triple is a string, it's parsed as a jQuery.rdf.pattern. The pattern will be completed using the current matches on the jQuery.rdf object to create multiple triples, one for each set of bindings.
- {Object} options Optional
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings used to interpret CURIEs within the triple. Defaults to the namespace bindings defined on the jQuery.rdf#databank.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret any relative URIs used within the triple. Defaults to the base URI defined on the jQuery.rdf#databank.
- Returns:
- {jQuery.rdf} This jQuery.rdf object.
baseURI = jQuery('html').rdf().base();
jQuery('html').rdf().base('http://www.example.org/');
- Parameters:
- {String|jQuery.uri} base Optional
- Returns:
- A jQuery.uri if no base URI is specified, otherwise returns this jQuery.rdf object.
$.rdf.dump($('html').rdf().describe(['<photo1.jpg>']));
$('html').rdf() .where('?person foaf:img ?picture') .describe(['?photo'])
- Parameters:
- {(String|jQuery.rdf.resource)[]} bindings
- An array that can contain strings, jQuery.rdf.resources or a mixture of the two. Any strings that begin with a question mark (
?
) are taken as variable names; each matching resource is described by the function.
- Returns:
- {jQuery} A jQuery object that contains jQuery.rdf.triples that describe the listed resources.
- Parameters:
- {Object} options Optional
- Options that control the formatting of the triples. See jQuery.rdf.dump for details.
- See:
- jQuery.rdf.dump
- Parameters:
- {jQuery.rdf.triple[]} triples
- An array (or jQuery object) of jQuery.rdf.triples.
- {Object} options Optional
- Options that control the format of the dump.
- {String} options.format Optional, Default: 'application/json'
- The mime type of the format of the dump. The supported formats are:
mime type description application/json
An RDF/JSON object application/rdf+xml
An DOMDocument node holding XML in RDF/XML syntax - {Object} options.namespaces Optional, Default: {}
- A set of namespace bindings used when mapping resource URIs to CURIEs or QNames (particularly in a RDF/XML serialisation).
- {boolean} options.serialize Optional, Default: false
- If true, rather than creating an Object, the function will return a string which is ready to display or send to a server.
- Returns:
- {Object|String} The alternative representation of the triples.
var rdf = $('html').rdf() .where('?photo dc:creator ?creator') .where('?creator foaf:img ?photo') .each(function () { photos.push(this.photo.value); });
- Parameters:
- {Function} callback
- A function that is called for each match on the jQuery.rdf object. Within the function,
this
is set to the object representing the variable bindings. The function can take up to three parameters:- i
- The index of the match amongst the other matches.
- bindings
- An object representing the variable bindings for the match, the same as
this
. - triples
- An array of jQuery.rdf.triples associated with the particular match.
- Returns:
- {jQuery.rdf} The jQuery.rdf object.
- See:
- jQuery.rdf#map
$('html').rdf() .where('?person foaf:family_name "Hacker"') .where('?person foaf:givenname "Alice"') .each(...do something with Alice Hacker...) .end() .where('?person foaf:givenname "Bob"') .each(...do something with Bob Hacker...);
- Returns:
- {jQuery.rdf}
var rdf = $.rdf() .prefix('foaf', 'http://xmlns.com/foaf/0.1/') .add('_:a foaf:name "Alice" .') .add('_:a foaf:homepage <http://work.example.org/alice/> .') .add('_:b foaf:name "Bob" .') .add('_:b foaf:mbox <mailto:bob@work.example> .') .where('?x foaf:name ?name') .eq(1);
- Parameters:
- {Integer} n
- The index number of the match that should be selected.
- Returns:
- {jQuery.rdf} A new jQuery.rdf object with just that match.
- Parameters:
- {jQuery.rdf} query
var rdf = $.rdf() .prefix('foaf', 'http://xmlns.com/foaf/0.1/') .add('_:a foaf:surname "Jones" .') .add('_:b foaf:surname "Macnamara" .') .add('_:c foaf:surname "O\'Malley"') .add('_:d foaf:surname "MacFee"') .where('?person foaf:surname ?surname') .filter('surname', /^Ma?c/) .each(function () { scottish.push(this.surname.value); }) .end() .filter('surname', /^O'/) .each(function () { irish.push(this.surname.value); }) .end();
var rdf = $.rdf() .prefix('foaf', 'http://xmlns.com/foaf/0.1/') .add('_:a foaf:surname "Jones" .') .add('_:b foaf:surname "Macnamara" .') .add('_:c foaf:surname "O\'Malley"') .add('_:d foaf:surname "MacFee"') .where('?person foaf:surname ?surname') .filter(function () { return this.surname !== "Jones"; })
- Parameters:
- {Function|String} property
In the two-argument version, this is the name of a property to be tested against the condition specified in the second argument. In the one-argument version, this is a function in which
this
is an object whose properties are a set of jQuery.rdf.resource, jQuery.rdf.literal or jQuery.rdf.blank objects and whose arguments are:- i
- The index of the set of bindings amongst the other matches
- bindings
- An object representing the bindings (the same as
this
) - triples
- The jQuery.rdf.triples that underly this set of bindings
- {RegExp|String} condition
- In the two-argument version of this function, the condition that the property's must match. If it is a regular expression, the value must match the regular expression. If it is a jQuery.rdf.literal, the value of the literal must match the property's value. Otherwise, they must be the same resource.
- Returns:
- {jQuery.rdf} A new jQuery.rdf object whose jQuery.rdf#parent is this jQuery.rdf.
$('html').rdf() .where('?person a foaf:Person') .get(0) .subject .value;
- Parameters:
- {Integer} num Optional
- The number of the item to be returned.
- Returns:
- {Object[]|Object} Returns either a single Object representing variable bindings or an array of such.
- Returns:
- {jQuery}
- Parameters:
- data
- {Object} options Optional
var photos = $('html').rdf() .where('?photo dc:creator ?creator') .where('?creator foaf:img ?photo') .map(function () { return this.photo.value; });
- Parameters:
- {Function} callback
- A function that is called for each match on the jQuery.rdf object. Within the function,
this
is set to the object representing the variable bindings. The function can take up to three parameters and should return some kind of value:- i
- The index of the match amongst the other matches.
- bindings
- An object representing the variable bindings for the match, the same as
this
. - triples
- An array of jQuery.rdf.triples associated with the particular match.
- Returns:
- {jQuery} A jQuery object holding the results of the function for each of the matches on the original jQuery.rdf object.
var rdf = $.rdf() .prefix('foaf', 'http://xmlns.com/foaf/0.1/') .prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#') .add('_:a rdf:type foaf:Person .') .add('_:a foaf:name "Alice" .') .add('_:a foaf:mbox <mailto:alice@example.com> .') .add('_:a foaf:mbox <mailto:alice@work.example> .') .add('_:b rdf:type foaf:Person .') .add('_:b foaf:name "Bob" .') .where('?x foaf:name ?name') .optional('?x foaf:mbox ?mbox');
- Parameters:
- {String|jQuery.rdf.pattern} filter
- An pattern for a set of bindings that might be added to those in this jQuery.rdf object.
- {Object} options Optional
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings used to interpret any CURIEs within the pattern. Defaults to the namespace bindings defined on the jQuery.rdf#databank.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret any relative URIs used within the pattern. Defaults to the base URI defined on the jQuery.rdf#databank.
- Returns:
- {jQuery.rdf} A new jQuery.rdf object whose jQuery.rdf#parent is this jQuery.rdf.
namespace = jQuery('html').rdf().prefix('foaf');
jQuery('html').rdf().prefix('foaf', 'http://xmlns.com/foaf/0.1/');
- Parameters:
- {String} prefix Optional
- {String} namespace Optional
- Returns:
- {Object|jQuery.uri|jQuery.rdf} If no prefix or namespace is specified, returns an object providing all namespace bindings on the jQuery.rdf.databank. If a prefix is specified without a namespace, returns the jQuery.uri associated with that prefix. Otherwise returns this jQuery.rdf object after setting the namespace binding.
Defined in: jquery.rules.js.
- Parameters:
- {jQuery.rdf.rule|jQuery.rdf.ruleset} rules
- The rules to run over the databank.
- {Object} options Optional
- {Integer} options.limit Optional, Default: 50
- The rules in this ruleset are generally run over the jQuery.rdf.databank until it stops growing. In some situations, notably when creating blank nodes, this can lead to an infinite loop. The limit option indicates the maximum number of times the ruleset will be run before halting.
- Returns:
- {jQuery.rdf} The original jQuery.rdf object, although it may now contain more matches because of the new triples added to its underlying databank.
var rdf = $('html').rdf() .prefix('foaf', ns.foaf) .where('?person foaf:givenname ?gname') .where('?person foaf:family_name ?fname') .remove('?person foaf:family_name ?fname');
- Parameters:
- {String|jQuery.rdf.triple|jQuery.rdf.pattern} triple
- The triple to be removed, or a jQuery.rdf.pattern that matches the triples that should be removed.
- {Object} options Optional
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings used to interpret any CURIEs within the triple or pattern. Defaults to the namespace bindings defined on the jQuery.rdf#databank.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret any relative URIs used within the triple or pattern. Defaults to the base URI defined on the jQuery.rdf#databank.
- Returns:
- {jQuery.rdf} The jQuery.rdf object itself.
$('html').rdf() .where('?person foaf:family_name "Hacker"') .where('?person foaf:givenname "Alice"') .each(...do something with Alice Hacker...) .reset() .where('?person foaf:family_name "Jones"') .where('?person foaf:givenname "Bob"') .each(...do something with Bob Jones...);
- Returns:
- {jQuery.rdf} An empty jQuery.rdf object.
var filtered = rdf .where('?photo dc:creator ?creator') .where('?creator foaf:img ?photo'); var selected = rdf.select(['creator']);
- Parameters:
- {String[]} bindings Optional
- The variables that you're interested in. The returned objects will only contain those variables. If bindings is undefined, you will get all the variable bindings in the returned objects.
- Returns:
- {Object[]} An array of objects with the properties named by the bindings parameter.
- Returns:
- {Integer} The number of matches in this jQuery.rdf object.
- See:
- jQuery.rdf#length
$('html').rdf() .where('?thing a foaf:Person') .sources() .each(function () { ...do something with the array of triples... });
- Returns:
- {jQuery} A jQuery object containing arrays of jQuery.rdf.triple objects. A jQuery object is returned so that you can easily iterate over the contents.
var rdf = $.rdf() .prefix('foaf', ns.foaf) .add('_:a foaf:givenname "Alice" .') .add('_:a foaf:family_name "Hacker" .') .add('_:b foaf:givenname "Bob" .') .add('_:b foaf:family_name "Hacker" .') .where('?person foaf:family_name "Hacker"') .where('?person foaf:givenname "Bob");
- Parameters:
- {String|jQuery.rdf.pattern} filter
- An expression that filters the triples in the jQuery.rdf#databank to locate matches based on the matches on this jQuery.rdf object. If it's a string, the filter is parsed as a jQuery.rdf.pattern.
- {Object} options Optional
- {Object} options.namespaces Optional
- An object representing a set of namespace bindings used to interpret any CURIEs within the pattern. Defaults to the namespace bindings defined on the jQuery.rdf#databank.
- {String|jQuery.uri} options.base Optional
- The base URI used to interpret any relative URIs used within the pattern. Defaults to the base URI defined on the jQuery.rdf#databank.
- {boolean} options.optional Optional
- Not usually used (use jQuery.rdf#optional instead).
- Returns:
- {jQuery.rdf} A new jQuery.rdf object whose jQuery.rdf#parent is this jQuery.rdf.