Rdflib query value of a related triple

51 Views Asked by At

On below example ttl I'm trying to run a query that would give me the relationshipLabel for specific combination of subject and object stated as canRelateTo.

So for example: I want to query the value of relationshipLabel for the combination of

which should return "Data Product consists of"

I tried it using this query (where subj/obj are for example the values above):

    query = f"""
    SELECT ?relationshipLabel 
    WHERE {{
        <{subj}> :canRelateTo ?canRelateTo ;
            :relationshipLabel ?relationshipLabel .
    FILTER (?canRelateTo = <{obj}> )
    }}
    """
    if (subj.endswith("Type-Data_Product")):
        print(query)

    results = graph.query(query)

But this query would return all values of relationshipLabel, so: "Data Product consists of", "has data quality rule", "is governed by", "see also", "is a data product".

Als tried various combinations using the Graph.value() method but without success.

Any idea how I can achieve this?

Example ttl:

destination-org:Type-Data_Product
        :canRelateTo        <https://open-kos.org/ext/kos-powerbi/PowerBIReport> ;
        :relationshipLabel  "Data Product consists of" .

destination-org:Type-Data_Product
        :canRelateTo        destination-org:Type-Data_Quality_rule ;
        :relationshipLabel  "has data quality rule" .

destination-org:Type-Data_Product
        :canRelateTo        destination-org:Type-Policy ;
        :relationshipLabel  "is governed by" .

destination-org:Type-Data_Product
        :canRelateTo        dwec:BusinessTerm ;
        :relationshipLabel  "see also" .


<https://open-kos.org/ext/kos-powerbi/PowerBIReport>
        :canRelateTo        destination-org:Type-Data_Product ;
        :relationshipLabel  "is a data product" .
0

There are 0 best solutions below