2015-09-11 35 views
0

My previous question是關於TitanFactory類的語法。現在我想知道如何使用它?TitanFactory.open()configration

例如,我可以像下面那樣構建RexsterGraph對象,它的作用就像一個魅力。

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

現在我想導入csv文件到泰坦。所以我需要TitanGraph對象。我發現以下帖子來做到這一點。

How to import a CSV file into Titan graph database?

而且我又寫道下面的代碼,這讓我的錯誤。

找不到實現類: 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()); 
    } 

我唯一需要的是,我要像RexsterGraph例如,對於一些代碼獲取TitanGraph對象的實例。我該怎麼辦?順便說一下我對我的本地運行的代碼,但圖中正在遠程Linux機器

+0

你會編輯你的問題,並描述你的Titan設置多一點?看起來你想用一個遠程Cassandra集羣作爲Titan的存儲後端?如果您的應用程序可以訪問遠程Cassandra集羣,則不一定需要Rexster將圖形數據加載到Titan中。對於圖實例,rexster config xml的外觀如何? –

回答

1

樣品test.csv線

ID:1,名稱:XXX,年齡:20,...... ..

ID:2,名稱:YYY,年齡:21,........

我不知道什麼是您的CSV文件大小,但它是小,可以像這樣的進口

  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()); 
        } 
       } 

      } 
相關問題