Raymond; All good questions - see below.
<Can you access a SPARQL endpoint from within a SPIN rule?>
Yes, you can use the SPQRQL 1.1 Service keyword:
SERVICE <http://x> {?s ?p ?o}
An example would be:
SERVICE {<http://dbpedia.org/resource/Arnold_Schwarzenegger>
<http://dbpedia.org/property/name> ?name .} .
This can be placed anywhere in a WHERE clause.
<Building on the question above. Is it possible to reference variables
defined in a SPARQL motion script within a SPIN rule?>
The notion of a SPARQL module as the "endpoint" for the script and a
SPARQL Endpoint may have become confused here. I'll answer this for
SPARQLMotion.
A SPIN function effectively extends the SPARQL language by creating a
named function. The body of this function can be implemented with a
SPARQL query (spin:body), a SPARQLMotion script (sm:returnModule) or a
Javascript function (spinx:javaScriptFile or spinx:javaScriptCode).
In your scenario, let's say you want to create a function
"CreateABirthDate" whose body is a SPARQLMotion Script.
CreateABirthDate is in turn called by a SPIN function. You would do
the following:
1. Create your SPARQLMotion script. Let's say the return module is
named script_ReturnBirthDate
2. Create a SPIN function named CreateABirthDate (the subclass of
spin:Functions is named this)
3. Add script_ReturnBirthDate to the sm:returnModule of
CreateABirthDate
At this point you can use LET (?x := :CreateABirthDate()) in any
SPARQL query where this function is defined. Including any SPIN
functions.
<As another example, can I have a rule that creates a birthday
property only when the user's last name begins some user specified
value (established in the SPARQL Motion script). >
You can use a FILTER with regex. For example, suppose you had a
function named :getName (ala SPIN functions above). Then the
following would do what you need:
LET (?namePart := getName())
FILTER regex(?name, ?namePart)
The last statements on SPIN vs. SPARQLMotion are mostly correct. One
part to add about SPIN processing is that the rules are applied to all
instance of the class the rule is defined on, and all subclasses. The
variable name ?this is bound to each instance when executing the
rule. SPARQLMotion is much more general-purpose, as you can generate
arbitrary sets of triples that you can compute on.
As a simple example, let's say you have a model with classes A, B, C,
and D, all rdfs:subClassOf Z. You want to process the name for A, B,
and C, but not D. There are various ways you can manipulate this, but
the difficulty with SPIN is that you can't define the rule on Z,
because it would be applied to D. In SPARQLMotion, you can use
ApplyConstruct to create a set of triples from A, B and C (or any
other triples for that matter), then run your rule against that.
SPIN can be used in SPARQLMotion scripts. In the above example, you
could construct the triples from A B C and Z (Z would include the SPIN
rule) and run the TopSPIN module to execute the SPIN rules on all
valid members of the subset of the model constructed in the script.
Performance will depend on the complexity of the scripts and SPARQL
queries. SPIN has a hardcoded procedure (apply to each instance,
repeat until no new triples are constructed) and therefore may have
less overhead overall.
-- Scott
On Nov 11, 2:39 pm, Raymond Budd <[email protected]> wrote:
> Hi. I've been experimenting with SPARQL Motion and SPIN and have a
> couple of questions. Fyi, I'm using TopBraid ME v3.1.1.
>
> - Can you access a SPARQL endpoint from within a SPIN rule? For
> example, consider a BasicPerson class with first name and last name
> properties. Is it possible to define a SPIN rule for this class that
> creates a birthday property from a remote SPARQL endpoint?
>
> - Building on the question above. Is it possible to reference
> variables defined in a SPARQL motion script within a SPIN rule? For
> example, can I provide the address of the endpoint as an argument when
> I perform inferencing from a SPARQL Motion script? As another example,
> can I have a rule that creates a birthday property only when the
> user's last name begins some user specified value (established in the
> SPARQL Motion script).
>
> - It seems that you can encode the similar types of operations as SPIN
> rules or as SPARQL Motion construct statements. The main differences
> are when the processing takes place and what you do with the results.
> With SPIN the inferred triples are generated when inferencing is
> performed, and the results wind up in your in memory model. As new
> triples are added to the in memory model, the rule may be run against
> the new triples. When using SPARQL Motion, the triples are generated
> only when the script is explicitly executed, and are available for
> further manipulation, or export into a variety of forms (RDF, etc).
> Are there any other significant differences to be aware of? Is
> performance between the two roughly the same or is one faster/more
> efficient than the other (assuming I'm working with a relatively
> static set of instance data)?
>
> Thanks,
> Ray
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TopBraid Composer Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-composer-users?hl=en
-~----------~----~----~----~------~----~------~--~---