Skip to content

Commit

Permalink
Changed generation of lattice labels in dot export
Browse files Browse the repository at this point in the history
  • Loading branch information
s_yevtushenko committed Nov 14, 2006
1 parent 3a925b5 commit 46e12e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
26 changes: 22 additions & 4 deletions src/conexp/frontend/latticeeditor/DotExporter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package conexp.frontend.latticeeditor;

import conexp.core.ContextEntity;
import conexp.core.Lattice;
import conexp.core.LatticeElement;
import util.FileNameMangler;
Expand All @@ -9,6 +10,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down Expand Up @@ -139,15 +141,31 @@ public static final String getArcList(

// ------------------------------------------------------------------------


public static final String asStringNodeDot(LatticeElement latticeElement) {
StringBuffer string = new StringBuffer();
writeContextEntities(latticeElement.ownAttribsIterator(), string);
string.append("\\n");
writeContextEntities(latticeElement.ownObjectsIterator(), string);
return string.toString();
}

string.append(latticeElement.getAttribs());
private static void writeContextEntities(Iterator entityIterator, StringBuffer string) {
boolean first = true;
for (Iterator iterator = entityIterator; iterator.hasNext();) {
ContextEntity entity = (ContextEntity) iterator.next();
if (first) {
first = false;
} else {
string.append(",");
}
string.append(escapeString(entity.getName()));

string.append("\\n");
}
}

string.append(latticeElement.getObjects());
return string.toString();
public static String escapeString(String name) {
return name.replaceAll("\"", "\\\\\"");
}

}
16 changes: 10 additions & 6 deletions src/conexp/frontend/latticeeditor/tests/DotExporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class DotExporterTest extends TestCase {
"\tratio=fill;\n" +
"\tsize=\"7.5,10\";\n" +
"\n" +
"\tnode_1 [label=\"{1, 0, 0}\\n{1, 1}\"];\n" +
"\tnode_2 [label=\"{1, 0, 1}\\n{1, 0}\"];\n" +
"\tnode_3 [label=\"{1, 1, 1}\\n{0, 0}\"];\n" +
"\tnode_4 [label=\"{1, 1, 0}\\n{0, 1}\"];\n" +
"\tnode_1 [label=\"Attr 1\\n\"];\n" +
"\tnode_2 [label=\"Attr 3\\nObj 1\"];\n" +
"\tnode_3 [label=\"\\n\"];\n" +
"\tnode_4 [label=\"Attr 2\\nObj 2\"];\n" +
"\n" +
"\t{\n" +
"\tnode_2;\n" +
Expand All @@ -33,8 +33,8 @@ public class DotExporterTest extends TestCase {
"\tratio=fill;\n" +
"\tsize=\"7.5,10\";\n" +
"\n" +
"\tnode_1 [label=\"{1, 0, 0}\\n{1, 1}\"];\n" +
"\tnode_2 [label=\"{1, 1, 0}\\n{0, 1}\"];\n" +
"\tnode_1 [label=\"Attr 1\\nObj 1\"];\n" +
"\tnode_2 [label=\"Attr 2\\nObj 2\"];\n"+
"\n" +
"\t{\n" +
"\tnode_2;\n" +
Expand Down Expand Up @@ -66,4 +66,8 @@ private static Context makeTestContext() {
}


public void testEscapeString() throws Exception {
assertEquals("abc", DotExporter.escapeString("abc"));
assertEquals("a\\\"b", DotExporter.escapeString("a\"b"));
}
}

0 comments on commit 46e12e2

Please sign in to comment.