本文整理汇总了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
示例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
示例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)
示例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)
示例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
示例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)