知识图谱查询
Property Graphs
定义
Also called Labeled Property Graphs (LPG)
It is a framework for representing data and metadata with a graph of nodes and links
- both nodes and links may have additional key/value pairs (“properties”)
- nodes are “just” nodes, not necessarily URLs
Link annotations are very useful to assign temporal, spatial, provenance, etc.
LPG vs. RDF
Similarity:
Both represent directed graphs as a basic data structure;
Both have associated graph-oriented query languages;
In practice, both are used as “graph stores”, accessible via HTTP and/or various API-s;
Differences:
RDF has an emphasis on OWA, and is rooted in the Web via URL-s. Not the case for PG, PG node is oblivious to what it “contains”: can be a URL, can be a literal; (node不一定是uri)
PG includes the possibility to add simple key/value pairs to “relationships” (i.e., RDF predicates) (关系中可以带属性)
RDF triple-stores vs. Graph DBs
In RDF triple-stores everything is expressed in terms of SPO and its predicates can’t have attributes;
In Graph DBs predicates can have attributes;
Fair to say that RDF triple-stores are a kind of Graph DB;
SPARQL (SPARQL Protocol and RDF Query Language)
SELECT/ASK/CONSTRUCT/DESCRIBE
Main idea: Pattern matching (想像成对图进行搜索)
Queries describe sub-graphs of the queried graph;
Graph patterns are RDF graphs specified in Turtle syntax, which contain variables (prefixed by either “?” or “$”);
Sub-graphs that match the graph patterns yield a result
图模式 Graph Pattern
基本匹配: Where a set of triple patterns must match
集合匹配 {}: Where a set of graph patterns must all match
可选匹配 OPTIONAL: Where additional patterns may extend the solution => 简单理解就是这个节点有属性则加,无则省略
附加匹配 UNION: Where two or more possible patterns are tried
命名图 GRAPH: Where patterns are matched against named graphs
FILTER NOT EXISTS vs. MINUS
1 |
|
简单的说, FILTER 共享对象引用 MINUS 不共享, 例子
1 |
|
Aggregation
SELECT (SUM(?lprice) AS ?totalPrice)
GROUP BY ?org
GROUP BY ?a ?b ?c
HAVING (SUM(?lprice) > 10)
Subqueries
原则: 先计算内部,在算外部的
RDF Dataset
RDF Dataset =
default graph
+ named graph 1
+ named graph 2
+ …
Separate graphs enable you to reason about who said what and when
常用SPARQL语句
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!