我想使用GraphMLReader类从带有JUNG2.0的graphML中读取无向图。
代码如下:
import edu.uci.ics.jung.io.*;
import edu.uci.ics.jung.io.graphml.*;
import java.io.*;
import java.util.*;
import org.apache.commons.collections15.Transformer;
import edu.uci.ics.jung.graph.*;
class Vertex{
int id;
String type;
String value;
}
class Edge{
int id ;
String type;
String value;
}
public class Loader{
static String src = "test.xsl";
public static void Main( String[] args){
Reader reader = new FileReader(src );
Transformer<NodeMetadata, Vertex> vtrans = new Transformer<NodeMetadata,Vertex>(){
public Vertex transform(NodeMetadata nmd ){
Vertex v = new Vertex() ;
v.type = nmd.getProperty("type");
v.value = nmd.getProperty("value");
v.id = Integer.valueOf( nmd.getId() );
return v;
}
};
Transformer<EdgeMetadata, Edge> etrans = new Transformer<EdgeMetadata,Edge>(){
public Edge transform( EdgeMetadata emd ){
Edge e = new Edge() ;
e.type = emd.getProperty("type");
e.value = emd.getProperty("value");
e.id = Integer.valueOf( emd.getId() );
return e;
}
};
Transformer<HyperEdgeMetadata, Edge> hetrans = new Transformer<HyperEdgeMetadata,Edge>(){
public Edge transform( HyperEdgeMetadata emd ){
Edge e = new Edge() ;
e.type = emd.getProperty("type");
e.value = emd.getProperty("value");
e.id = Integer.valueOf( emd.getId() );
return e;
}
};
Transformer< GraphMetadata , UndirectedSparseGraph> gtrans = new Transformer<GraphMetadata,UndirectedSparseGraph>(){
public UndirectedSparseGraph<Vertex,Edge> transform( GraphMetadata gmd ){
return new UndirectedSparseGraph<Vertex,Edge>();
}
};
GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> , Vertex , Edge> gmlr =
new GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> ,Vertex, Edge>(
reader,
gtrans,
vtrans,
etrans,
hetrans);
UndirectedSparseGraph<Vertex,Edge> g = gmlr.readGraph();
return ;
}
}
但是,编译器警告:
Loader.java:60: cannot find symbol
symbol : constructor GraphMLReader2(java.io.Reader,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.GraphMetadata,edu.uci.ics.jung.graph.UndirectedSparseGraph>,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.NodeMetadata,Vertex>,org.apache.commons.collections15.Transformer<edu.uci.ics.jung.io.graphml.EdgeMetadata,Edge>)
location: class edu.uci.ics.jung.io.graphml.GraphMLReader2<edu.uci.ics.jung.graph.UndirectedSparseGraph<Vertex,Edge>,Vertex,Edge>
new GraphMLReader2< UndirectedSparseGraph<Vertex,Edge> ,Vertex, Edge>(
^
1 error
我怎么解决这个问题?谢谢。
最佳答案
在图形转换器声明中,您还需要在尖括号中包括顶点和边类型。像这样:
Transformer< GraphMetadata , UndirectedSparseGraph<Vertex, Edge> > gtrans
关于java - 如何在Jung中使用GraphMLReader2?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2662046/