package com.neusoft;
import it.uniroma1.dis.wsngroup.gexf4j.core.EdgeType;
import it.uniroma1.dis.wsngroup.gexf4j.core.Gexf;
import it.uniroma1.dis.wsngroup.gexf4j.core.Graph;
import it.uniroma1.dis.wsngroup.gexf4j.core.Mode;
import it.uniroma1.dis.wsngroup.gexf4j.core.Node;
import it.uniroma1.dis.wsngroup.gexf4j.core.data.Attribute;
import it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeClass;
import it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeList;
import it.uniroma1.dis.wsngroup.gexf4j.core.data.AttributeType;
import it.uniroma1.dis.wsngroup.gexf4j.core.impl.GexfImpl;
import it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter;
import it.uniroma1.dis.wsngroup.gexf4j.core.impl.data.AttributeListImpl;
import java.io.*;
import java.util.*;
public class App {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new FileReader("part-r-00000"));
Gexf gexf = new GexfImpl();
Calendar date = Calendar.getInstance();
gexf.getMetadata()
.setLastModified(date.getTime())
.setCreator("Gephi.org")
.setDescription("A Web network");
gexf.setVisualization(true);
Graph graph = gexf.getGraph();
graph.setDefaultEdgeType(EdgeType.UNDIRECTED).setMode(Mode.STATIC);
AttributeList attrList = new AttributeListImpl(AttributeClass.NODE);
graph.getAttributeLists().add(attrList);
Attribute attClass = attrList.createAttribute("class", AttributeType.INTEGER, "Class");
Attribute attPageRank = attrList.createAttribute("pageranks", AttributeType.DOUBLE, "PageRank");
String line = "";
int nodeIndex = 1;
Map<String,Node> map = new HashMap<>();
Map<String,String> mapName2Pr = new HashMap<>();
while ((line = bufferedReader.readLine()) != null)
{
String[] arr = line.split("\\t");
String[] arr2 = arr[1].split("#");
Node node = graph.createNode(String.valueOf(nodeIndex));
nodeIndex++;
node.setLabel(arr[0])
.getAttributeValues()
.addValue(attClass, "1")
.addValue(attPageRank, arr2[0]);
map.put(arr[0],node);
String[] arr3 = arr2[1].split(";");
for(String string : arr3)
{
String[] Arr4 = string.split(":");
mapName2Pr.put(arr[0] + "&" + Arr4[0],Arr4[1]);
}
}
int edgeId = 1;
for(Map.Entry<String,String> entry : mapName2Pr.entrySet())
{
String twoPerson = entry.getKey();
String[] persons = twoPerson.split("&");
Node node1 = map.get(persons[0]);
Node node2 = map.get(persons[1]);
node1.connectTo(String.valueOf(edgeId),node2).setWeight(Float.parseFloat(entry.getValue()));
edgeId++;
}
StaxGraphWriter graphWriter = new StaxGraphWriter();
File f = new File("static_graph_sample.gexf");
Writer out;
try {
out = new FileWriter(f, false);
graphWriter.writeToStream(gexf, out, "UTF-8");
System.out.println(f.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
java生成gexf的工具gexf4j的用法2
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來辛孵,“玉大人丛肮,你說我怎么就攤上這事∑歉浚” “怎么了宝与?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我伴鳖,道長节值,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任榜聂,我火速辦了婚禮搞疗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘须肆。我一直安慰自己匿乃,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布豌汇。 她就那樣靜靜地躺著幢炸,像睡著了一般。 火紅的嫁衣襯著肌膚如雪拒贱。 梳的紋絲不亂的頭發(fā)上宛徊,一...
- 文/蒼蘭香墨 我猛地睜開眼瓤逼,長吁一口氣:“原來是場噩夢啊……” “哼笼吟!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起霸旗,我...
- 序言:老撾萬榮一對情侶失蹤贷帮,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后诱告,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體皿桑,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年蔬啡,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了诲侮。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布恨旱,位于F島的核電站,受9級特大地震影響坝疼,放射性物質(zhì)發(fā)生泄漏搜贤。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一钝凶、第九天 我趴在偏房一處隱蔽的房頂上張望仪芒。 院中可真熱鬧,春花似錦耕陷、人聲如沸掂名。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽饺蔑。三九已至,卻和暖如春嗜诀,著一層夾襖步出監(jiān)牢的瞬間猾警,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓筑公,卻偏偏與公主長得像,于是被迫代替她去往敵國和親尊浪。 傳聞我的和親對象是個(gè)殘疾皇子匣屡,可洞房花燭夜當(dāng)晚...