Search code examples
sparqlrdfowlontologygeosparql

SPARQL - Get all Data Properties directly assigned to an individual and all indirectly assigned to other individuals via an object property


My code so far is this:

    PREFIX : <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>

SELECT ?property ?value
WHERE{
    ?poi :POIhasID 7878787.
    ?poi ?property ?value;
    filter (?property not in (rdf:type))
    #filter isLiteral(?value) 

}

What am I trying to do is get a certain individual with ID 7878787 for example, give to me all his direct data type properties, exclude rdf:type answers, exclude any non literal values, and give me all indirect data type properties that are on another individual that is connected with the first one via an object property. In particular I use geosparql and I want to get the Place's data properties along with GPS coordinates assigned to a Point Individual subclass of Geometry that is connected with the Place individual with geo:hasGeometry object property. The ideal scenario would be something recursive to happen, for example, ?value that it not literal appear in the same columnas ?property, and ?value2 for example appear in the same column as value, I keep in mind the export to JSON which is the next step


Solution

  • that seems to be the case:

    PREFIX : <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    
    SELECT ?property ?value ?value2
    WHERE{
        {?poi :POIhasID 7878787.
        ?poi ?property ?value
        filter (?property not in (rdf:type))
        filter isLiteral(?value)
        } UNION {
        ?poi :POIhasID 7878787.
        ?poi ?prop2 ?value2.
        ?value2 ?property ?value
        filter isLiteral(?value)
    
        }
    }