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

2024-02-22 Thread Holger Knublauch
To get the COUNT of a path expression, spl:objectCount will not help.

Normally, counting can be done via a nested SELECT query with a COUNT in 
SPARQL. However, nested queries by default do not "see" variables from the 
outside, making them rather inefficient. There is a new SPARQL keyword, 
LATERAL, supported in places but I have not used that yet.

It's a tricky topic, and further help may become too complex for this mailing 
list. If you are a paying TopBraid customer, maybe you want to contact our 
professional services/premium support?

Holger


> On 22 Feb 2024, at 7:05 pm, Marie Valadez  wrote:
> 
> Thank you Holger. That's a good idea to use count to narrow down the ones 
> that are the same. 
> 
> Do you happen to have more documentation on the spl:ObjectCount? 
> 
> I am trying to find a way to utilize this with inherited ones as well through 
> skos:broader*/ex:category where in some cases they might have both directly 
> stated and inherited connections to the blank node. 
> 
> 
> On Thursday, February 22, 2024 at 8:45:00 AM UTC-7 Holger Knublauch wrote:
>> Ok, to express that, I believe you need to 
>> 
>> 1) Make sure that the number of property values is the same for both 
>> concepts, and that
>> 2) The second concept does NOT have any values that the first concept does 
>> not also have.
>> This can be expressed using FILTER NOT EXISTS { … }.
>> 
>> To count values of a property (for step 1), you can use this function
>> 
>> BIND ((?conceptA, ex:property) AS 
>> ?countA) .
>> 
>> HTH
>> Holger
>> 
>> 
>> 
>>> On 22 Feb 2024, at 4:37 pm, Marie Valadez > wrote:
>>> 
>> 
>>> Hi Holger, 
>>> 
>>> Thanks for getting back to me so quickly. 
>>> 
>>> I only want to return Concept B since it has exactly the same blank nodes 
>>> as Concept A. I don't want to return Concept C and Concept D since they 
>>> either have 1 less or 1 more than Concept A.
>>> 
>>> On Thursday, February 22, 2024 at 2:55:09 AM UTC-7 Holger Knublauch wrote:
 The results look correct )with ex:ConceptA the selected resource):
 
 
 
 because all of the concepts match with at least one blank node. SPARQL 
 operates with "EXISTS" semantics and will here return any concept where 
 the same linked values exist, even if they also have other values.
 
 Are you saying you want C and D not to match because they also have other 
 values?
 
 Holger
 
 
 
> On 21 Feb 2024, at 10:14 pm, Marie Valadez > wrote:
> 
 
> 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 

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

2024-02-22 Thread Marie Valadez
Thank you Holger. That's a good idea to use count to narrow down the ones 
that are the same. 

Do you happen to have more documentation on the spl:ObjectCount? 

I am trying to find a way to utilize this with inherited ones as well 
through skos:broader*/ex:category where in some cases they might have both 
directly stated and inherited connections to the blank node. 


On Thursday, February 22, 2024 at 8:45:00 AM UTC-7 Holger Knublauch wrote:

> Ok, to express that, I believe you need to 
>
> 1) Make sure that the number of property values is the same for both 
> concepts, and that
> 2) The second concept does NOT have any values that the first concept does 
> not also have.
> This can be expressed using FILTER NOT EXISTS { … }.
>
> To count values of a property (for step 1), you can use this function
>
> BIND ((?conceptA, ex:property) AS 
> ?countA) .
>
> HTH
> Holger
>
>
> On 22 Feb 2024, at 4:37 pm, Marie Valadez  wrote:
>
> Hi Holger, 
>
> Thanks for getting back to me so quickly. 
>
> I only want to return Concept B since it has exactly the same blank nodes 
> as Concept A. I don't want to return Concept C and Concept D since they 
> either have 1 less or 1 more than Concept A.
>
> On Thursday, February 22, 2024 at 2:55:09 AM UTC-7 Holger Knublauch wrote:
>
>> The results look correct )with ex:ConceptA the selected resource):
>>
>> [image: PastedGraphic-1.png]
>>
>> because all of the concepts match with at least one blank node. SPARQL 
>> operates with "EXISTS" semantics and will here return any concept where the 
>> same linked values exist, even if they also have other values.
>>
>> Are you saying you want C and D not to match because they also have other 
>> values?
>>
>> Holger
>>
>>
>> On 21 Feb 2024, at 10:14 pm, Marie Valadez  wrote:
>>
>> 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 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/310db76e-c5bc-4448-9c14-1afba788bd8en%40googlegroups.com
>>  
>> 
>> .
>>
>>
>>
> -- 
> The topics of this mailing list include TopBraid EDG and related 
> technologies such as SHACL.
> To post to this group, 

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

2024-02-22 Thread Holger Knublauch
Ok, to express that, I believe you need to 

1) Make sure that the number of property values is the same for both concepts, 
and that
2) The second concept does NOT have any values that the first concept does not 
also have.
This can be expressed using FILTER NOT EXISTS { … }.

To count values of a property (for step 1), you can use this function

BIND ((?conceptA, ex:property) AS ?countA) .

HTH
Holger


> On 22 Feb 2024, at 4:37 pm, Marie Valadez  wrote:
> 
> Hi Holger, 
> 
> Thanks for getting back to me so quickly. 
> 
> I only want to return Concept B since it has exactly the same blank nodes as 
> Concept A. I don't want to return Concept C and Concept D since they either 
> have 1 less or 1 more than Concept A.
> 
> On Thursday, February 22, 2024 at 2:55:09 AM UTC-7 Holger Knublauch wrote:
>> The results look correct )with ex:ConceptA the selected resource):
>> 
>> 
>> 
>> because all of the concepts match with at least one blank node. SPARQL 
>> operates with "EXISTS" semantics and will here return any concept where the 
>> same linked values exist, even if they also have other values.
>> 
>> Are you saying you want C and D not to match because they also have other 
>> values?
>> 
>> Holger
>> 
>> 
>> 
>>> On 21 Feb 2024, at 10:14 pm, Marie Valadez > wrote:
>>> 
>> 
>>> 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 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/310db76e-c5bc-4448-9c14-1afba788bd8en%40googlegroups.com
>>>  
>>> .
>> 
> 
> 
> -- 
> 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 

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

2024-02-22 Thread Marie Valadez
Hi Holger, 

Thanks for getting back to me so quickly. 

I only want to return Concept B since it has exactly the same blank nodes 
as Concept A. I don't want to return Concept C and Concept D since they 
either have 1 less or 1 more than Concept A.

On Thursday, February 22, 2024 at 2:55:09 AM UTC-7 Holger Knublauch wrote:

> The results look correct )with ex:ConceptA the selected resource):
>
> [image: PastedGraphic-1.png]
>
> because all of the concepts match with at least one blank node. SPARQL 
> operates with "EXISTS" semantics and will here return any concept where the 
> same linked values exist, even if they also have other values.
>
> Are you saying you want C and D not to match because they also have other 
> values?
>
> Holger
>
>
> On 21 Feb 2024, at 10:14 pm, Marie Valadez  wrote:
>
> 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 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/310db76e-c5bc-4448-9c14-1afba788bd8en%40googlegroups.com
>  
> 
> .
>
>
>

-- 
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/5eb85678-fbef-4974-9d5c-ce4019b81f4fn%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.