자바 생 성 gexf 도구 gexf4j 의 용법 2
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 map = new HashMap<>();
Map 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 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();
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.