Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Alpha version of the GexfWriter

  • Loading branch information...
commit c5fd84cffecebfe77a1041a5a9d02756a64e31af 1 parent f4a9981
@jmcampanini authored
Showing with 573 additions and 321 deletions.
  1. +1 −1  pom.xml
  2. +3 −0  src/main/java/com/ojn/gexf4j/core/Gexf.java
  3. +3 −2 src/main/java/com/ojn/gexf4j/core/Graph.java
  4. +2 −2 src/main/java/com/ojn/gexf4j/core/Node.java
  5. +6 −0 src/main/java/com/ojn/gexf4j/core/data/AttributeList.java
  6. +10 −0 src/main/java/com/ojn/gexf4j/core/data/AttributeValueList.java
  7. +1 −3 src/main/java/com/ojn/gexf4j/core/data/Datum.java
  8. +12 −0 src/main/java/com/ojn/gexf4j/core/impl/GexfImpl.java
  9. +8 −16 src/main/java/com/ojn/gexf4j/core/impl/GraphImpl.java
  10. +21 −6 src/main/java/com/ojn/gexf4j/core/impl/NodeImpl.java
  11. +5 −7 src/main/java/com/ojn/gexf4j/core/impl/SliceableDatumBase.java
  12. +5 −20 src/main/java/com/ojn/gexf4j/core/impl/StaxGraphReader.java
  13. +2 −2 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeImpl.java
  14. +30 −0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeListImpl.java
  15. +1 −0  src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueImpl.java
  16. +34 −0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueListImpl.java
  17. +1 −1  src/main/java/com/ojn/gexf4j/core/impl/dynamic/DynamicBase.java
  18. +2 −8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgeEntityParser.java
  19. +2 −8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgesEntityParser.java
  20. +2 −6 src/main/java/com/ojn/gexf4j/core/impl/reader/GexfEntityParser.java
  21. +4 −9 src/main/java/com/ojn/gexf4j/core/impl/reader/GraphEntityParser.java
  22. +2 −11 src/main/java/com/ojn/gexf4j/core/impl/reader/MetaEntityParser.java
  23. +1 −1  src/main/java/com/ojn/gexf4j/core/impl/viz/NodeShapeImpl.java
  24. +5 −1 src/main/java/com/ojn/gexf4j/core/impl/writer/AbstractEntityWriter.java
  25. +14 −7 src/main/java/com/ojn/gexf4j/core/impl/writer/GexfEntityWriter.java
  26. +7 −2 src/main/java/com/ojn/gexf4j/core/impl/writer/GraphEntityWriter.java
  27. +4 −11 src/main/java/com/ojn/gexf4j/core/impl/writer/NodeEntityWriter.java
  28. +17 −11 src/test/java/com/ojn/gexf4j/core/GraphWriterTest.java
  29. +2 −2 src/test/java/com/ojn/gexf4j/core/impl/StaxGraphWriterTest.java
  30. +12 −15 src/test/java/com/ojn/gexf4j/core/testgraphs/BasicGraphBuilder.java
  31. +49 −45 src/test/java/com/ojn/gexf4j/core/testgraphs/DataGraphBuilder.java
  32. +100 −71 src/test/java/com/ojn/gexf4j/core/testgraphs/DynamicGraphBuilder.java
  33. +26 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/GexfBuilder.java
  34. +0 −10 src/test/java/com/ojn/gexf4j/core/testgraphs/GraphBuilder.java
  35. +52 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyInlineBuilder.java
  36. +60 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyPIDBuilder.java
  37. +0 −43 src/test/java/com/ojn/gexf4j/core/testgraphs/MetaDataGraphBuilder.java
  38. +31 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/PhylogenyBuilder.java
  39. +36 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/VisualizationBuilder.java
