Search code examples
sparqlontology

Can anyone tell me what is wrong in this query


Image of prefixes with query

when I remove filter it gives output but on adding FILTER nothing comes up.

SELECT distinct ?ID
WHERE { ?ID  rdf:type foaf:ID
    FILTER (foaf:has_Rel.WinRate >= "0.3"^^xsd:double)
}

After all the suggestions I came up with this query, but filter is still not working

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf:    <http://www.semanticweb.org/abhin/ontologies/2021/11/stock_project#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace#>

SELECT ?ID 
    WHERE { ?ID foaf:has_AnnualReturn ?AnnualReturn;
        foaf:has_ExcessReturn ?ExcessReturn.
        FILTER (?AnnualReturn > "0.3")
        }

In filter I have also tried type conversion but that did not work snap of ontograph

snap of an individual


Solution

  • Your filter relies on a property foaf:has_ref.WinRate existing with certain values in your data. As you do not get any results, no such property is found.

    With the snippet provided, the issue becomes clear:

    <ObjectPropertyAssertion>
        <ObjectProperty IRI="#has_AnnualReturn"/>
        <NamedIndividual IRI="#10-ID"/>
        <NamedIndividual IRI="#0.5853214994439921"/>
    </ObjectPropertyAssertion>
    

    The statements are about object properties, between individuals, where the IRIs happen to contain numbers. The SPARQL functions apply to numeric literals, not to individual IRIs, so the query will not find any matches because the input cannot be compared to the condition.

    For your query to work, it is necessary that the properties be data properties, and instead of connecting an individual to another individual they should connect an individual to a literal.

    The data should look something like this (adapting a different snippet of data from your file):

    <DataPropertyAssertion>
        <DataProperty IRI="#has_AnnualReturn"/>
        <NamedIndividual IRI="#10-ID"/>
        <Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#double">0.5853214994439921</Literal>
    </DataPropertyAssertion>