How to list and count the different types of node and edge entities in the graph data using SPARQL query?

前端 未结 1 387
萌比男神i
萌比男神i 2021-01-23 06:25

I\'m looking to provide some summary stats for a data set and I want to list the different types of edge entities and node(vertex) entities in the graph.

For example:

1条回答
  •  再見小時候
    2021-01-23 06:59

    You can use the UNION clause to combine two patterns in conjunction with a FILTER clause using the IsLiteral() function to omit literals e.g.

    SELECT DISTINCT ?vertex
    WHERE
    {
      { 
        ?vertex ?p [] 
      }
      UNION
      { 
        [] ?p ?vertex 
        FILTER(!IsLiteral(?vertex))
      }
    }
    

    The [] is an anonymous variable because you don't care about the some of the positions on either side of the UNION so by giving them an anonymous variable we match any value but don't carry those values out in the query.

    The FILTER clause in the RHS of the union is used to filter out objects which are literals. It is not necessary to have this in the LHS because RDF forbids literal subjects so any ?vertex value from the LHS must be a resource i.e. a URI/blank node

    0 讨论(0)
提交回复
热议问题