Commit 97e221e8 authored by Lucas Moura's avatar Lucas Moura

Imported Upstream version 0.6.4

parent b299f6ca
Pipeline #3859159 failed with stage
in 58 seconds
......@@ -52,8 +52,9 @@ class Config(Singleton):
os.abort()
if not hasattr(self, 'initialized'):
# data_source options
# self.base_dir = '/var/lib/apprecommender'
self.base_dir = os.path.expanduser('~/.app-recommender')
self.base_dir = os.environ.get(
'APPREC_DATA', '~/.apprecommender')
self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join(self.home_dir, 'apprec.log')
self.user_data_dir = os.path.join(self.base_dir, "user_data/")
# general options
......@@ -127,8 +128,9 @@ class Config(Singleton):
"""
self.debug = int(self.read_option('general', 'debug'))
self.debug = int(self.read_option('general', 'verbose'))
self.base_dir = os.path.expanduser(
self.read_option('data_sources', 'base_dir'))
self.base_dir = os.environ.get(
'APPREC_DATA', '~/.apprecommender')
self.base_dir = os.path.expanduser(self.base_dir)
self.output = os.path.join(
self.home_dir, self.read_option('data_sources',
'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
from apprecommender.main.app_recommender import AppRecommender
from apprecommender.config import Config
from apprecommender.initialize import Initialize
from apprecommender.load_options import LoadOptions
from apprecommender.strategy import (MachineLearning, MachineLearningBVA,
MachineLearningBOW)
from apprecommender.main import collect_user_data
from apprecommender.main.options import get_parser
SUCCESS = 0
ERROR_INIT = 1
......@@ -16,15 +16,23 @@ ERROR_TRAIN = 2
PERMISSION_DENIED = 3
def check_for_flag(options, short_flag, long_flag):
for option, _ in options:
if option in (short_flag, long_flag):
return True
def parse_options(args, config):
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:
app_recommender = AppRecommender()
app_recommender.make_recommendation()
......@@ -38,12 +46,8 @@ def run_apprecommender(options):
return PERMISSION_DENIED
def run():
load_options = LoadOptions()
load_options.load()
options = load_options.options
if check_for_flag(options, '-i', '--init'):
def run(args):
if args['init']:
print "Initializing AppRecommender"
initialize = Initialize()
......@@ -53,7 +57,7 @@ def run():
return PERMISSION_DENIED
return SUCCESS
elif check_for_flag(options, '-t', '--train'):
elif args['train']:
print "Training machine learning"
try:
......@@ -63,14 +67,19 @@ def run():
return PERMISSION_DENIED
return SUCCESS
elif check_for_flag(options, '-c', '--contribute'):
elif args['contribute']:
collect_user_data.main()
else:
return run_apprecommender(load_options.options)
config = Config()
parse_options(args, config)
return run_apprecommender()
def main():
result = run()
parser = get_parser()
args = vars(parser.parse_args())
result = run(args)
if result is ERROR_INIT:
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
import logging
import apprecommender.main.cli as apprec
from apprecommender.main.options import get_parser
from apprecommender.config import Config
from apprecommender.ml.data import MachineLearningData
......@@ -15,18 +17,21 @@ class RunTests(unittest.TestCase):
self.axi_desktopapps = Config().axi_desktopapps
parser = get_parser()
self.args = vars(parser.parse_args(''))
def tearDown(self):
Config().axi_desktopapps = self.axi_desktopapps
def test_success_run_apprec(self):
logging.getLogger().disabled = False
result = apprec.run()
result = apprec.run(self.args)
self.assertEqual(apprec.SUCCESS, result)
def test_error_init_on_run_apprec(self):
Config().axi_desktopapps = "asd"
result = apprec.run()
result = apprec.run(self.args)
self.assertEqual(apprec.ERROR_INIT, result)
......@@ -38,7 +43,7 @@ class RunTests(unittest.TestCase):
training_path = MachineLearningData.MACHINE_LEARNING_TRAINING
MachineLearningData.MACHINE_LEARNING_TRAINING = "error.txt"
result = apprec.run()
result = apprec.run(self.args)
config.strategy = strategy
MachineLearningData.MACHINE_LEARNING_TRAINING = training_path
......
......@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup(
name='apprecommender',
description="Package recommender for GNU packages",
version='0.6.3',
version='0.6.4',
url='https://github.com/tassia/AppRecommender',
author='Tassia Camoes Araujo',
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