Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » JUNG loading grpah question
JUNG loading grpah question [message #653759] Fri, 11 February 2011 02:46 Go to next message
Eddie Mising name is currently offline Eddie Mising nameFriend
Messages: 6
Registered: February 2011
Junior Member
i get this error when i try to load the graph from the text file

java.io.IOException: specified 'source' attribute "A" does not match any node ID
at edu.uci.ics.jung.io.GraphMLReader.parse(GraphMLReader.java:2 46)
at edu.uci.ics.jung.io.GraphMLReader.load(GraphMLReader.java:19 2)
at hyperGraph.loadGraph(hyperGraph.java:189)
at hyperGraph.main(hyperGraph.java:233)

here is the code
class VertexM {
String name = "";

public VertexM() {
}

public VertexM(String name) {
this.name = name;
}

public String toString() {
return name;
}

public boolean equals(Object obj) {
if (obj == this) {
return true;
}

if (obj == null) {
return false;
}
VertexM other = (VertexM) obj;

boolean a = this.getName().equals(other.getName());
return a;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public int getCount() {
return 1;
}

public int hashCode() {
return name.hashCode();
}
}

class EdgeM {
float count;
String id = "";

public EdgeM() {
this.count = 0;
}

public EdgeM(String d, String v1, String v2) {
this.id = v1 + v2;
this.count = Integer.parseInt(d);
}

public String toString() {
return id;
}

public void addCount() {
count++;
}

public void setId(String id) {
this.id = id;
}

public float getCount() {
return count;
}

public boolean equals(Object obj) {
if (obj == this) {
return true;
}
)
if (obj == null) {
return false;
}
EdgeM other = (EdgeM) obj;

boolean a = this.toString().equals(other.toString());
return a;
}

@Override
public int hashCode() {
int result = Math.round(count) * 37 + id.hashCode();
return result;
}
}


public static UndirectedSparseGraph<VertexM, EdgeM> loadGraph(Reader reader) {
class EdgeMFactory implements Factory<EdgeM> {

@Override
public EdgeM create() {
return new EdgeM();
}

}

class VertexMFactory implements Factory<VertexM> {
public VertexM create() {
return new VertexM();
}

}
GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM, EdgeM> graphReader = null;
try {
graphReader = new GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM, EdgeM>(
new VertexMFactory(), new EdgeMFactory());
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e1) {
e1.printStackTrace();
}

UndirectedSparseGraph<VertexM, EdgeM> fixGraph = new UndirectedSparseGraph<VertexM, EdgeM>();
try {
graphReader.load(reader, fixGraph);
Map<String, GraphMLMetadata<VertexM>> nodeMetaData = graphReader
.getVertexMetadata();

for (VertexM node : fixGraph.getVertices()) {
String nodeName = ((String) (nodeMetaData.get("NodeName").transformer.transform(node)));
System.out.println("NODE" + nodeName);

node.setName(nodeName);
}

} catch (IOException e) {
e.printStackTrace();
}

return fixGraph;
}

/**
* @param args
* @throws SAXException
* @throws ParserConfigurationException
*/
public static void main(String[] args) {

try { FileReader in = new FileReader(
"C:\\Program Files\\Eclipse for FYP\\output\\test.txt");
Hypergraph<VertexM, EdgeM> hg = loadGraph(in);
System.out.println(hg.getVertices()); } catch
(ArrayIndexOutOfBoundsException e) {

System.out.println("Usage: java ReadFile filename\n");

} catch (IOException e) { e.printStackTrace(); }
}

and the save file is
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns/graphml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/graphml">
<key id="NodeName" for="node">
<desc>File Name</desc>
<default></default>
</key>
<key id="EdgeName" for="edge">
<desc>Edge Visit Name</desc>
<default></default>
</key>
<key id="EdgeCount" for="edge">
<desc>Edge Visit Count</desc>
<default></default>
</key>
<graph edgedefault="undirected">
<node id="A">
<data key="NodeName">A</data>
</node>
<node id="B">
<data key="NodeName">B</data>
</node>
<node id="C">
<data key="NodeName">C</data>
</node>
<edge source="A" target="C">
<data key="EdgeName">AC</data>
<data key="EdgeCount">3.0</data>
</edge>
<edge source="A" target="B">
<data key="EdgeName">AB</data>
<data key="EdgeCount">2.0</data>
</edge>
</graph>
</graphml>

is there any problem for my code?
Re: JUNG loading grpah question [message #653801 is a reply to message #653759] Fri, 11 February 2011 09:36 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2359
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Eddie,
this a newsgroup for RAP related questions. Maybe you post in a wrong
newsgroup.
Best,
Ivan

On 2/11/2011 4:46 AM, Eddie wrote:
> i get this error when i try to load the graph from the text file
>
> java.io.IOException: specified 'source' attribute "A" does not match
> any node ID
> at edu.uci.ics.jung.io.GraphMLReader.parse(GraphMLReader.java:2 46)
> at edu.uci.ics.jung.io.GraphMLReader.load(GraphMLReader.java:19 2)
> at hyperGraph.loadGraph(hyperGraph.java:189)
> at hyperGraph.main(hyperGraph.java:233)
>
> here is the code
> class VertexM {
> String name = "";
>
> public VertexM() {
> }
>
> public VertexM(String name) {
> this.name = name;
> }
>
> public String toString() { return name; }
>
> public boolean equals(Object obj) {
> if (obj == this) {
> return true;
> }
>
> if (obj == null) {
> return false;
> }
> VertexM other = (VertexM) obj;
>
> boolean a = this.getName().equals(other.getName());
> return a;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public String getName() {
> return name;
> }
>
> public int getCount() {
> return 1;
> }
>
> public int hashCode() {
> return name.hashCode();
> }
> }
>
> class EdgeM {
> float count;
> String id = "";
>
> public EdgeM() {
> this.count = 0;
> }
>
> public EdgeM(String d, String v1, String v2) {
> this.id = v1 + v2;
> this.count = Integer.parseInt(d);
> }
>
> public String toString() {
> return id;
> }
>
> public void addCount() {
> count++;
> }
>
> public void setId(String id) {
> this.id = id;
> }
>
> public float getCount() {
> return count;
> }
>
> public boolean equals(Object obj) {
> if (obj == this) {
> return true;
> }
> )
> if (obj == null) {
> return false;
> }
> EdgeM other = (EdgeM) obj;
>
> boolean a = this.toString().equals(other.toString());
> return a;
> }
>
> @Override
> public int hashCode() {
> int result = Math.round(count) * 37 + id.hashCode();
> return result;
> }
> }
>
>
> public static UndirectedSparseGraph<VertexM, EdgeM> loadGraph(Reader
> reader) {
> class EdgeMFactory implements Factory<EdgeM> {
>
> @Override
> public EdgeM create() {
> return new EdgeM();
> }
>
> }
>
> class VertexMFactory implements Factory<VertexM> {
> public VertexM create() {
> return new VertexM();
> }
>
> }
> GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM,
> EdgeM> graphReader = null;
> try {
> graphReader = new
> GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM, EdgeM>(
> new VertexMFactory(), new EdgeMFactory());
> } catch (ParserConfigurationException e1) {
> e1.printStackTrace();
> } catch (SAXException e1) {
> e1.printStackTrace();
> }
>
> UndirectedSparseGraph<VertexM, EdgeM> fixGraph = new
> UndirectedSparseGraph<VertexM, EdgeM>();
> try {
> graphReader.load(reader, fixGraph);
> Map<String, GraphMLMetadata<VertexM>> nodeMetaData =
> graphReader
> .getVertexMetadata();
>
> for (VertexM node : fixGraph.getVertices()) {
> String nodeName = ((String)
> (nodeMetaData.get("NodeName").transformer.transform(node)));
> System.out.println("NODE" + nodeName);
>
> node.setName(nodeName);
> }
>
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> return fixGraph;
> }
>
> /**
> * @param args
> * @throws SAXException
> * @throws ParserConfigurationException
> */
> public static void main(String[] args) {
>
> try { FileReader in = new FileReader(
> "C:\\Program Files\\Eclipse for FYP\\output\\test.txt");
> Hypergraph<VertexM, EdgeM> hg = loadGraph(in);
> System.out.println(hg.getVertices()); } catch
> (ArrayIndexOutOfBoundsException e) {
> System.out.println("Usage: java ReadFile
> filename\n");
> } catch (IOException e) { e.printStackTrace(); }
> }
>
> and the save file is <?xml version="1.0" encoding="UTF-8"?>
> <graphml xmlns="http://graphml.graphdrawing.org/xmlns/graphml"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/graphml">
> <key id="NodeName" for="node">
> <desc>File Name</desc>
> <default></default>
> </key>
> <key id="EdgeName" for="edge">
> <desc>Edge Visit Name</desc>
> <default></default>
> </key>
> <key id="EdgeCount" for="edge">
> <desc>Edge Visit Count</desc>
> <default></default>
> </key>
> <graph edgedefault="undirected">
> <node id="A">
> <data key="NodeName">A</data>
> </node>
> <node id="B">
> <data key="NodeName">B</data>
> </node>
> <node id="C">
> <data key="NodeName">C</data>
> </node>
> <edge source="A" target="C">
> <data key="EdgeName">AC</data>
> <data key="EdgeCount">3.0</data>
> </edge>
> <edge source="A" target="B">
> <data key="EdgeName">AB</data>
> <data key="EdgeCount">2.0</data>
> </edge>
> </graph>
> </graphml>
>
> is there any problem for my code?
Re: JUNG loading grpah question [message #653857 is a reply to message #653801] Fri, 11 February 2011 15:26 Go to previous messageGo to next message
Eddie Mising name is currently offline Eddie Mising nameFriend
Messages: 6
Registered: February 2011
Junior Member
oh sorry...
where can i ask the jung question?
Re: JUNG loading grpah question [message #653866 is a reply to message #653857] Fri, 11 February 2011 15:48 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2359
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Eddie,
you could start from here: http://jung.sourceforge.net/support.html
Best,
Ivan

On 2/11/2011 5:26 PM, Eddie wrote:
> oh sorry...
> where can i ask the jung question?
Previous Topic:Controlling the Scrollbar position in a Text Widget
Next Topic:porting a single user app to RAP
Goto Forum:
  


Current Time: Sat Oct 23 03:10:09 GMT 2021

Powered by FUDForum. Page generated in 0.01762 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top