Allison; Since the AnotherExample:ScoreAttendedCollege returns one value, not a set of values (multiple rows) or a list of values (multiple columns), then the best choice is to use a SPIN function.  Change the type of :ScoreAttendedCollege to spin:Functions and use in a BIND or projection:

SELECT ?score
WHERE {
      BIND(AnotherExample:ScoreCollege("John") AS ?score).
}

...and the projection version would be as follows:


SELECT (AnotherExample:ScoreCollege("John") AS ?score)
WHERE {}

These translate into the exact same SPARQL algebra, so it's a matter of preference which one you use.

For your magic property, I think you just got it backwards the subject of the magic property are the variables bound in the WHERE clauseThe object are the selected variables.  So I think the following will work:

SELECT *
WHERE {
     
("John") AnotherExample:ScoreCollege (?score) .
}


-- Scott

On 5/9/2013 10:42 AM, Alison Callahan wrote:
Hi Scott,

Thanks for your detailed reply. I successfully followed your MagicExample:FindNamesOfCollegeGrad example.

I have a follow-up question, based on another thread: If I use a magic property in the spin:body of another magic property, and there is more than one result when the magic property is executed, how can I retrieve all of the results?

For example, when John Kennedy is passed in to the FindNamesOfCollegeGrad magic property in a SPARQL query, i.e. 

SELECT *
WHERE
{  ?person a kennedys:Person .
   ?person kennedys:almaMater ?college .
   (?person ?college) MagicExample:FindNamesOfCollegeGrad ("John" ?middle ?last)
}

there are two results for ?college: kennedys:Harvard and kennedys:Princeton.

Now let's say I have another magic property called 'AnotherExample:ScoreAttendedCollege' where a first name is passed in as ?arg1 and the spin:body of the property is:

SELECT ?collegeScore
WHERE
{  
   (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?middle ?last) .
   BIND(IF((?college = kennedys:Princeton), 1, 0) AS ?collegeScore) .
}

In other words, if the person with the specified first name attended Princeton, return a score of 1, else return a score of 0.

I created this magic property, but when I use it in a SPARQL query as follows:

SELECT *
WHERE {
     (?score) AnotherExample:ScoreCollege("John") .
}

there are no results. However, if I use it in a SPARQL query this way:

SELECT ?score
WHERE {
      BIND(AnotherExample:ScoreCollege("John") AS ?score).
}

the result of the query is 0. My hunch is that this is because only the first bound result (kennedys:Harvard) was evaluated by the 'AnotherExample:ScoreCollege' magic property, i.e. the kennedys:Princeton result is never evaluated because the iteration seems to break. Is this correct? 

How can I use AnotherExample:ScoreCollege to return the score for each value bound to the ?college variable returned by the MagicExample:FindNameOfCollegeGrad magic property? If I can't use BIND within a magic property to assign a value based on the result of an embedded magic property, what alternatives exist?

Thanks again!

Alison


On Wed, May 8, 2013 at 4:11 PM, Scott Henninger <[email protected]> wrote:
Allison, probably the best way to learn magic properties is by example.  In the Composer navigator, go to TopBraid/Examples/kennedysSPINMagic.ttl and open that.

In the Classes view find spin:MagicProperties.  A Magic property is a subclass of
spin:MagicProperties.  You can see the body of the definition for age (after running inferences), grandfather, and grandMother.  These are used in SPARQL as a property that instead calls the body of the query (hence a "magic" property).

An example, let's say you want to find a grandfather:
SELECT *
WHERE
{   ?person a kennedys:Person .
    ?person kspin:grandFather ?gf
}

Note you can use this magic property either way.  So to find all grandchildren of Joe Kennedy:
SELECT *
WHERE
{    ?gchild kspin:grandFather kennedys:JosephKennedy
}

I know, I haven't answered the question yet.  For multiple parameters of values, use a list structure (see, for example top:files in Help > TopBraid Composer > Reference > SPARQL Property Functions).  As an additional example, I've added an example in the attached file to define a magic property named MagicExample:FindNamesOfCollegeGrad (kinda a silly example, buyt it gets the idea across)

You can use it this way for example:

SELECT *
WHERE
{  ?person a kennedys:Person .
   ?person kennedys:almaMater ?college .
   (?person ?college) MagicExample:FindParentsOfCollegeGrad (?first ?middle ?last)
}

You can bind/not bind any of the input parameters or output values.  For example to find all John's try this.

SELECT *
WHERE
{   ?person a kennedys:Person .
   ?person kennedys:almaMater ?college .
   (?person ?college) MagicExample:FindParentsOfCollegeGrad ("John" ?middle ?last)
}

Given that
as an interesting example to explore, let us know if that answers the question or if you have follows.

 
-- Scott

On 5/8/2013 11:51 AM, Alison Callahan wrote:
Hi Holger, 

I have looked at Magic Properties, and thought they were relevant to my question, but I couldn't find any examples of how to create a magic property that returns multiple values. On the page you linked to, it says "Magic properties can also take multiple arguments and result values using a (rather obscure) list syntax - these cases are technically supported but complex to represent in the SPIN RDF syntax". 

Could you provide more detail or a link that describes this list syntax for creating a magic property that returns multiple values?

Thanks!

Alison


On Mon, Apr 29, 2013 at 7:00 PM, Holger Knublauch <[email protected]> wrote:
Hi Allison,

yes take a look at Magic Properties

http://spinrdf.org/spin.html#spin-magic

These may not only return multiple "rows" but also multiple variables per row.

Please take a look at the online material and get back to us if you have specific follow-up questions.

HTH
Holger



On 4/30/2013 1:01, Alison Callahan wrote:
Hello all,

I would like to be able to define the body of a SPIN function that returns two variables, e.g.

SELECT ?x ?y
WHERE {
    ?example test:x ?x .
    ?example text:y ?y .
}

My question is: if such a function is possible, how are the results bound when the function is called? In my experience with SPIN I have written functions that return one variable, and thus the result is bound to a single variable when the function is called. For example, if I have a SPIN function called "functionA" where the spin:body is:

SELECT ?a
WHERE {
    ?example test:a ?a .
}

I would call this function and bind the result as

BIND(:functionA(?aVariable) AS ?returnedA) .

Is it possible to write a similar function that returns two (or more) variables?

Any help is appreciated!

Alison
--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
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-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.



--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
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-users?hl=en
--- You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.



--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
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-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
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-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply via email to