orientdb 加载节点和边的图 csv [英] orientdb load graph csv of nodes and edges

查看:21
本文介绍了orientdb 加载节点和边的图 csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Orientdb 的新手.我有一个包含节点和边的 csv 文件,我需要从该 csv 文件中创建一个图形.csv 文件

I'm a newbie in Orientdb . I have a csv file which has both the nodes and the edge and I need to create a graph out of that csv file . csv file

"p1","p2","score"
"LGG_00001","LGG_01682",282
"LGG_00001",".LGG_01831",183
"LGG_00001","LGG_01491",238

边缘是IsActingWith,它有score属性

The edge is IsActingWith which had the score attribute

{
"source": {
    "file": {
        "path": "C:/Users/sams/Desktop/OrientDB2/lac2.csv"
    }
},
"extractor": {
    "csv": {}
},
"transformers": [
    {
        "vertex": {
            "class": "lac2"
        }
    },
    {
        "vertex": {
            "class": "lac2"
        }
    },

    {
        "edge":
        {
                "class": "IsActingWith",
                "joinFieldName": "score_p",
                "lookup": "acore",
                "direction": "out"
        }
    }

],
"loader": {
    "orientdb": {
        "dbURL": "plocal:C:/Users/sams/Desktop/OrientDB2/database/proj",
        "dbType": "graph",
        "dbAutoCreate": true,
        "classes": [
            {
                "name": "lac2",
                "extends": "V"
            },
            {
                "name": "lac2",
                "extends": "V"
            },
            {
                "name": "IsActingWith",
                "extends": "E"
            },

        ]

    }
}
}

这就是我尝试过的,但对我来说似乎不合逻辑.我正在寻找的最终结果是有一个由 p1->ACTINGWITH-> 组成的图形.p2ACTINGWITH 有score 属性的score

That is what I tried but it does not seem logic to me. The final result I'm looking for is to have a graaph made of p1->ACTINGWITH-> p2 and ACTINGWITH has score of the score attribute

推荐答案

也许有更好的解决方案,但这是有效的.我的计划是使用 3 个不同的 etl 脚本:第一个和第二个用于插入顶点,第三个用于边缘.当然,您需要按顺序执行它们.

maybe there's a better solution but this works. My plan is to use 3 different etl scripts: first and second for inserting the vertices and the third for the edges. Of course you'll need to execute them in order.

vertex_import_p1.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "UPDATE lac2 set p='${input.p1}' UPSERT WHERE p='${input.p1}'"} }      
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

vertex_import_p2.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "UPDATE lac2 set p='${input.p2}' UPSERT WHERE p='${input.p2}'"} }      
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

edge_import_s.json

{
    "source": { "file": { "path": "/home/ivan/Cose/OrientDB/issues/stack/44641116/file.csv" } },
    "extractor": { "csv": {
        "separator": ",",
    "columns": ["p1:String","p2:String","s:Integer"] } },
    "transformers": [
        { "command": { "command": "CREATE EDGE isActingWith FROM (SELECT FROM lac2 WHERE p='${input.p1}') TO (SELECT FROM lac2 WHERE p='${input.p2}') set score=${input.s}"} }
    ],
    "loader": {
        "orientdb": {
            "dbURL": "plocal:/home/ivan/Cose/OrientDB/issues/stack/44641116/db",
            "dbUser": "admin",
            "dbPassword": "admin",
            "dbType": "graph",
            "classes": [
                {"name": "lac2", "extends": "V"},
                {"name": "isActingWith", "extends": "E"}
            ]
        }
    }
}

<小时>

这是处决后的情况:


And here are the situation after the executions:

orientdb {db=db}> select from lac2

+----+-----+------+---------+-------------------+---------------+
|#   |@RID |@CLASS|p        |out_isActingWith   |in_isActingWith|
+----+-----+------+---------+-------------------+---------------+
|0   |#21:6|lac2  |LGG_00001|[#25:5,#26:1,#27:1]|               |
|1   |#21:7|lac2  |LGG_01682|                   |[#25:5]        |
|2   |#22:3|lac2  |LGG_01831|                   |[#26:1]        |
|3   |#23:1|lac2  |LGG_01491|                   |[#27:1]        |
+----+-----+------+---------+-------------------+---------------+

4 item(s) found. Query executed in 0.003 sec(s).
orientdb {db=db}> select from isActingWith

+----+-----+------------+-----+-----+-----+
|#   |@RID |@CLASS      |score|out  |in   |
+----+-----+------------+-----+-----+-----+
|0   |#25:5|isActingWith|282  |#21:6|#21:7|
|1   |#26:1|isActingWith|183  |#21:6|#22:3|
|2   |#27:1|isActingWith|238  |#21:6|#23:1|
+----+-----+------------+-----+-----+-----+

3 item(s) found. Query executed in 0.004 sec(s).

这篇关于orientdb 加载节点和边的图 csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