[Debtags-commits] [svn] r947 - in libdebtags1/trunk: debtags swig swig/python tests

Enrico Zini debtags-commits@lists.alioth.debian.org
Mon, 27 Jun 2005 17:42:50 +0000


Author: enrico
Date: Mon Jun 27 17:42:49 2005
New Revision: 947

Added:
   libdebtags1/trunk/debtags/DebtagsUtils.cc
   libdebtags1/trunk/debtags/DebtagsUtils.h
Modified:
   libdebtags1/trunk/debtags/DebtagsSimple.cc
   libdebtags1/trunk/debtags/DebtagsSimple.h
   libdebtags1/trunk/debtags/Makefile.am
   libdebtags1/trunk/debtags/Update.cc
   libdebtags1/trunk/debtags/instantiations1.cc
   libdebtags1/trunk/swig/libdebtags.i
   libdebtags1/trunk/swig/python/browser.py
   libdebtags1/trunk/tests/Makefile.am
Log:
Improved browser.py: now it also includes related packages

Modified: libdebtags1/trunk/debtags/DebtagsSimple.cc
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.cc	(original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.cc	Mon Jun 27 17:42:49 2005
@@ -106,6 +106,20 @@
 	return _tagDB.hasTagDatabase();
 }
 
+template<class ITEM>
+void DebtagsSimple<ITEM>::outputPackages(const OpSet<ITEM>& items, Tagcoll::TagcollConsumer<ITEM, Tag>& out)
+{
+	for (typename OpSet<ITEM>::const_iterator i = items.begin(); i != items.end(); i++)
+		out.consume(*i, _tagDB.getTags(*i));
+}
+
+template<class ITEM>
+OpSet<ITEM> DebtagsSimple<ITEM>::getRelated(const OpSet<Tag>& tags, int maxDistance)
+{
+	return _tagDB.getRelatedItems(tags, maxDistance);
+}
+
+
 };
 
 #if 0

Modified: libdebtags1/trunk/debtags/DebtagsSimple.h
==============================================================================
--- libdebtags1/trunk/debtags/DebtagsSimple.h	(original)
+++ libdebtags1/trunk/debtags/DebtagsSimple.h	Mon Jun 27 17:42:49 2005
@@ -73,6 +73,10 @@
 	Tagcoll::ImplicationList<Debtags::Facet> getFacetImplications() const;
 
 	FacetSet getToplevelFacets(int flattenThreshold = 0) const;
+
+	void outputPackages(const OpSet<ITEM>& items, Tagcoll::TagcollConsumer<ITEM, Tag>& out);
+
+	OpSet<ITEM> getRelated(const OpSet<Tag>& tags, int maxDistance);
 };
 
 };

Modified: libdebtags1/trunk/debtags/Makefile.am
==============================================================================
--- libdebtags1/trunk/debtags/Makefile.am	(original)
+++ libdebtags1/trunk/debtags/Makefile.am	Mon Jun 27 17:42:49 2005
@@ -53,6 +53,7 @@
 	DebtagsTODO.cc \
 	DebtagsSimple.cc \
 	DebtagsFilters.cc \
+	DebtagsUtils.cc \
 	instantiations.cc \
 	instantiations1.cc
 #libdebtags1_la_LDFLAGS = -version-info @LIBDEBTAGS_VERSION_INFO@ -static
@@ -70,6 +71,7 @@
 	Paths_pic.o \
 	Regexp_pic.o \
 	ZlibParserInput_pic.o \
+	DebtagsStatus_pic.o \
 	DebDBParser_pic.o \
 	VocabularyMerger_pic.o \
 	TagImpl_pic.o \
@@ -80,12 +82,15 @@
 	Update_pic.o \
 	TagSet_pic.o \
 	PackageDB_pic.o \
-	DebtagsSimple_pic.o \
 	PackageImpl_pic.o \
 	Package_pic.o \
 	PackageSet_pic.o \
 	BasicTagMatcher_pic.o \
 	BasicPackageMatcher_pic.o \
+	DebtagsTODO_pic.o \
+	DebtagsSimple_pic.o \
+	DebtagsFilters_pic.o \
+	DebtagsUtils_pic.o \
 	instantiations_pic.o \
 	instantiations1_pic.o
 #libdebtags1_pic_la_LDFLAGS = -static

