On a semi-related note, tasks like this are why I suggested a pathfinding 
extension to the SPARQL specification such that these types of operations 
would be supported across implementations 
https://github.com/w3c/sparql-dev/issues/191

On Thursday, March 7, 2024 at 11:52:52 AM UTC-5 Holger Knublauch wrote:

> Hi Steve,
>
> this is implemented in Java, but yes there is no rocket science and it 
> could be reimplemented in other languages. Basically do a breadth-first 
> traversal.
>
> Holger
>
>
> On 7 Mar 2024, at 4:33 pm, steveray...@gmail.com <steveray...@gmail.com> 
> wrote:
>
> Holger, this thread was very interesting for me to read, because it 
> addresses a navigational problem we're looking at. However, some of my 
> colleagues do not use the TopQuadrant tools, so they don't have 
> spif:shortestObjectsPath available. Am I correct that this was coded in 
> another language? Would the best approach be to tackle this using the 
> Javascript extension to SHACL mechanism? (Or even better, do you have the 
> Javascript code?).
>
> On Wednesday, February 21, 2024 at 11:15:12 PM UTC-5 Marie Valadez wrote:
>
>> Thank you so much! Appreciate all your help. 
>>
>> On Tuesday, February 20, 2024 at 12:29:47 PM UTC-7 Holger Knublauch wrote:
>>
>>>
>>> On 20 Feb 2024, at 6:11 pm, Marie Valadez <meval...@gmail.com> wrote:
>>>
>>> Thank Holger. 
>>>
>>> Is there a way to return a count with this that shows the distance?
>>>
>>>
>>> Sure. The function returns a ?path string with one space between path 
>>> segments.
>>>
>>> You can use
>>>
>>> BIND (REPLACE(?path, "[^ ]", "") AS ?spaces) .
>>> BIND (STRLEN(?spaces) AS ?depth) .
>>>
>>> to count the spaces.
>>>
>>> Holger
>>>
>>>
>>>
>>> On Monday, February 19, 2024 at 12:37:20 AM UTC-7 Holger Knublauch wrote:
>>>
>>>> Yes, g:Europe is the end node and is optional. If no end node is 
>>>> specified, it will stop at whenever a node doesn't have further values of 
>>>> skos:broader.
>>>>
>>>> You can use spif:shortestSubjectsPath for the inverse direction.
>>>>
>>>> To find the paths to each child, loop over the children:
>>>>
>>>> SELECT *
>>>> WHERE {
>>>>     ?child skos:broader g:Europe .
>>>>     BIND (spif:shortestObjectsPath(?child, skos:broader, g:Europe) AS 
>>>> ?path) .
>>>> }
>>>>
>>>> For anything more complex, ADS JavaScript is often a good choice as it 
>>>> gives you more control:
>>>>
>>>> https://datashapes.org/active/
>>>>
>>>> Holger
>>>>
>>>>
>>>> On 19 Feb 2024, at 12:35 am, Marie Valadez <meval...@gmail.com> wrote:
>>>>
>>>> Thank you for the example use case. What does g:Europe represent in 
>>>> this case? Is that the ending node? Is it necessary to specify the ending 
>>>> node? For instance if I wanted to find all the descendants of a concept 
>>>> using the inverse of skos:broader and the distance each one is away from 
>>>> the current concept, then I wouldn't want to specify a single child 
>>>> concept. 
>>>>
>>>> On Sun, Feb 18, 2024 at 3:24 AM Holger Knublauch <
>>>> hol...@topquadrant.com> wrote:
>>>>
>>>> Here is an example:
>>>>>
>>>>> <PastedGraphic-1.png>
>>>>>
>>>>> where $this is some skos:Concept deep in the hierarchy such as 
>>>>> g:Vienna.
>>>>>
>>>>> For easier copy and paste:
>>>>>
>>>>> PREFIX g: <http://topquadrant.com/ns/examples/geography#>
>>>>> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> 
>>>>> PREFIX spif: <http://spinrdf.org/spif#> 
>>>>>
>>>>> SELECT *
>>>>> WHERE {
>>>>> BIND (spif:shortestObjectsPath(g:Vienna, skos:broader, g:Europe) AS 
>>>>> ?path) .
>>>>> }
>>>>>
>>>>> HTH
>>>>> Holger
>>>>>
>>>>>
>>>>> On 17 Feb 2024, at 7:15 pm, Marie Valadez <meval...@gmail.com> wrote:
>>>>>
>>>>> The way skos:broader is being used in our case is a tree like 
>>>>> structure with some having multiple parents that can be broader but will 
>>>>> point back to the same main broad concept which branches out to its 
>>>>> children, grandchildren, etc. I need the shortest path from whichever 
>>>>> instance is selected to all of its descendants. All will have the 
>>>>> connection to each other through the skos:broader within the family tree 
>>>>> (some can have more than 1 direct skos:broader concept (parent)). 
>>>>>
>>>>> Do you have any example documentation on how those functions can be 
>>>>> utilized? 
>>>>>
>>>>> On Sat, Feb 17, 2024 at 2:44 AM Holger Knublauch <
>>>>> hol...@topquadrant.com> wrote:
>>>>>
>>>>>> Hi Marie,
>>>>>>
>>>>>> we do have some built-in functions including spif:shortestObjectsPath 
>>>>>> and swa:shortestPathsBetweenNodes that may help.
>>>>>>
>>>>>> To clarify your requirements, is it true that one of the nodes is 
>>>>>> always an (indirect) parent of the other node, or does the algorithm 
>>>>>> also 
>>>>>> need to walk in one direction and then in another direction of the tree 
>>>>>> structure?
>>>>>>
>>>>>> And are we talking about tree structures at all, or arbitrary graphs?
>>>>>>
>>>>>> Holger
>>>>>>
>>>>>>
>>>>>> On 16 Feb 2024, at 10:48 pm, Marie Valadez <meval...@gmail.com> 
>>>>>> wrote:
>>>>>>
>>>>>> I have searched and tested out multiple ways to get the distance 
>>>>>> between two nodes. I want a query that will show the child concepts and 
>>>>>> how 
>>>>>> far away they are from the current concept so that I can create a table 
>>>>>> on 
>>>>>> a form showcasing this.
>>>>>>
>>>>>> The following query works if a ?sub concept does not have two 
>>>>>> connection through skos:broader. But once a ?sub has two parent concepts 
>>>>>> with the skos:broader it overcounts. I have included a basic example 
>>>>>> diagram on the issue I am dealing with. Any ideas on how to get an 
>>>>>> accurate 
>>>>>> count?
>>>>>>
>>>>>> SELECT ?sub  (count(distinct ?mid) as ?distance) 
>>>>>> WHERE {
>>>>>>   $this ^skos:broader* ?mid .
>>>>>>   ?mid ^skos:broader+ ?sub .
>>>>>> } 
>>>>>> group by $this ?sub
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> The topics of this mailing list include TopBraid EDG and related 
>>>>>> technologies such as SHACL.
>>>>>> To post to this group, send email to topbrai...@googlegroups.com
>>>>>> --- 
>>>>>> 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.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/topbraid-users/be2ebc41-1fa7-4a70-a3ca-d8ee2cf575ddn%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/topbraid-users/be2ebc41-1fa7-4a70-a3ca-d8ee2cf575ddn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> <stepcount-Page-2.drawio.png>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> The topics of this mailing list include TopBraid EDG and related 
>>>>>> technologies such as SHACL.
>>>>>> To post to this group, send email to topbrai...@googlegroups.com
>>>>>> --- 
>>>>>> You received this message because you are subscribed to a topic in 
>>>>>> the Google Groups "TopBraid Suite Users" group.
>>>>>> To unsubscribe from this topic, visit 
>>>>>> https://groups.google.com/d/topic/topbraid-users/CUgBING_53U/unsubscribe
>>>>>> .
>>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>>> topbraid-user...@googlegroups.com.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/topbraid-users/D618E05A-6068-428F-B8DA-77C9D6C52A96%40topquadrant.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/topbraid-users/D618E05A-6068-428F-B8DA-77C9D6C52A96%40topquadrant.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>
>>>>> -- 
>>>>> The topics of this mailing list include TopBraid EDG and related 
>>>>> technologies such as SHACL.
>>>>> To post to this group, send email to topbrai...@googlegroups.com
>>>>> --- 
>>>>> 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.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/topbraid-users/CAH4XeR92ty0CU3k55_fYc%3DA_Vmjxy64b8vTcDKDU3uBUx9KjQA%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/topbraid-users/CAH4XeR92ty0CU3k55_fYc%3DA_Vmjxy64b8vTcDKDU3uBUx9KjQA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> The topics of this mailing list include TopBraid EDG and related 
>>>>> technologies such as SHACL.
>>>>> To post to this group, send email to topbrai...@googlegroups.com
>>>>> --- 
>>>>> You received this message because you are subscribed to a topic in the 
>>>>> Google Groups "TopBraid Suite Users" group.
>>>>> To unsubscribe from this topic, visit 
>>>>> https://groups.google.com/d/topic/topbraid-users/CUgBING_53U/unsubscribe
>>>>> .
>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>> topbraid-user...@googlegroups.com.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/topbraid-users/F370933F-CA50-4DFA-8FC6-622FF0020E86%40topquadrant.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/topbraid-users/F370933F-CA50-4DFA-8FC6-622FF0020E86%40topquadrant.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
>>>> -- 
>>>> The topics of this mailing list include TopBraid EDG and related 
>>>> technologies such as SHACL.
>>>> To post to this group, send email to topbrai...@googlegroups.com
>>>> --- 
>>>> 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.
>>>>
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/topbraid-users/CAH4XeR-6uzQ0gdaRe4q5Fry8%2BvLtokh3%3D1MbmcLnYsQbxRz0jQ%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/topbraid-users/CAH4XeR-6uzQ0gdaRe4q5Fry8%2BvLtokh3%3D1MbmcLnYsQbxRz0jQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>>
>>>>
>>> -- 
>>> The topics of this mailing list include TopBraid EDG and related 
>>> technologies such as SHACL.
>>> To post to this group, send email to topbrai...@googlegroups.com
>>> --- 
>>> 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.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/topbraid-users/bb6a78ff-0569-49a0-9e3f-da3e0e97fb07n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/topbraid-users/bb6a78ff-0569-49a0-9e3f-da3e0e97fb07n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>>
>>>
> -- 
> The topics of this mailing list include TopBraid EDG and related 
> technologies such as SHACL.
> To post to this group, send email to topbrai...@googlegroups.com
> --- 
> 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.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/topbraid-users/e84cc166-8a54-4b20-b460-668db07dc178n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/topbraid-users/e84cc166-8a54-4b20-b460-668db07dc178n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
The topics of this mailing list include TopBraid EDG and related technologies 
such as SHACL.
To post to this group, send email to topbraid-users@googlegroups.com
--- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/9bb367cf-dd79-43b6-b4b4-2359b1750e96n%40googlegroups.com.

Reply via email to