예제 #1
0
def port_sv():
    print '---- Porting the SV database ----'
    db1 = connect_to_database()
    db1.add_son_manipulator(TransformToBinary())    
    db = NeoEngine('/data/neo4j')

    db.create_collection('sv')

    cnt = db1.sv.find().count()
    cntidx = bar([i for i in range(cnt)])
    for sv in db1.sv.find():
        #print type(sv['sv'].value())
        cntidx.next()
        data = {'speaker_name': _udecode(sv['speaker_name']),
                'sv': sv['sv'].value(),
                'random': random.random()}
        node = db.insert('sv', data)
        
        # check data integrity
        try:
            assert _udecode(sv['speaker_name']) == db.get('sv', {'id': node['id']})['speaker_name']
            assert np.array_equal(sv['sv'].value(), NeoCustomType(node['sv']))
        except Exception:
            print sv['speaker_name']
            db.shutdown()
        
    db.create_index('sv', 'speaker_name')

    db.shutdown()
예제 #2
0
def test_port_speaker():
    print '---- Testing speaker database integrity ----'
    db1 = connect_to_database()
    db = NeoEngine('/data/neo4j')

    for speaker in bar(Speaker.objects):
        nodes = db.get('speaker', {'name': _udecode(speaker.name)})
        if len(nodes) > 1:
            print len(nodes)
            raise Exception, "Non-unique name in database"
        node = nodes.single

        for key in ['name', 'gender', 'language', 'dialect']:
            try:
                assert _udecode(speaker[key]) == node[key]
            except AssertionError:
                print "Failed (%s): %s" % (key, speaker.name)
    db.shutdown()
예제 #3
0
    for sv_rec in sv_rec_cursor:
        if idx in random_idx:
            print sv_rec['speaker_name']
            sv_data = NeoCustomType(sv_rec['sv'])
            reshape_size = np.max([np.size(sv_data,1), np.size(sv_data,0)])

            sv_data = np.reshape(sv_data, (1,reshape_size))

            if not stacked_sv.any():
                stacked_sv = sv_data
            else:
                stacked_sv = np.vstack((stacked_sv, sv_data))
            if np.size(stacked_sv,0) == limit:
                break
        idx = idx + 1

    return stacked_sv

if __name__ == '__main__':
    from spkrec.db.neo4j import NeoEngine

    db = NeoEngine('/data/neo4j')

    for speaker in db.get('speaker'):
        print speaker['name']

        stacked = stack_SVs_random(db, speaker['name'], 10)
        print np.size(stacked,0)

    db.shutdown()
        if idx in random_idx:
            print sv_rec['speaker_name']
            sv_data = NeoCustomType(sv_rec['sv'])
            reshape_size = np.max([np.size(sv_data, 1), np.size(sv_data, 0)])

            sv_data = np.reshape(sv_data, (1, reshape_size))

            if not stacked_sv.any():
                stacked_sv = sv_data
            else:
                stacked_sv = np.vstack((stacked_sv, sv_data))
            if np.size(stacked_sv, 0) == limit:
                break
        idx = idx + 1

    return stacked_sv


if __name__ == '__main__':
    from spkrec.db.neo4j import NeoEngine

    db = NeoEngine('/data/neo4j')

    for speaker in db.get('speaker'):
        print speaker['name']

        stacked = stack_SVs_random(db, speaker['name'], 10)
        print np.size(stacked, 0)

    db.shutdown()