Modified: libdebtags1/trunk/debtags/Update.cc
==============================================================================
--- libdebtags1/trunk/debtags/Update.cc	(original)
+++ libdebtags1/trunk/debtags/Update.cc	Mon Jun 27 17:42:49 2005
@@ -88,7 +88,7 @@
 	OpSet<string> patched;
 	for (OpSet<string>::const_iterator i = tags.begin();
 			i != tags.end(); i++)
-		if (voc.hasTag(*i))
+		if (voc.hasTag(*i) && *i != "special::invalid-tag")
 			patched += *i;
 //		else
 //			fprintf(stderr, "Removing tag %.*s not found in vocabulary (package %.*s)\n", PFSTR(*i), PFSTR(item));
@@ -105,7 +105,7 @@
 	OpSet<string> patched;
 	for (OpSet<string>::const_iterator i = tags.begin();
 			i != tags.end(); i++)
-		if (voc.hasTag(*i))
+		if (voc.hasTag(*i) && *i != "special::invalid-tag")
 			patched += *i;
 			/*
 		else

Modified: libdebtags1/trunk/debtags/instantiations1.cc
==============================================================================
--- libdebtags1/trunk/debtags/instantiations1.cc	(original)
+++ libdebtags1/trunk/debtags/instantiations1.cc	Mon Jun 27 17:42:49 2005
@@ -9,6 +9,7 @@
 #include <tagcoll/Implications.cc>
 #include <tagcoll/SmartHierarchy.cc>
 #include <debtags/DebtagsTODO.cc>
+#include <debtags/DebtagsUtils.cc>
 #include <debtags/BasicPackageMatcher.cc>
 /*
 #include <tagcoll/FilterChain.cc>
@@ -37,6 +38,8 @@
 template class DebtagsTODOSpecials<Debtags::Package>;
 template class BasicPackageMatcher<std::string>;
 template class BasicPackageMatcher<Debtags::Package>;
+template class SearchHelper<std::string>;
+//template class SearchHelper<Debtags::Package>;
 
 /*
 template class InputMerger<Debtags::Package, Debtags::Tag>;

Modified: libdebtags1/trunk/swig/libdebtags.i
==============================================================================
--- libdebtags1/trunk/swig/libdebtags.i	(original)
+++ libdebtags1/trunk/swig/libdebtags.i	Mon Jun 27 17:42:49 2005
@@ -192,7 +192,7 @@
 %template(TagCollStringTag) Tagcoll::TagCollection<std::string, Debtags::Tag>;
 %template(TagCollPackageTag) Tagcoll::TagCollection<Debtags::Package, Debtags::Tag>;
 %template(SearchHelperString) Debtags::SearchHelper<std::string>;
-%template(SearchHelperPackage) Debtags::SearchHelper<Debtags::Package>;
+//%template(SearchHelperPackage) Debtags::SearchHelper<Debtags::Package>;
 
 // TODO:
 // Rename the static method to be called as MailFolder.enumerateFolders

Modified: libdebtags1/trunk/swig/python/browser.py
==============================================================================
--- libdebtags1/trunk/swig/python/browser.py	(original)
+++ libdebtags1/trunk/swig/python/browser.py	Mon Jun 27 17:42:49 2005
@@ -1,3 +1,10 @@
+# TODO:
+#  Limit foundTags to the top-5 (or top-7) by cardinality
+#  Also show packages `debtags related the-top-5-or-7-tags`
+#  Change 'more like these' in 'like these'
+# Allow to increase the distance ("give me more!")
+
+
 import Debtags
 import sys, os
 
@@ -17,14 +24,15 @@
 		self._dt = Debtags.DebtagsString(0)
 		self._search = Debtags.SearchHelperString(self._dt)
 		self._coll = Debtags.TagCollStringTag()
-		self._foundTags = Debtags.DtTagSet()
 	
 	def search (self, string):
 		input = os.popen("apt-cache search " + string, "r");
 		self._search.clearStartPackages()
 		for i in input:
 			pkg = i.split(' - ')[0]
+			print "adding " + pkg
 			self._search.addStartPackage(pkg)
+		print "done adding"
 
 		self._search.clearWanted()
 		self._search.clearUnwanted()
@@ -35,7 +43,7 @@
 		return self._search.getFound()
 
 	def foundTags (self):
-		return self._foundTags
+		return self._search.getPivot()
 
 	def wantTags (self):
 		return self._search.getWanted()
@@ -70,11 +78,9 @@
 		self._search.compute();
 
 		# Build the merged tagset with the tags of the items found
-		self._foundTags.clear()
 		self._coll = Debtags.TagCollStringTag()
 		for i in self._search.getFound().getIterable():
 			tags = self._dt.getTags(i)
-			self._foundTags += tags
 			self._coll.consume(i, tags)
 
 		self.emit('changed')
@@ -142,7 +148,7 @@
 			self.model.append([i.fullname(), i.sdesc()])
 		
 
-class TagListWithCard(gtk.ScrolledWindow):
+class FoundTagList(gtk.ScrolledWindow):
 	def __init__(self, name, engine):
 		gtk.ScrolledWindow.__init__(self)
 		self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@@ -190,9 +196,20 @@
 
 	def update (self, data = None):
 		self.model.clear()
+		cards = {}
 		for i in (self.engine.foundTags() - self.engine.wantTags()).getIterable():
-			card = self.engine.getCardinality(i)
-			self.model.append([i.fullname(), i.sdesc(), card])
+			cards[i.fullname()] = (i, self.engine.getCardinality(i))
+
+		tmp = cards.values()
+		tmp.sort(lambda x, y: -cmp(x[1], y[1]))
+		for i in tmp[0:7]:
+			tag, card = i
+			self.model.append([tag.fullname(), tag.sdesc(), card])
+#			card = self.engine.getCardinality(i)
+#			self.model.append([i.fullname(), i.sdesc(), card])
+#		for i in (self.engine.foundTags() - self.engine.wantTags()).getIterable():
+#			card = self.engine.getCardinality(i)
+#			self.model.append([i.fullname(), i.sdesc(), card])
 
 class BrowserWindow:
 	def __init__(self):
@@ -206,7 +223,7 @@
 		self.packageListModel = gtk.ListStore(str)
 		self.packageList = gtk.TreeView(self.packageListModel)
 
-		self.tagList = TagListWithCard("Tags", self.engine)
+		self.tagList = FoundTagList("Tags", self.engine)
 		self.wantList = WantedTagList("More like these", self.engine)
 		self.nowantList = UnwantedTagList("Not like these", self.engine)
 

Modified: libdebtags1/trunk/tests/Makefile.am
==============================================================================
--- libdebtags1/trunk/tests/Makefile.am	(original)
+++ libdebtags1/trunk/tests/Makefile.am	Mon Jun 27 17:42:49 2005
@@ -3,7 +3,7 @@
 libdebtags_test_SOURCES = tut-main.cpp test-vocabulary.cc
 libdebtags_test_LDADD = ../debtags/libdebtags1.a @LIBTAGCOLL1_LIBS@ -lapt-pkg 
 
-noinst_PROGRAMS = test-update test-packages test-packagedata test-dbcat test-dbcat1 ex-showpkg ex-showpkgs
+noinst_PROGRAMS = test-update test-packages test-packagedata test-dbcat test-dbcat1 ex-showpkg ex-showpkgs ex-search
 #ex-showfacetimpl
 #test-maintainers 
 
@@ -35,6 +35,9 @@
 ex_showpkgs_SOURCES = ex-showpkgs.cc
 ex_showpkgs_LDADD = ../debtags/libdebtags1.a @LIBTAGCOLL1_LIBS@ -lapt-pkg
 
+ex_search_SOURCES = ex-search.cc
+ex_search_LDADD = ../debtags/libdebtags1.a @LIBTAGCOLL1_LIBS@ -lapt-pkg
+
 #ex_showfacetimpl_SOURCES = ex-showfacetimpl.cc
 #ex_showfacetimpl_LDADD = ../debtags/libdebtags1.a @LIBTAGCOLL1_LIBS@ -lapt-pkg