美文网首页
Grakn 学习笔记

Grakn 学习笔记

作者: 走在成长的道路上 | 来源:发表于2019-02-25 14:29 被阅读0次

    Grakn 是一个开源知识图谱存储及查询系统,其自带 grakn console 等数据交互接口,具有自动推理功能,具有 CNN 等图谱深度学习扩展组件。

    安装

    下载 grakn linux 安装包, 并解压,接着执行如下命令启动即可

    $ ./grakn server start
    ====================================================================================================
          ________  _____     _______  __    __  __    __      _______  _______  _____     _______
         |   __   ||   _  \  |   _   ||  |  /  /|  \  |  |    |   _   ||   _   ||   _  \  |   ____|
         |  |  |__||  | |  | |  | |  ||  | /  / |   \ |  |    |  | |__||  | |  ||  | |  | |  |
         |  | ____ |  |_| /  |  |_|  ||  |/  /  |    \|  |    |  |     |  | |  ||  |_| /  |  |____
         |  ||_   ||   _  \  |   _   ||   _  \  |   _    |    |  |  __ |  | |  ||   _  \  |   ____|
         |  |__|  ||  | \  \ |  | |  ||  | \  \ |  | \   |    |  |_|  ||  |_|  ||  | \  \ |  |____
         |________||__|  \__\|__| |__||__|  \__\|__|  \__|    |_______||_______||__|  \__\|_______|
    
                                             THE KNOWLEDGE GRAPH
    ====================================================================================================
    
    Starting Storage............SUCCESS
    Starting Engine.....................SUCCESS
    

    导入数据

    • 导入 schema
    1. 将下列内容存放为 schema.gpl 文件
    define
    
    marriage sub relationship,
      has picture,
      relates spouse;
    
    parentship sub relationship,
      relates parent,
      relates child;
    
    person sub entity,
      has first-name,
      has middle-name,
      has surname,
      has picture,
      has age,
      has birth-date,
      has death-date,
      has gender,
      plays parent,
      plays child,
      plays spouse;
    
    name sub attribute datatype string;
    first-name sub name datatype string;
    middle-name sub name datatype string;
    surname sub name datatype string;
    picture sub attribute datatype string;
    age sub attribute datatype long;
    event-date sub attribute datatype date;
    birth-date sub event-date datatype date;
    death-date sub event-date datatype date;
    gender sub attribute datatype string;
    
    1. 执行 console 导入命令
    ./graql console --keyspace genealogy --file schema.gql
    

    其中 --keyspace genealogy 表示图谱空间

    • 导入数据
    1. 下载数据内容 data.gql
    ./graql console --keyspace genealogy --file data.gql
    

    查询

    • 获取年龄大于 60 的人
    >>> match $p isa person has age > 60; get;
    
    • 获取所有人,包含名称及年龄
    >>> match $p isa person has first-name $fn, has age $a; offset 0; get;
    
    • 插入数据
    >>> insert $p isa person has first-name "Johny", has middle-name "Jimbly", has surname "Joe", has gender "male";
    >>> commit
    
    • 更新数据
    >>> match $p id V139280; insert $p has age 77;
    >>> commit
    
    • 删除数据
    >>> match $p isa person has first-name "Johny", has surname "Joe"; delete;
    >>> commit
    

    相关文章

      网友评论

          本文标题:Grakn 学习笔记

          本文链接:https://www.haomeiwen.com/subject/cbidsqtx.html