2

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:

-> In Twitter Social network graph of users and following relationship (Homogeneous graph), there is only one type of vertex entity (user), but in heterogeneous graphs such as ConceptNet data, it will have multiple values.

-> The edge entities can be computed by just counting the different number of predicates I believe using the query :

SELECT DISTINCT (?p AS ?DistinctEdges)  { ?s ?p ?o }

But I am not sure how to do so for vertices. The vertex type can be from a subject or object field of the triple and the object in turn can be either a value(literal) or another resource itself.

Please excuse me if I have gone wrong with the vocabulary anywhere. I have just started working on building a semantic web application.

4

1 回答 1

2

您可以使用该UNION子句将两种模式与FILTER使用该IsLiteral()函数的子句结合起来以省略文字,例如

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

The[]是一个匿名变量,因为您不关心 the 两侧的某些位置,UNION因此通过给它们一个匿名变量,我们匹配任何值但不在查询中携带这些值。

union 的 RHS 中的FILTER子句用于过滤掉作为文字的对象。在 LHS 中没有必要这样做,因为 RDF 禁止文字主题,因此?vertex来自 LHS 的任何值都必须是资源,即 URI/空白节点

于 2014-06-12T16:36:26.427 回答