Ejemplo n.º 1
0
 def apply(self, trace_link):
     new_trace_links = []
     trace_link_file_name = trace_link.get_code_key(True)
     if not trace_link_file_name.endswith(".java"):
         if trace_link_file_name in self._class2file_map:
             trace_link_file_name = self._class2file_map[
                 trace_link_file_name]
         else:
             log.error(
                 f"Can't resolve {trace_link_file_name} to its containing java file"
             )
     req_embedding = trace_link.req_embedding
     if not trace_link_file_name in self._implements_inheritance_dict:
         log.info(f"{trace_link_file_name} is not in the inheritance graph")
         return []
     if self._direction == RelationDirection.up or self._direction == RelationDirection.both:
         for super_classifier in self._implements_inheritance_dict[
                 trace_link_file_name][0]:
             new_trace_links.append(
                 TraceLink(req_embedding,
                           MockEmbedding(super_classifier, None, None)))
     if self._direction == RelationDirection.down or self._direction == RelationDirection.both:
         for super_classifier in self._implements_inheritance_dict[
                 trace_link_file_name][1]:
             new_trace_links.append(
                 TraceLink(req_embedding,
                           MockEmbedding(super_classifier, None, None)))
     return new_trace_links
Ejemplo n.º 2
0
def extract_moran_trace_links(file_path):
    lines = FileUtil.read_textfile_into_lines_list(file_path)
    lines = lines[6:]  # first 6 lines contain no similarity data
    trace_links = []
    for line in lines:
        req, code, sim = line.split(" ")
        code = _remove_package(code)
        if code.endswith(".jsp") or code.endswith(".txt"):
            continue
        sim = float(sim)
        trace_links.append(
            TraceLink(MockEmbedding(_lowercase_extension(req)),
                      MockEmbedding(_lowercase_extension(code)), sim))
    return trace_links
Ejemplo n.º 3
0
def _build_req_dict_for_map(trace_link_candidates,
                            dataset: Dataset,
                            reverse_compare=False):
    trace_link_candidates = list(
        dict.fromkeys(trace_link_candidates
                      ))  # Deterministic duplicate removal (set is not stable)

    if len(trace_link_candidates) < dataset.num_original_links():
        # trace_link_candidates does not contain all possible link between reqs and code
        # -> Add missing links as dummy links with 0 similarity
        code_filenames = dataset.all_original_code_file_names(True)
        req_filenames = dataset.all_original_req_file_names(True)
        for req_name in req_filenames:
            for code_name in code_filenames:
                no_similarity = 1 if reverse_compare else 0
                dummy_trace_link = TraceLink(MockEmbedding(req_name),
                                             MockEmbedding(code_name),
                                             no_similarity)
                if not dummy_trace_link in trace_link_candidates:
                    trace_link_candidates.append(dummy_trace_link)
    assert len(trace_link_candidates) == dataset.num_original_links(
    ), f"{len(trace_link_candidates)} != {dataset.num_original_links()}"

    req_dict = {
    }  # req_dict["req_name"] = [(sim_to_code_1: float, relevant: bool), (sim_to_code_2, relevant), ...]
    sol_matrix_copy = Util.deep_copy(dataset.solution_matrix(
    ))  # Use copy to track false negatives and avoid duplicate trace links
    for trace_link in trace_link_candidates:
        req_name = trace_link.get_req_key(dataset.keys_with_extension())
        code_name = trace_link.get_code_key(dataset.keys_with_extension())
        sim_rel_tuple_to_add = (trace_link.similarity, False)
        if sol_matrix_copy.contains_req_code_pair(req_name, code_name):
            sim_rel_tuple_to_add = (trace_link.similarity, True)
            sol_matrix_copy.remove_trace_pair(req_name, code_name)
        if req_name in req_dict:
            req_dict[req_name].append(sim_rel_tuple_to_add)
        else:
            req_dict[req_name] = [sim_rel_tuple_to_add]

    if PRINT_FALSE_NEGATIVES:
        _print_false_negatives(sol_matrix_copy)

    return req_dict
Ejemplo n.º 4
0
 def apply(self, trace_link):
     new_trace_links = []
     trace_link_file_name = trace_link.get_code_key()
     req_embedding = trace_link.req_embedding
     if not trace_link_file_name in self._call_graph:
         log.info(f"{trace_link_file_name} is not in the call graph")
         return []
     if self._direction == RelationDirection.up or self._direction == RelationDirection.both:
         for class_that_called_me in self._call_graph[trace_link_file_name][
                 "called_by"]:
             new_trace_links.append(
                 TraceLink(req_embedding,
                           MockEmbedding(class_that_called_me, None, None)))
     if self._direction == RelationDirection.down or self._direction == RelationDirection.both:
         for called_class in self._call_graph[trace_link_file_name][
                 "calls"]:
             new_trace_links.append(
                 TraceLink(req_embedding,
                           MockEmbedding(called_class, None, None)))
     return new_trace_links
Ejemplo n.º 5
0
 def _create_embeddings(self, file_representation):
     return [
         MockEmbedding(file_representation.file_path, file_representation)
     ]
Ejemplo n.º 6
0
 def init_candidate_tracelink(self, code_file):
     return CodeToRequirementsCandidates(
         MockEmbedding(code_file[TracePairPrecalculator.CODE_FILENAME]))
Ejemplo n.º 7
0
 def req_emb(self, req_file):
     return MockEmbedding(self.req_filename(req_file))