Commit 5ea55440 authored by Lucas Moura's avatar Lucas Moura

Merge tag 'upstream/0.6.4'

Upstream version 0.6.4

# gpg: Signature made Wed 03 Aug 2016 10:26:45 AM BRT using RSA key ID 2DA5B48C
# gpg: Good signature from "Lucas Albuquerque Medeiros de Moura <lucas.moura128@gmail.com>"
parents d799abbb 97e221e8
...@@ -52,8 +52,9 @@ class Config(Singleton): ...@@ -52,8 +52,9 @@ class Config(Singleton):
os.abort() os.abort()
if not hasattr(self, 'initialized'): if not hasattr(self, 'initialized'):
# data_source options # data_source options
# self.base_dir = '/var/lib/apprecommender' self.base_dir = os.environ.get(
self.base_dir = os.path.expanduser('~/.app-recommender') 'APPREC_DATA', '~/.apprecommender')
self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join(self.home_dir, 'apprec.log') self.output = os.path.join(self.home_dir, 'apprec.log')
self.user_data_dir = os.path.join(self.base_dir, "user_data/") self.user_data_dir = os.path.join(self.base_dir, "user_data/")
# general options # general options
...@@ -127,8 +128,9 @@ class Config(Singleton): ...@@ -127,8 +128,9 @@ class Config(Singleton):
""" """
self.debug = int(self.read_option('general', 'debug')) self.debug = int(self.read_option('general', 'debug'))
self.debug = int(self.read_option('general', 'verbose')) self.debug = int(self.read_option('general', 'verbose'))
self.base_dir = os.path.expanduser( self.base_dir = os.environ.get(
self.read_option('data_sources', 'base_dir')) 'APPREC_DATA', '~/.apprecommender')
self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join( self.output = os.path.join(
self.home_dir, self.read_option('data_sources', self.home_dir, self.read_option('data_sources',
'output')) 'output'))
......
#!/usr/bin/env python
import getopt
import sys
import logging
from apprecommender.config import Config
from apprecommender.singleton import Singleton
class LoadOptions(Singleton):
def __init__(self):
self.options = []
def load(self):
config = Config()
short_options = 'hdvo:d:v:s:z:idvo:tdvo:b:n:cdvo'
long_options = ['help', 'debug', 'verbose', 'strategy=',
'profile_size=', 'init', 'train', 'because',
'nrecommendation', 'contribute']
try:
opts, args = getopt.getopt(sys.argv[1:], short_options,
long_options)
self.options = opts
except getopt.GetoptError as error:
config.set_logger()
logging.error('Bad syntax: {}'.format(str(error)))
self.usage()
sys.exit()
for o, p in opts:
if o in ('-h', '--help'):
self.usage()
sys.exit()
elif o in ('-d', '--debug'):
config.debug = 1
elif o in ('-v', '--verbose'):
config.verbose = 1
elif o in ('-s', '--strategy'):
config.strategy = p
elif o in ('-z', '--profile_size'):
config.profile_size = int(p)
elif o in ('-i', '--init'):
continue
elif o in ('-t', '--train'):
continue
elif o in ('-b', '--because'):
config.because = True
elif o in ('-n', '--num-recommendations'):
config.num_recommendations = int(p)
elif o in ('-c', '--contribute'):
continue
else:
assert False, "unhandled option"
config.set_logger()
def usage(self):
"""
Print usage help.
"""
print "[FIXME: deprecated help]"
print "\n [ general ]"
print " -h, --help Print this help"
print " -i, --init Initialize AppRecommender data"
print " -t, --train Make training of AppRecommender" \
" machine learning"
print " -n, --num-recommendations Set the number of packages that" \
" will be recommended"
print " -b, --because Display user packages that" \
" generated a given recommendation"
print " -d, --debug Set logging level to debug"
print " -v, --verbose Set logging level to verbose"
print ""
print " [ recommender ]"
print " -s, --strategy=OPTION Recommendation strategy"
print " -z, --profilesize=k Size of user profile"
print ""
print " [ strategy options ] "
print " cb = content-based, mixed profile"
print " cbt = content-based, tags only profile"
print " cbd = content-based, description terms only profile"
print " cbh = content-based, half-half profile"
print " cbtm = content-based, time-context profile"
print " cb_eset = cb with eset profiling"
print " cbt_eset = cbt with eset profiling"
print " cbd_eset = cbd_eset with eset profiling"
print " cbh_eset = cbh with eset profiling"
print " mlbva = machine_learning, Binary Vector Approach"
print " mlbow = machine_learning, Bag Of Words"
print ""
print " [ contribute with AppRecommender ]"
print " -c, --contribute classify recommendations" \
" helping AppRecommender to improve recommendations"
...@@ -5,10 +5,10 @@ import xapian ...@@ -5,10 +5,10 @@ import xapian
from apprecommender.main.app_recommender import AppRecommender from apprecommender.main.app_recommender import AppRecommender
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.initialize import Initialize from apprecommender.initialize import Initialize
from apprecommender.load_options import LoadOptions
from apprecommender.strategy import (MachineLearning, MachineLearningBVA, from apprecommender.strategy import (MachineLearning, MachineLearningBVA,
MachineLearningBOW) MachineLearningBOW)
from apprecommender.main import collect_user_data from apprecommender.main import collect_user_data
from apprecommender.main.options import get_parser
SUCCESS = 0 SUCCESS = 0
ERROR_INIT = 1 ERROR_INIT = 1
...@@ -16,15 +16,23 @@ ERROR_TRAIN = 2 ...@@ -16,15 +16,23 @@ ERROR_TRAIN = 2
PERMISSION_DENIED = 3 PERMISSION_DENIED = 3
def check_for_flag(options, short_flag, long_flag): def parse_options(args, config):
for option, _ in options:
if option in (short_flag, long_flag):
return True
return False if args['strategy']:
config.strategy = args['strategy']
if args['debug']:
config.debug = 1
if args['verbose']:
config.verbose = 1
if args['profile_size']:
config.profile_size = args['profile_size']
if args['because']:
config.because = True
if args['num_recommendations']:
config.num_recommendations = args['num_recommendations']
def run_apprecommender(options): def run_apprecommender():
try: try:
app_recommender = AppRecommender() app_recommender = AppRecommender()
app_recommender.make_recommendation() app_recommender.make_recommendation()
...@@ -38,12 +46,8 @@ def run_apprecommender(options): ...@@ -38,12 +46,8 @@ def run_apprecommender(options):
return PERMISSION_DENIED return PERMISSION_DENIED
def run(): def run(args):
load_options = LoadOptions() if args['init']:
load_options.load()
options = load_options.options
if check_for_flag(options, '-i', '--init'):
print "Initializing AppRecommender" print "Initializing AppRecommender"
initialize = Initialize() initialize = Initialize()
...@@ -53,7 +57,7 @@ def run(): ...@@ -53,7 +57,7 @@ def run():
return PERMISSION_DENIED return PERMISSION_DENIED
return SUCCESS return SUCCESS
elif check_for_flag(options, '-t', '--train'): elif args['train']:
print "Training machine learning" print "Training machine learning"
try: try:
...@@ -63,14 +67,19 @@ def run(): ...@@ -63,14 +67,19 @@ def run():
return PERMISSION_DENIED return PERMISSION_DENIED
return SUCCESS return SUCCESS
elif check_for_flag(options, '-c', '--contribute'): elif args['contribute']:
collect_user_data.main() collect_user_data.main()
else: else:
return run_apprecommender(load_options.options) config = Config()
parse_options(args, config)
return run_apprecommender()
def main(): def main():
result = run() parser = get_parser()
args = vars(parser.parse_args())
result = run(args)
if result is ERROR_INIT: if result is ERROR_INIT:
print "\n" print "\n"
......
import argparse
def get_parser():
apprec_description = 'Package recommender system for Debian (and derived) \
distros'
parser = argparse.ArgumentParser(description=apprec_description)
parser.add_argument(
'-s', '--strategy',
help='select strategy to run apprecommender (default: cb)',
type=str)
parser.add_argument(
'-d', '--debug',
help='run apprecommender on debug mode',
type=int)
parser.add_argument(
'-v', '--verbose',
help='run apprecommender on verbose mode',
type=int)
parser.add_argument(
'-z', '--profile-size',
help='set the profile size of an user on apprecommender',
type=int)
parser.add_argument(
'-i', '--init',
help='initialize apprecommender database',
action='store_true')
parser.add_argument(
'-t', '--train',
help='train machine learning algorithms',
action='store_true')
parser.add_argument(
'-b', '--because',
help="display which user's packages generated a recommendation",
action='store_true')
parser.add_argument(
'-n', '--num-recommendations',
help='set the number of packages that will be recommended',
type=int)
parser.add_argument(
'-c', '--contribute',
help='classify recommendations and help apprecommender to improve',
action='store_true')
return parser
...@@ -4,6 +4,8 @@ import unittest ...@@ -4,6 +4,8 @@ import unittest
import logging import logging
import apprecommender.main.cli as apprec import apprecommender.main.cli as apprec
from apprecommender.main.options import get_parser
from apprecommender.config import Config from apprecommender.config import Config
from apprecommender.ml.data import MachineLearningData from apprecommender.ml.data import MachineLearningData
...@@ -15,18 +17,21 @@ class RunTests(unittest.TestCase): ...@@ -15,18 +17,21 @@ class RunTests(unittest.TestCase):
self.axi_desktopapps = Config().axi_desktopapps self.axi_desktopapps = Config().axi_desktopapps
parser = get_parser()
self.args = vars(parser.parse_args(''))
def tearDown(self): def tearDown(self):
Config().axi_desktopapps = self.axi_desktopapps Config().axi_desktopapps = self.axi_desktopapps
def test_success_run_apprec(self): def test_success_run_apprec(self):
logging.getLogger().disabled = False logging.getLogger().disabled = False
result = apprec.run() result = apprec.run(self.args)
self.assertEqual(apprec.SUCCESS, result) self.assertEqual(apprec.SUCCESS, result)
def test_error_init_on_run_apprec(self): def test_error_init_on_run_apprec(self):
Config().axi_desktopapps = "asd" Config().axi_desktopapps = "asd"
result = apprec.run() result = apprec.run(self.args)
self.assertEqual(apprec.ERROR_INIT, result) self.assertEqual(apprec.ERROR_INIT, result)
...@@ -38,7 +43,7 @@ class RunTests(unittest.TestCase): ...@@ -38,7 +43,7 @@ class RunTests(unittest.TestCase):
training_path = MachineLearningData.MACHINE_LEARNING_TRAINING training_path = MachineLearningData.MACHINE_LEARNING_TRAINING
MachineLearningData.MACHINE_LEARNING_TRAINING = "error.txt" MachineLearningData.MACHINE_LEARNING_TRAINING = "error.txt"
result = apprec.run() result = apprec.run(self.args)
config.strategy = strategy config.strategy = strategy
MachineLearningData.MACHINE_LEARNING_TRAINING = training_path MachineLearningData.MACHINE_LEARNING_TRAINING = training_path
......
...@@ -4,7 +4,7 @@ from setuptools import setup, find_packages ...@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup( setup(
name='apprecommender', name='apprecommender',
description="Package recommender for GNU packages", description="Package recommender for GNU packages",
version='0.6.3', version='0.6.4',
url='https://github.com/tassia/AppRecommender', url='https://github.com/tassia/AppRecommender',
author='Tassia Camoes Araujo', author='Tassia Camoes Araujo',
author_email='tassia@acaia.ca', author_email='tassia@acaia.ca',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment