zoukankan      html  css  js  c++  java
  • tinkerpop(1) 地图数据库console科研

    原创文章连接: http://blog.csdn.net/freewebsys/article/details/46348975 转载请注明出处。

    1,关于图数据库

    tinkerpop是apache孵化器以下的一个项目。
    开源图数据库引擎。图数据库用的最多的是neo4j,可是有版权限制,要是使用社区版本号就仅仅能是,单机执行。

    http://tinkerpop.incubator.apache.org/

    http://tinkerpop.incubator.apache.org/

    文档參考:
    http://tinkerpop.incubator.apache.org/docs/3.0.0.M9-incubating/

    2。启动console

    wget https://dist.apache.org/repos/dist/release/incubator/tinkerpop/3.0.0.M9-incubating/apache-gremlin-console-3.0.0.M9-incubating-bin.zip
    unzip apache-gremlin-console-3.0.0.M9-incubating-bin.zip
    mv apache-gremlin-console-3.0.0.M9-incubating console

    启动console:(能够单独启动)能够尝试命令,測试数据。可是数据存储在内存中。关闭就丢失了。

    cd console
    # sh bin/gremlin.sh 
    
             \,,,/
             (o o)
    -----oOOo-(3)-oOOo-----
    plugin activated: tinkerpop.server
    plugin activated: tinkerpop.utilities
    plugin activated: tinkerpop.sugar
    plugin activated: tinkerpop.tinkergraph
    #打开连接
    gremlin> g = TinkerGraph.open()
    ==>tinkergraph[vertices:0 edges:0]
    #创建张三数据
    gremlin> zhangsan = g.addVertex("name","zhangsan")
    ==>v[0]
    #创建李四数据
    gremlin> lisi = g.addVertex("name","lisi")
    ==>v[2]
    #创建王五数据
    gremlin> wangwu = g.addVertex("name","wangwu")
    ==>v[4]
    #设置李四和王五朋友关系,friend是连接的名字,能够任意取。
    gremlin> lisi.addEdge("friend",zhangsan)
    ==>e[6][2-friend->0]
    #设置王五和李四朋友关系
    gremlin> wangwu.addEdge("friend",lisi)
    ==>e[7][4-friend->2]
    #查询所有数据
    gremlin> g.vertices()
    ==>v[0]
    ==>v[2]
    ==>v[4]
    #查询关系
    gremlin> g.edges()
    ==>e[6][2-friend->0]
    ==>e[7][4-friend->2]
    gremlin> zhangsan
    ==>v[0]
    #删除张三数据
    gremlin> zhangsan.remove()
    ==>null
    #删除后所有数据
    gremlin> g.vertices()
    ==>v[2]
    ==>v[4]
    #删除后关系数据
    gremlin> g.edges()
    ==>e[7][4-friend->2]

    开启OLTP变量引擎

    #开启变量引擎gt
    gremlin> gt = g.traversal(standard())
    ==>graphtraversalsource[tinkergraph[vertices:2 edges:1], standard]
    gremlin> 
    #查看数据
    gremlin> gt.V()
    ==>v[2]
    ==>v[4]
    #查询名字叫lisi的用户
    gremlin> gt.V().has("name","lisi")
    ==>v[2]
    #查询李四的朋友,由于刚才把张三删除了。

    所有没有数据。

    gremlin> gt.V().has("name","lisi").out("friend").values("name") #查询王五的朋友。关系是单向的。 gremlin> gt.V().has("name","wangwu").out("friend").values("name") ==>lisi

    使用官方样例说明:

    这里写图片描写叙述

    #初始化数据
    gremlin> g = TinkerFactory.createModern()
    ==>tinkergraph[vertices:6 edges:6]
    #初始化遍历引擎
    gremlin> gt = g.traversal(standard())
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    #查询marko knows的人
    gremlin> gt.V().has('name','marko').out('knows').values('name')
    ==>vadas
    ==>josh
    #查询marko created的人
    gremlin> gt.V().has('name','marko').out('created').values('name')
    ==>lop
    #查询marko knows的人。且这些人 created的人
    gremlin> gt.V().has('name','marko').out('knows').out('created').values('name')
    ==>ripple
    ==>lop
    #查询josh created的人
    gremlin> gt.V().has('name','josh').out('created').values('name')
    ==>ripple
    ==>lop

    图的数据库给人直观的插入,查询,很方便。
    很多其它查询參考官网: http://tinkerpop.incubator.apache.org/docs/3.0.0.M9-incubating/

    3,总结

    本文原文连接: http://blog.csdn.net/freewebsys/article/details/46348975 转载请注明出处。

    图数据库很方便,console是一个单机的内存版本号,能够进行測试。查询。
    生产环境部署须要使用server版本号。继续研究。

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    docker 安装mysql
    Java web项目搭建系列之二 Jetty下运行项目
    Java web项目搭建系列之一 Eclipse中新建Maven项目
    Maven 添加其他Maven组件配置问题
    C# 中定义扩展方法
    Oracle 函数
    【Webservice】2 counts of IllegalAnnotationExceptions Two classes have the same XML type name
    Linux精简版系统安装网络配置问题解决
    Rsync 故障排查整理
    Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4836556.html
Copyright © 2011-2022 走看看