1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- """
- @author: luojunhui
- """
- import aiohttp
- empty_list = []
- def jcd_title_similarity(ori_title, search_title):
- """
- simple ways to calculate the similarity of titles
- :param ori_title:
- :param search_title:
- :return:
- """
- set1 = set(ori_title)
- set2 = set(search_title)
- intersection = len(set1 & set2)
- union = len(set1 | set2)
- return intersection / union
- async def nlp_title_similarity(url, ori_title, search_title_list):
- """
- nlp title similarity
- """
- headers = {"Content-Type": "application/json"}
- body = {
- "data": {
- "text_list_a": [ori_title],
- "text_list_b": search_title_list,
- },
- "function": "similarities_cross",
- "use_cache": False
- }
- async with aiohttp.ClientSession() as session:
- async with session.post(url, headers=headers, json=body) as response:
- response_text = await response.text()
- if response_text and response.status == 200:
- res = await response.json()
- score_list = res['score_list_list'][0]
- return score_list
- else:
- return empty_list
|