当前位置: 首页>>代码示例>>Python>>正文


Python Vector.cosTheta方法代码示例

本文整理汇总了Python中vector.Vector.cosTheta方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.cosTheta方法的具体用法?Python Vector.cosTheta怎么用?Python Vector.cosTheta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vector.Vector的用法示例。


在下文中一共展示了Vector.cosTheta方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: computeScores

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def computeScores(inputDir, outCSV, acceptTypes):
    
    with open(outCSV, "wb") as outF:
        a = csv.writer(outF, delimiter=',')
        a.writerow(["x-coordinate","y-coordinate","Similarity_score"])        

        files_tuple = itertools.combinations(filterFiles(inputDir, acceptTypes), 2)
        for file1, file2 in files_tuple:
            try:
                row_cosine_distance = [file1, file2]
            
                file1_parsedData = parser.from_file(file1)
                file2_parsedData = parser.from_file(file2)
           
                v1 = Vector(file1, ast.literal_eval(file1_parsedData["content"]))
                v2 = Vector(file2, ast.literal_eval(file2_parsedData["content"]))
            

                row_cosine_distance.append(v1.cosTheta(v2))            

                a.writerow(row_cosine_distance)  
            except ConnectionError:
                sleep(1)
            except KeyError:
                continue
            except Exception, e:
                pass    
开发者ID:jainn3,项目名称:ContentDetection,代码行数:29,代码来源:cosine_similarity.py

示例2: computeScoresJson

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def computeScoresJson(inputDir, outCSV, acceptTypes, jsonKey):
    
    with open(outCSV, "wb") as outF:
        a = csv.writer(outF, delimiter=',')
        a.writerow(["x-coordinate","y-coordinate","Similarity_score"])        

        files_tuple = itertools.combinations(filterFiles(inputDir, acceptTypes), 2)
        for file1, file2 in files_tuple:
            try:
                row_cosine_distance = [file1, file2]
                
                with open(file1) as json_file1 , open(file2) as json_file2:
                    print "######"
                    jsonDict1 = json.load(json_file1)
                    jsonDict2 = json.load(json_file2)
                    if ((jsonKey in jsonDict1) and (jsonKey in jsonDict2)):
                        v1 = Vector(file1, {jsonKey : jsonDict1[jsonKey] })
                        print v1.getFileName(),
                        print v1.getFeature()
                       
                        v2 = Vector(file2, {jsonKey : jsonDict2[jsonKey] })
                        print v2.getFileName(),
                        print v2.getFeature()
                        row_cosine_distance.append(v1.cosTheta(v2))
                        a.writerow(row_cosine_distance)  
            except ConnectionError:
                sleep(1)
            except KeyError:
                continue                
开发者ID:raviraju,项目名称:ContentDetectionBigDataAnalysis_HomeWork2,代码行数:31,代码来源:cosine_similarity.py

示例3: computeScores1

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def computeScores1(type, query, output_file):
    solr = SolrClient('http://localhost:8983/solr')

    res = solr.query(query['index'], {
        'q': '*:*',
        'wt': 'json',
        'indent': True,
        'rows': 1000,
    })

    docs = res.data['response']['docs']

    with open(output_file, "wb") as outF:
        a = csv.writer(outF, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
        a.writerow(["type", "x-coordinate", "y-coordinate", "Similarity_score"])

        for doc in docs:
            for key in doc:
                if key in ["id", "_version_"]:
                    continue
                try:
                    doc[key] = doc[key][0].encode("ascii", "ignore")
                except:
                    doc[key] = str(doc[key][0]).decode("unicode_escape").encode("ascii", "ignore")

        doc_tuples = itertools.combinations(docs, 2)
        for raw1, raw2 in doc_tuples:

            doc1 = raw1.copy()
            doc2 = raw2.copy()

            if "Name" in doc1:
                row_cosine_distance = [type, doc1["Name"], doc2["Name"]]
            else:
                row_cosine_distance = [type, doc1["name"], doc2["name"]]

            v1 = Vector(row_cosine_distance[0], doc1)
            v2 = Vector(row_cosine_distance[1], doc2)

            row_cosine_distance.append(v1.cosTheta(v2))

            a.writerow(row_cosine_distance)
开发者ID:jdramani,项目名称:599-2,代码行数:44,代码来源:cosine_similarity.py

示例4: computeScores

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def computeScores(inputDir, outCSV, acceptTypes):
    
    with open(outCSV, "wb") as outF:
        a = csv.writer(outF, delimiter=',')
        a.writerow(["x-coordinate","y-coordinate","Similarity_score"])        

        files_tuple = itertools.combinations(filterFiles(inputDir, acceptTypes), 2)
        for file1, file2 in files_tuple:

            row_cosine_distance = [file1, file2]
            
            file1_parsedData = parser.from_file(file1)
            file2_parsedData = parser.from_file(file2)

            v1 = Vector(file1_parsedData["metadata"])
            v2 = Vector(file2_parsedData["metadata"])

            row_cosine_distance.append(v1.cosTheta(v2))            

            a.writerow(row_cosine_distance)  
开发者ID:harsham05,项目名称:edit-distance-similarity,代码行数:22,代码来源:cosine_similarity.py

示例5: computeScores2

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def computeScores2(inputFile, outCSV):
    with open(outCSV, "wb") as outF:
        a = csv.writer(outF, delimiter=',')
        a.writerow(["x-coordinate", "y-coordinate", "Similarity_score"])

        file1_parsedData = parser.from_file(inputFile)
        row_list = ast.literal_eval(file1_parsedData["content"])

        rows_tuple = itertools.combinations(row_list, 2)
        for row1, row2 in rows_tuple:

            try:
                row_cosine_distance = [row_list.index(row1), row_list.index(row2)]

                v1 = Vector(inputFile, row1)
                v2 = Vector(inputFile, row2)

                row_cosine_distance.append(v1.cosTheta(v2))

                a.writerow(row_cosine_distance)
            except ConnectionError:
                sleep(1)
            except KeyError:
                continue
开发者ID:chrismattmann,项目名称:tika-similarity,代码行数:26,代码来源:cosine_similarity.py

示例6: cosinedistance

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import cosTheta [as 别名]
def cosinedistance(feature1,feature2,config_params):
    v1 = Vector(feature1['id'], feature1,config_params)
    v2 = Vector(feature2['id'], feature2,config_params)
    return v1.cosTheta(v2)
开发者ID:chrismattmann,项目名称:tika-similarity,代码行数:6,代码来源:affinity_propagation.py


注:本文中的vector.Vector.cosTheta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。