如何从关系三元组创建图数据库?

时间:2018-01-22 10:37:11

标签: database graph neo4j orientdb google-knowledge-graph

我想为特定的故事情节构建一个知识图,因此我使用OpenIE提取了关系三元组(S,P,O)。现在我想从这些关系三元组创建图形数据库,我不知道该怎么做。 所以这是我的问题:
1)我应该使用哪个图形数据库?为什么?
2)如何从关系三元组创建数据库或是否可以在原始关系三元组的任何图形数据库中创建关系图?

例如,假设我选择Neo4j作为图数据库:
关系三元组看起来像:['Barack Obama', ' was born in', ' Hawaii']
如何从['Barack Obama', ' was born in', ' Hawaii']以编程方式创建Neo4j图?

  

Barak Obama and HawaiiNodes
  was born inRelationship   

1 个答案:

答案 0 :(得分:2)

使用OrientDB,您可以这样做:

create class Person extends V
create property Person.name string
create property Person.surname string
insert into Person(name, surname) values ("Barack","Obama")

create class Country extends V
create property Country.name string
insert into Country(name) values ("Hawaii")

create class was_born_in extends E

create edge was_born_in from (select from Person where name = "Barack") to (select from Country where name = "Hawaii")

情况就是这样:

+----+-----+-------+------+-------+---------------+--------------+
|#   |@RID |@CLASS |name  |surname|out_was_born_in|in_was_born_in|
+----+-----+-------+------+-------+---------------+--------------+
|0   |#17:0|Person |Barack|Obama  |[#25:0]        |              |
|1   |#21:0|Country|Hawaii|       |               |[#25:0]       |
+----+-----+-------+------+-------+---------------+--------------+

如果您运行此查询:

select expand(in('was_born_in')) from Country where name = "Hawaii"

你将得到所有居住在夏威夷的人

+----+-----+------+------+-------+---------------+
|#   |@RID |@CLASS|name  |surname|out_was_born_in|
+----+-----+------+------+-------+---------------+
|0   |#17:0|Person|Barack|Obama  |[#25:0]        |
+----+-----+------+------+-------+---------------+

希望有所帮助

此致