Mercurial > hg > dml-open-cliopatria
comparison dml-cla/python/places_hist.py @ 0:718306e29690 tip
commiting public release
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 21:05:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:718306e29690 |
---|---|
1 # Part of DML (Digital Music Laboratory) | |
2 # Copyright 2014-2015 Daniel Wolff, City University | |
3 | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public | |
15 # License along with this library; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | |
18 # -*- coding: utf-8 -*- | |
19 __author__='wolffd' | |
20 | |
21 | |
22 from rdflib import RDF, RDFS | |
23 from csvutils import * | |
24 from aggregate import * | |
25 from n3Parser import get_rdf_graph_from_n3 | |
26 import numpy | |
27 from scipy.spatial import distance | |
28 from collections import defaultdict | |
29 | |
30 | |
31 | |
32 def per_file(inputs,opts={}): | |
33 places = [] | |
34 lists = [] | |
35 | |
36 #print_status(str(inputs)) | |
37 # simtype = opts['sim_type'] | |
38 | |
39 def accum(item): | |
40 | |
41 # add uri if everything went well | |
42 places.append(item['place']) | |
43 lists.append(item['list']) | |
44 | |
45 # accumulation | |
46 st=for_each(inputs,accum) | |
47 | |
48 # get the histogram | |
49 (histo,index) = histogram(places) | |
50 | |
51 # get the songs for each place | |
52 list = [] | |
53 for row in index.values(): | |
54 list += [lists[i] for i in row] | |
55 | |
56 return { 'result': { 'hist': histo }, #AK requested this removed, 'lists': list}, | |
57 'stats' : st } | |
58 | |
59 | |
60 | |
61 # histogram the returns revers index as well | |
62 def histogram(strin = []): | |
63 # build histogram | |
64 histo = dict() | |
65 index = defaultdict(list) | |
66 for num, row in enumerate(strin): | |
67 histo[row] = histo.get(row, 0) + 1 | |
68 index[row] += [num] | |
69 | |
70 # return most frequent key | |
71 return ({'counts':histo.values(), 'places':histo.keys()}, index) |