Commit 27763f38d96c28cabebccc046208019b940d7b1f

Authored by Tássia Camões Araújo
1 parent 4d46623e
Exists in master and in 1 other branch add_vagrant

Added configuration file example and fixed config class bugs.

Showing 2 changed files with 64 additions and 32 deletions   Show diff stats
src/config.py
... ... @@ -38,9 +38,7 @@ class Config():
38 38 self.debug = 0
39 39 self.verbose = 0
40 40 self.output = "/dev/null"
41   - self.config = None
42 41 self.axi = "/var/lib/apt-xapian-index/index"
43   - self.axi_values = "/var/lib/apt-xapian-index/values"
44 42 self.popcon_index = os.path.expanduser("~/.app-recommender/popcon_index")
45 43 self.popcon_dir = os.path.expanduser("~/.app-recommender/popcon_dir")
46 44 self.clusters_dir = os.path.expanduser("~/.app-recommender/clusters_dir")
... ... @@ -48,6 +46,7 @@ class Config():
48 46 self.index_mode = "old"
49 47 self.strategy = "cb"
50 48 self.weight = "bm25"
  49 + self.profile_size = 50
51 50 self.load_options()
52 51 self.set_logger()
53 52  
... ... @@ -56,21 +55,23 @@ class Config():
56 55 Print usage help.
57 56 """
58 57 print "\n [ general ]"
59   - print " -h, --help Print this help"
60   - print " -d, --debug Set logging level to debug"
61   - print " -v, --verbose Set logging level to verbose"
62   - print " -o, --output=PATH Path to file to save output"
63   - print " -c, --config=PATH Path to configuration file"
  58 + print " -h, --help Print this help"
  59 + print " -d, --debug Set logging level to debug"
  60 + print " -v, --verbose Set logging level to verbose"
  61 + print " -o, --output=PATH Path to file to save output"
  62 + print ""
  63 + print " [ data sources ]"
  64 + print " -a, --axi=PATH Path to apt-xapian-index"
  65 + print " -p, --popconindex=PATH Path to popcon index"
  66 + print " -m, --popcondir=PATH Path to popcon submissions dir"
  67 + print " -u, --indexmode= 'old'|'reindex'|'cluster'|'recluster'"
  68 + print " -l, --clustersdir=PATH Path to popcon clusters dir"
  69 + print " -e, --medoids=k Number of medoids for clustering"
64 70 print ""
65 71 print " [ recommender ]"
66   - print " -a, --axi=PATH Path to Apt-xapian-index"
67   - print " -p, --popconindex=PATH Path to popcon dedicated index"
68   - print " -m, --popcondir=PATH Path to popcon submissions dir"
69   - print " -u, --indexmode= old, reindex, cluster, recluster"
70   - print " -l, --clustersdir=PATH Path to popcon clusters dir"
71   - print " -e, --medoids=k Number of medoids for clustering"
72   - print " -w, --weight=OPTION Search weighting scheme"
73   - print " -s, --strategy=OPTION Recommendation strategy"
  72 + print " -w, --weight=OPTION Search weighting scheme"
  73 + print " -s, --strategy=OPTION Recommendation strategy"
  74 + print " -z, --profile_size=SIZE Size of user profile"
74 75 print ""
75 76 print " [ weight options ] "
76 77 print " trad = traditional probabilistic weighting"
... ... @@ -81,8 +82,7 @@ class Config():
81 82 print " cbt = content-based using only tags as content "
82 83 print " cbd = content-based using only package descriptions as content "
83 84 print " col = collaborative "
84   - #print " colct = collaborative through tags content "
85   - #print " colcp = collaborative through package descriptions content "
  85 + print " colct = collaborative through tags content "
86 86  
87 87 def read_option(self, section, option):
88 88 """
... ... @@ -102,7 +102,8 @@ class Config():
102 102 try:
103 103 self.config = ConfigParser()
104 104 self.config.read(['/etc/apprecommender/recommender.conf',
105   - os.path.expanduser('~/apprecommender.rc')])
  105 + os.path.expanduser('~/.app_recommender.rc'),
  106 + 'app_recommender.cfg'])
