diff --git a/src/app_recommender.py b/src/app_recommender.py index 9e7684b..00dece2 100755 --- a/src/app_recommender.py +++ b/src/app_recommender.py @@ -1,21 +1,23 @@ -#!/usr/bin/python - -# AppRecommender - a GNU/Linux application recommender. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +""" + AppRecommender - A GNU/Linux application recommender +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import os import sys diff --git a/src/clustering.py b/src/clustering.py index 1f8fb0b..2ff4bcb 100755 --- a/src/clustering.py +++ b/src/clustering.py @@ -1,22 +1,23 @@ -#!/usr/bin/python - -# Clustering - a python script to perform clustering of popcon data. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +""" + Clustering - A python script to perform clustering of popcon data. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import os import sys import logging diff --git a/src/config.py b/src/config.py index 32f03a0..dd8b714 100644 --- a/src/config.py +++ b/src/config.py @@ -1,21 +1,23 @@ -#!/usr/bin/python - -# config - python module for configuration options. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +""" + config - python module for configuration options. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import getopt import sys diff --git a/src/cross_validation.py b/src/cross_validation.py index ee32644..f0aaf8e 100755 --- a/src/cross_validation.py +++ b/src/cross_validation.py @@ -1,22 +1,24 @@ -#!/usr/bin/python - -# CrossValidation - python module for classes and methods related to -# recommenders evaluation. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +""" + CrossValidation - python module for classes and methods related to + recommenders evaluation. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import os import sys diff --git a/src/data.py b/src/data.py index 2e8b979..eb23dfc 100644 --- a/src/data.py +++ b/src/data.py @@ -1,21 +1,23 @@ -#!/usr/bin/python - -# data - python module for data sources classes and methods. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +""" + data - python module for data sources classes and methods. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import os import sys diff --git a/src/demo_rec.py b/src/demo_rec.py deleted file mode 100755 index ea6802d..0000000 --- a/src/demo_rec.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/python - -# DemoRecommender - demonstration of a GNU/Linux application recommender. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import os -import sys -import commands -import re - -import xapian -from debian import debtags -from strategy import PkgMatchDecider - -DB_PATH = "/var/lib/debtags/package-tags" -INDEX_PATH = os.path.expanduser("~/.app-recommender/debtags_index") - -def load_debtags_db(path): - """ Load debtags database. """ - debtags_db = debtags.DB() - tag_filter = re.compile(r"^special::.+$|^.+::TODO$") - try: - debtags_db.read(open(path, "r"), lambda x: not tag_filter.match(x)) - except IOError: - print >> sys.stderr, ("IOError: could not open debtags file \'%s\'" % - path) - exit(1) - return debtags_db - -def get_system_pkgs(): - """ Return set of system packages. """ - dpkg_output = commands.getoutput('/usr/bin/dpkg --get-selections') - return dpkg_output.replace('install','\t').split() - -def get_most_relevant_tags(debtags_db,pkgs_list): - """ Return most relevant tags considering a list of packages. """ - relevant_db = debtags_db.choose_packages(pkgs_list) - relevance_index = debtags.relevance_index_function(debtags_db,relevant_db) - sorted_relevant_tags = sorted(relevant_db.iter_tags(), - lambda a, b: cmp(relevance_index(a), - relevance_index(b))) - return normalize_tags(' '.join(sorted_relevant_tags[-50:])) - -def normalize_tags(string): - """ Normalize tag string so that it can be indexed and retrieved. """ - return string.replace(':','_').replace('-','\'') - -def create_debtags_index(debtags_db,index_path): - """ Create a xapian index for debtags info based on file 'debtags_db' and - place it at 'index_path'. - """ - if not os.path.exists(index_path): - os.makedirs(index_path) - print "Creating new debtags xapian index at \'%s\'" % index_path - debtags_index = xapian.WritableDatabase(index_path, - xapian.DB_CREATE_OR_OVERWRITE) - for pkg,tags in debtags_db.iter_packages_tags(): - doc = xapian.Document() - doc.set_data(pkg) - for tag in tags: - doc.add_term(normalize_tags(tag)) - print "indexing ",debtags_index.add_document(doc) - return debtags_index - -def load_debtags_index(debtags_db,reindex): - """ Load an existing or new debtags index, based on boolean reindex. """ - if not reindex: - try: - print ("Opening existing debtags xapian index at \'%s\'" % - INDEX_PATH) - debtags_index = xapian.Database(INDEX_PATH) - except DatabaseError: - print "Could not open debtags xapian index" - reindex = 1 - if reindex: - debtags_index = create_debtags_index(debtags_db,INDEX_PATH) - return debtags_index - - -if __name__ == '__main__': - - reindex = 0 - if len(sys.argv) == 2: - DB_PATH = sys.argv[1] - reindex = 1 - print "reindex true" - elif len(sys.argv) > 2: - print >> sys.stderr, ("Usage: %s [PATH_TO_DEBTAGS_DATABASE]" % - sys.argv[0]) - sys.exit(1) - - debtags_db = load_debtags_db(DB_PATH) - installed_pkgs = get_system_pkgs() - best_tags = get_most_relevant_tags(debtags_db,installed_pkgs) - - debtags_index = load_debtags_index(debtags_db,reindex) - qp = xapian.QueryParser() - query = qp.parse_query(best_tags) - enquire = xapian.Enquire(debtags_index) - enquire.set_query(query) - - mset = enquire.get_mset(0, 20, None, PkgMatchDecider(installed_pkgs)) - for m in mset: - print "%2d: %s" % (m.rank, m.document.get_data()) diff --git a/src/dissimilarity.py b/src/dissimilarity.py index a44ec78..3e48400 100644 --- a/src/dissimilarity.py +++ b/src/dissimilarity.py @@ -1,22 +1,24 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + similarity - python module for classes and methods related to similarity + measuring between two sets of data. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -# similarity - python module for classes and methods related to similarity -# measuring between two sets of data. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import math import stats diff --git a/src/error.py b/src/error.py index 8a38e00..367a5d4 100644 --- a/src/error.py +++ b/src/error.py @@ -1,21 +1,23 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + error.py - python module for error definition. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -# error.py - python module for error definition. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" class Error(Exception): """ diff --git a/src/evaluation.py b/src/evaluation.py index 84c4da5..9349cf8 100644 --- a/src/evaluation.py +++ b/src/evaluation.py @@ -1,22 +1,24 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + evaluation - python module for classes and methods related to recommenders + evaluation. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -# evaluation - python module for classes and methods related to recommenders -# evaluation. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import math import random diff --git a/src/examples/demo_rec.py b/src/examples/demo_rec.py new file mode 100755 index 0000000..bd44492 --- /dev/null +++ b/src/examples/demo_rec.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +""" + DemoRecommender - demonstration of a GNU/Linux application recommender. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + +import os +import sys +import commands +import re + +import xapian +from debian import debtags +from strategy import PkgMatchDecider + +DB_PATH = "/var/lib/debtags/package-tags" +INDEX_PATH = os.path.expanduser("~/.app-recommender/debtags_index") + +def load_debtags_db(path): + """ Load debtags database. """ + debtags_db = debtags.DB() + tag_filter = re.compile(r"^special::.+$|^.+::TODO$") + try: + debtags_db.read(open(path, "r"), lambda x: not tag_filter.match(x)) + except IOError: + print >> sys.stderr, ("IOError: could not open debtags file \'%s\'" % + path) + exit(1) + return debtags_db + +def get_system_pkgs(): + """ Return set of system packages. """ + dpkg_output = commands.getoutput('/usr/bin/dpkg --get-selections') + return dpkg_output.replace('install','\t').split() + +def get_most_relevant_tags(debtags_db,pkgs_list): + """ Return most relevant tags considering a list of packages. """ + relevant_db = debtags_db.choose_packages(pkgs_list) + relevance_index = debtags.relevance_index_function(debtags_db,relevant_db) + sorted_relevant_tags = sorted(relevant_db.iter_tags(), + lambda a, b: cmp(relevance_index(a), + relevance_index(b))) + return normalize_tags(' '.join(sorted_relevant_tags[-50:])) + +def normalize_tags(string): + """ Normalize tag string so that it can be indexed and retrieved. """ + return string.replace(':','_').replace('-','\'') + +def create_debtags_index(debtags_db,index_path): + """ Create a xapian index for debtags info based on file 'debtags_db' and + place it at 'index_path'. + """ + if not os.path.exists(index_path): + os.makedirs(index_path) + print "Creating new debtags xapian index at \'%s\'" % index_path + debtags_index = xapian.WritableDatabase(index_path, + xapian.DB_CREATE_OR_OVERWRITE) + for pkg,tags in debtags_db.iter_packages_tags(): + doc = xapian.Document() + doc.set_data(pkg) + for tag in tags: + doc.add_term(normalize_tags(tag)) + print "indexing ",debtags_index.add_document(doc) + return debtags_index + +def load_debtags_index(debtags_db,reindex): + """ Load an existing or new debtags index, based on boolean reindex. """ + if not reindex: + try: + print ("Opening existing debtags xapian index at \'%s\'" % + INDEX_PATH) + debtags_index = xapian.Database(INDEX_PATH) + except DatabaseError: + print "Could not open debtags xapian index" + reindex = 1 + if reindex: + debtags_index = create_debtags_index(debtags_db,INDEX_PATH) + return debtags_index + + +if __name__ == '__main__': + + reindex = 0 + if len(sys.argv) == 2: + DB_PATH = sys.argv[1] + reindex = 1 + print "reindex true" + elif len(sys.argv) > 2: + print >> sys.stderr, ("Usage: %s [PATH_TO_DEBTAGS_DATABASE]" % + sys.argv[0]) + sys.exit(1) + + debtags_db = load_debtags_db(DB_PATH) + installed_pkgs = get_system_pkgs() + best_tags = get_most_relevant_tags(debtags_db,installed_pkgs) + + debtags_index = load_debtags_index(debtags_db,reindex) + qp = xapian.QueryParser() + query = qp.parse_query(best_tags) + enquire = xapian.Enquire(debtags_index) + enquire.set_query(query) + + mset = enquire.get_mset(0, 20, None, PkgMatchDecider(installed_pkgs)) + for m in mset: + print "%2d: %s" % (m.rank, m.document.get_data()) diff --git a/src/generate_doc.sh b/src/generate_doc.sh index e6597d1..b1228f8 100755 --- a/src/generate_doc.sh +++ b/src/generate_doc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/env bash # # generate_doc.sh - shell script to generate documentation using doxygen. # diff --git a/src/recommender.py b/src/recommender.py index 9a30b6d..e2055a6 100644 --- a/src/recommender.py +++ b/src/recommender.py @@ -1,21 +1,23 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + recommender - python module for classes related to recommenders. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -# recommender - python module for classes related to recommenders. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" from operator import itemgetter from data import * diff --git a/src/similarity.py b/src/similarity.py deleted file mode 100644 index ccc2ce9..0000000 --- a/src/similarity.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/python - -# similarity - python module for classes and methods related to similarity -# measuring between two sets of data. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import math -import stats - -def norm(x): - """ - Return vector norm. - """ - return math.sqrt(sum([x_i**2 for x_i in x])) - -def dot_product(x,y): - """ - Return dot product of vectors 'x' and 'y'. - """ - return sum([(x[i] * y[i]) for i in range(len(x))]) - -class SimilarityMeasure: - """ - Abstraction for diferent similarity measure approaches. - """ - -class Distance(SimilarityMeasure): - """ - Euclidian distance measure. - """ - def __call__(self,x,y): - """ - Return euclidian distance between vectors 'x' and 'y'. - """ - sum_pow = sum([((x[i] - y[i]) ** 2) for i in range(len(x))]) - return math.sqrt(sum_pow) - -class Cosine(SimilarityMeasure): - """ - Cosine similarity measure. - """ - def __call__(self,x,y): - """ - Return cosine of angle between vectors 'x' and 'y'. - """ - return float(dot_product(x,y)/(norm(x)*norm(y))) - -class Pearson(SimilarityMeasure): - """ - Pearson coeficient measure. - """ - def __call__(self,x,y): - """ Return Pearson coeficient between vectors 'x' and 'y'. """ - return stats.pearsonr(x,y) # FIXME: ZeroDivisionError - -class Spearman(SimilarityMeasure): - """ - Spearman correlation measure. - """ - def __call__(self,x,y): - """ - Return Spearman correlation between vectors 'x' and 'y'. - """ - return stats.spearmanr(x,y) # FIXME: ZeroDivisionError - -class Tanimoto(SimilarityMeasure): - """ - Tanimoto coeficient measure. - """ - def __call__(self,x,y): - """ - Return Tanimoto coeficient between vectors 'x' and 'y'. - """ - z = [v for v in x if v in y] - return float(len(z))/(len(x)+len(y)-len(z)) diff --git a/src/singleton.py b/src/singleton.py index 5d17807..ea25001 100644 --- a/src/singleton.py +++ b/src/singleton.py @@ -1,21 +1,24 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + singleton - python class that implements singleton design pattern. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" -# singleton - python class that implements singleton design pattern. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . class Singleton(object): """ Base class for inheritance of only-one-instance classes. diff --git a/src/strategy.py b/src/strategy.py index 5732cc8..307555c 100644 --- a/src/strategy.py +++ b/src/strategy.py @@ -1,22 +1,24 @@ -#!/usr/bin/python - -# strategy - python module for classes and methods related to recommendation -# strategies. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +""" + strategy - python module for classes and methods related to recommendation + strategies. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import os, re import xapian diff --git a/src/user.py b/src/user.py index b8c4a21..536f30c 100644 --- a/src/user.py +++ b/src/user.py @@ -1,21 +1,23 @@ -#!/usr/bin/python +#!/usr/bin/env python +""" + user - python module for classes and methods related to recommenders' users. +""" +__author__ = "Tassia Camoes Araujo " +__copyright__ = "Copyright (C) 2011 Tassia Camoes Araujo" +__license__ = """ + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -# user - python module for classes and methods related to recommenders' users. -# -# Copyright (C) 2010 Tassia Camoes -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" import commands import xapian -- libgit2 0.21.2