Commit 0e5dbe900569c8a749146e46256c9f7fc17d58e2
1 parent
67a25822
Exists in
master
and in
1 other branch
Sharing class PkgMatchDecider.
Showing
5 changed files
with
388 additions
and
408 deletions
Show diff stats
demo_rec.py
... | ... | @@ -1,128 +0,0 @@ |
1 | -#!/usr/bin/python | |
2 | - | |
3 | -# AppRecommender - A GNU/Linux application recommender | |
4 | -# | |
5 | -# Copyright (C) 2010 Tassia Camoes <tassia@gmail.com> | |
6 | -# | |
7 | -# This program is free software: you can redistribute it and/or modify | |
8 | -# it under the terms of the GNU General Public License as published by | |
9 | -# the Free Software Foundation, either version 3 of the License, or | |
10 | -# (at your option) any later version. | |
11 | -# | |
12 | -# This program is distributed in the hope that it will be useful, | |
13 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | -# GNU General Public License for more details. | |
16 | -# | |
17 | -# You should have received a copy of the GNU General Public License | |
18 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | - | |
20 | -import os | |
21 | -import sys | |
22 | -import commands | |
23 | -import re | |
24 | - | |
25 | -import xapian | |
26 | -from debian import debtags | |
27 | - | |
28 | -DB_PATH = "/var/lib/debtags/package-tags" | |
29 | -INDEX_PATH = os.path.expanduser("~/.app-recommender/debtags_index") | |
30 | - | |
31 | -def load_debtags_db(path): | |
32 | - """ Load debtags database. """ | |
33 | - debtags_db = debtags.DB() | |
34 | - tag_filter = re.compile(r"^special::.+$|^.+::TODO$") | |
35 | - try: | |
36 | - debtags_db.read(open(path, "r"), lambda x: not tag_filter.match(x)) | |
37 | - except IOError: | |
38 | - print >> sys.stderr, ("IOError: could not open debtags file \'%s\'" % | |
39 | - path) | |
40 | - exit(1) | |
41 | - return debtags_db | |
42 | - | |
43 | -def get_system_pkgs(): | |
44 | - """ Return set of system packages. """ | |
45 | - dpkg_output = commands.getoutput('/usr/bin/dpkg --get-selections') | |
46 | - return dpkg_output.replace('install','\t').split() | |
47 | - | |
48 | -def get_most_relevant_tags(debtags_db,pkgs_list): | |
49 | - """ Return most relevant tags considering a list of packages. """ | |
50 | - relevant_db = debtags_db.choose_packages(pkgs_list) | |
51 | - relevance_index = debtags.relevance_index_function(debtags_db,relevant_db) | |
52 | - sorted_relevant_tags = sorted(relevant_db.iter_tags(), | |
53 | - lambda a, b: cmp(relevance_index(a), | |
54 | - relevance_index(b))) | |
55 | - return normalize_tags(' '.join(sorted_relevant_tags[-50:])) | |
56 | - | |
57 | -def normalize_tags(string): | |
58 | - """ Normalize tag string so that it can be indexed and retrieved. """ | |
59 | - return string.replace(':','_').replace('-','\'') | |
60 | - | |
61 | -def create_debtags_index(debtags_db,index_path): | |
62 | - """ Create a xapian index for debtags info based on file 'debtags_db' and | |
63 | - place it at 'index_path'. | |
64 | - """ | |
65 | - if not os.path.exists(index_path): | |
66 | - os.makedirs(index_path) | |
67 | - print "Creating new debtags xapian index at \'%s\'" % index_path | |
68 | - debtags_index = xapian.WritableDatabase(index_path, | |
69 | - xapian.DB_CREATE_OR_OVERWRITE) | |
70 | - for pkg,tags in debtags_db.iter_packages_tags(): | |
71 | - doc = xapian.Document() | |
72 | - doc.set_data(pkg) | |
73 | - for tag in tags: | |
74 | - doc.add_term(normalize_tags(tag)) | |
75 | - print "indexing ",debtags_index.add_document(doc) | |
76 | - return debtags_index | |
77 | - | |
78 | -def load_debtags_index(debtags_db,reindex): | |
79 | - """ Load an existing or new debtags index, based on boolean reindex. """ | |
80 | - if not reindex: | |
81 | - try: | |
82 | - print ("Opening existing debtags xapian index at \'%s\'" % | |
83 | - INDEX_PATH) | |
84 | - debtags_index = xapian.Database(INDEX_PATH) | |
85 | - except DatabaseError: | |
86 | - print "Could not open debtags xapian index" | |
87 | - reindex = 1 | |
88 | - if reindex: | |
89 | - debtags_index = create_debtags_index(debtags_db,INDEX_PATH) | |
90 | - return debtags_index | |
91 | - | |
92 | - | |
93 | -class PkgMatchDecider(xapian.MatchDecider): | |
94 | - """ Extends xapian.MatchDecider to disconsider installed packages. """ | |
95 | - | |
96 | - def __init__(self, installed_pkgs): | |
97 | - xapian.MatchDecider.__init__(self) | |
98 | - self.installed_pkgs = installed_pkgs | |
99 | - | |
100 | - def __call__(self, doc): | |
101 | - return doc.get_data() not in self.installed_pkgs | |
102 | - | |
103 | - | |
104 | -if __name__ == '__main__': | |
105 | - | |
106 | - reindex = 0 | |
107 | - if len(sys.argv) == 2: | |
108 | - DB_PATH = sys.argv[1] | |
109 | - reindex = 1 | |
110 | - print "reindex true" | |
111 | - elif len(sys.argv) > 2: | |
112 | - print >> sys.stderr, ("Usage: %s [PATH_TO_DEBTAGS_DATABASE]" % | |
113 | - sys.argv[0]) | |
114 | - sys.exit(1) | |
115 | - | |
116 | - debtags_db = load_debtags_db(DB_PATH) | |
117 | - installed_pkgs = get_system_pkgs() | |
118 | - best_tags = get_most_relevant_tags(debtags_db,installed_pkgs) | |
119 | - | |
120 | - debtags_index = load_debtags_index(debtags_db,reindex) | |
121 | - qp = xapian.QueryParser() | |
122 | - query = qp.parse_query(best_tags) | |
123 | - enquire = xapian.Enquire(debtags_index) | |
124 | - enquire.set_query(query) | |
125 | - | |
126 | - mset = enquire.get_mset(0, 20, None, PkgMatchDecider(installed_pkgs)) | |
127 | - for m in mset: | |
128 | - print "%2d: %s" % (m.rank, m.document.get_data()) |
... | ... | @@ -0,0 +1,270 @@ |
1 | +# Doxyfile 1.7.1 | |
2 | + | |
3 | +#--------------------------------------------------------------------------- | |
4 | +# Project related configuration options | |
5 | +#--------------------------------------------------------------------------- | |
6 | +DOXYFILE_ENCODING = UTF-8 | |
7 | +PROJECT_NAME = App Recommender | |
8 | +PROJECT_NUMBER = 0.1 | |
9 | +OUTPUT_DIRECTORY = doc/ | |
10 | +CREATE_SUBDIRS = NO | |
11 | +OUTPUT_LANGUAGE = English | |
12 | +BRIEF_MEMBER_DESC = YES | |
13 | +REPEAT_BRIEF = YES | |
14 | +ABBREVIATE_BRIEF = | |
15 | +ALWAYS_DETAILED_SEC = NO | |
16 | +INLINE_INHERITED_MEMB = NO | |
17 | +FULL_PATH_NAMES = YES | |
18 | +STRIP_FROM_PATH = | |
19 | +STRIP_FROM_INC_PATH = | |
20 | +SHORT_NAMES = NO | |
21 | +JAVADOC_AUTOBRIEF = NO | |
22 | +QT_AUTOBRIEF = NO | |
23 | +MULTILINE_CPP_IS_BRIEF = NO | |
24 | +INHERIT_DOCS = YES | |
25 | +SEPARATE_MEMBER_PAGES = NO | |
26 | +TAB_SIZE = 4 | |
27 | +ALIASES = | |
28 | +OPTIMIZE_OUTPUT_FOR_C = NO | |
29 | +OPTIMIZE_OUTPUT_JAVA = NO | |
30 | +OPTIMIZE_FOR_FORTRAN = NO | |
31 | +OPTIMIZE_OUTPUT_VHDL = NO | |
32 | +EXTENSION_MAPPING = | |
33 | +BUILTIN_STL_SUPPORT = NO | |
34 | +CPP_CLI_SUPPORT = NO | |
35 | +SIP_SUPPORT = NO | |
36 | +IDL_PROPERTY_SUPPORT = YES | |
37 | +DISTRIBUTE_GROUP_DOC = NO | |
38 | +SUBGROUPING = YES | |
39 | +TYPEDEF_HIDES_STRUCT = NO | |
40 | +SYMBOL_CACHE_SIZE = 0 | |
41 | +#--------------------------------------------------------------------------- | |
42 | +# Build related configuration options | |
43 | +#--------------------------------------------------------------------------- | |
44 | +EXTRACT_ALL = NO | |
45 | +EXTRACT_PRIVATE = NO | |
46 | +EXTRACT_STATIC = NO | |
47 | +EXTRACT_LOCAL_CLASSES = YES | |
48 | +EXTRACT_LOCAL_METHODS = YES | |
49 | +EXTRACT_ANON_NSPACES = NO | |
50 | +HIDE_UNDOC_MEMBERS = NO | |
51 | +HIDE_UNDOC_CLASSES = NO | |
52 | +HIDE_FRIEND_COMPOUNDS = NO | |
53 | +HIDE_IN_BODY_DOCS = NO | |
54 | +INTERNAL_DOCS = NO | |
55 | +CASE_SENSE_NAMES = YES | |
56 | +HIDE_SCOPE_NAMES = NO | |
57 | +SHOW_INCLUDE_FILES = YES | |
58 | +FORCE_LOCAL_INCLUDES = NO | |
59 | +INLINE_INFO = YES | |
60 | +SORT_MEMBER_DOCS = YES | |
61 | +SORT_BRIEF_DOCS = NO | |
62 | +SORT_MEMBERS_CTORS_1ST = NO | |
63 | +SORT_GROUP_NAMES = NO | |
64 | +SORT_BY_SCOPE_NAME = NO | |
65 | +GENERATE_TODOLIST = YES | |
66 | +GENERATE_TESTLIST = YES | |
67 | +GENERATE_BUGLIST = YES | |
68 | +GENERATE_DEPRECATEDLIST= YES | |
69 | +ENABLED_SECTIONS = | |
70 | +MAX_INITIALIZER_LINES = 30 | |
71 | +SHOW_USED_FILES = YES | |
72 | +SHOW_DIRECTORIES = NO | |
73 | +SHOW_FILES = YES | |
74 | +SHOW_NAMESPACES = YES | |
75 | +FILE_VERSION_FILTER = | |
76 | +LAYOUT_FILE = | |
77 | +#--------------------------------------------------------------------------- | |
78 | +# configuration options related to warning and progress messages | |
79 | +#--------------------------------------------------------------------------- | |
80 | +QUIET = NO | |
81 | +WARNINGS = YES | |
82 | +WARN_IF_UNDOCUMENTED = YES | |
83 | +WARN_IF_DOC_ERROR = YES | |
84 | +WARN_NO_PARAMDOC = NO | |
85 | +WARN_FORMAT = "$file:$line: $text" | |
86 | +WARN_LOGFILE = | |
87 | +#--------------------------------------------------------------------------- | |
88 | +# configuration options related to the input files | |
89 | +#--------------------------------------------------------------------------- | |
90 | +INPUT = | |
91 | +INPUT_ENCODING = UTF-8 | |
92 | +FILE_PATTERNS = | |
93 | +RECURSIVE = YES | |
94 | +EXCLUDE = | |
95 | +EXCLUDE_SYMLINKS = NO | |
96 | +EXCLUDE_PATTERNS = | |
97 | +EXCLUDE_SYMBOLS = | |
98 | +EXAMPLE_PATH = | |
99 | +EXAMPLE_PATTERNS = | |
100 | +EXAMPLE_RECURSIVE = NO | |
101 | +IMAGE_PATH = | |
102 | +INPUT_FILTER = | |
103 | +FILTER_PATTERNS = | |
104 | +FILTER_SOURCE_FILES = NO | |
105 | +#--------------------------------------------------------------------------- | |
106 | +# configuration options related to source browsing | |
107 | +#--------------------------------------------------------------------------- | |
108 | +SOURCE_BROWSER = YES | |
109 | +INLINE_SOURCES = NO | |
110 | +STRIP_CODE_COMMENTS = YES | |
111 | +REFERENCED_BY_RELATION = NO | |
112 | +REFERENCES_RELATION = NO | |
113 | +REFERENCES_LINK_SOURCE = YES | |
114 | +USE_HTAGS = NO | |
115 | +VERBATIM_HEADERS = YES | |
116 | +#--------------------------------------------------------------------------- | |
117 | +# configuration options related to the alphabetical class index | |
118 | +#--------------------------------------------------------------------------- | |
119 | +ALPHABETICAL_INDEX = YES | |
120 | +COLS_IN_ALPHA_INDEX = 5 | |
121 | +IGNORE_PREFIX = | |
122 | +#--------------------------------------------------------------------------- | |
123 | +# configuration options related to the HTML output | |
124 | +#--------------------------------------------------------------------------- | |
125 | +GENERATE_HTML = YES | |
126 | +HTML_OUTPUT = html | |
127 | +HTML_FILE_EXTENSION = .html | |
128 | +HTML_HEADER = | |
129 | +HTML_FOOTER = | |
130 | +HTML_STYLESHEET = | |
131 | +HTML_COLORSTYLE_HUE = 220 | |
132 | +HTML_COLORSTYLE_SAT = 100 | |
133 | +HTML_COLORSTYLE_GAMMA = 80 | |
134 | +HTML_TIMESTAMP = YES | |
135 | +HTML_ALIGN_MEMBERS = YES | |
136 | +HTML_DYNAMIC_SECTIONS = NO | |
137 | +GENERATE_DOCSET = NO | |
138 | +DOCSET_FEEDNAME = "Doxygen generated docs" | |
139 | +DOCSET_BUNDLE_ID = org.doxygen.Project | |
140 | +DOCSET_PUBLISHER_ID = org.doxygen.Publisher | |
141 | +DOCSET_PUBLISHER_NAME = Publisher | |
142 | +GENERATE_HTMLHELP = NO | |
143 | +CHM_FILE = | |
144 | +HHC_LOCATION = | |
145 | +GENERATE_CHI = NO | |
146 | +CHM_INDEX_ENCODING = | |
147 | +BINARY_TOC = NO | |
148 | +TOC_EXPAND = NO | |
149 | +GENERATE_QHP = NO | |
150 | +QCH_FILE = | |
151 | +QHP_NAMESPACE = org.doxygen.Project | |
152 | +QHP_VIRTUAL_FOLDER = doc | |
153 | +QHP_CUST_FILTER_NAME = | |
154 | +QHP_CUST_FILTER_ATTRS = | |
155 | +QHP_SECT_FILTER_ATTRS = | |
156 | +QHG_LOCATION = | |
157 | +GENERATE_ECLIPSEHELP = NO | |
158 | +ECLIPSE_DOC_ID = org.doxygen.Project | |
159 | +DISABLE_INDEX = NO | |
160 | +ENUM_VALUES_PER_LINE = 4 | |
161 | +GENERATE_TREEVIEW = NO | |
162 | +USE_INLINE_TREES = NO | |
163 | +TREEVIEW_WIDTH = 250 | |
164 | +EXT_LINKS_IN_WINDOW = NO | |
165 | +FORMULA_FONTSIZE = 10 | |
166 | +FORMULA_TRANSPARENT = YES | |
167 | +SEARCHENGINE = YES | |
168 | +SERVER_BASED_SEARCH = NO | |
169 | +#--------------------------------------------------------------------------- | |
170 | +# configuration options related to the LaTeX output | |
171 | +#--------------------------------------------------------------------------- | |
172 | +GENERATE_LATEX = NO | |
173 | +LATEX_OUTPUT = latex | |
174 | +LATEX_CMD_NAME = latex | |
175 | +MAKEINDEX_CMD_NAME = makeindex | |
176 | +COMPACT_LATEX = NO | |
177 | +PAPER_TYPE = a4wide | |
178 | +EXTRA_PACKAGES = | |
179 | +LATEX_HEADER = | |
180 | +PDF_HYPERLINKS = YES | |
181 | +USE_PDFLATEX = YES | |
182 | +LATEX_BATCHMODE = NO | |
183 | +LATEX_HIDE_INDICES = NO | |
184 | +LATEX_SOURCE_CODE = NO | |
185 | +#--------------------------------------------------------------------------- | |
186 | +# configuration options related to the RTF output | |
187 | +#--------------------------------------------------------------------------- | |
188 | +GENERATE_RTF = NO | |
189 | +RTF_OUTPUT = rtf | |
190 | +COMPACT_RTF = NO | |
191 | +RTF_HYPERLINKS = NO | |
192 | +RTF_STYLESHEET_FILE = | |
193 | +RTF_EXTENSIONS_FILE = | |
194 | +#--------------------------------------------------------------------------- | |
195 | +# configuration options related to the man page output | |
196 | +#--------------------------------------------------------------------------- | |
197 | +GENERATE_MAN = NO | |
198 | +MAN_OUTPUT = man | |
199 | +MAN_EXTENSION = .3 | |
200 | +MAN_LINKS = NO | |
201 | +#--------------------------------------------------------------------------- | |
202 | +# configuration options related to the XML output | |
203 | +#--------------------------------------------------------------------------- | |
204 | +GENERATE_XML = NO | |
205 | +XML_OUTPUT = xml | |
206 | +XML_SCHEMA = | |
207 | +XML_DTD = | |
208 | +XML_PROGRAMLISTING = YES | |
209 | +#--------------------------------------------------------------------------- | |
210 | +# configuration options for the AutoGen Definitions output | |
211 | +#--------------------------------------------------------------------------- | |
212 | +GENERATE_AUTOGEN_DEF = NO | |
213 | +#--------------------------------------------------------------------------- | |
214 | +# configuration options related to the Perl module output | |
215 | +#--------------------------------------------------------------------------- | |
216 | +GENERATE_PERLMOD = NO | |
217 | +PERLMOD_LATEX = NO | |
218 | +PERLMOD_PRETTY = YES | |
219 | +PERLMOD_MAKEVAR_PREFIX = | |
220 | +#--------------------------------------------------------------------------- | |
221 | +# Configuration options related to the preprocessor | |
222 | +#--------------------------------------------------------------------------- | |
223 | +ENABLE_PREPROCESSING = YES | |
224 | +MACRO_EXPANSION = NO | |
225 | +EXPAND_ONLY_PREDEF = NO | |
226 | +SEARCH_INCLUDES = YES | |
227 | +INCLUDE_PATH = | |
228 | +INCLUDE_FILE_PATTERNS = | |
229 | +PREDEFINED = | |
230 | +EXPAND_AS_DEFINED = | |
231 | +SKIP_FUNCTION_MACROS = YES | |
232 | +#--------------------------------------------------------------------------- | |
233 | +# Configuration::additions related to external references | |
234 | +#--------------------------------------------------------------------------- | |
235 | +TAGFILES = | |
236 | +GENERATE_TAGFILE = | |
237 | +ALLEXTERNALS = NO | |
238 | +EXTERNAL_GROUPS = YES | |
239 | +PERL_PATH = /usr/bin/perl | |
240 | +#--------------------------------------------------------------------------- | |
241 | +# Configuration options related to the dot tool | |
242 | +#--------------------------------------------------------------------------- | |
243 | +CLASS_DIAGRAMS = YES | |
244 | +MSCGEN_PATH = | |
245 | +HIDE_UNDOC_RELATIONS = YES | |
246 | +HAVE_DOT = NO | |
247 | +DOT_NUM_THREADS = 0 | |
248 | +DOT_FONTNAME = FreeSans.ttf | |
249 | +DOT_FONTSIZE = 10 | |
250 | +DOT_FONTPATH = | |
251 | +CLASS_GRAPH = YES | |
252 | +COLLABORATION_GRAPH = YES | |
253 | +GROUP_GRAPHS = YES | |
254 | +UML_LOOK = NO | |
255 | +TEMPLATE_RELATIONS = NO | |
256 | +INCLUDE_GRAPH = YES | |
257 | +INCLUDED_BY_GRAPH = YES | |
258 | +CALL_GRAPH = NO | |
259 | +CALLER_GRAPH = NO | |
260 | +GRAPHICAL_HIERARCHY = YES | |
261 | +DIRECTORY_GRAPH = YES | |
262 | +DOT_IMAGE_FORMAT = png | |
263 | +DOT_PATH = | |
264 | +DOTFILE_DIRS = | |
265 | +DOT_GRAPH_MAX_NODES = 50 | |
266 | +MAX_DOT_GRAPH_DEPTH = 0 | |
267 | +DOT_TRANSPARENT = NO | |
268 | +DOT_MULTI_TARGETS = YES | |
269 | +GENERATE_LEGEND = YES | |
270 | +DOT_CLEANUP = YES | ... | ... |
doxy_config
... | ... | @@ -1,270 +0,0 @@ |
1 | -# Doxyfile 1.7.1 | |
2 | - | |
3 | -#--------------------------------------------------------------------------- | |
4 | -# Project related configuration options | |
5 | -#--------------------------------------------------------------------------- | |
6 | -DOXYFILE_ENCODING = UTF-8 | |
7 | -PROJECT_NAME = App Recommender | |
8 | -PROJECT_NUMBER = 0.1 | |
9 | -OUTPUT_DIRECTORY = doc/ | |
10 | -CREATE_SUBDIRS = NO | |
11 | -OUTPUT_LANGUAGE = English | |
12 | -BRIEF_MEMBER_DESC = YES | |
13 | -REPEAT_BRIEF = YES | |
14 | -ABBREVIATE_BRIEF = | |
15 | -ALWAYS_DETAILED_SEC = NO | |
16 | -INLINE_INHERITED_MEMB = NO | |
17 | -FULL_PATH_NAMES = YES | |
18 | -STRIP_FROM_PATH = | |
19 | -STRIP_FROM_INC_PATH = | |
20 | -SHORT_NAMES = NO | |
21 | -JAVADOC_AUTOBRIEF = NO | |
22 | -QT_AUTOBRIEF = NO | |
23 | -MULTILINE_CPP_IS_BRIEF = NO | |
24 | -INHERIT_DOCS = YES | |
25 | -SEPARATE_MEMBER_PAGES = NO | |
26 | -TAB_SIZE = 4 | |
27 | -ALIASES = | |
28 | -OPTIMIZE_OUTPUT_FOR_C = NO | |
29 | -OPTIMIZE_OUTPUT_JAVA = NO | |
30 | -OPTIMIZE_FOR_FORTRAN = NO | |
31 | -OPTIMIZE_OUTPUT_VHDL = NO | |
32 | -EXTENSION_MAPPING = | |
33 | -BUILTIN_STL_SUPPORT = NO | |
34 | -CPP_CLI_SUPPORT = NO | |
35 | -SIP_SUPPORT = NO | |
36 | -IDL_PROPERTY_SUPPORT = YES | |
37 | -DISTRIBUTE_GROUP_DOC = NO | |
38 | -SUBGROUPING = YES | |
39 | -TYPEDEF_HIDES_STRUCT = NO | |
40 | -SYMBOL_CACHE_SIZE = 0 | |
41 | -#--------------------------------------------------------------------------- | |
42 | -# Build related configuration options | |
43 | -#--------------------------------------------------------------------------- | |
44 | -EXTRACT_ALL = NO | |
45 | -EXTRACT_PRIVATE = NO | |
46 | -EXTRACT_STATIC = NO | |
47 | -EXTRACT_LOCAL_CLASSES = YES | |
48 | -EXTRACT_LOCAL_METHODS = YES | |
49 | -EXTRACT_ANON_NSPACES = NO | |
50 | -HIDE_UNDOC_MEMBERS = NO | |
51 | -HIDE_UNDOC_CLASSES = NO | |
52 | -HIDE_FRIEND_COMPOUNDS = NO | |
53 | -HIDE_IN_BODY_DOCS = NO | |
54 | -INTERNAL_DOCS = NO | |
55 | -CASE_SENSE_NAMES = YES | |
56 | -HIDE_SCOPE_NAMES = NO | |
57 | -SHOW_INCLUDE_FILES = YES | |
58 | -FORCE_LOCAL_INCLUDES = NO | |
59 | -INLINE_INFO = YES | |
60 | -SORT_MEMBER_DOCS = YES | |
61 | -SORT_BRIEF_DOCS = NO | |
62 | -SORT_MEMBERS_CTORS_1ST = NO | |
63 | -SORT_GROUP_NAMES = NO | |
64 | -SORT_BY_SCOPE_NAME = NO | |
65 | -GENERATE_TODOLIST = YES | |
66 | -GENERATE_TESTLIST = YES | |
67 | -GENERATE_BUGLIST = YES | |
68 | -GENERATE_DEPRECATEDLIST= YES | |
69 | -ENABLED_SECTIONS = | |
70 | -MAX_INITIALIZER_LINES = 30 | |
71 | -SHOW_USED_FILES = YES | |
72 | -SHOW_DIRECTORIES = NO | |
73 | -SHOW_FILES = YES | |
74 | -SHOW_NAMESPACES = YES | |
75 | -FILE_VERSION_FILTER = | |
76 | -LAYOUT_FILE = | |
77 | -#--------------------------------------------------------------------------- | |
78 | -# configuration options related to warning and progress messages | |
79 | -#--------------------------------------------------------------------------- | |
80 | -QUIET = NO | |
81 | -WARNINGS = YES | |
82 | -WARN_IF_UNDOCUMENTED = YES | |
83 | -WARN_IF_DOC_ERROR = YES | |
84 | -WARN_NO_PARAMDOC = NO | |
85 | -WARN_FORMAT = "$file:$line: $text" | |
86 | -WARN_LOGFILE = | |
87 | -#--------------------------------------------------------------------------- | |
88 | -# configuration options related to the input files | |
89 | -#--------------------------------------------------------------------------- | |
90 | -INPUT = | |
91 | -INPUT_ENCODING = UTF-8 | |
92 | -FILE_PATTERNS = | |
93 | -RECURSIVE = YES | |
94 | -EXCLUDE = | |
95 | -EXCLUDE_SYMLINKS = NO | |
96 | -EXCLUDE_PATTERNS = | |
97 | -EXCLUDE_SYMBOLS = | |
98 | -EXAMPLE_PATH = | |
99 | -EXAMPLE_PATTERNS = | |
100 | -EXAMPLE_RECURSIVE = NO | |
101 | -IMAGE_PATH = | |
102 | -INPUT_FILTER = | |
103 | -FILTER_PATTERNS = | |
104 | -FILTER_SOURCE_FILES = NO | |
105 | -#--------------------------------------------------------------------------- | |
106 | -# configuration options related to source browsing | |
107 | -#--------------------------------------------------------------------------- | |
108 | -SOURCE_BROWSER = YES | |
109 | -INLINE_SOURCES = NO | |
110 | -STRIP_CODE_COMMENTS = YES | |
111 | -REFERENCED_BY_RELATION = NO | |
112 | -REFERENCES_RELATION = NO | |
113 | -REFERENCES_LINK_SOURCE = YES | |
114 | -USE_HTAGS = NO | |
115 | -VERBATIM_HEADERS = YES | |
116 | -#--------------------------------------------------------------------------- | |
117 | -# configuration options related to the alphabetical class index | |
118 | -#--------------------------------------------------------------------------- | |
119 | -ALPHABETICAL_INDEX = YES | |
120 | -COLS_IN_ALPHA_INDEX = 5 | |
121 | -IGNORE_PREFIX = | |
122 | -#--------------------------------------------------------------------------- | |
123 | -# configuration options related to the HTML output | |
124 | -#--------------------------------------------------------------------------- | |
125 | -GENERATE_HTML = YES | |
126 | -HTML_OUTPUT = html | |
127 | -HTML_FILE_EXTENSION = .html | |
128 | -HTML_HEADER = | |
129 | -HTML_FOOTER = | |
130 | -HTML_STYLESHEET = | |
131 | -HTML_COLORSTYLE_HUE = 220 | |
132 | -HTML_COLORSTYLE_SAT = 100 | |
133 | -HTML_COLORSTYLE_GAMMA = 80 | |
134 | -HTML_TIMESTAMP = YES | |
135 | -HTML_ALIGN_MEMBERS = YES | |
136 | -HTML_DYNAMIC_SECTIONS = NO | |
137 | -GENERATE_DOCSET = NO | |
138 | -DOCSET_FEEDNAME = "Doxygen generated docs" | |
139 | -DOCSET_BUNDLE_ID = org.doxygen.Project | |
140 | -DOCSET_PUBLISHER_ID = org.doxygen.Publisher | |
141 | -DOCSET_PUBLISHER_NAME = Publisher | |
142 | -GENERATE_HTMLHELP = NO | |
143 | -CHM_FILE = | |
144 | -HHC_LOCATION = | |
145 | -GENERATE_CHI = NO | |
146 | -CHM_INDEX_ENCODING = | |
147 | -BINARY_TOC = NO | |
148 | -TOC_EXPAND = NO | |
149 | -GENERATE_QHP = NO | |
150 | -QCH_FILE = | |
151 | -QHP_NAMESPACE = org.doxygen.Project | |
152 | -QHP_VIRTUAL_FOLDER = doc | |
153 | -QHP_CUST_FILTER_NAME = | |
154 | -QHP_CUST_FILTER_ATTRS = | |
155 | -QHP_SECT_FILTER_ATTRS = | |
156 | -QHG_LOCATION = | |
157 | -GENERATE_ECLIPSEHELP = NO | |
158 | -ECLIPSE_DOC_ID = org.doxygen.Project | |
159 | -DISABLE_INDEX = NO | |
160 | -ENUM_VALUES_PER_LINE = 4 | |
161 | -GENERATE_TREEVIEW = NO | |
162 | -USE_INLINE_TREES = NO | |
163 | -TREEVIEW_WIDTH = 250 | |
164 | -EXT_LINKS_IN_WINDOW = NO | |
165 | -FORMULA_FONTSIZE = 10 | |
166 | -FORMULA_TRANSPARENT = YES | |
167 | -SEARCHENGINE = YES | |
168 | -SERVER_BASED_SEARCH = NO | |
169 | -#--------------------------------------------------------------------------- | |
170 | -# configuration options related to the LaTeX output | |
171 | -#--------------------------------------------------------------------------- | |
172 | -GENERATE_LATEX = NO | |
173 | -LATEX_OUTPUT = latex | |
174 | -LATEX_CMD_NAME = latex | |
175 | -MAKEINDEX_CMD_NAME = makeindex | |
176 | -COMPACT_LATEX = NO | |
177 | -PAPER_TYPE = a4wide | |
178 | -EXTRA_PACKAGES = | |
179 | -LATEX_HEADER = | |
180 | -PDF_HYPERLINKS = YES | |
181 | -USE_PDFLATEX = YES | |
182 | -LATEX_BATCHMODE = NO | |
183 | -LATEX_HIDE_INDICES = NO | |
184 | -LATEX_SOURCE_CODE = NO | |
185 | -#--------------------------------------------------------------------------- | |
186 | -# configuration options related to the RTF output | |
187 | -#--------------------------------------------------------------------------- | |
188 | -GENERATE_RTF = NO | |
189 | -RTF_OUTPUT = rtf | |
190 | -COMPACT_RTF = NO | |
191 | -RTF_HYPERLINKS = NO | |
192 | -RTF_STYLESHEET_FILE = | |
193 | -RTF_EXTENSIONS_FILE = | |
194 | -#--------------------------------------------------------------------------- | |
195 | -# configuration options related to the man page output | |
196 | -#--------------------------------------------------------------------------- | |
197 | -GENERATE_MAN = NO | |
198 | -MAN_OUTPUT = man | |
199 | -MAN_EXTENSION = .3 | |
200 | -MAN_LINKS = NO | |
201 | -#--------------------------------------------------------------------------- | |
202 | -# configuration options related to the XML output | |
203 | -#--------------------------------------------------------------------------- | |
204 | -GENERATE_XML = NO | |
205 | -XML_OUTPUT = xml | |
206 | -XML_SCHEMA = | |
207 | -XML_DTD = | |
208 | -XML_PROGRAMLISTING = YES | |
209 | -#--------------------------------------------------------------------------- | |
210 | -# configuration options for the AutoGen Definitions output | |
211 | -#--------------------------------------------------------------------------- | |
212 | -GENERATE_AUTOGEN_DEF = NO | |
213 | -#--------------------------------------------------------------------------- | |
214 | -# configuration options related to the Perl module output | |
215 | -#--------------------------------------------------------------------------- | |
216 | -GENERATE_PERLMOD = NO | |
217 | -PERLMOD_LATEX = NO | |
218 | -PERLMOD_PRETTY = YES | |
219 | -PERLMOD_MAKEVAR_PREFIX = | |
220 | -#--------------------------------------------------------------------------- | |
221 | -# Configuration options related to the preprocessor | |
222 | -#--------------------------------------------------------------------------- | |
223 | -ENABLE_PREPROCESSING = YES | |
224 | -MACRO_EXPANSION = NO | |
225 | -EXPAND_ONLY_PREDEF = NO | |
226 | -SEARCH_INCLUDES = YES | |
227 | -INCLUDE_PATH = | |
228 | -INCLUDE_FILE_PATTERNS = | |
229 | -PREDEFINED = | |
230 | -EXPAND_AS_DEFINED = | |
231 | -SKIP_FUNCTION_MACROS = YES | |
232 | -#--------------------------------------------------------------------------- | |
233 | -# Configuration::additions related to external references | |
234 | -#--------------------------------------------------------------------------- | |
235 | -TAGFILES = | |
236 | -GENERATE_TAGFILE = | |
237 | -ALLEXTERNALS = NO | |
238 | -EXTERNAL_GROUPS = YES | |
239 | -PERL_PATH = /usr/bin/perl | |
240 | -#--------------------------------------------------------------------------- | |
241 | -# Configuration options related to the dot tool | |
242 | -#--------------------------------------------------------------------------- | |
243 | -CLASS_DIAGRAMS = YES | |
244 | -MSCGEN_PATH = | |
245 | -HIDE_UNDOC_RELATIONS = YES | |
246 | -HAVE_DOT = NO | |
247 | -DOT_NUM_THREADS = 0 | |
248 | -DOT_FONTNAME = FreeSans.ttf | |
249 | -DOT_FONTSIZE = 10 | |
250 | -DOT_FONTPATH = | |
251 | -CLASS_GRAPH = YES | |
252 | -COLLABORATION_GRAPH = YES | |
253 | -GROUP_GRAPHS = YES | |
254 | -UML_LOOK = NO | |
255 | -TEMPLATE_RELATIONS = NO | |
256 | -INCLUDE_GRAPH = YES | |
257 | -INCLUDED_BY_GRAPH = YES | |
258 | -CALL_GRAPH = NO | |
259 | -CALLER_GRAPH = NO | |
260 | -GRAPHICAL_HIERARCHY = YES | |
261 | -DIRECTORY_GRAPH = YES | |
262 | -DOT_IMAGE_FORMAT = png | |
263 | -DOT_PATH = | |
264 | -DOTFILE_DIRS = | |
265 | -DOT_GRAPH_MAX_NODES = 50 | |
266 | -MAX_DOT_GRAPH_DEPTH = 0 | |
267 | -DOT_TRANSPARENT = NO | |
268 | -DOT_MULTI_TARGETS = YES | |
269 | -GENERATE_LEGEND = YES | |
270 | -DOT_CLEANUP = YES |
src/data.py
... | ... | @@ -68,16 +68,6 @@ class DebtagsDB(debtags.DB): |
68 | 68 | relevance_index(b))) |
69 | 69 | return normalize_tags(' '.join(sorted_relevant_tags[-qtd_of_tags:])) |
70 | 70 | |
71 | -class PkgMatchDecider(xapian.MatchDecider): | |
72 | - """ Extends xapian.MatchDecider to disconsider installed packages. """ | |
73 | - | |
74 | - def __init__(self, installed_pkgs): | |
75 | - xapian.MatchDecider.__init__(self) | |
76 | - self.installed_pkgs = installed_pkgs | |
77 | - | |
78 | - def __call__(self, doc): | |
79 | - return doc.get_data() not in self.installed_pkgs | |
80 | - | |
81 | 71 | class DebtagsIndex: |
82 | 72 | def __init__(self,path): |
83 | 73 | self.path = path | ... | ... |
... | ... | @@ -0,0 +1,118 @@ |
1 | +#!/usr/bin/python | |
2 | + | |
3 | +# AppRecommender - A GNU/Linux application recommender | |
4 | +# | |
5 | +# Copyright (C) 2010 Tassia Camoes <tassia@gmail.com> | |
6 | +# | |
7 | +# This program is free software: you can redistribute it and/or modify | |
8 | +# it under the terms of the GNU General Public License as published by | |
9 | +# the Free Software Foundation, either version 3 of the License, or | |
10 | +# (at your option) any later version. | |
11 | +# | |
12 | +# This program is distributed in the hope that it will be useful, | |
13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | +# GNU General Public License for more details. | |
16 | +# | |
17 | +# You should have received a copy of the GNU General Public License | |
18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | + | |
20 | +import os | |
21 | +import sys | |
22 | +import commands | |
23 | +import re | |
24 | + | |
25 | +import xapian | |
26 | +from debian import debtags | |
27 | +from strategy import PkgMatchDecider | |
28 | + | |
29 | +DB_PATH = "/var/lib/debtags/package-tags" | |
30 | +INDEX_PATH = os.path.expanduser("~/.app-recommender/debtags_index") | |
31 | + | |
32 | +def load_debtags_db(path): | |
33 | + """ Load debtags database. """ | |
34 | + debtags_db = debtags.DB() | |
35 | + tag_filter = re.compile(r"^special::.+$|^.+::TODO$") | |
36 | + try: | |
37 | + debtags_db.read(open(path, "r"), lambda x: not tag_filter.match(x)) | |
38 | + except IOError: | |
39 | + print >> sys.stderr, ("IOError: could not open debtags file \'%s\'" % | |
40 | + path) | |
41 | + exit(1) | |
42 | + return debtags_db | |
43 | + | |
44 | +def get_system_pkgs(): | |
45 | + """ Return set of system packages. """ | |
46 | + dpkg_output = commands.getoutput('/usr/bin/dpkg --get-selections') | |
47 | + return dpkg_output.replace('install','\t').split() | |
48 | + | |
49 | +def get_most_relevant_tags(debtags_db,pkgs_list): | |
50 | + """ Return most relevant tags considering a list of packages. """ | |
51 | + relevant_db = debtags_db.choose_packages(pkgs_list) | |
52 | + relevance_index = debtags.relevance_index_function(debtags_db,relevant_db) | |
53 | + sorted_relevant_tags = sorted(relevant_db.iter_tags(), | |
54 | + lambda a, b: cmp(relevance_index(a), | |
55 | + relevance_index(b))) | |
56 | + return normalize_tags(' '.join(sorted_relevant_tags[-50:])) | |
57 | + | |
58 | +def normalize_tags(string): | |
59 | + """ Normalize tag string so that it can be indexed and retrieved. """ | |
60 | + return string.replace(':','_').replace('-','\'') | |
61 | + | |
62 | +def create_debtags_index(debtags_db,index_path): | |
63 | + """ Create a xapian index for debtags info based on file 'debtags_db' and | |
64 | + place it at 'index_path'. | |
65 | + """ | |
66 | + if not os.path.exists(index_path): | |
67 | + os.makedirs(index_path) | |
68 | + print "Creating new debtags xapian index at \'%s\'" % index_path | |
69 | + debtags_index = xapian.WritableDatabase(index_path, | |
70 | + xapian.DB_CREATE_OR_OVERWRITE) | |
71 | + for pkg,tags in debtags_db.iter_packages_tags(): | |
72 | + doc = xapian.Document() | |
73 | + doc.set_data(pkg) | |
74 | + for tag in tags: | |
75 | + doc.add_term(normalize_tags(tag)) | |
76 | + print "indexing ",debtags_index.add_document(doc) | |
77 | + return debtags_index | |
78 | + | |
79 | +def load_debtags_index(debtags_db,reindex): | |
80 | + """ Load an existing or new debtags index, based on boolean reindex. """ | |
81 | + if not reindex: | |
82 | + try: | |
83 | + print ("Opening existing debtags xapian index at \'%s\'" % | |
84 | + INDEX_PATH) | |
85 | + debtags_index = xapian.Database(INDEX_PATH) | |
86 | + except DatabaseError: | |
87 | + print "Could not open debtags xapian index" | |
88 | + reindex = 1 | |
89 | + if reindex: | |
90 | + debtags_index = create_debtags_index(debtags_db,INDEX_PATH) | |
91 | + return debtags_index | |
92 | + | |
93 | + | |
94 | +if __name__ == '__main__': | |
95 | + | |
96 | + reindex = 0 | |
97 | + if len(sys.argv) == 2: | |
98 | + DB_PATH = sys.argv[1] | |
99 | + reindex = 1 | |
100 | + print "reindex true" | |
101 | + elif len(sys.argv) > 2: | |
102 | + print >> sys.stderr, ("Usage: %s [PATH_TO_DEBTAGS_DATABASE]" % | |
103 | + sys.argv[0]) | |
104 | + sys.exit(1) | |
105 | + | |
106 | + debtags_db = load_debtags_db(DB_PATH) | |
107 | + installed_pkgs = get_system_pkgs() | |
108 | + best_tags = get_most_relevant_tags(debtags_db,installed_pkgs) | |
109 | + | |
110 | + debtags_index = load_debtags_index(debtags_db,reindex) | |
111 | + qp = xapian.QueryParser() | |
112 | + query = qp.parse_query(best_tags) | |
113 | + enquire = xapian.Enquire(debtags_index) | |
114 | + enquire.set_query(query) | |
115 | + | |
116 | + mset = enquire.get_mset(0, 20, None, PkgMatchDecider(installed_pkgs)) | |
117 | + for m in mset: | |
118 | + print "%2d: %s" % (m.rank, m.document.get_data()) | ... | ... |