예제 #1
0
def cosine_similarity(song1, song2):
    """
    Wrapper around `bl_cosine_similarity` function.

    Params:
        - filename1 is the first file to use.
        - filename2 is the second file to use.

    Returns a dict {similarity, song1, song2} containing the computed cosine
    similarity and the created `bl_song` objects.
    """
    if isinstance(song1, str) and isinstance(song2, str):
        filename1 = ffi.new("char[]", song1.encode("utf-8"))
        filename2 = ffi.new("char[]", song2.encode("utf-8"))
        song1 = ffi.new("struct bl_song *")
        song2 = ffi.new("struct bl_song *")
        return {
            "similarity": lib.bl_cosine_similarity_file(filename1, filename2,
                                                        song1, song2),
            "song1": bl_song(c_struct=song1),
            "song2": bl_song(c_struct=song2)
        }
    elif isinstance(song1, bl_song) and isinstance(song2, bl_song):
        return {
            "similarity": lib.bl_cosine_similarity(song1["force_vector"],
                                                   song2["force_vector"]),
            "song1": song1,
            "song2": song2
        }
    else:
        return {
            "similarity": None,
            "song1": None,
            "song2": None
        }
예제 #2
0
파일: bl_song.py 프로젝트: Phyks/bliss
def cosine_similarity(filename1, filename2):
    """
    Wrapper around `bl_cosine_similarity` function.

    Params:
        - filename1 is the first file to use.
        - filename2 is the second file to use.

    Returns a dict {similarity, song1, song2} containing the computed cosine
    similarity and the created `bl_song` objects.
    """
    song1 = ffi.new("struct bl_song *")
    song2 = ffi.new("struct bl_song *")
    filename1 = ffi.new("char[]", filename1.encode("utf-8"))
    filename2 = ffi.new("char[]", filename2.encode("utf-8"))
    return {
        "similarity": lib.bl_cosine_similarity(filename1, filename2, song1, song2),
        "song1": bl_song(c_struct=song1),
        "song2": bl_song(c_struct=song2),
    }
예제 #3
0
def cosine_similarity(filename1, filename2):
    """
    Wrapper around `bl_cosine_similarity` function.

    Params:
        - filename1 is the first file to use.
        - filename2 is the second file to use.

    Returns a dict {similarity, song1, song2} containing the computed cosine
    similarity and the created `bl_song` objects.
    """
    song1 = ffi.new("struct bl_song *")
    song2 = ffi.new("struct bl_song *")
    filename1 = ffi.new("char[]", filename1.encode("utf-8"))
    filename2 = ffi.new("char[]", filename2.encode("utf-8"))
    return {
        "similarity": lib.bl_cosine_similarity(filename1, filename2, song1,
                                               song2),
        "song1": bl_song(c_struct=song1),
        "song2": bl_song(c_struct=song2)
    }
예제 #4
0
파일: distance.py 프로젝트: moumar/bliss
def cosine_similarity(song1, song2):
    """
    Wrapper around `bl_cosine_similarity` function.

    Params:
        - filename1 is the first file to use.
        - filename2 is the second file to use.

    Returns a dict {similarity, song1, song2} containing the computed cosine
    similarity and the created `bl_song` objects.
    """
    if isinstance(song1, str) and isinstance(song2, str):
        filename1 = ffi.new("char[]", song1.encode("utf-8"))
        filename2 = ffi.new("char[]", song2.encode("utf-8"))
        song1 = ffi.new("struct bl_song *")
        song2 = ffi.new("struct bl_song *")
        return {
            "similarity":
            lib.bl_cosine_similarity_file(filename1, filename2, song1, song2),
            "song1":
            bl_song(c_struct=song1),
            "song2":
            bl_song(c_struct=song2)
        }
    elif isinstance(song1, bl_song) and isinstance(song2, bl_song):
        return {
            "similarity":
            lib.bl_cosine_similarity(song1["force_vector"],
                                     song2["force_vector"]),
            "song1":
            song1,
            "song2":
            song2
        }
    else:
        return {"similarity": None, "song1": None, "song2": None}