TitanFactory.open() configration

柔情痞子 提交于 2019-12-25 14:13:01

问题


My previous question was about the syntax of the TitanFactory class. Now i wonder how to use it?

For example i can construct RexsterGraph object like the following and it works like a charm.

Graph graph = new RexsterGraph(http://190.188.20.11:8183/graphs/graph");

Now i want to import csv file into the titan. So i need TitanGraph object. I found the following post to do that.

How to import a CSV file into Titan graph database?

And i worte the following code and it gives me error.

Could not find implementation class: com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager

    TitanGraph titanGraph = null;
    try {
        titanGraph = TitanFactory
                .open("D:\\TEMP\\titan-cassandra.properties");
    } catch (Exception e) {
        System.err.println(e.getMessage());

        System.out.println("\n");

        System.err.println(e.getStackTrace());
    }

The only thing i need is that i want some code like RexsterGraph example for getting instance of TitanGraph object. What should i do? by the way i run the code on my local but graph is working remote linux machine


回答1:


sample test.csv lines

id:1,name:xxx,age:20,........

id:2,name:yyy,age:21,........

I don't know what is your csv file size but it is small, you can import like this

            String path = "c:\\test.csv";
            Charset encoding = Charset.forName("ISO-8859-1");
            try {
                List<String> lines = Files.readAllLines(Paths.get(path), encoding);
                Graph graph = new RexsterGraph("http://190.188.20.11:8183/graphs/graph");

                for (String line : lines) {
                    Vertex currentNode = graph.addVertex(null);
                    String[] values = line.split(",");
                    for (String value : values) {
                        String[] property = value.split(":");
                        currentNode.setProperty(property[0].toString(), property[1].toString());
                    }
                }

            }


来源:https://stackoverflow.com/questions/32519516/titanfactory-open-configration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!