db_utils.py 文件源码

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

项目:UrbanSearch 作者: urbansearchTUD 项目源码 文件源码
def compute_all_ic_rels_with_threshold(threshold):
    """
    Computes all intercity relations for documents classified with higher probability
    than the given threshold.

    :param threshold: The minimum probability
    :result: A list of dictionaries with city_a, city_b, category and score fields.
    """
    query = '''
        UNWIND [{0}] AS category
        MATCH (a:City)-[:{1}]->(i:Index)<-[:{1}]-(b:City)
        WHERE ID(a) < ID(b) AND a.name <> b.name AND i[category] >= {2}
        MATCH (a)-[r:{3}]->(b)
        WITH a.name AS city_a, a.population AS pop_a, b.name AS city_b,
            b.population AS pop_b, r.total AS total, COUNT(i) AS count, category,
            2 * 6371 * asin(sqrt(haversin(radians(a.latitude - b.latitude)) +
            cos(radians(a.latitude)) * cos(radians(b.latitude)) *
            haversin(radians(a.longitude - b.longitude)))) AS dist
        RETURN city_a, pop_a, city_b, pop_b, dist, total, category, SUM(count) AS score
    '''.format(','.join('"{}"'.format(c) for c in CAT_NO_OTHER), OCCURS_IN, threshold, RELATES_TO)

    return perform_query(query, [], access_mode='read')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号