如何在GRAPHSON中添加标签到顶点(基于JSON的图形元素格式)

时间:2015-10-01 10:47:43

标签: json titan gremlin tinkerpop tinkerpop-blueprint

参考链接

https://github.com/tinkerpop/blueprints/wiki/GraphSON-Reader-and-Writer-Library

如何标记json文件中的顶点,这将导致加速图遍历。我正在使用泰坦图db。因此,GRAPHSON将用于将json转换为图形实例并使用gremlin查询语言。因此,为了加快顶点的检索,我需要标记这些顶点以进行分类。我怎样才能添加标签?

{
"mode":"EXTENDED",
"vertices": [
    {
        "name": {
            "type": "string",
            "value": "lop"
        },
        "lang": {
            "type": "string",
            "value": "java"
        },
        "_id": "3",
        "_type": "vertex"
    },
    {
        "name": {
            "type": "string",
            "value": "vadas"
        },
        "age": {
            "type": "integer",
            "value": 27
        },
        "_id": "2",
        "_type": "vertex"
    },
    {
        "name": {
            "type": "string",
            "value": "marko"
        },
        "age": {
            "type": "integer",
            "value": 29
        },
        "_id": "1",
        "_type": "vertex"
    },
    {
        "name": {
            "type": "string",
            "value": "peter"
        },
        "age": {
            "type": "integer",
            "value": 35
        },
        "_id": "6",
        "_type": "vertex"
    },
    {
        "name": {
            "type": "string",
            "value": "ripple"
        },
        "lang": {
            "type": "string",
            "value": "java"
        },
        "_id": "5",
        "_type": "vertex"
    },
    {
        "name": {
            "type": "string",
            "value": "josh"
        },
        "age": {
            "type": "integer",
            "value": 32
        },
        "_id": "4",
        "_type": "vertex"
    }
],
"edges": [
    {
        "weight": {
            "type": "float",
            "value": 1
        },
        "_id": "10",
        "_type": "edge",
        "_outV": "4",
        "_inV": "5",
        "_label": "created"
    },
    {
        "weight": {
            "type": "float",
            "value": 0.5
        },
        "_id": "7",
        "_type": "edge",
        "_outV": "1",
        "_inV": "2",
        "_label": "knows"
    },
    {
        "weight": {
            "type": "float",
            "value": 0.4000000059604645
        },
        "_id": "9",
        "_type": "edge",
        "_outV": "1",
        "_inV": "3",
        "_label": "created"
    },
    {
        "weight": {
            "type": "float",
            "value": 1
        },
        "_id": "8",
        "_type": "edge",
        "_outV": "1",
        "_inV": "4",
        "_label": "knows"
    },
    {
        "weight": {
            "type": "float",
            "value": 0.4000000059604645
        },
        "_id": "11",
        "_type": "edge",
        "_outV": "4",
        "_inV": "3",
        "_label": "created"
    },
    {
        "weight": {
            "type": "float",
            "value": 0.20000000298023224
        },
        "_id": "12",
        "_type": "edge",
        "_outV": "6",
        "_inV": "3",
        "_label": "created"
    }
]

}

1 个答案:

答案 0 :(得分:0)

TinkerPop 2.x没有对顶点标签的原生支持,因此,GraphSON 2.x也不支持它。 TinkerPop 3.x(以及Titan 1.0)有这样的支持:

http://tinkerpop.incubator.apache.org/docs/3.0.1-incubating/#graphson-reader-writer

您需要升级到Titan 1.0 / TP3或在早期版本的Titan / TP2中使用Titan API编写自定义GraphSON处理器。

相关问题