Example #1
0
from libunison.utils import print_track

DATASET_ROOT = '../data/lastfm_raw'


def tid(string):
    if len(string) != 18 or string != string.upper() or string[:2] != 'TR':
        raise argparse.ArgumentTypeError('invalid tid')
    return string


def _parse_args():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--folder', default=DATASET_ROOT)
    parser.add_argument('tid', type=tid)
    return parser.parse_args()


if __name__ == '__main__':
    args = _parse_args()
    path = '%s/%s/%s/%s/%s.json' % (args.folder, args.tid[2], args.tid[3],
                                    args.tid[4], args.tid)
    try:
        data = open(path).read()
    except IOError:
        # We probably don't know this tid.
        print "Could not find specified tid (%s)." % tid
        sys.exit(0)
    print_track(json.loads(data))
Example #2
0
from libunison.utils import print_track


DATASET_ROOT = '../data/lastfm_raw'


def tid(string):
    if len(string) != 18 or string != string.upper() or string[:2] != 'TR':
        raise argparse.ArgumentTypeError('invalid tid')
    return string


def _parse_args():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--folder', default=DATASET_ROOT)
    parser.add_argument('tid', type=tid)
    return parser.parse_args()


if __name__ == '__main__':
    args = _parse_args()
    path = '%s/%s/%s/%s/%s.json' % (args.folder, args.tid[2], args.tid[3],
            args.tid[4], args.tid)
    try:
        data = open(path).read()
    except IOError:
        # We probably don't know this tid.
        print "Could not find specified tid (%s)." % tid
        sys.exit(0)
    print_track(json.loads(data))
Example #3
0
        curr, gw = get_vector(db_conn, tag)
        if curr is None:
            continue
        weight = gw * log1p(float(count)) / log(2)
        vector = [(weight * x + y) for x, y in zip(curr, vector)]
    norm = sqrt(sum([x * x for x in vector]))
    if norm > 0:
        return tuple([x / norm for x in vector])
    else:
        return tuple(vector)


def _parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('track1', type=open)
    parser.add_argument('track2', type=open)
    parser.add_argument('--db', default=DB_PATH)
    return parser.parse_args()


if __name__ == '__main__':
    args = _parse_args()
    t1 = json.loads(args.track1.read())
    t2 = json.loads(args.track2.read())
    print('-------- Track 1')
    print_track(t1)
    print('-------- Track 2')
    print_track(t2)
    db_conn = sqlite3.connect(args.db)
    print similarity(t1, t2, db_conn)
Example #4
0
        curr, gw = get_vector(db_conn, tag)
        if curr is None:
            continue
        weight = gw * log1p(float(count)) / log(2)
        vector = [(weight*x + y) for x, y in zip(curr, vector)]
    norm = sqrt(sum([x*x for x in vector]))
    if norm > 0:
        return tuple([x / norm for x in vector])
    else:
        return tuple(vector)


def _parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('track1', type=open)
    parser.add_argument('track2', type=open)
    parser.add_argument('--db', default=DB_PATH)
    return parser.parse_args()


if __name__ == '__main__':
    args = _parse_args()
    t1 = json.loads(args.track1.read())
    t2 = json.loads(args.track2.read())
    print('-------- Track 1')
    print_track(t1)
    print('-------- Track 2')
    print_track(t2)
    db_conn = sqlite3.connect(args.db)
    print similarity(t1, t2, db_conn)