I have multiple resources like A, B, C
.
I want to know these resources exist in my database or not.
Here is a sample of query for one of them:
ASK { <http://fkg.iust.ac.ir/resource/A> ?p ?o }
This query returns true
or false
.
It's better to use one query, and I need to get 2 columns, resource
& existing
.
Here is my sample response:
---------------------------------------------------
| resource | existing |
|========================|========================|
| :A | true |
|------------------------|------------------------|
| :B | false |
|------------------------|------------------------|
| :C | true |
---------------------------------------------------
I know ASK
and UNION
, but how can I put them together for this sample?
Query:
PREFIX : <http://fkg.iust.ac.ir/resource/>
SELECT ?resource (EXISTS { ?resource ?p ?o } AS ?existing) {
VALUES ?resource { :A :B :C }
}
Test data:
<http://fkg.iust.ac.ir/resource/A> a _:dummy.
<http://fkg.iust.ac.ir/resource/C> a _:dummy.
Result:
-----------------------
| resource | existing |
=======================
| :A | true |
| :B | false |
| :C | true |
-----------------------
SELECT
instead of ASK
VALUES
EXISTS
is like a mini-ASK
query that can be embedded into expressionsSELECT (expression AS ?variable)
form to bind the result of the mini-ASK
to the variable ?existing
ASK
query as written checks whether there is any triple that has the node as its subject. For completeness, one may want to check for the object position as well:
(EXISTS { ?resource ?p ?o } || EXISTS { ?s ?p ?resource })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With