Knowledge Graph知识图谱—7. Labeled Property Graphs带标签的属性图

7. Labeled Property Graphs (LPG)

7.1 Verbosity of RDF Graphs

Verbosity of RDF Graphs1
Verbosity of RDF Graphs2

7.1.1 RDF Reification

将关系本身作为资源进行建模
RDF Reification1

RDF Reification2

7.1.2 RDF Named Graphs

RDF Named Graphs1
RDF Named Graphs2

Named Graphs(命名图)是一种在图数据模型中用于组织和标识图数据的方法。它允许在一个大的图中将数据分为不同的图形组件,每个组件都有一个唯一的标识符,通常称为图名或图标签。Named Graphs 主要用于在图数据库和语义网中进行数据建模和查询。

RDF seems particularly bad at representing non-triple information
Choice:
(1) Blow up RDF graph (like DBpedia)
(2) Use non-straightforward representation: Reification or Named Graphs
(3) Other approaches in academia (singleton property, NDFluents, …): Not very handy either and Little adoption
In any case: Querying gets harder

Motivation for labeled property graphs
Modeling would be much easier if we could simply attach information to edges
Attempt in the Semantic Web Technologies Toolstack: RDF* / SPARQL*

7.2 RDF*

RDFRDF*
SubjectURIs or blank nodesURIs, blank nodes, or quoted statements
PredicateURIsURIs
ObjectURIs, blank nodes, literalsURIs, blank nodes, literals, or quoted statements

Quoting triples Example

<<dbr:Dirk_Nowitzki dbo:team dbr:DJK_Wuerzburg>>
dbo:activeYearsStartYear 1994 ;
dbo:activeYearsEndYear 1998 .

The subject of the statement is a triple.

7.2.1 Nesting in RDF*

RDF* statements can be subjects and objects themselves

<<
<<dbr:Dirk_Nowitzki dbo:team dbr:DJK_Wuerzburg>> 
dbo:activeYearsStartYear 1994 ; 
dbo:activeYearsEndYear 1998 .
>>
rdfs:definedBy
<http://dbpedia.org/>

7.2.2 Interpretation of RDF* vs. RDF

In RDF, we cannot make statements about two contradictory statements A and B without the entire graph being contradictory.

Example of contradictory

In RDF, when we make a statement about a statement S, S is automatically assumed to be true.

Example of contradictory in RDF*

7.2.3 RDF*: Quoted vs. Asserted Triples

Quoted triples are not automatically true
If we want to make them true (asserted), we have to do so explicitly.

dbr:Dirk_Nowitzki dbo:team dbr:DJK_Wuerzburg .
<<dbr:Dirk_Nowitzki dbo:team dbr:DJK_Wuerzburg>> 
dbo:activeYearsStartYear 1994 ; 
dbo:activeYearsEndYear 1998 .

# For this, there is a syntactic shortcut:
dbr:Dirk_Nowitzki dbo:team dbr:DJK_Wuerzburg 
{| dbo:activeYearsStartYear 1994 ; 
dbo:activeYearsEndYear 1998 |} .

7.3 SPARQL*: Querying RDF* Graphs

SPARQL*: Just like ordinary SPARQL
Triple patterns can contain Quoted triples and Triple annotations + a few more builtin functions

Example of SPARQL*

7.3.1 SPARQL* Return Types

SPARQL* Return Types1SPARQL* Return Types2

SPARQL return types: Resource with URI, Blank node, Literal, Number
SPARQL* adds a fifth return type: Triple

7.3.2 Other Query Types with SPARQL*

ASK and DESCRIBE: work as in SPARQL
CONSTRUCT: can also construct RDF*
CONSTRUCT in SPARQL*

Not all quoted triples are asserted.
The default graph of SPARQL results is only asserted triples
SPARQL 查询结果的默认图只包含那些已经被断言的三元组(只有那些在查询中找到匹配并已被显式断言的三元组会出现在默认图中),而引用的三元组可能只是查询中的临时结构或条件,并不一定成为最终结果中的事实。Mind the Assertion Gap1

从第一句:Julia :loves :Peter .是asserted triples,因此返回结果是:Julia
Mind the Assertion Gap2

RDF*/SPARQL*: Not (yet) a standard, but lots of tools support RDF* and/or SPARQL*

7.4 RDF* and Inference

RDF* and Inference1

RDF* and Inference2

7.5 Cypher

Labeled Property graphs: A combination of property/value stores(NoSQL) and graphs
Definition
Labeled Property graphs

Started as a proprietary query language for the graph database system neo4j in 2011
Like SPARQL, Cypher is based on pattern matching.

() denotes a node
[] denotes a relation
()-[]->() denotes a directed path
()-[]-() denotes an undirected path

7.5.1 Simple Query

Example

# Simple query: matching any node
MATCH (n) return n
# Would return all nodes

# Simple query: matching nodes with labels
MATCH (n:Movie) return n
# Would return only movie nodes

7.5.2 Restrictions on Keys

