string_functions.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:vityBot 作者: GDGVIT 项目源码 文件源码
def find_match(course_list, query_string):
    """
    find the most matching course for a given name and return the course
    :param course_list: list of courses
    :param query_string: query of the user
    :return: course object
    """

    max_out = 0  # the max ratio among the courses
    max_course = None

    for course in course_list:
        if 'lab' not in query_string.lower():
            if course.subject_type == 'Embedded Lab':
                continue
        else:
            if course.subject_type == 'Embedded Theory':
                continue

        max_in = 0  # the max ratio among different names of the course

        for name in course.names:
            ratio = fuzz.token_set_ratio(name, query_string)

            if ratio > max_in:
                max_in = ratio

        if max_out < max_in:
            max_out = max_in
            max_course = course

    return max_course if max_out > 50 else None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号