Пример #1
0
def load_tags(defects_path, validation_set=None, sound_only=False):
    with open(defects_path, "r") as fid:
        defects = json.load(fid)

    result = dict()
    instance_tags = defects["tags"]

    for instance in instance_tags:
        numeric_tags = instance_tags[instance]

        if validation_set is not None:
            if instance not in validation_set:
                continue

        if sound_only:
            filtered_tags = []
            for tag_num in numeric_tags:
                filtered_tags.append(tag_num)
                if is_unsafe_tag(Tag(tag_num)):
                    break
            numeric_tags = filtered_tags

        result[instance] = numeric_tags
    return result
Пример #2
0
def get_tag_for_alert(alert, defects):
    tags = defects.get(alert.file)
    if tags is not None:
        return Tag(tags[int(alert.line) - 1])
    else:
        return None
Пример #3
0
            }
            for tag in [e.value for e in Tag]
        }
        for tool in all_tools
    }

    for instance, tags in instance_tags.items():
        for tag, line in zip(tags, range(1, len(tags) + 1)):
            # Hits are positive response to the tag
            hits = alert_index[(instance, line)]

            for hit in hits:
                # Indicate a positive response
                scores[hit][tag][True] += 1
                logging.debug("RESPONSE,%s,%s,%s,%d",
                              Tag(tag).name, hit, instance, line)
            for other in (all_tools - hits):
                # Indicate a negative response
                scores[other][tag][False] += 1
                logging.debug("NO_RESPONSE,%s,%s,%s,%d",
                              Tag(tag).name, other, instance, line)

    tag_sets = [
        ("cond", Tag.INTCALCFLOW_COND_UNSAFE, Tag.INTCALCFLOW_COND_SAFE),
        ("taut", Tag.INTCALCFLOW_TAUT_UNSAFE, Tag.INTCALCFLOW_TAUT_SAFE),
    ]

    writer = csv.writer(sys.stdout)
    writer.writerow(["tool", "kind", "tp", "tn", "fp", "fn"])

    for tool in sorted(scores.keys()):