[Debtags-commits] [svn] r1388 - in tagcoll/trunk: . tagcoll tests

Enrico Zini enrico at costa.debian.org
Thu Sep 29 16:14:37 UTC 2005


Author: enrico
Date: Thu Sep 29 16:14:36 2005
New Revision: 1388

Modified:
   tagcoll/trunk/   (props changed)
   tagcoll/trunk/tagcoll/experiments.cc
   tagcoll/trunk/tagcoll/experiments.h
   tagcoll/trunk/tests/mkgraph.cc
Log:
 r5445 at viaza:  enrico | 2005-09-28 00:00:17 -0500
 More fixed to graph generation functions


Modified: tagcoll/trunk/tagcoll/experiments.cc
==============================================================================
--- tagcoll/trunk/tagcoll/experiments.cc	(original)
+++ tagcoll/trunk/tagcoll/experiments.cc	Thu Sep 29 16:14:36 2005
@@ -20,12 +20,13 @@
 
 #include <tagcoll/experiments.h>
 
+#include <iostream>
+#include <fstream>
+
 #include <vector>
 #include <set>
 
 
-#include <iostream>
-
 namespace std {
 
 template<typename TAG, typename _Traits>
@@ -244,8 +245,21 @@
 	//return "node";
 }
 
+template<typename TAG>
+static string formatItems(const OpSet<TAG>& node)
+{
+	string res;
+	for (typename OpSet<TAG>::const_iterator i = node.begin();
+			i != node.end(); i++)
+		if (i == node.begin())
+			res += *i;
+		else
+			res += " " + *i;
+	return res;
+}
+
 template<typename ITEM, typename TAG>
-void Graph<ITEM,TAG>::buildSubGraph(const OpSet<TAG>& node, OpSet< OpSet<TAG> >& selected, int maxdist)
+void Graph<ITEM,TAG>::buildSubGraph(std::ostream& out, const OpSet<TAG>& node, OpSet< OpSet<TAG> >& selected, int maxdist)
 {
 	// Lay out the nodes in order of distance
 	for (int i = 1; i <= maxdist && !selected.empty(); i++)
@@ -256,9 +270,25 @@
 				j != selected.end(); j++)
 			if ((*j).distance(node) == i)
 			{
+				OpSet<TAG> added = *j - node;
+				OpSet<TAG> removed = node - *j;
+				string diff;
+				for (typename OpSet<TAG>::const_iterator n = added.begin();
+						n != added.end(); n++)
+					if (diff.empty())
+						diff += "+" + *n;
+					else
+						diff += "\\n+" + *n;
+				for (typename OpSet<TAG>::const_iterator n = removed.begin();
+						n != removed.end(); n++)
+					if (diff.empty())
+						diff += "-" + *n;
+					else
+						diff += "\\n-" + *n;
+				
 				// Connect to the main node
-				cout << "node" << getHandle(node) << "--node" << getHandle(*j) << "[" <<
-					"label=\"" << i << "\"," <<
+				out << "node" << getHandle(node) << "--node" << getHandle(*j) << "[" <<
+					"label=\"" << diff << "\"," <<
 					"weight=\"" << i << "\"" <<
 					"];" << endl;
 				connected.push_back(*j);
@@ -276,7 +306,7 @@
 				j != connected.end(); j++)
 		{
 			OpSet< OpSet<TAG> > subselected(selected);
-			buildSubGraph(*j, subselected, maxdist - i);
+			buildSubGraph(out, *j, subselected, maxdist - i);
 			removed += selected - subselected;
 		}
 
@@ -286,13 +316,16 @@
 
 
 template<typename ITEM, typename TAG>