View
2  pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ojn.gexf4j</groupId>
<artifactId>gexf4j-core</artifactId>
- <version>0.1.0</version>
+ <version>0.2.0-ALPHA</version>
<name>gexf4j-core</name>
<build>
<plugins>
View
3  src/main/java/com/ojn/gexf4j/core/Gexf.java
@@ -12,4 +12,7 @@
Metadata getMetadata();
Graph getGraph();
+
+ boolean hasVisualization();
+ Gexf setVisualization(boolean viz);
}
View
5 src/main/java/com/ojn/gexf4j/core/Graph.java
@@ -1,5 +1,7 @@
package com.ojn.gexf4j.core;
+import java.util.List;
+
import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.dynamic.Dynamic;
import com.ojn.gexf4j.core.dynamic.TimeType;
@@ -18,6 +20,5 @@
TimeType getTimeType();
Graph setTimeType(TimeType timeType);
- AttributeList getNodeAttributes();
- AttributeList getEdgeAttributes();
+ List<AttributeList> getAttributeLists();
}
View
4 src/main/java/com/ojn/gexf4j/core/Node.java
@@ -43,6 +43,6 @@
boolean hasPID();
Node clearPID();
- Node getPID();
- Node setPID(Node pid);
+ String getPID();
+ Node setPID(String pid);
}
View
6 src/main/java/com/ojn/gexf4j/core/data/AttributeList.java
@@ -11,4 +11,10 @@
Mode getMode();
AttributeList setMode(Mode mode);
+
+ Attribute createAttribute(AttributeType type, String title);
+ Attribute createAttribute(String id, AttributeType type, String title);
+
+ AttributeList addAttribute(AttributeType type, String title);
+ AttributeList addAttribute(String id, AttributeType type, String title);
}
View
10 src/main/java/com/ojn/gexf4j/core/data/AttributeValueList.java
@@ -0,0 +1,10 @@
+package com.ojn.gexf4j.core.data;
+
+import java.util.List;
+
+public interface AttributeValueList extends List<AttributeValue> {
+
+ AttributeValueList addValue(Attribute attribute, String value);
+
+ AttributeValue createValue(Attribute attribute, String value);
+}
View
4 src/main/java/com/ojn/gexf4j/core/data/Datum.java
@@ -1,8 +1,6 @@
package com.ojn.gexf4j.core.data;
-import java.util.List;
-
public interface Datum {
- List<AttributeValue> getAttributeValues();
+ AttributeValueList getAttributeValues();
}
View
12 src/main/java/com/ojn/gexf4j/core/impl/GexfImpl.java
@@ -13,6 +13,7 @@
private String variant = null;
private Graph graph = null;
private Metadata meta = null;
+ private boolean viz = false;
public GexfImpl() {
graph = new GraphImpl();
@@ -58,4 +59,15 @@ public Gexf setVariant(String variant) {
this.variant = variant;
return this;
}
+
+ @Override
+ public boolean hasVisualization() {
+ return viz;
+ }
+
+ @Override
+ public Gexf setVisualization(boolean viz) {
+ this.viz = viz;
+ return this;
+ }
}
View
24 src/main/java/com/ojn/gexf4j/core/impl/GraphImpl.java
@@ -12,25 +12,21 @@
import com.ojn.gexf4j.core.IDType;
import com.ojn.gexf4j.core.Mode;
import com.ojn.gexf4j.core.Node;
-import com.ojn.gexf4j.core.data.AttributeClass;
import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.dynamic.TimeType;
-import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
import com.ojn.gexf4j.core.impl.dynamic.DynamicBase;
public class GraphImpl extends DynamicBase<Graph> implements Graph {
private EdgeType edgeType = EdgeType.UNDIRECTED;
- private AttributeList edgeAttributeList = null;
- private AttributeList nodeAttributeList = null;
+ private List<AttributeList> attributeLists = null;
private IDType idType = IDType.STRING;
private Mode mode = Mode.STATIC;
private List<Node> nodes = null;
private TimeType timeType = TimeType.DATE;
public GraphImpl() {
- edgeAttributeList = new AttributeListImpl(AttributeClass.EDGE);
- nodeAttributeList = new AttributeListImpl(AttributeClass.NODE);
+ attributeLists = new ArrayList<AttributeList>();
nodes = new ArrayList<Node>();
}
@@ -45,11 +41,6 @@ public EdgeType getDefaultEdgeType() {
}
@Override
- public AttributeList getEdgeAttributes() {
- return edgeAttributeList;
- }
-
- @Override
public IDType getIDType() {
return idType;
}
@@ -60,11 +51,6 @@ public Mode getMode() {
}
@Override
- public AttributeList getNodeAttributes() {
- return nodeAttributeList;
- }
-
- @Override
public TimeType getTimeType() {
return timeType;
}
@@ -114,6 +100,7 @@ public Node createNode(String id) {
for (Node n : nodes) {
rv.addAll(n.getEdges());
+ rv.addAll(n.getAllEdges());
}
return rv;
@@ -123,4 +110,9 @@ public Node createNode(String id) {
public List<Node> getNodes() {
return nodes;
}
+
+ @Override
+ public List<AttributeList> getAttributeLists() {
+ return attributeLists;
+ }
}
View
27 src/main/java/com/ojn/gexf4j/core/impl/NodeImpl.java
@@ -9,7 +9,9 @@
import com.ojn.gexf4j.core.Edge;
import com.ojn.gexf4j.core.Node;
+import com.ojn.gexf4j.core.impl.viz.NodeShapeImpl;
import com.ojn.gexf4j.core.viz.Color;
+import com.ojn.gexf4j.core.viz.NodeShape;
import com.ojn.gexf4j.core.viz.NodeShapeEntity;
import com.ojn.gexf4j.core.viz.Position;
@@ -18,7 +20,7 @@
private String id = "";
private String label = "";
private Color color = null;
- private Node pid = null;
+ private String pid = null;
private Position position = null;
private NodeShapeEntity shape = null;
private float size = Float.MIN_VALUE;
@@ -38,6 +40,7 @@ public NodeImpl(String id) {
this.nodes = new ArrayList<Node>();
this.edges = new ArrayList<Edge>();
this.parentForList = new ArrayList<Node>();
+ this.shape = new NodeShapeImpl();
}
@Override
@@ -109,7 +112,7 @@ public String getLabel() {
}
@Override
- public Node getPID() {
+ public String getPID() {
checkState(hasPID(), "PID has not been set.");
return pid;
}
@@ -127,7 +130,6 @@ public Position getPosition() {
@Override
public NodeShapeEntity getShapeEntity() {
- checkState(hasShape(), "Shape has not been set.");
return shape;
}
@@ -149,7 +151,7 @@ public boolean hasPosition() {
@Override
public boolean hasShape() {
- return (shape != null);
+ return (shape.getNodeShape() != NodeShape.NOTSET);
}
@Override
@@ -165,8 +167,9 @@ public Node setLabel(String label) {
}
@Override
- public Node setPID(Node pid) {
+ public Node setPID(String pid) {
checkArgument(pid != null, "PID cannot be null.");
+ checkArgument(!pid.trim().isEmpty(), "PID cannot be empty or blank.");
this.pid = pid;
return this;
}
@@ -240,9 +243,21 @@ public Node createNode(String id) {
List<Edge> rv = new ArrayList<Edge>();
for (Node n : getNodes()) {
- rv.addAll(n.getEdges());
+ _getEdges(rv, n);
}
return rv;
}
+
+ private List<Edge> _getEdges(List<Edge> soFar, Node n) {
+ // add the nodes' edges
+ soFar.addAll(n.getEdges());
+
+ // call this function on all of the sub nodes
+ for (Node subNode : n.getNodes()) {
+ _getEdges(soFar, subNode);
+ }
+
+ return soFar;
+ }
}
View
12 src/main/java/com/ojn/gexf4j/core/impl/SliceableDatumBase.java
@@ -1,22 +1,20 @@
package com.ojn.gexf4j.core.impl;
-import java.util.ArrayList;
-import java.util.List;
-
import com.ojn.gexf4j.core.SlicableDatum;
-import com.ojn.gexf4j.core.data.AttributeValue;
+import com.ojn.gexf4j.core.data.AttributeValueList;
+import com.ojn.gexf4j.core.impl.data.AttributeValueListImpl;
import com.ojn.gexf4j.core.impl.dynamic.SlicableBase;
public abstract class SliceableDatumBase<T extends Object> extends SlicableBase<T> implements SlicableDatum<T> {
- private List<AttributeValue> attributes = null;
+ private AttributeValueList attributes = null;
public SliceableDatumBase() {
- attributes = new ArrayList<AttributeValue>();
+ attributes = new AttributeValueListImpl();
}
@Override
- public List<AttributeValue> getAttributeValues() {
+ public AttributeValueList getAttributeValues() {
return attributes;
}
}
View
25 src/main/java/com/ojn/gexf4j/core/impl/StaxGraphReader.java
@@ -3,30 +3,15 @@
import java.io.IOException;
import java.io.InputStream;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import com.ojn.gexf4j.core.Graph;
+import com.ojn.gexf4j.core.Gexf;
import com.ojn.gexf4j.core.GexfReader;
-import com.ojn.gexf4j.core.impl.reader.GexfEntityParser;
public class StaxGraphReader implements GexfReader {
@Override
- public Graph readFromStream(InputStream in) throws IOException {
-
- try {
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- XMLStreamReader reader = inputFactory.createXMLStreamReader(in);
-
- GexfEntityParser gexfParser = new GexfEntityParser(reader);
-
- return gexfParser.getGraph();
-
- } catch (XMLStreamException e) {
- e.printStackTrace();
- return null;
- }
+ public Gexf readFromStream(InputStream in) throws IOException {
+ // TODO Auto-generated method stub
+ return null;
}
+
}
View
4 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeImpl.java
@@ -20,9 +20,9 @@
public AttributeImpl(String id, AttributeType type, String title) {
checkArgument(id != null, "ID cannot be null.");
- checkArgument(id.trim().isEmpty(), "ID cannot be null or blank.");
+ checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
checkArgument(title != null, "Title cannot be null.");
- checkArgument(title.trim().isEmpty(), "Title cannot be null or blank.");
+ checkArgument(!title.trim().isEmpty(), "Title cannot be null or blank.");
this.id = id;
this.type = type;
View
30 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeListImpl.java
@@ -5,11 +5,13 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.UUID;
import com.ojn.gexf4j.core.Mode;
import com.ojn.gexf4j.core.data.Attribute;
import com.ojn.gexf4j.core.data.AttributeClass;
import com.ojn.gexf4j.core.data.AttributeList;
+import com.ojn.gexf4j.core.data.AttributeType;
public class AttributeListImpl extends ArrayList<Attribute> implements AttributeList {
private static final long serialVersionUID = 8240096318919688740L;
@@ -90,4 +92,32 @@ public AttributeList setStartDate(Date startDate) {
this.endDate = startDate;
return this;
}
+
+ @Override
+ public Attribute createAttribute(AttributeType type, String title) {
+ return createAttribute(UUID.randomUUID().toString(), type, title);
+ }
+
+ @Override
+ public Attribute createAttribute(String id, AttributeType type, String title) {
+ checkArgument(id != null, "ID cannot be null.");
+ checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
+ checkArgument(title != null, "Title cannot be null.");
+ checkArgument(!title.trim().isEmpty(), "Title cannot be empty or blank.");
+
+ Attribute rv = new AttributeImpl(id, type, title);
+ this.add(rv);
+ return rv;
+ }
+
+ @Override
+ public AttributeList addAttribute(AttributeType type, String title) {
+ return addAttribute(UUID.randomUUID().toString(), type, title);
+ }
+
+ @Override
+ public AttributeList addAttribute(String id, AttributeType type, String title) {
+ createAttribute(id, type, title);
+ return this;
+ }
}
View
1  src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueImpl.java
@@ -34,6 +34,7 @@ public String getValue() {
@Override
public AttributeValue setValue(String value) {
checkArgument(value != null, "Value cannot be null.");
+ this.value = value;
return this;
}
}
View
34 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueListImpl.java
@@ -0,0 +1,34 @@
+package com.ojn.gexf4j.core.impl.data;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.ArrayList;
+
+import com.ojn.gexf4j.core.data.Attribute;
+import com.ojn.gexf4j.core.data.AttributeValue;
+import com.ojn.gexf4j.core.data.AttributeValueList;
+
+public class AttributeValueListImpl extends ArrayList<AttributeValue> implements AttributeValueList {
+ private static final long serialVersionUID = 7730475001078826140L;
+
+ public AttributeValueListImpl() {
+ // do nothing
+ }
+
+ @Override
+ public AttributeValueList addValue(Attribute attribute, String value) {
+ createValue(attribute, value);
+ return this;
+ }
+
+ @Override
+ public AttributeValue createValue(Attribute attribute, String value) {
+ checkArgument(value != null, "Value cannot be null.");
+
+ AttributeValue rv = new AttributeValueImpl(attribute);
+ rv.setValue(value);
+ add(rv);
+
+ return rv;
+ }
+}
View
2  src/main/java/com/ojn/gexf4j/core/impl/dynamic/DynamicBase.java
@@ -61,7 +61,7 @@ public T setEndDate(Date endDate) {
@Override
public T setStartDate(Date startDate) {
checkArgument(startDate != null, "Start Date cannot be null.");
- this.endDate = startDate;
+ this.startDate = startDate;
return getSelf();
}
}
View
10 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgeEntityParser.java
@@ -1,13 +1,7 @@
package com.ojn.gexf4j.core.impl.reader;
-import javax.xml.stream.XMLStreamReader;
-import com.ojn.gexf4j.core.Edge;
-import com.ojn.gexf4j.core.EdgeType;
-import com.ojn.gexf4j.core.Graph;
-import com.ojn.gexf4j.core.Node;
-
-public class EdgeEntityParser extends AbstractEntityParser<Edge> {
+public class EdgeEntityParser { /*extends AbstractEntityParser<Edge> {
private static final String ATTRIB_ID = "id";
private static final String ATTRIB_LABEL = "label";
private static final String ATTRIB_SOURCE = "source";
@@ -76,5 +70,5 @@ protected void onEndElement() {
e.setEdgeType(type);
e.setLabel(label);
e.setWeight(weight);
- }
+ }*/
}
View
10 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgesEntityParser.java
@@ -1,13 +1,7 @@
package com.ojn.gexf4j.core.impl.reader;
-import java.util.List;
-import javax.xml.stream.XMLStreamReader;
-
-import com.ojn.gexf4j.core.Edge;
-import com.ojn.gexf4j.core.Graph;
-
-public class EdgesEntityParser extends AbstractEntityParser<List<Edge>> {
+public class EdgesEntityParser { /*extends AbstractEntityParser<List<Edge>> {
private static final String ENTITY_EDGE = "edge";
private Graph graph = null;
@@ -43,5 +37,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
@Override
protected void onEndElement() {
// do nothing
- }
+ }*/
}
View
8 src/main/java/com/ojn/gexf4j/core/impl/reader/GexfEntityParser.java
@@ -1,11 +1,7 @@
package com.ojn.gexf4j.core.impl.reader;
-import javax.xml.stream.XMLStreamReader;
-import com.ojn.gexf4j.core.Graph;
-import com.ojn.gexf4j.core.impl.GraphImpl;
-
-public class GexfEntityParser extends AbstractEntityParser<Graph> {
+public class GexfEntityParser { /*extends AbstractEntityParser<Graph> {
private static final String ATTRIB_VERSION = "version";
private static final String ENTITY_META = "meta";
private static final String ENTITY_GRAPH = "graph";
@@ -52,5 +48,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
@Override
protected void onEndElement() {
// do nothing
- }
+ } */
}
View
13 src/main/java/com/ojn/gexf4j/core/impl/reader/GraphEntityParser.java
@@ -1,12 +1,7 @@
package com.ojn.gexf4j.core.impl.reader;
-import javax.xml.stream.XMLStreamReader;
-import com.ojn.gexf4j.core.EdgeType;
-import com.ojn.gexf4j.core.Graph;
-import com.ojn.gexf4j.core.Mode;
-
-public class GraphEntityParser extends AbstractEntityParser<Graph> {
+public class GraphEntityParser { /*extends AbstractEntityParser<Graph> {
private static final String ATTRIB_EDGETYPE = "defaultedgetype";
private static final String ATTRIB_MODE = "mode";
private static final String ENTITY_ATTRIBUTES = "attributes";
@@ -34,12 +29,12 @@ protected void onAttribute(String name, String value) {
@Override
protected void onStartElement(XMLStreamReader reader) {
if (ENTITY_ATTRIBUTES.equalsIgnoreCase(reader.getLocalName())) {
- /*AttributesEntityParser aep = new AttributesEntityParser(reader);
+ AttributesEntityParser aep = new AttributesEntityParser(reader);
if (aep.getAttClass() == AttributeClass.NODE) {
attribsNodes = aep.getEntity();
} else if (aep.getAttClass() == AttributeClass.EDGE) {
attribsEdges = aep.getEntity();
- }*/
+ }
} else if (ENTITY_NODES.equalsIgnoreCase(reader.getLocalName())) {
new NodesEntityParser(reader, graph);
@@ -62,5 +57,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
@Override
protected void onEndElement() {
// do nothing
- }
+ } */
}
View
13 src/main/java/com/ojn/gexf4j/core/impl/reader/MetaEntityParser.java
@@ -1,16 +1,7 @@
package com.ojn.gexf4j.core.impl.reader;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import javax.xml.stream.XMLStreamReader;
-
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-import com.ojn.gexf4j.core.Graph;
-import com.ojn.gexf4j.core.Metadata;
-
-public class MetaEntityParser extends AbstractEntityParser<Metadata> {
+public class MetaEntityParser { /*extends AbstractEntityParser<Metadata> {
private static final String ENTITY_CREATOR = "creator";
private static final String ENTITY_DESCRIPTION = "description";
private static final String ENTITY_KEYWORDS = "keywords";
@@ -73,5 +64,5 @@ protected void onCharacters(XMLStreamReader reader) {
@Override
protected void onOther(XMLStreamReader reader, int eventType) {
// do nothing
- }
+ } */
}
View
2  src/main/java/com/ojn/gexf4j/core/impl/viz/NodeShapeImpl.java
@@ -7,7 +7,7 @@
public class NodeShapeImpl implements NodeShapeEntity {
- private NodeShape shape = NodeShape.DISC;
+ private NodeShape shape = NodeShape.NOTSET;
private String uri = null;
public NodeShapeImpl() {
View
6 src/main/java/com/ojn/gexf4j/core/impl/writer/AbstractEntityWriter.java
@@ -35,7 +35,7 @@ public AbstractEntityWriter(XMLStreamWriter writer, T entity) {
protected void write() {
try {
- writer.writeStartElement(getElementName());
+ writeStartElement();
writeAttributes();
writeElements();
@@ -46,4 +46,8 @@ protected void write() {
e.printStackTrace();
}
}
+
+ protected void writeStartElement() throws XMLStreamException {
+ writer.writeStartElement(getElementName());
+ }
}
View
21 src/main/java/com/ojn/gexf4j/core/impl/writer/GexfEntityWriter.java
@@ -9,9 +9,10 @@
private static final String ENTITY = "gexf";
private static final String ATTRIBUTE_VERSION = "version";
private static final String ATTRIBUTE_VARIANT = "variant";
- private static final String ATTRIBUTE_XMLNS = "xmlns";
- private static final String VALUE_XMLNS = "http://www.gexf.net/1.1draft";
-
+ private static final String XMLNS_URL = "http://www.gexf.net/1.1draft";
+ private static final String XMLNS_VIZ = "viz";
+ private static final String XMLNS_VIZ_URL = "http://www.gexf.net/1.1draft/viz";
+
public GexfEntityWriter(XMLStreamWriter writer, Gexf entity) {
super(writer, entity);
write();
@@ -28,10 +29,6 @@ protected void writeAttributes() throws XMLStreamException {
ATTRIBUTE_VERSION,
entity.getVersion());
- writer.writeAttribute(
- ATTRIBUTE_XMLNS,
- VALUE_XMLNS);
-
if (entity.hasVariant()) {
writer.writeAttribute(
ATTRIBUTE_VARIANT,
@@ -40,6 +37,16 @@ protected void writeAttributes() throws XMLStreamException {
}
@Override
+ protected void writeStartElement() throws XMLStreamException {
+ writer.writeStartElement(getElementName());
+ writer.writeDefaultNamespace(XMLNS_URL);
+
+ if (entity.hasVisualization()) {
+ writer.writeNamespace(XMLNS_VIZ, XMLNS_VIZ_URL);
+ }
+ }
+
+ @Override
protected void writeElements() throws XMLStreamException {
new MetadataEntityWriter(writer, entity.getMetadata());
new GraphEntityWriter(writer, entity.getGraph());
View
9 src/main/java/com/ojn/gexf4j/core/impl/writer/GraphEntityWriter.java
@@ -4,6 +4,7 @@
import javax.xml.stream.XMLStreamWriter;
import com.ojn.gexf4j.core.Graph;
+import com.ojn.gexf4j.core.data.AttributeList;
public class GraphEntityWriter extends DynamicEntityWriter<Graph> {
private static final String ENTITY = "graph";
@@ -41,13 +42,17 @@ protected void writeAttributes() throws XMLStreamException {
entity.getTimeType().toString().toLowerCase());
AbstractEntityWriter.writerTimeType = entity.getTimeType();
+ super.writeAttributes();
}
@Override
protected void writeElements() throws XMLStreamException {
- new AttributesEntityWriter(writer, entity.getNodeAttributes());
- new AttributesEntityWriter(writer, entity.getEdgeAttributes());
+ for (AttributeList attList : entity.getAttributeLists()) {
+ new AttributesEntityWriter(writer, attList);
+ }
+
new NodesEntityWriter(writer, entity.getNodes());
new EdgesEntityWriter(writer, entity.getAllEdges());
+ super.writeElements();
}
}
View
15 src/main/java/com/ojn/gexf4j/core/impl/writer/NodeEntityWriter.java
@@ -36,7 +36,7 @@ protected void writeAttributes() throws XMLStreamException {
if (entity.hasPID()) {
writer.writeAttribute(
ATTRIB_PID,
- entity.getPID().getId());
+ entity.getPID());
}
}
@@ -65,14 +65,7 @@ protected void writeElements() throws XMLStreamException {
new ParentsEntityWriter(writer, entity.getParentForList());
new NodesEntityWriter(writer, entity.getNodes());
- new EdgesEntityWriter(writer, entity.getAllEdges());
+ // TODO: Verify this is supposed to be commented out.
+ // new EdgesEntityWriter(writer, entity.getAllEdges());
}
-}
-
-
-
-/*
-edge
-viz:thickness ???
-viz:shape [viz:edge-shape] ???
-*/
+}
View
28 src/test/java/com/ojn/gexf4j/core/GraphWriterTest.java
@@ -23,8 +23,11 @@
import com.ojn.gexf4j.core.testgraphs.BasicGraphBuilder;
import com.ojn.gexf4j.core.testgraphs.DataGraphBuilder;
import com.ojn.gexf4j.core.testgraphs.DynamicGraphBuilder;
-import com.ojn.gexf4j.core.testgraphs.GraphBuilder;
-import com.ojn.gexf4j.core.testgraphs.MetaDataGraphBuilder;
+import com.ojn.gexf4j.core.testgraphs.GexfBuilder;
+import com.ojn.gexf4j.core.testgraphs.HierarchyInlineBuilder;
+import com.ojn.gexf4j.core.testgraphs.HierarchyPIDBuilder;
+import com.ojn.gexf4j.core.testgraphs.PhylogenyBuilder;
+import com.ojn.gexf4j.core.testgraphs.VisualizationBuilder;
@RunWith(Parameterized.class)
public abstract class GraphWriterTest {
@@ -32,35 +35,38 @@
protected abstract String getFileNamePrefix();
protected abstract GexfWriter newGraphWriter();
- protected GraphBuilder builder = null;
+ protected GexfBuilder builder = null;
@Parameters
public static List<Object[]> getData() {
List<Object[]> rv = new ArrayList<Object[]>();
- rv.add(new GraphBuilder[] { new BasicGraphBuilder() });
- rv.add(new GraphBuilder[] { new DataGraphBuilder() });
- rv.add(new GraphBuilder[] { new MetaDataGraphBuilder() });
- rv.add(new GraphBuilder[] { new DynamicGraphBuilder() });
+ rv.add(new GexfBuilder[] { new BasicGraphBuilder() });
+ rv.add(new GexfBuilder[] { new DataGraphBuilder() });
+ rv.add(new GexfBuilder[] { new DynamicGraphBuilder() });
+ rv.add(new GexfBuilder[] { new HierarchyInlineBuilder() });
+ rv.add(new GexfBuilder[] { new HierarchyPIDBuilder() });
+ rv.add(new GexfBuilder[] { new PhylogenyBuilder() });
+ rv.add(new GexfBuilder[] { new VisualizationBuilder() });
return rv;
}
- public GraphWriterTest(GraphBuilder builder) {
+ public GraphWriterTest(GexfBuilder builder) {
this.builder = builder;
}
@Test
public void writeToStream() throws SAXException, IOException {
- Graph g = builder.buildGraph();
+ Gexf gexf = builder.buildGexf();
GexfWriter gw = newGraphWriter();
String fileName = "target/" + getFileNamePrefix() + "_" + builder.getSuffix() + ".gexf";
File f = new File(fileName);
FileOutputStream fos = new FileOutputStream(f);
- gw.writeToStream(g, fos);
+ gw.writeToStream(gexf, fos);
- URL schemaFile = new URL(builder.getXsdUrl());
+ URL schemaFile = new URL(builder.getSchemaUrl());
Source xmlFile = new StreamSource(f);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
View
4 src/test/java/com/ojn/gexf4j/core/impl/StaxGraphWriterTest.java
@@ -2,11 +2,11 @@
import com.ojn.gexf4j.core.GexfWriter;
import com.ojn.gexf4j.core.GraphWriterTest;
-import com.ojn.gexf4j.core.testgraphs.GraphBuilder;
+import com.ojn.gexf4j.core.testgraphs.GexfBuilder;
public class StaxGraphWriterTest extends GraphWriterTest {
- public StaxGraphWriterTest(GraphBuilder builder) {
+ public StaxGraphWriterTest(GexfBuilder builder) {
super(builder);
}
View
27 src/test/java/com/ojn/gexf4j/core/testgraphs/BasicGraphBuilder.java
@@ -1,10 +1,11 @@
package com.ojn.gexf4j.core.testgraphs;
+import com.ojn.gexf4j.core.Gexf;
import com.ojn.gexf4j.core.Graph;
import com.ojn.gexf4j.core.Node;
-import com.ojn.gexf4j.core.impl.GraphImpl;
+import com.ojn.gexf4j.core.impl.GexfImpl;
-public class BasicGraphBuilder implements GraphBuilder {
+public class BasicGraphBuilder extends GexfBuilder {
@Override
public String getSuffix() {
@@ -12,21 +13,17 @@ public String getSuffix() {
}
@Override
- public String getXsdUrl() {
- return "http://gexf.net/1.1draft/gexf.xsd";
- }
-
- @Override
- public Graph buildGraph() {
- Graph g = new GraphImpl();
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+ Graph g = gexf.getGraph();
- Node n1 = g.createNode();
- Node n2 = g.createNode();
- Node n3 = g.createNode();
+ Node hello = g.createNode("0")
+ .setLabel("Hello");
+ Node world = g.createNode("1")
+ .setLabel("World");
- n1.connectTo(n2);
- n1.connectTo(n3);
+ hello.connectTo("0", world);
- return g;
+ return gexf;
}
}
View
94 src/test/java/com/ojn/gexf4j/core/testgraphs/DataGraphBuilder.java
@@ -1,69 +1,73 @@
package com.ojn.gexf4j.core.testgraphs;
-import com.ojn.gexf4j.core.Graph;
+import com.ojn.gexf4j.core.Gexf;
import com.ojn.gexf4j.core.Node;
import com.ojn.gexf4j.core.data.Attribute;
import com.ojn.gexf4j.core.data.AttributeClass;
+import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.data.AttributeType;
-import com.ojn.gexf4j.core.impl.GraphImpl;
-import com.ojn.gexf4j.core.impl.data.AttributeImpl;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
-public class DataGraphBuilder implements GraphBuilder {
+public class DataGraphBuilder extends GexfBuilder {
+
@Override
public String getSuffix() {
return "data";
}
@Override
- public String getXsdUrl() {
- return "http://gexf.net/1.1draft/gexf.xsd";
- }
-
- @Override
- public Graph buildGraph() {
- Graph rv = new GraphImpl();
-
- Attribute attribUrl = new AttributeImpl(AttributeType.STRING, "0", AttributeClass.NODE);
- Attribute attribInDegree = new AttributeImpl(AttributeType.STRING, "1", AttributeClass.NODE);
- Attribute attribFrog = new AttributeImpl(AttributeType.STRING, "2", AttributeClass.NODE);
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
- attribUrl.setTitle("url");
- attribInDegree.setTitle("indegree");
- attribFrog.setTitle("frog");
+ gexf.getMetadata()
+ .setLastModified(toDate("2009-03-20"))
+ .setCreator("Gephi.org")
+ .setDescription("A Web network");
- rv.getNodeAttributes().add(attribUrl);
- rv.getNodeAttributes().add(attribInDegree);
- rv.getNodeAttributes().add(attribFrog);
+ AttributeList attrList = new AttributeListImpl(AttributeClass.NODE);
+ gexf.getGraph().getAttributeLists().add(attrList);
- Node nGephi = rv.createNode("0");
- nGephi.setLabel("Gephi");
- nGephi.getAttributeValues().add(attribUrl.createValue("http://gephi.org"));
- nGephi.getAttributeValues().add(attribInDegree.createValue("1"));
+ Attribute attUrl = attrList.createAttribute("0", AttributeType.STRING, "url");
+ Attribute attIndegree = attrList.createAttribute("1", AttributeType.FLOAT, "indegree");
+ Attribute attFrog = attrList.createAttribute("2", AttributeType.BOOLEAN, "frog")
+ .setDefaultValue("true");
- Node nWebatlas = rv.createNode("1");
- nWebatlas.setLabel("Webatlas");
- nWebatlas.getAttributeValues().add(attribUrl.createValue("http://webatlas.fr"));
- nWebatlas.getAttributeValues().add(attribInDegree.createValue("2"));
+ Node gephi = gexf.getGraph().createNode("0");
+ gephi
+ .setLabel("Gephi")
+ .getAttributeValues()
+ .addValue(attUrl, "http://gephi.org")
+ .addValue(attIndegree, "1");
- Node nRTGI = rv.createNode("2");
- nRTGI.setLabel("RTGI");
- nRTGI.getAttributeValues().add(attribUrl.createValue("http://rtgi.fr"));
- nRTGI.getAttributeValues().add(attribInDegree.createValue("1"));
+ Node webatlas = gexf.getGraph().createNode("1");
+ webatlas
+ .setLabel("Webatlas")
+ .getAttributeValues()
+ .addValue(attUrl, "http://webatlas.fr")
+ .addValue(attIndegree, "2");
- Node nBar = rv.createNode("3");
- nBar.setLabel("BarabasiLab");
- nBar.getAttributeValues().add(attribUrl.createValue("http://barabasilab.com"));
- nBar.getAttributeValues().add(attribInDegree.createValue("1"));
- nBar.getAttributeValues().add(attribFrog.createValue("false"));
+ Node rtgi = gexf.getGraph().createNode("2");
+ rtgi
+ .setLabel("RTGI")
+ .getAttributeValues()
+ .addValue(attUrl, "http://rtgi.fr")
+ .addValue(attIndegree, "1");
- nGephi.connectTo("0", nWebatlas);
- nGephi.connectTo("1", nRTGI);
- nWebatlas.connectTo("2", nGephi);
- nRTGI.connectTo("3", nWebatlas);
- nGephi.connectTo("4", nBar);
+ Node blab = gexf.getGraph().createNode("3");
+ blab
+ .setLabel("BarabasiLab")
+ .getAttributeValues()
+ .addValue(attUrl, "http://barabasilab.com")
+ .addValue(attIndegree, "1")
+ .addValue(attFrog, "false");
- nGephi.getEdges().get(0).getAttributeValues().add(attribFrog.createValue("true"));
+ gephi.connectTo("0", webatlas);
+ gephi.connectTo("1", rtgi);
+ webatlas.connectTo("2", gephi);
+ rtgi.connectTo("3", webatlas);
+ gephi.connectTo("4", blab);
- return rv;
+ return gexf;
}
}
View
171 src/test/java/com/ojn/gexf4j/core/testgraphs/DynamicGraphBuilder.java
@@ -1,19 +1,17 @@
package com.ojn.gexf4j.core.testgraphs;
-import java.util.Date;
-
-import com.ojn.gexf4j.core.Graph;
+import com.ojn.gexf4j.core.Gexf;
+import com.ojn.gexf4j.core.Mode;
import com.ojn.gexf4j.core.Node;
import com.ojn.gexf4j.core.data.Attribute;
import com.ojn.gexf4j.core.data.AttributeClass;
+import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.data.AttributeType;
-import com.ojn.gexf4j.core.impl.EdgeImpl;
-import com.ojn.gexf4j.core.impl.GraphImpl;
-import com.ojn.gexf4j.core.impl.NodeImpl;
-import com.ojn.gexf4j.core.impl.data.AttributeImpl;
-import com.ojn.gexf4j.core.impl.data.AttributeValueImpl;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
+import com.ojn.gexf4j.core.impl.dynamic.SliceImpl;
-public class DynamicGraphBuilder implements GraphBuilder {
+public class DynamicGraphBuilder extends GexfBuilder {
@Override
public String getSuffix() {
@@ -21,67 +19,98 @@ public String getSuffix() {
}
@Override
- public String getXsdUrl() {
- return "http://gexf.net/1.1draft/gexf.xsd";
- }
-
- @Override
- public Graph buildGraph() {
- GraphImpl rv = new GraphImpl();
-
- rv.setStartDate(new Date());
-
- Attribute attribUrl = new AttributeImpl(AttributeType.STRING, "0", AttributeClass.NODE);
- Attribute attribInDegree = new AttributeImpl(AttributeType.STRING, "1", AttributeClass.NODE);
- Attribute attribFrog = new AttributeImpl(AttributeType.STRING, "2", AttributeClass.NODE);
-
- attribUrl.setTitle("url");
- attribInDegree.setTitle("indegree");
- attribFrog.setTitle("frog");
-
- rv.getNodeAttributes().add(attribUrl);
- rv.getNodeAttributes().add(attribInDegree);
- rv.getNodeAttributes().add(attribFrog);
-
- NodeImpl nGephi = (NodeImpl) rv.createNode("0");
- nGephi.setLabel("Gephi");
- nGephi.getAttributeValues().add(attribUrl.createValue("http://gephi.org"));
- nGephi.getAttributeValues().add(attribInDegree.createValue("1"));
-
- nGephi.setStartDate(new Date());
- nGephi.setEndDate(new Date());
-
- Node nWebatlas = rv.createNode("1");
- nWebatlas.setLabel("Webatlas");
- nWebatlas.getAttributeValues().add(attribUrl.createValue("http://webatlas.fr"));
- nWebatlas.getAttributeValues().add(attribInDegree.createValue("2"));
-
- Node nRTGI = rv.createNode("2");
- nRTGI.setLabel("RTGI");
- nRTGI.getAttributeValues().add(attribUrl.createValue("http://rtgi.fr"));
- nRTGI.getAttributeValues().add(attribInDegree.createValue("1"));
-
- Node nBar = rv.createNode("3");
- nBar.setLabel("BarabasiLab");
- nBar.getAttributeValues().add(attribUrl.createValue("http://barabasilab.com"));
- nBar.getAttributeValues().add(attribInDegree.createValue("1"));
- nBar.getAttributeValues().add(attribFrog.createValue("false"));
-
- AttributeValueImpl avi = (AttributeValueImpl) nBar.getAttributeValues().get(0);
- avi.setStartDate(new Date());
- avi.setEndDate(new Date());
-
- nGephi.connectTo("0", nWebatlas);
- nGephi.connectTo("1", nRTGI);
- nWebatlas.connectTo("2", nGephi);
- nRTGI.connectTo("3", nWebatlas);
- nGephi.connectTo("4", nBar);
-
- nGephi.getEdges().get(0).getAttributeValues().add(attribFrog.createValue("true"));
- EdgeImpl ei = (EdgeImpl) nGephi.getEdges().get(0);
- ei.setStartDate(new Date());
- ei.setEndDate(new Date());
-
- return rv;
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+
+ gexf.getMetadata()
+ .setLastModified(toDate("2009-03-20"))
+ .setCreator("Gexf.net")
+ .setDescription("A Web network changing over time");
+
+ gexf.getGraph()
+ .setStartDate(toDate("2009-01-01"))
+ .setEndDate(toDate("2009-03-20"));
+
+ AttributeList attrListStatic = new AttributeListImpl(AttributeClass.NODE);
+ gexf.getGraph().getAttributeLists().add(attrListStatic);
+
+ AttributeList attrListDynamic = new AttributeListImpl(AttributeClass.NODE)
+ .setMode(Mode.DYNAMIC);
+ gexf.getGraph().getAttributeLists().add(attrListDynamic);
+
+ Attribute attUrl = attrListStatic.createAttribute("0", AttributeType.STRING, "url");
+ Attribute attFrog = attrListStatic.createAttribute("1", AttributeType.BOOLEAN, "frog")
+ .setDefaultValue("true");
+
+ Attribute attIndegree = attrListDynamic.createAttribute("2", AttributeType.FLOAT, "indegree");
+
+ Node gephi = gexf.getGraph().createNode("0");
+ gephi
+ .setLabel("Gephi")
+ .setStartDate(toDate("2009-03-01"))
+ .getAttributeValues()
+ .addValue(attUrl, "http://gephi.org")
+ .addValue(attIndegree, "1");
+
+ Node webatlas = gexf.getGraph().createNode("1");
+ webatlas
+ .setLabel("Webatlas")
+ .getAttributeValues()
+ .addValue(attUrl, "http://webatlas.fr");
+
+ webatlas.getAttributeValues().createValue(attIndegree, "1")
+ .setEndDate(toDate("2009-03-01"));
+ webatlas.getAttributeValues().createValue(attIndegree, "2")
+ .setStartDate(toDate("2009-03-01"))
+ .setEndDate(toDate("2009-03-10"));
+ webatlas.getAttributeValues().createValue(attIndegree, "1")
+ .setStartDate(toDate("2009-03-10"));
+
+ Node rtgi = gexf.getGraph().createNode("2");
+ rtgi
+ .setLabel("RTGI")
+ .getAttributeValues()
+ .addValue(attUrl, "http://rtgi.fr");
+
+ rtgi.getAttributeValues().createValue(attIndegree, "0")
+ .setEndDate(toDate("2009-03-01"));
+ rtgi.getAttributeValues().createValue(attIndegree, "1")
+ .setStartDate(toDate("2009-03-01"));
+
+ rtgi.getSlices().add(new SliceImpl()
+ .setEndDate(toDate("2009-03-01")));
+ rtgi.getSlices().add(new SliceImpl()
+ .setStartDate(toDate("2009-03-05"))
+ .setEndDate(toDate("2009-03-10")));
+
+ Node blab = gexf.getGraph().createNode("3");
+ blab
+ .setLabel("BarabasiLab")
+ .getAttributeValues()
+ .addValue(attUrl, "http://barabasilab.com")
+ .addValue(attFrog, "false");
+
+ blab.getAttributeValues().createValue(attIndegree, "0")
+ .setEndDate(toDate("2009-03-01"));
+ blab.getAttributeValues().createValue(attIndegree, "1")
+ .setStartDate(toDate("2009-03-01"));
+
+ gephi.connectTo("0", webatlas)
+ .setStartDate(toDate("2009-03-01"));
+
+ gephi.connectTo("1", rtgi)
+ .setStartDate(toDate("2009-03-01"))
+ .setEndDate(toDate("2009-03-10"));
+
+ webatlas.connectTo("2", gephi)
+ .setStartDate(toDate("2009-03-01"));
+
+ rtgi.connectTo("3", webatlas)
+ .setEndDate(toDate("2009-03-10"));
+
+ gephi.connectTo("4",blab)
+ .setStartDate(toDate("2009-03-01"));
+
+ return gexf;
}
}
View
26 src/test/java/com/ojn/gexf4j/core/testgraphs/GexfBuilder.java
@@ -0,0 +1,26 @@
+package com.ojn.gexf4j.core.testgraphs;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.ojn.gexf4j.core.Gexf;
+
+public abstract class GexfBuilder {
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+ public abstract Gexf buildGexf();
+ public abstract String getSuffix();
+
+ protected Date toDate(String s) {
+ try {
+ return sdf.parse(s);
+ } catch (ParseException e) {
+ return null;
+ }
+ }
+
+ public String getSchemaUrl() {
+ return "http://gexf.net/1.1draft/gexf.xsd";
+ }
+}
View
10 src/test/java/com/ojn/gexf4j/core/testgraphs/GraphBuilder.java
@@ -1,10 +0,0 @@
-package com.ojn.gexf4j.core.testgraphs;
-
-import com.ojn.gexf4j.core.Graph;
-
-public interface GraphBuilder {
-
- Graph buildGraph();
- String getSuffix();
- String getXsdUrl();
-}
View
52 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyInlineBuilder.java
@@ -0,0 +1,52 @@
+package com.ojn.gexf4j.core.testgraphs;
+
+import com.ojn.gexf4j.core.EdgeType;
+import com.ojn.gexf4j.core.Gexf;
+import com.ojn.gexf4j.core.Mode;
+import com.ojn.gexf4j.core.Node;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+
+public class HierarchyInlineBuilder extends GexfBuilder {
+
+ @Override
+ public String getSuffix() {
+ return "hierarchyInline";
+ }
+
+ @Override
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+
+ gexf.getGraph()
+ .setMode(Mode.STATIC)
+ .setDefaultEdgeType(EdgeType.DIRECTED);
+
+ Node kb = gexf.getGraph().createNode("a");
+ kb.setLabel("Kevin Bacon");
+
+ Node god = kb.createNode("b");
+ god.setLabel("God");
+
+ Node c = god.createNode("c");
+ c.setLabel("human1");
+
+ Node d = god.createNode("d");
+ d.setLabel("human2");
+
+ Node me = kb.createNode("e");
+ me.setLabel("Me");
+
+ Node f = me.createNode("f");
+ f.setLabel("frog1");
+
+ Node g = me.createNode("g");
+ g.setLabel("frog2");
+
+ god.connectTo("0", me);
+ c.connectTo("1", d);
+ g.connectTo("2", god);
+ f.connectTo("3", kb);
+
+ return gexf;
+ }
+}
View
60 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyPIDBuilder.java
@@ -0,0 +1,60 @@
+package com.ojn.gexf4j.core.testgraphs;
+
+import com.ojn.gexf4j.core.EdgeType;
+import com.ojn.gexf4j.core.Gexf;
+import com.ojn.gexf4j.core.Mode;
+import com.ojn.gexf4j.core.Node;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+
+public class HierarchyPIDBuilder extends GexfBuilder {
+
+ @Override
+ public String getSuffix() {
+ return "hierarchyPID";
+ }
+
+ @Override
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+
+
+ gexf.getGraph()
+ .setMode(Mode.STATIC)
+ .setDefaultEdgeType(EdgeType.DIRECTED);
+
+ Node g = gexf.getGraph().createNode("g");
+ g.setLabel("frog2")
+ .setPID("e");
+
+ Node a = gexf.getGraph().createNode("a");
+ a.setLabel("Kevin Bacon");
+
+ Node c = gexf.getGraph().createNode("c");
+ c.setLabel("human1")
+ .setPID("b");
+
+ Node b = gexf.getGraph().createNode("b");
+ b.setLabel("God")
+ .setPID("a");
+
+ Node e = gexf.getGraph().createNode("e");
+ e.setLabel("Me")
+ .setPID("a");
+
+ Node d = gexf.getGraph().createNode("d");
+ d.setLabel("human2")
+ .setPID("b");
+
+ Node f = gexf.getGraph().createNode("f");
+ f.setLabel("frog1")
+ .setPID("e");
+
+
+ b.connectTo("0", e);
+ c.connectTo("1", d);
+ g.connectTo("2", b);
+ f.connectTo("3", a);
+
+ return gexf;
+ }
+}
View
43 src/test/java/com/ojn/gexf4j/core/testgraphs/MetaDataGraphBuilder.java
@@ -1,43 +0,0 @@
-package com.ojn.gexf4j.core.testgraphs;
-
-import java.util.Date;
-
-import com.ojn.gexf4j.core.Graph;
-import com.ojn.gexf4j.core.Node;
-import com.ojn.gexf4j.core.impl.GraphImpl;
-import com.ojn.gexf4j.core.impl.MetadataImpl;
-
-public class MetaDataGraphBuilder implements GraphBuilder {
-
- @Override
- public String getSuffix() {
- return "meta";
- }
-
- @Override
- public String getXsdUrl() {
- return "http://gexf.net/1.1draft/gexf.xsd";
- }
-
- @Override
- public Graph buildGraph() {
- Graph g = new GraphImpl();
-
- MetadataImpl meta = (MetadataImpl) g.getMetadata();
-
- meta.setCreator("creatorString");
- meta.setDescription("my description goes here");
- meta.setLastModified(new Date());
- meta.getKeywords().add("keyword1");
- meta.getKeywords().add("keyword2");
-
- Node n1 = g.createNode();
- Node n2 = g.createNode();
- Node n3 = g.createNode();
-
- n1.connectTo(n2);
- n1.connectTo(n3);
-
- return g;
- }
-}
View
31 src/test/java/com/ojn/gexf4j/core/testgraphs/PhylogenyBuilder.java
@@ -0,0 +1,31 @@
+package com.ojn.gexf4j.core.testgraphs;
+
+import com.ojn.gexf4j.core.Gexf;
+import com.ojn.gexf4j.core.Node;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+
+public class PhylogenyBuilder extends GexfBuilder {
+
+ @Override
+ public String getSuffix() {
+ return "phylogeny";
+ }
+
+ @Override
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+
+ Node a = gexf.getGraph().createNode("a");
+ a.setLabel("cheese");
+
+ Node b = gexf.getGraph().createNode("b");
+ b.setLabel("cherry");
+
+ Node c = gexf.getGraph().createNode("c");
+ c.setLabel("cake");
+ c.getParentForList().add(a);
+ c.getParentForList().add(b);
+
+ return gexf;
+ }
+}
View
36 src/test/java/com/ojn/gexf4j/core/testgraphs/VisualizationBuilder.java
@@ -0,0 +1,36 @@
+package com.ojn.gexf4j.core.testgraphs;
+
+import com.ojn.gexf4j.core.Gexf;
+import com.ojn.gexf4j.core.impl.GexfImpl;
+import com.ojn.gexf4j.core.impl.viz.ColorImpl;
+import com.ojn.gexf4j.core.impl.viz.PositionImpl;
+import com.ojn.gexf4j.core.viz.NodeShape;
+
+public class VisualizationBuilder extends GexfBuilder {
+
+ @Override
+ public String getSuffix() {
+ return "viz";
+ }
+
+ @Override
+ public Gexf buildGexf() {
+ Gexf gexf = new GexfImpl();
+
+ gexf
+ .setVisualization(true)
+ .getGraph().createNode("a")
+ .setLabel("glossy")
+ .setColor(new ColorImpl(239, 173, 66))
+ .setPosition(new PositionImpl(15.783598f, 40.109245f, 0.0f))
+ .setSize(2.0375757f)
+ .getShapeEntity().setNodeShape(NodeShape.DISC);
+
+ return gexf;
+ }
+
+ @Override
+ public String getSchemaUrl() {
+ return "http://gexf.net/1.1draft/viz.xsd";
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.