106 107 except (MissingSectionHeaderError), err:
107 108 logging.error("Error in config file syntax: %s", str(err))
108 109 os.abort()
... ... @@ -110,21 +111,23 @@ class Config():
110 111 self.debug = self.read_option('general', 'debug')
111 112 self.debug = self.read_option('general', 'verbose')
112 113 self.output_filename = self.read_option('general', 'output')
113   - self.config = self.read_option('general', 'config')
114   -
115   - self.axi = self.read_option('recommender', 'axi')
116   - self.popcon_index = self.read_option('recommender', 'popcon_index')
117   - self.popcon_dir = self.read_option('recommender', 'popcon_dir')
118   - self.index_mode = self.read_option('recommender', 'index_mode')
119   - self.clusters_dir = self.read_option('recommender', 'clusters_dir')
120   - self.k_medoids = self.read_option('recommender', 'k_medoids')
  114 +
  115 + self.axi = self.read_option('data_sources', 'axi')
  116 + self.popcon_index = os.path.expanduser(self.read_option('data_sources','popcon_index'))
  117 + self.popcon_dir = os.path.expanduser(self.read_option('data_sources', 'popcon_dir'))
  118 + self.index_mode = self.read_option('data_sources', 'index_mode')
  119 + self.clusters_dir = os.path.expanduser(self.read_option('data_sources', 'clusters_dir'))
  120 + self.k_medoids = self.read_option('data_sources', 'k_medoids')
  121 +
121 122 self.weight = self.read_option('recommender', 'weight')
122 123 self.strategy = self.read_option('recommender', 'strategy')
  124 + self.profile_size = self.read_option('recommender', 'profile_size')
123 125  
124   - short_options = "hdvo:c:a:p:m:ul:e:w:s:"
125   - long_options = ["help", "debug", "verbose", "output=", "config=",
  126 + short_options = "hdvo:a:p:m:ul:e:w:s:z:"
  127 + long_options = ["help", "debug", "verbose", "output=",
126 128 "axi=", "popconindex=", "popcondir=", "indexmode=",
127   - "clustersdir=", "kmedoids=", "weight=", "strategy="]
  129 + "clustersdir=", "kmedoids=", "weight=", "strategy=",
  130 + "profile_size="]
128 131 try:
129 132 opts, args = getopt.getopt(sys.argv[1:], short_options,
130 133 long_options)
... ... @@ -144,11 +147,8 @@ class Config():
144 147 self.verbose = 1
145 148 elif o in ("-o", "--output"):
146 149 self.output = p
147   - elif o in ("-c", "--config"):
148   - self.config = p
149 150 elif o in ("-a", "--axi"):
150 151 self.axi = p + "/index"
151   - self.axi_values = p + "/values"
152 152 elif o in ("-p", "--popconindex"):
153 153 self.popcon_index = p
154 154 elif o in ("-m", "--popcondir"):
... ... @@ -163,6 +163,8 @@ class Config():
163 163 self.weight = p
164 164 elif o in ("-s", "--strategy"):
165 165 self.strategy = p
  166 + elif o in ("-z", "--profile_size"):
  167 + self.strategy = p
166 168 else:
167 169 assert False, "unhandled option"
168 170  
... ...
src/examples/app_recommender.cfg 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +# Config file for AppRecommender
  2 +
  3 +[general]
  4 +# logging level
  5 +debug = 0
  6 +verbose = 0
  7 +# output file
  8 +output = /dev/null
  9 +
  10 +[data_sources]
  11 +# path to apt-xapian-index
  12 +axi = /var/lib/apt-xapian-index/index
  13 +# old, reindex, cluster, recluster
  14 +index_mode = old
  15 +# path to popcon index
  16 +popcon_index = ~/.app-recommender/popcon_index
  17 +# path to popcon submissions dir
  18 +popcon_dir = ~/.app-recommender/popcon_dir
  19 +# path to popcon clusters dir
  20 +clusters_dir = ~/.app-recommender/clusters_dir
  21 +# number of medoids for clustering
  22 +k_medoids = 100
  23 +
  24 +[recommender]
  25 +# recommendation strategy
  26 +strategy = cb
  27 +# search weighting scheme ('trad' or 'bm25')
  28 +weight = bm25
  29 +# user profile size
  30 +profile_size = 50
... ...