-void Graph<ITEM,TAG>::buildGraph(const OpSet<TAG>& node, int maxdist)
+void Graph<ITEM,TAG>::buildGraph(std::ostream& out, const OpSet<TAG>& node, int maxdist)
 {
 	int dist;
 
-	cout << "node" << getHandle(node) << "[" <<
+	out << "root=node" << getHandle(node) << ";" << endl;
+
+	out << "node" << getHandle(node) << "[" <<
 		"label=\"" << formatNode(node) << "\"," <<
-		"fontsize=" << maxdist+2 <<
+		"tooltip=\"" << formatItems(this->tagsets[node]) << "\"," <<
+		"fontsize=" << (maxdist + 3) * 2 <<
 		"];" << endl;
 
 	// Choose and output the nodes that will go in the graph
@@ -303,13 +336,15 @@
 		{
 			selected.insert(i->first);
 
-			cout << "node" << getHandle(i->first) << "[" <<
+			out << "node" << getHandle(i->first) << "[" <<
 				"label=\"" << formatNode(i->first) << "\"," <<
-				"fontsize=" << maxdist + 2 - dist <<
+				"URL=\"node" << getHandle(i->first) << ".html\"," <<
+				"tooltip=\"" << formatItems(this->tagsets[i->first]) << "\"," <<
+				"fontsize=" << (maxdist - dist + 3) * 2 <<
 				"];" << endl;
 		}
 
-	buildSubGraph(node, selected, maxdist);
+	buildSubGraph(out, node, selected, maxdist);
 
 #if 0
 		if (i->second.distance(node) == 1)
@@ -320,6 +355,25 @@
 #endif
 }
 
+template<typename ITEM, typename TAG>
+void Graph<ITEM,TAG>::buildGraphs(const std::string& dir, int maxdist)
+{
+	for (typename tagsets_t::const_iterator i = this->tagsets.begin();
+			i != this->tagsets.end(); i++)
+	{
+		string fname = dir + "/node";
+		char buf[20];
+		snprintf(buf, 20, "%d", getHandle(i->first));
+		fname += string(buf) + ".dot";
+		ofstream out(fname.c_str(), ios::out | ios::trunc);
+
+		out << "strict graph {" << endl;
+		out << "overlap=scale;" << endl;
+		out << "splines=true;" << endl;
+		buildGraph(out, i->first, maxdist);
+		out << "}" << endl;
+	}
+}
 
 }
 

Modified: tagcoll/trunk/tagcoll/experiments.h
==============================================================================
--- tagcoll/trunk/tagcoll/experiments.h	(original)
+++ tagcoll/trunk/tagcoll/experiments.h	Thu Sep 29 16:14:36 2005
@@ -27,6 +27,7 @@
 #include <tagcoll/Expression.h>
 
 #include <vector>
+#include <ostream>
 
 namespace Tagcoll
 {
@@ -115,12 +116,13 @@
 	std::map< OpSet<TAG>, int > handles;
 
 	int getHandle(const OpSet<TAG>& node);
-	void buildSubGraph(const OpSet<TAG>& node, OpSet< OpSet<TAG> >& selected, int maxdist);
+	void buildSubGraph(std::ostream& out, const OpSet<TAG>& node, OpSet< OpSet<TAG> >& selected, int maxdist);
 
 public:
 	Graph() : seq(0) {}
 
-	void buildGraph(const OpSet<TAG>& node, int maxdist = 3);
+	void buildGraph(std::ostream& out, const OpSet<TAG>& node, int maxdist = 3);
+	void buildGraphs(const std::string& dir, int maxdist = 3);
 };
 
 }

Modified: tagcoll/trunk/tests/mkgraph.cc
==============================================================================
--- tagcoll/trunk/tests/mkgraph.cc	(original)
+++ tagcoll/trunk/tests/mkgraph.cc	Thu Sep 29 16:14:36 2005
@@ -21,11 +21,7 @@
 
 		TextFormat<string, string>::parse(conv, conv, in, graph);
 
-		cout << "strict graph {" << endl;
-
-		graph.buildGraph(graph.getTags("debtags"));
-
-		cout << "}" << endl;
+		graph.buildGraphs("graph");
 
 		//TextFormat<string, string> writer(conv, conv, stdout);
 		//graph.output(writer);



More information about the Debtags-commits mailing list