6
$\begingroup$

I try to detect the probability of common authorship (person, company) of different kind of source code texts (webpages, program codes). My first idea is to apply the usual NLP tools like any token based document representation (TF-IDF or embeddings) and computing similarity on these but somehow I find this approach a bit clumsy. I want to detect "handprints" (characteristic comment and abbreviation style, folder structure, used 3rd party tools, order of elements in the code etc.) that seem out of the scope of this approach.

Moreover, I cannot find place for any proper machine learning here. Clearly, finding weights for the any future quantitative features would be nice but this similarity task is not classification/regression, so how to define the target? Clustering seems to be a better tool but we cannot define as many categories as potential authors.

Could you kindly suggest any more reliable method? Does any literature exist for this topic?

$\endgroup$
  • 2
    $\begingroup$ You can find the literature by searching for code stylometry or authorship attribution. $\endgroup$ – Emre Mar 23 '18 at 16:15
  • $\begingroup$ Is your goal to predict whether two pieces of coffee have the same author, but not necessarily who the author is? $\endgroup$ – Nicholas James Bailey Apr 17 at 5:40
1
$\begingroup$

Why not use all non-code indicators as 'handprints?' For example, many IDE's will add specific comments to documents when they are started. Also, and this is one that would be easy to detect my work, I have a tendency in python to copy entire import blocks from one script to another, whether or not I actually need all the imports or not. If someone uses a copied import or include statement, then their imports will all be in the same order. If you track the order of imports, you may be able to find patterns.

There are also issues of whether you use spaces or tabs for indentation, preferred number of spaces or tabs, etc. For languages with braces, you can see if braces are used following an if statement, or at the start of the next line. I believe this will give you enough 'handprints' to identify people distinctly.

Once you do this, you can use multilevel clustering to attempt to assign documents first to a group of possible originators (i.e. all originators who use a certain IDE or text editor). Then you can go through and look for certain patterns within each group, clustering again within each cluster.

| improve this answer | |
$\endgroup$
  • $\begingroup$ This is a great answer. I’d also look our for the occurrence of special characters and reserved words in the language - people use control flow (for, if else, while) in different ways and may use certain operators (e.g. **, %) to different extents. $\endgroup$ – Nicholas James Bailey Apr 17 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.