def get_package_freq(local_ctx_id, source, prelease):
    linksets = ReleaseLinkSet.objects\
            .filter(code_reference__local_object_id=local_ctx_id)\
            .filter(code_reference__source=source)\
            .filter(project_release=prelease).all()

    packages = defaultdict(int)

    for linkset in linksets:
        if linkset.links.count() == 1:
            package_name = find_package(linkset.first_link.code_element)
            if package_name is not None:
                packages[package_name] += 1

    package_freq = [(k, packages[k]) for k in packages]
    package_freq.sort(key=lambda v: v[1], reverse=True)

    return package_freq
dataset/ETHPy150Open bartdag/recodoc2/recodoc2/apps/codebase/linker/java_linkers.py/get_package_freq/original