To unsubscribe from this group, send email to
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 topbraid-users+unsubscribe@googlegroups.com.
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
To unsubscribe from this group, send email to
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 topbraid-users+unsubscribe@googlegroups.com.
To unsubscribe from this group, send email to
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 topbraid-user...@googlegroups.com.
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
To unsubscribe from this group, send email to
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 topbraid-user...@googlegroups.com.
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
To unsubscribe from this group, send email to
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 topbraid-user...@googlegroups.com.
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...and the projection version would be as follows:
WHERE {
BIND(AnotherExample:ScoreCollege("John") AS ?score).
}
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 clause. The object are the selected variables. So I think the following will work:
SELECT *
WHERE {
("John") AnotherExample:ScoreCollege (?score) .
}
Hi again Scott,Please see my follow-up question below.
Thanks.
On Thu, May 9, 2013 at 2:26 PM, Scott Henninger <shenn...@topquadrant.com> wrote:
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...and the projection version would be as follows:
WHERE {
BIND(AnotherExample:ScoreCollege("John") AS ?score).
}
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.
Because John Kennedy attended multiple colleges, is it not correct that making AnotherExample:ScoreCollege a spin:function and not magic property would mean that only one of the colleges he attended would be evaluated and its score returned? How could I, for example, have a function evaluate all colleges he attended and return the maximum value and the associated college? I apologize for the very specific example, but this is really the behaviour I'm going after.
For your magic property, I think you just got it backwards the subject of the magic property are the variables bound in the WHERE clause. The object are the selected variables. So I think the following will work:
SELECT *
WHERE {
("John") AnotherExample:ScoreCollege (?score) .
}
Yes, I had it backwards. This worked.
Alison,
If by a maximum value, you mean the highest degree earned, you could write two functions – one to get the highest degree earned, another the associated college. If, however, a person earned two masters at two different colleges, the result of the second function will be uncertain – sometimes it may return one college, sometimes the other. Same if he earned a BS degree and a BA degree and they are both at the same level, making it unclear which one is the highest.
In this case, your question boils down to how to write a function that will return the highest degree earned. In SPARQL, this can be accomplished by the following query:
SELECT ?maxDegree
WHERE {?person :degree ?maxDegree.
?maxDegree hasRank ?maxDegreeRank.
NOT EXISTS {?person :degree ?degree.
?degree hasRank ?degreeRank.
FILTER (?degreeRank < ?maxDegreeRank)}
}
You will need to have all this information in the model and Kennedys example does not cover it. You could try with Kennedy’s to get the oldest of a person’s parents.
Regards,
Irene Polikoff
Hello again all,
I wanted to ask a question again (below), as this thread has gotten quite long and I didn't get a reply to my latest email. Thanks,
Alison----------------------
I have created a magic property AnotherExample:ScoreCollege that assigns a score to a Kennedy based on the college they attended - 1 if they attended Princeton, and 0 otherwise.
The spin:body of this property is as follows:
SELECT ?collegeScore ?collegeWHERE{ ��� (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?middle ?last) .���BIND(IF((?college = kennedys:Princeton), 1, 0) AS ?collegeScore) .}
The magic property MagicExample:FindNamesOfCollegeGrad was provided by Scott and defined as:
SELECT ?fname ?mname ?lname
WHERE {
� � �?arg1 kennedys:almaMater ?arg2 .� � �?arg1 kennedys:firstName ?fname .� � �?arg1 kennedys:middleName ?mname .� � �?arg1 kennedys:LastName ?lname .
}
When I use AnotherExample:ScoreCollege in a SPARQL query, as in:
SELECT ?college ?score
WHERE {
� ���("John")�AnotherExample:ScoreCollege�(?score ?college) .
}
The result is two scores - 0 for Harvard, and 1 one Princeton.
My question is: how can I use this magic property to get all colleges attended and then return the maximum score and the college that corresponds to it. Based on Irene's above example, I created a magic property with this spin:body:
SELECT ?collegeScore ?collegeWHERE {
� � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?collegeScore) .� � NOT EXISTS {� � � � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � � � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?lowerCollegeScore .� � � � FILTER(?lowerCollegeScore < ?collegeScore).� �}
}
When I use this property as above, I get two results: 0 for Harvard and 1 for Princeton.
When I make a corresponding spin:Function called AnotherExample:ScoreCollegeFunction that returns only ?collegeScore e.g.
SELECT ?collegeScoreWHERE {� � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?collegeScore) .� � NOT EXISTS {� � � � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � � � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?lowerCollegeScore .� � � � FILTER(?lowerCollegeScore < ?collegeScore).� �}}
and call it in a SPARQL query as in:
SELECT * score {
� � BIND(AnotherExample:ScoreCollegeFunction("John") AS ?score) .
}
it returns one value: 0. I think that this is because the spin:Function is only executed on the first result of the magic property MagicExample:FindNamesOfCollegeGrad and then stops.
Is it possible to write a function that uses a magic property to get a set of values, and then evaluates the entire set in some way? (In this case, to return the maximum score for an attended college?) Do I need to incorporate a foreach to iterate over the results?
On Thu, May 16, 2013 at 11:09 AM, Alison Callahan <alison....@gmail.com> wrote:
Hi Irene,
Thanks for your reply.
Earlier in this email thread I specified a magic property AnotherExample:ScoreCollege that assigns a score to a Kennedy based on the college they attended - 1 if they attended Princeton, and 0 otherwise.
The spin:body of this property is as follows:
SELECT ?collegeScore ?collegeWHERE{ ��� (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?middle ?last) .���BIND(IF((?college = kennedys:Princeton), 1, 0) AS ?collegeScore) .}
The magic property MagicExample:FindNamesOfCollegeGrad was provided by Scott and defined as:
SELECT ?fname ?mname ?lname
WHERE {
� � �?arg1 kennedys:almaMater ?arg2 .� � �?arg1 kennedys:firstName ?fname .� � �?arg1 kennedys:middleName ?mname .� � �?arg1 kennedys:LastName ?lname .
}
When I use AnotherExample:ScoreCollege in a SPARQL query, as in:
SELECT ?college ?score
WHERE {
� ���("John")�AnotherExample:ScoreCollege�(?score ?college) .
}
The result is two scores - 0 for Harvard, and 1 one Princeton.
My question is: how can I use this magic property to get all colleges attended and then return the maximum score and the college that corresponds to it. Based on your above example, I created a magic property with this spin:body:
SELECT ?collegeScore ?collegeWHERE {
� � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?collegeScore) .� � NOT EXISTS {� � � � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � � � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?lowerCollegeScore .� � � � FILTER(?lowerCollegeScore < ?collegeScore).� �}
}
When I use this property as above, I still get two results: 0 for Harvard and 1 for Princeton.
When I make a corresponding spin:Function called AnotherExample:ScoreCollegeFunction that returns only ?collegeScore e.g.
SELECT ?collegeScoreWHERE {� � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?collegeScore) .� � NOT EXISTS {� � � � (?person ?college) MagicExample:FindNamesOfCollegeGrad (?arg1 ?mname ?lname) .� � � � BIND(IF((?college = kennedys:Princeton), 1, 0) as ?lowerCollegeScore .� � � � FILTER(?lowerCollegeScore < ?collegeScore).� �}}
and call it in a SPARQL query as in:
SELECT * score {
� � BIND(AnotherExample:ScoreCollegeFunction("John") AS ?score) .
}
it returns one value: 0. I think that this is because the spin:Function is only executed on the first result of the magic property MagicExample:FindNamesOfCollegeGrad and then stops.
Is it possible to write a function that uses a magic property to get a set of values, and then evaluates the entire set in some way? (In this case, to return the maximum score for an attended college?) Do I need to incorporate a foreach to iterate over the results?
Thanks,
Alison
On Thu, May 16, 2013 at 10:32 AM, Irene Polikoff <ir...@topquadrant.com> wrote:
Alison,
�
If by a maximum value, you mean the highest degree earned, you could write two functions � one to get the highest degree earned, another the associated college. If, however, a person earned two masters at two different colleges, the result of the second function will be uncertain � sometimes it may return one college, sometimes the other. Same if he earned a BS degree and a BA degree and they are both at the same level, making it unclear which one is the highest.
�
In this case, your question boils down to how to write a function that will return the highest degree earned. In SPARQL, this can be accomplished by the following query:
�
SELECT ?maxDegree
WHERE {?person :degree ?maxDegree.
?maxDegree hasRank ?maxDegreeRank.
NOT EXISTS {?person :degree ?degree.
?degree hasRank ?degreeRank.
FILTER (?degreeRank < ?maxDegreeRank)}
}
�
You will need to have all this information in the model and Kennedys example does not cover it. You could try with Kennedy�s to get the oldest of a person�s parents.
�
Regards,
�
Irene Polikoff
From: topbrai...@googlegroups.com [mailto:topbrai...@googlegroups.com] On Behalf Of Alison Callahan
Sent: Thursday, May 16, 2013 9:17 AM
To: Scott Henninger; topbrai...@googlegroups.com
Subject: Re: [topbraid-users] defining a SPIN function that returns multiple variables
�
Hi again Scott,
�
Please see my follow-up question below.
Thanks.On Thu, May 9, 2013 at 2:26 PM, Scott Henninger�<shenn...@topquadrant.com>�wrote:
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.
�
Because kennedys:JohnKennedy has kennedys:almaMater more than one college, is it not correct that making AnotherExample:ScoreCollege a spin:function and not magic property would mean that only one of the colleges he attended would be evaluated and its score returned? How could one, for example, have a function evaluate all colleges he attended and return the maximum value and the associated college? Apologies for the very specific example, but this is really the behaviour I'm going after.
�
For your magic property, I think you just got it backwards the�subject of the magic property�are the variables bound in the WHERE clause.�The object�are the selected variables.� So�I think the following will work:
SELECT *
WHERE {
������("John")�AnotherExample:ScoreCollege�(?score) .
}�
Yes, I had it backwards. This worked. �
�
On Wed, May 15, 2013 at 3:37 PM, Alison Callahan <alison....@gmail.com> wrote:
Hi again Scott,
�
Please see my follow-up question below.
Thanks.
On Thu, May 9, 2013 at 2:26 PM, Scott Henninger <shenn...@topquadrant.com> wrote:
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.
�
Because John Kennedy attended multiple colleges, is it not correct that making AnotherExample:ScoreCollege a spin:function and not magic property would mean that only one of the colleges he attended would be evaluated and its score returned? How could I, for example, have a function evaluate all colleges he attended and return the maximum value and the associated college? I apologize for the very specific example, but this is really the behaviour I'm going after.
�
For your magic property, I think you just got it backwards the subject of the magic property are the variables bound in the WHERE clause.� The object are the selected variables.� So I think the following will work:
SELECT *
WHERE {
����� ("John") AnotherExample:ScoreCollege (?score) .
}�
Yes, I had it backwards. This worked. �
-- 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 <shenn...@topquadrant.com> 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 <hol...@topquadrant.com> 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 .
�
--
-- 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
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
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 topbraid-user...@googlegroups.com.
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
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
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 topbraid-user...@googlegroups.com.
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
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
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 topbraid-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
�
