-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
annotate.py: Add and test HaPy-Bug auto annotations as line callback
This commit takes the code that was used for creating initial automatic annotations in the HaPy-Bug dataset, and tries to translate it into current shape of the line callback function, putting this code into data/experiments/HaPy-Bug/hapybug_line_callback_func.py file. The added tests/test_cli.py::test_annotate_patch_with_line_callback_hapybug test checks that it works as intended. Experiments with different patches have shown however that the current implementation doesn't fully do what the original HaPy-Bug code did. For that, we will need to change the signature of line callback function, again... Includes lots of commented-out debug-print lines.
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
def line_callback(file_purpose, tokens): | ||
# NOTE: function definition *must* currently be first line of the file | ||
|
||
# based on the code used to generate initial annotations for HaPy-Bug | ||
# https://github.com/ncusi/python_cve_dataset/blob/main/annotation/annotate.py#L80 | ||
|
||
#print(f"RUNNING line_callback({file_purpose!r}, ...) -> {''.join([t[2] for t in tokens]).rstrip()}") | ||
line_type = file_purpose | ||
|
||
# the original code uses file _type_ here (the "type" field in 'languages.yml'); | ||
# file purpose is here often the same as file type, but not always (!) | ||
# see Languages._path2purpose(path: str, filetype: str) -> str | ||
if file_purpose != "programming": | ||
if file_purpose not in ["documentation", "test"]: | ||
line_type = "bug(fix)" | ||
else: | ||
# For programming languages | ||
if line_is_comment(tokens): | ||
line_type = "documentation" | ||
#print(f" line is comment, {file_purpose=}, {line_type=}") | ||
elif file_purpose == "test": | ||
line_type = "test" | ||
else: | ||
line_type = "bug(fix)" | ||
|
||
#print(f" returning {line_type=}") | ||
return line_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters