示例#1
0
def update_licenses_relations_rec(new_neo_license, new_object_license,
                                  neo_license, object_license):
    # update precedings and followings of license recursively.
    grand_follower = False
    for neo_license_following in neo_license.followings:
        object_license_following = ObjectFactory.objectLicense(
            neo_license_following)
        if new_object_license.is_following(object_license_following):
            # new license is a follower of a following
            grand_follower = True
        if new_object_license.is_preceding(object_license_following):
            if Constraints.is_compatibility_viable(new_object_license,
                                                   object_license_following):
                neo_license_following.precedings.connect(new_neo_license)
            if new_object_license.is_following(object_license):
                # new_license is between license and its following_license.
                if Constraints.is_compatibility_viable(object_license,
                                                       new_object_license):
                    neo_license.followings.connect(new_neo_license)
                    neo_license.followings.disconnect(neo_license_following)
        else:
            update_licenses_relations_rec(new_neo_license, new_object_license,
                                          neo_license_following,
                                          object_license_following)
    if not grand_follower and new_object_license.is_following(object_license):
        # then its just the next follower of the current license
        if Constraints.is_compatibility_viable(object_license,
                                               new_object_license):
            neo_license.followings.connect(new_neo_license)
示例#2
0
def add_license_to_db(object_license):
    neo_license = LicenseModel.nodes.get_or_none(
        hashed_sets=object_license.hash())
    if neo_license:
        # update of labels list if needed
        neo_license.labels = list(
            set(object_license.get_labels()).union(neo_license.labels))
        neo_license.save()
    else:
        # license does not exists in db
        license_leaves = get_leaf_licenses()
        neo_license = NeoFactory.NeoLicense(object_license)
        neo_license.save()
        for neo_license_leaf in license_leaves:
            object_license_leaf = ObjectFactory.objectLicense(neo_license_leaf)
            if object_license.is_preceding(object_license_leaf):
                if Constraints.is_compatibility_viable(object_license,
                                                       object_license_leaf):
                    neo_license_leaf.precedings.connect(neo_license)
            else:
                update_licenses_relations_rec(neo_license, object_license,
                                              neo_license_leaf,
                                              object_license_leaf)
    for dataset in object_license.get_datasets():
        neo_dataset = DatasetModel.nodes.get_or_none(hashed_uri=dataset.hash())
        if not neo_dataset:
            neo_dataset = NeoFactory.NeoDataset(dataset)
            neo_dataset.save()
        neo_license.datasets.connect(neo_dataset)
    object_license = ObjectFactory.objectLicense(neo_license)
    return object_license
示例#3
0
def update_licenses_relations_supremum_rec(new_neo_license, new_object_license,
                                           neo_license, object_license,
                                           viability_check, nb_visit,
                                           tested_licenses):
    # update precedings and followings of license recursively.
    if object_license in tested_licenses:
        return nb_visit
    nb_visit += 1
    tested_licenses.append(object_license)
    grand_preceder = False
    for neo_license_preceding in neo_license.precedings:
        object_license_preceding = ObjectFactory.objectLicense(
            neo_license_preceding)
        if already_preceder(object_license_preceding, new_neo_license):
            continue
        if new_object_license.is_following(object_license_preceding) and (
                Constraints.is_compatibility_viable(object_license_preceding,
                                                    new_object_license)
                or not viability_check):
            update_transitivity_preceder(new_neo_license,
                                         object_license_preceding)
            new_neo_license.precedings.connect(neo_license_preceding)
            if new_object_license.is_preceding(object_license) and (
                    Constraints.is_compatibility_viable(
                        new_object_license, object_license)
                    or not viability_check):
                new_neo_license.followings.connect(neo_license)
                neo_license.precedings.disconnect(neo_license_preceding)
        else:
            if new_object_license.is_preceding(object_license_preceding) and (
                    Constraints.is_compatibility_viable(
                        new_object_license, object_license_preceding)
                    or not viability_check):
                grand_preceder = True
            nb_visit = update_licenses_relations_supremum_rec(
                new_neo_license, new_object_license, neo_license_preceding,
                object_license_preceding, viability_check, nb_visit,
                tested_licenses)
    if not grand_preceder and (
            new_object_license.is_preceding(object_license) and
        (Constraints.is_compatibility_viable(
            new_object_license, object_license) or not viability_check)):
        new_neo_license.followings.connect(neo_license)
    return nb_visit
示例#4
0
def update_licenses_relations_supremum(object_license,
                                       viability_check,
                                       nb_visit,
                                       graph='ld'):
    tested_licenses = [object_license]
    license_roots = get_root_licenses(graph)
    neo_license = NeoFactory.NeoLicense(object_license, graph)
    neo_license.save()
    for neo_license_root in license_roots:
        object_license_root = ObjectFactory.objectLicense(neo_license_root)
        if object_license.is_following(object_license_root) and (
                Constraints.is_compatibility_viable(object_license_root,
                                                    object_license)
                or not viability_check):
            update_transitivity_preceder(neo_license, object_license_root)
            neo_license_root.followings.connect(neo_license)
        else:
            nb_visit = update_licenses_relations_supremum_rec(
                neo_license, object_license, neo_license_root,
                object_license_root, viability_check, nb_visit,
                tested_licenses)
    return neo_license, nb_visit
示例#5
0
def update_licenses_relations_infimum(object_license,
                                      viability_check,
                                      nb_visit,
                                      graph='ld'):
    tested_licenses = [object_license]
    license_leaves = get_leaf_licenses(graph)
    neo_license = NeoFactory.NeoLicense(object_license, graph)
    neo_license.save()
    for neo_license_leaf in license_leaves:
        object_license_leaf = ObjectFactory.objectLicense(neo_license_leaf)
        if object_license.is_preceding(object_license_leaf) and (
                Constraints.is_compatibility_viable(object_license,
                                                    object_license_leaf)
                or not viability_check):
            update_transitivity_follower(neo_license, object_license_leaf)
            neo_license_leaf.precedings.connect(neo_license)
        else:
            nb_visit = update_licenses_relations_infimum_rec(
                neo_license, object_license, neo_license_leaf,
                object_license_leaf, viability_check, nb_visit,
                tested_licenses)
    return neo_license, nb_visit