コード例 #1
0
ファイル: distance.py プロジェクト: Polochon-street/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
        }
コード例 #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}