mercredi 13 janvier 2021

SPARQL query to get subjects linked to object 2 that are not linked to object 1, using IF or NOT EXISTS or any other way?

I hope you are doing well. Here is the basic structure of my graph database. Components have estimation methods, estimation methods have parameters and parameters have data sources.

c -> em -> p -> ds

Where,

c stands for components
em stands for estimation methods
p stands for parameters
ds stands for data sources

I am able to query individuals in the structured format like this:

SELECT ?c ?em ?p ?ds WHERE {

    ?c wb:hasEstimationMethod ?em.
 
        OPTIONAL {
            ?em wb:hasParameter ?p.
            
            OPTIONAL{
                ?p wb:hasDataSource ?ds.
            }
        }
    }

I use OPTIONAL clause because there is a possibility that estimation method might not have any parameters and similarly parameters might not have any data sources.

However, there are few cases where, for example, an estimation method is unknown but we know the parameter. So for example in that case, components will directly have parameters and I would prefer to have blank for estimation methods. So here is the output I would like to have,

c em p ds
component-1 estimation method-1 parameter-1 data source-1
component-2 parameter-2 data source-2
component-3 parameter-3

If you notice the last two rows have have missing info which is what I want to have in my output if that is the case. In other words, I want to skip a step in the hierarchical structure.

So my question is, how can I first query ?c wb:hasEstimationMethod ?em but if it does not have any value, I want to tell SPARQL to use query ?c wb:hasParameter ?p and similarly if that has no value as well, do ?c wb:hasDataSource ?ds ?

Any help will be greatly appreciated! Please let me know if I am not using the right terminology. Have a wonderful day :)

Aucun commentaire:

Enregistrer un commentaire