{'fraction_non_alphanumeric': 0.02564102564102564, 'fraction_numerical': 0.0035366931918656055, 'mean_word_length': 4.521951219512195, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A-Index: Semantic-based Anomaly Index for Source Code

The software development community has been using handcrafted code quality metrics for a long time. Despite their widespread use, these metrics have a number of known shortcomings. The metrics do not take into account project-specific coding conventions, the wisdom of the crowd, etc. To address these issues, we propose a novel semantic-based approach to calculating an anomaly index for the source code. This index called A-INDEX is the output of a model trained in unsupervised mode on a source code corpus. The larger the index value, the more atypical the code fragment is. To test A-INDEX we use it to find anomalous code fragments in Python repositories. We also apply the index for a variant of the source code defect prediction problem. Using BugsInPy and PyTraceBugs datasets, we investigate how A-INDEX changes when the bug is fixed. The experiments show that in 63% of cases, the index decreases when the bug is fixed. If one keeps only those code fragments for which the index changes significantly, then in 71% of cases the index decreases when the bug is fixed.