Re: [topbraid-users] SPARQL Query for distance between nodes

2024-02-21 Thread Marie Valadez
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  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  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  
>> wrote:
>>
>> Here is an example:
>>>
>>> 
>>>
>>> where $this is some skos:Concept deep in the hierarchy such as g:Vienna.
>>>
>>> For easier copy and paste:
>>>
>>> PREFIX g: 
>>> PREFIX skos:  
>>> PREFIX 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  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  
>>> 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  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
  
 

[topbraid-users] SPARQL Query to find Instances with the same values for property

2024-02-21 Thread Marie Valadez
I am in EDG trying to find instances where another Concept has the exact 
same values for the property (no more or less). The values can be inherited 
through skos:broader or directly stated on the concept itself. The property 
connects to a blank node which contains 2 additional properties and values. 
Example:
ConceptA ex:category [ex:map ex:default ;
  ex:attribute ex:S03.01] ;
 [ex:map ex:alternate ;
   ex:attribute ex:S03.02] .
ConceptB ex:category [ex:map ex:default ;
  ex:attribute ex:S03.01] ;
 [ex:map ex:alternate ;
   ex:attribute ex:S03.02] .
ConceptC ex:category [ex:map ex:default ;
  ex:attribute ex:S03.01] .
ConceptD ex:category [ex:map ex:default ;
  ex:attribute ex:S03.01] ;
 [ex:map ex:alternate ;
   ex:attribute ex:S03.02] ;
 [ex:map ex:alternate ;
   ex:attribute ex:S03.03] .

I want to return both ConceptA and ConceptB but not ConceptC or ConceptD 
since it doesn't match ConceptA exactly. 

I have tried different variations of a sparql query shown below (removed 
FILTER clause) but haven't been able to return the results I am expecting.

SELECT DISTINCT $this ?concept ?map ?attr
WHERE { $this skos:broader*/ex:category ?blank .
?blank ex:map ?map ;
  ex:attribute ?attr .
?concept skos:broader*/ex:category ?blank1 .
?blank1 ex:map ?map ;
  ex:attribute ?attr .
  FILTER(?concept != $this)
   
}

#find concept with the same modeling
SELECT DISTINCT $this ?map ?attr
WHERE { $this skos:broader*/ex:category ?blank .
?blank ex:map ?map ;
   ex:attribute ?attr .
 FILTER EXISTS{?concept skos:broader*/ex:category ?blank1 .
?blank1 ex:map ?map ;
 ex:attribute ?attr .
  FILTER(?concept != $this)}
}

-- 
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/310db76e-c5bc-4448-9c14-1afba788bd8en%40googlegroups.com.