图数据库相关
2018-01-29 18:52
316 查看
OrientDB 入门
OrientDB是什么?
用一句话概括:一种Nosql数据库,支持文档、Key/Value,文档,图多种模型。基础概念
记录
是读取和存储的最小单元。有四种类型:* 文档(Document)
* 字节流(RecordBytes)
* 顶点(Vertex)
* 边(Edge)
文档
文档是OrientDB中最灵活的记录类型。文档默认有类型,通过约束的模式来定义,但是也可以使用无模式的。字节流
用于加载和存储二进制数据,类似于关系型数据中的BLOB顶点
节点是图形数据中最基本的数据单元,OrientDB中叫做顶点边
图形数据库中两个节点的连接叫做弧,OrientDB叫做边簇(Cluster)
存储数据的地方,可以存储在物理空间和内存空间记录ID
当OrientDB产生一条记录时,会自动分配一个唯一的单元标示,叫做Record ID,簇标示和位置组成的。格式如下:#<cluster>:<position>
簇标示(cluster):这个数字表示记录所属的簇。正数表示记录是被持久化的,负数表示临时存储
位置(position):这个数字表示了在簇中的记录的绝对位置。
类(Class)
类似关系型数据库中表的概念。class概念来自面向对象编程,可以继承。也可以有抽象类(Abstract Class)引用关系(referenced)
customer Record A -------------> Record B CLASS=Invoice CLASS=Customer RID=5:23 RID=10:2
这里, 记录A在属性customer中包含了记录B的引用。 记录相互可以被对方访问,因为有记录ID,文档API中, 边被表示为两个链接,分别存储在对应的顶点中来处理双向连接关系
基础操作
使用OrientDB SQL dialectOrientDB支持以Sql的方式来查询数据,和传统Sql非常类似,有一些细微区别
JOINs(关联查询)
传统SQL
SELECT * FROM Employee A, City B WHERE A.city = B.id AND B.name = 'Rome'
OrientDB Sql
SELECT * FROM Employee WHERE city.name = 'Rome'
DISTINCT
传统Sql
SELECT DISTINCT name FROM City
OrientDB Sql
SELECT DISTINCT(name) FROM City
Graph Sql语法
创建Vertex
CREATE VERTEX [<class>] [CLUSTER <cluster>] [SET <field> = <expression>[,]*]
删除Vertex
CREATE VERTEX [<class>] [CLUSTER <cluster>] [SET <field> = <expression>[,]*]
Select
SELECT [ <Projections> ] [ FROM <Target> [ LET <Assignment>* ] ] [ WHERE <Condition>* ] [ GROUP BY <Field>* ] [ ORDER BY <Fields>* [ ASC|DESC ] * ] [ UNWIND <Field>* ] [ SKIP <SkipRecords> ] [ LIMIT <MaxRecords> ] [ FETCHPLAN <FetchPlan> ] [ TIMEOUT <Timeout> [ <STRATEGY> ] [ LOCK default|record ] [ PARALLEL ] [ NOCACHE ]
转自http://blog.csdn.net/wangp_yong/article/details/70598265
OrientDB在知识图谱中的应用(一)
以笑傲江湖(SwordsMan)中简单的人物关系为例,描述如何利用orientDB图数据库表达构建知识图谱这里默认大家都是了解OrientDB基本语法,了解NoSql和图形数据库的小伙伴,不了解的可以自行查阅资料。废话不多说,我们开始吧。
创建一个名为SwordsMan的数据库:
create database plocal:/home/wangtd/local/orientdb/databases/SwordsMan #登录操作 connect plocal:/home/wangtd/local/orientdb/databases/SwordsMan admin admin
实体/关系梳理
我们假定一个简单的实体、关系模型,其中包括点(Vertex)和边(Edge),这两种类型是OrientDB中图数据库的重要类型。实体: 人物(令狐冲,岳不群,宁中则,任盈盈) 教派(华山派,日月神教) 功夫(华山剑法,独孤九剑,玉女十三剑) 关系:情侣,师徒,门徒,技能
创建类对象
create class Person extends V create class Group extends V create class KungFu extends V create class Lover extends E create class Student extends E create class Teacher extends E create class Disciple extends E create class Skill extends E
创建Vertex/Edge
创建基本实体create vertex Person set name="令狐冲",sex="男",age="25",group="华山派",kungfu="独孤九剑" create vertex Person set name="任盈盈",sex="女",age="18",group="日月神教",kungfu="长经双刀" create edge Lover from(select from Person where name="令狐冲") to (select from Person where name="任盈盈") create edge Lover from(select from Person where name="任盈盈") to (select from Person where name="令狐冲") create vertex Person set name="岳不群",sex="男",age="40",group="华山派",kungfu="辟邪剑谱" create vertex Person set name="宁中则",sex="女",age="35",group="华山派",kungfu="玉女十三剑" create edge Lover from(select from Person where name="岳不群") to (select from Person where name="宁中则") create edge Lover from(select from Person where name="宁中则") to (select from Person where name="岳不群")
创建边关系
create vertex Group set name="华山派",addr="华山" create vertex Group set name="日月神教",addr="黑木崖" create edge Disciple from(select from Person where group="华山派") to (select from Group where name="华山派") create edge Disciple from(select from Person where group="日月神教") to (select from Group where name="日月神教") create edge Teacher from(select from Person where name="令狐冲") to(select from Person where name="岳不群") create edge Teacher from(select from Person where name="令狐冲") to(select from Person where name="宁中则") create edge Student from(select from Person where name="岳不群") to(select from Person where name="令狐冲") create edge Student from(select from Person where name="宁中则") to(select from Person where name="令狐冲")
更新/维护关系
create vertex KungFu set name="华山剑法" create vertex KungFu set name="玉女十三剑" create vertex KungFu set name="长经双剑" create edge Skill from(select from Person where name="令狐冲") to(select from KungFu where name="华山剑法") create edge Skill from(select from Person where name="岳不群") to(select from KungFu where name="华山剑法") create edge Skill from(select from Person where name="宁中则") to(select from KungFu where name="玉女十三剑") create edge Skill from(select from Person where name="任盈盈") to(select from KungFu where name="长经双剑")
体会
因为orientDB本身支持sql语法,所以数据的增删改查比较方便
图数据库重要的两种类型Vertex和Edge
构建知识图谱前,要先定义Vertex和Edge的对象,要确定出Vertex的类型有哪些,Edge的类型有哪些
图谱关系是以In/Out代表的双向关系,一条边定义了有向的出度和入度
方向
图谱的构建是最基础的一步,在图谱构建之后:
完善图谱
使用java api query
达到知识图谱应用的效果
转自 :http://blog.csdn.net/cywtd/article/details/70214394
http://blog.csdn.net/jinnee/article/details/70224512
http://blog.csdn.net/zhufengyi/article/details/53037764
https://www.w3cschool.cn/orientdb/orientdb_console_modes.html
https://www.jianshu.com/p/b52fd9bff5c7
https://wenku.baidu.com/view/0ad37a858662caaedd3383c4bb4cf7ec4afeb60e.html?mark_pay_doc=2&mark_rec_page=1&mark_rec_position=2&clear_uda_param=1
相关文章推荐
- 图数据库Neo4j全栈Web技术解密
- 图数据库 Neo4j 之 Java Api 的使用
- Neo4j高级应用技术专题系列 - APOC存储过程库-【2】路径扩展过程
- Neo4j的免费在线培训教程
- 统计Titan图中的点数和边数
- Neo4J(Cypher语句)初识
- 图数据库NEO4j
- OrientDB 图状数据库示例
- orientdb实战
- 图数据库选型和调研
- ArangoDB数据导入
- 图数据库浅谈
- 试一试图数据库cayley
- 试一试dgraph
- OrientDB 踩坑记录
- OrientDB社区版Linux分布式部署失败
- 大数据图数据库之TAO数据库
- 大数据图数据库之数据分片
- 大数据图数据库之MapReduce用于图计算
- 大数据图数据库之离线挖掘计算模型