# Simple query: matching any node
MATCH (n:Movie {title: “The Matrix”}) return n
# Would return only the specific movie
# Also possible:
MATCH (n {title: “The Matrix”) return n
#Would return any node with a title “The Matrix”

7.5.3 Querying for Node Types

# What kind of node is “The Matrix”?
match(m {title:"The Matrix"}) return labels(m)

7.5.4 Path Expressions

Path Expressions
Path Expressions2
Path Expressions3
注意,应该是return n, r, e

Path Expressions4

7.5.5 Querying for Relation Types

# What kind of relation does Hugo Weaving have to the Matrix?
Match
(Movie {title:"The Matrix"})<-[r]-(Person {name:"Hugo Weaving"}) 
return type(r)

7.5.6 Return Types in Cypher

#So far, our return types were nodes or relations. We can also query for specific properties.

match(m:Movie {title: "The Matrix"}) 
return m.released

# return value can also be a property of a relation
# Which role(s) did Hugo Weaving play in The Matrix?
match(Movie {title: "The Matrix"}) <-[r:ACTED_IN]-(Person {name:"Hugo Weaving"}) 
return r.roles

7.5.7 Complex Paths & Combining Match Clauses

Complex Paths

Combining Match Clauses1
Combining Match Clauses2

7.5.8 Variable Binding

Variable Binding1
Variable Binding2

7.5.9 WHERE Clauses

WHERE Clauses1

WHERE Clauses2

WHERE Clauses3

WHERE Clauses4

7.5.10 Path Quantifiers

Path Quantifiers1

Path Quantifiers2

Pathfinding with Quantifiers

7.5.11 Graph Updates

Cypher also allows for adding and deleting information

# This requires a set instead of a return statement, e.g.,
match (p:Person)-[ACTED_IN]->(m:Movie) 
set p:Actor

Cypher also allows for adding and deleting properties

# This requires a set instead of a return statement, e.g.,
match(p:Person)-[ACTED_IN]->(m:Movie) 
with p,count(m) as moviecount 
where (moviecount>10) 
set p.famous="true"

Notes on this query:
Cipher allows counting (closed world semantics)
The with construct is used for variable scoping

  • Compute with first
  • Compute where second
    • cf.(confer=compare with) having in SQL

Cypher also allows for adding and deleting nodes and edges

#This requires a create instead of a return statement, e.g.,
match (p1:Person)-[r1:ACTED_IN]->(m:Movie) 
match (p2:Person)-[r2:ACTED_IN]->(m:Movie) 
create (p1)-[:KNOWS]->(p2)

Graph Updates - adding and deleting nodes and edges

Graph Updates vs. Reasoning
Inference in Cipher
We can infer additional edges using SET/CREATE commands. Those only apply for the current state of the graph, i.e., later changes are not respected
如果在之后对图数据库进行了更改,新增了新的边缘关系,这些更改不会受到之前推断的影响。换句话说,推理操作只适用于执行推理时图数据库的当前状态。

match (p:Person)-[ACTED_IN]->(m:Movie) 
set p:Actor
# Here, a later addition of a person acting in a movie would not get the Actor label!

Inference in RDF/S
Can be updated and/or evaluated at query time
RDF/S 允许推理操作的动态更新,这意味着当数据图发生更改时,可以根据推理规则对新数据进行重新评估,并进行相应的推理。

7.6 Comparison LPG+Cypher vs. RDF*/SPARQL*

Comparison LPG+Cypher vs. RDF*/SPARQL*

Summary

常识性知识图谱是一种以谱结构来组织和表示常识性知识的技术。它以实体、属性和关系为基本元素,将各种类型的常识性知识以节点和边的形式连接起来,形成一个丰富的知识网络。 在常识性知识图谱中,实体代表现实世界中的事物,如人物、地点、组织、概念等。属性表示实体的性质或特征,如人物的出生日期、地点的经纬度等。而关系则描述实体之间的关联或联系,如人物之间的亲属关系、地点之间的距离关系等。 常识性知识图谱的建立主要依靠自然语言处理、信息抽取和知识表示等技术。首先,通过自然语言处理技术,从多种文本资源中抽取出实体、属性和关系的信息。然后,利用信息抽取技术将这些信息结构化,并按照谱的形式进行组织。最后,通过知识表示技术,将这些结构化的知识表示为计算机可理解的形式,以便机器能够基于知识图谱进行推理和理解。 常识性知识图谱具有广泛的应用前景。它可以用于智能问答系统,提供准确、全面的答案;用于智能推荐系统,根据用户的兴趣和需求,为其推荐个性化的内容;用于智能机器人,帮助机器人具备理解和推理能力,提供更智能的服务等等。 然而,常识性知识图谱的构建面临一些挑战,如知识获取的可靠性和准确性,知识表示的一致性和丰富性等。未来,通过不断改进知识抽取、知识推理等技术,常识性知识图谱有望更好地支持人工智能系统的发展,为人们提供更智能、更高效的服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值