Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +5 -0
- Container/Dockerfile +21 -0
- Container/README.md +26 -0
- Container/start_container.sh +8 -0
- Contest/ExampleSimAnalysis/README.md +89 -0
- Contest/ExampleSimAnalysis/TestSetEval.py +259 -0
- Contest/ExampleSimAnalysis/test_eval.sh +16 -0
- LICENSE +201 -0
- README.md +270 -0
- assets/Project_CodeNet_statistics.xlsx +3 -0
- assets/Project_CodeNet_status.png +3 -0
- assets/Project_CodeNet_subs.png +3 -0
- assets/tiny.png +3 -0
- doc/HSQLDB.md +267 -0
- doc/README.md +32 -0
- doc/problem_descriptions.tar.gz +3 -0
- doc/srcml.md +245 -0
- doc/syntax-correct-tokenstream.md +209 -0
- doc/universal_tokens.md +215 -0
- metadata/Project_CodeNet.tar.gz +3 -0
- model-experiments/gnn-based-experiments/.gitignore +140 -0
- model-experiments/gnn-based-experiments/README.md +89 -0
- model-experiments/gnn-based-experiments/data/C++1000/raw/.gitignore +4 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/test.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/test.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/train.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/train.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/valid.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1000/split/random/valid.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/C++1400/raw/.gitignore +4 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/test.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/test.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/train.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/train.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/valid.csv +0 -0
- model-experiments/gnn-based-experiments/data/C++1400/split/random/valid.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Java250/raw/.gitignore +4 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/test.csv +0 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/test.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/train.csv +0 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/train.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/valid.csv +0 -0
- model-experiments/gnn-based-experiments/data/Java250/split/random/valid.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Python800/raw/.gitignore +4 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/test.csv +0 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/test.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/train.csv +0 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/train.csv.gz +3 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/valid.csv +0 -0
- model-experiments/gnn-based-experiments/data/Python800/split/random/valid.csv.gz +3 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
assets/Project_CodeNet_statistics.xlsx filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
model-experiments/token-based-similarity-classification/CodeMLtranslationDataset.pdf filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
model-experiments/token-based-similarity-classification/LargeDataCodeClassifier.pdf filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
model-experiments/token-based-similarity-classification/LargeDataCodeSimilarity.pdf filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
tools/json-graph/graph-json.pdf filter=lfs diff=lfs merge=lfs -text
|
Container/Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM centos:centos8
|
| 2 |
+
|
| 3 |
+
RUN yum -y update; yum clean all
|
| 4 |
+
RUN yum -y install net-tools iproute unzip git
|
| 5 |
+
RUN yum -y install openssh-server openssh-clients
|
| 6 |
+
|
| 7 |
+
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
|
| 8 |
+
RUN ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
|
| 9 |
+
RUN ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
|
| 10 |
+
|
| 11 |
+
RUN yum -y install wget tar maven gcc-c++
|
| 12 |
+
RUN yum -y install java-1.8.0-openjdk
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
RUN mkdir -p /root/.ssh
|
| 16 |
+
COPY ./authorized_keys /root/.ssh/
|
| 17 |
+
|
| 18 |
+
COPY ./start_container.sh /root/
|
| 19 |
+
|
| 20 |
+
EXPOSE 22
|
| 21 |
+
ENTRYPOINT ["/root/start_container.sh"]
|
Container/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Creating container that provides a 'VM' in which to experiment with the tools.
|
| 2 |
+
|
| 3 |
+
1. Place a public keys for ssh into file 'authorized_keys' in the 'Container' directory
|
| 4 |
+
|
| 5 |
+
2. docker build -t centos8_plain:v1 .
|
| 6 |
+
|
| 7 |
+
3. docker run --init -d centos8_plain:v1 .
|
| 8 |
+
|
| 9 |
+
4. docker ps -a
|
| 10 |
+
docker logs <containerid>
|
| 11 |
+
|
| 12 |
+
The log contains the network config of the container,
|
| 13 |
+
from which the ip address can be extracted.
|
| 14 |
+
|
| 15 |
+
An alternative is to 'inspect' the container.
|
| 16 |
+
|
| 17 |
+
5. ssh root@<container-ip-address>
|
| 18 |
+
|
| 19 |
+
If the host from which the ssh is initiated has proper access to
|
| 20 |
+
the docker network and the private key matching one of the
|
| 21 |
+
public keys deposited into the container, this allows
|
| 22 |
+
access similar to a real system/VM.
|
| 23 |
+
If the container has internet access, 'yum install ...' and
|
| 24 |
+
'git clone ...' inside the container work as well to
|
| 25 |
+
expand functionality.
|
| 26 |
+
|
Container/start_container.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
echo "Starting container"
|
| 4 |
+
|
| 5 |
+
ifconfig
|
| 6 |
+
|
| 7 |
+
/usr/sbin/sshd -D
|
| 8 |
+
|
Contest/ExampleSimAnalysis/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Example of contest test set evaluation
|
| 2 |
+
|
| 3 |
+
Author: [Vladimir Zolotov](mailto:zolotov@us.ibm.com)
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
This directory holds an example of program `TestSetEval.py` and `scrip test_eval.sh` for evaluating a contest test set on source code similarity.
|
| 7 |
+
|
| 8 |
+
The program is given only as an example. It is expected that the contestants write their own test set evaluation program better suitable for their operational environment, file formats and ML framework.
|
| 9 |
+
|
| 10 |
+
The program `TestSetEval.py` accepts a test set consisting of two components:
|
| 11 |
+
|
| 12 |
+
1. Directory with source code files of C++ programs to detect similarity or dissimilarity with each other.
|
| 13 |
+
2. csv file of a test set in the following format:
|
| 14 |
+
|
| 15 |
+
`<sample number>,<path to 1-st file>,<path to 2-nd file>`
|
| 16 |
+
|
| 17 |
+
where `path to 1-st file` and `path to 2-nd file` specify paths to the pair of files to detect similarity or dissimilarity. The paths are specified relative to the directory with source code files. Here is an example of the csv file of the test set:
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
pair-id,file1,file2
|
| 21 |
+
1,p02761/s682789980.cpp,p02761/s060579067.cpp
|
| 22 |
+
2,p02817/s224840938.cpp,p03360/s804824036.cpp
|
| 23 |
+
3,p01085/s591760635.cpp,p01085/s734466918.cpp
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
The program `TestSetEval.py` can also accept a csv file of ground truth labels in the following format:
|
| 27 |
+
`<sample number>,<label>`. Here is an example of the file with ground truth labels:
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
pair-id,similar
|
| 31 |
+
1,1
|
| 32 |
+
2,0
|
| 33 |
+
3,1
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
The program `TestSetEval.py` write down the computed similarity predictions as a csv file in the following format:
|
| 37 |
+
|
| 38 |
+
`<sample number>,<path to 1-st file>,<path to 2-nd file>,<similarity score><prediction>`
|
| 39 |
+
|
| 40 |
+
where `similarity score` is the computed probability that the pair of files are similar and, `prediction` is the computed prediction of the similarity. Here is an example of this file:
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
pair-id,file1,file2,confidence,prediction
|
| 44 |
+
1,f8610.cpp,f8588.cpp,0.06234602,Dissimilar
|
| 45 |
+
2,f1089.cpp,f9389.cpp,0.15431221,Dissimilar
|
| 46 |
+
3,f9570.cpp,f9593.cpp,0.89995503,Similar
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
If the file with ground truth labels is given the program also computes the accuracy of the test set evaluation and prints it to the console report.
|
| 50 |
+
|
| 51 |
+
The program uses the Codenet tokenizer from https://github.com/IBM/Project_CodeNet/tree/main/tools/tokenizer and
|
| 52 |
+
Keras API of TensorFlow ML framework. However, it can be easily modified to for a different ML framework.
|
| 53 |
+
|
| 54 |
+
Program has the following arguments:
|
| 55 |
+
* The directory with source code files to analyze similarity.
|
| 56 |
+
* The csv file with sample pairs to analyze similarity
|
| 57 |
+
* The path to tokenizer of source code files. This should be the Codenet tokenizer from https://github.com/IBM/Project_CodeNet/tree/main/tools/tokenizer. Its default value is `tokenize`.
|
| 58 |
+
* The TensorFlow checkpoint file with the trained DNN. Its default value is `./dnn_ckpt`.
|
| 59 |
+
* The csv file with ground truth labels. If it is omitted the program does not compute the accuracy of testset evaluation.
|
| 60 |
+
* The file to write down the computed similarity predictions.
|
| 61 |
+
* The batch size. Its default value is 400.
|
| 62 |
+
* The mode of Keras training progress bar. By default the program depicts the progress bar on the console.
|
| 63 |
+
|
| 64 |
+
The program usage can be obtained with the command: `python TestSetEval.py -h`, which gives the following output:
|
| 65 |
+
|
| 66 |
+
```
|
| 67 |
+
usage: TestSetEval [-h] [--labels LABELS] [--dnn DNN] [--tokenizer TOKENIZER]
|
| 68 |
+
[--predictions PREDICTIONS] [--batch BATCH]
|
| 69 |
+
[--progress {0,1,2}]
|
| 70 |
+
source_code test
|
| 71 |
+
|
| 72 |
+
positional arguments:
|
| 73 |
+
source_code directory with source code files to analyze similarity
|
| 74 |
+
test file with sample pairs to analyze similarity
|
| 75 |
+
|
| 76 |
+
optional arguments:
|
| 77 |
+
-h, --help show this help message and exit
|
| 78 |
+
--labels LABELS file with similarity labels of test samples
|
| 79 |
+
--dnn DNN checkpoint file with trained dnn
|
| 80 |
+
--tokenizer TOKENIZER
|
| 81 |
+
path to tokenizer of source code files
|
| 82 |
+
--predictions PREDICTIONS
|
| 83 |
+
file to write similarity predictions
|
| 84 |
+
--batch BATCH batch size
|
| 85 |
+
--progress {0,1,2} mode of Keras training progress bar
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
The directory has also a script calling the program with and without ground truth labels.
|
| 89 |
+
|
Contest/ExampleSimAnalysis/TestSetEval.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Program for predicting similarity of testset samples.
|
| 3 |
+
- The DNN is loaded from a given TensorFlow check point.
|
| 4 |
+
- The testset is a csv file with the following format:
|
| 5 |
+
<sample number>,<relative path to 1-st file>,<relative path to 2-nd file>
|
| 6 |
+
- The program converts source code into token sequences
|
| 7 |
+
using the tokenizer from Project_CodeNet
|
| 8 |
+
- Tokens coding is defined with dictionary of tokens hard coded in the program.
|
| 9 |
+
- It is required that tokens coding is the same as the one used for DNN training.
|
| 10 |
+
- More examples of token dictionaries can be found in Project_CodeNet Github
|
| 11 |
+
- Additionally to the testset the program can read a csv file with ground truth labels of the test set sample if it is given
|
| 12 |
+
- The file with labels has the following format:
|
| 13 |
+
<sample number>,<label>
|
| 14 |
+
* The label = 1 for similar source code files, otherwise label = 0
|
| 15 |
+
- The program computes the average accuracy of detecting similarity and dissimilarity of test set samples, if labels are defined
|
| 16 |
+
- The program also writes down file csv file with predicted probabilities that samples represent similar source code files
|
| 17 |
+
|
| 18 |
+
The program uses the following components:
|
| 19 |
+
- The tokenizer from Project_CodeNet
|
| 20 |
+
- Keras API of TensorFlow ML framework
|
| 21 |
+
|
| 22 |
+
Program arguments are described at the end of the file
|
| 23 |
+
"""
|
| 24 |
+
import sys
|
| 25 |
+
import os
|
| 26 |
+
import argparse
|
| 27 |
+
import csv
|
| 28 |
+
import numpy as np
|
| 29 |
+
import tensorflow as tf
|
| 30 |
+
|
| 31 |
+
def makeTokenSet():
|
| 32 |
+
"""
|
| 33 |
+
Make a token set
|
| 34 |
+
The set of tokens must be the same as it used for trainning the DNN
|
| 35 |
+
Here we make a CPP56X token set of C++ tokens
|
| 36 |
+
Returns a dictionary of tokens:
|
| 37 |
+
- Key is a string representing the token
|
| 38 |
+
- Value is integer value of token
|
| 39 |
+
"""
|
| 40 |
+
#CPP56 OPERATORS
|
| 41 |
+
operators = [
|
| 42 |
+
"=", "+", "-", "*", "/", #Assignment and arithmetic operators
|
| 43 |
+
"%", "&", "|", "^", "~", "<<", ">>", #Bitwise Operators
|
| 44 |
+
"+=", "-=", "*=", "/=", "%=", "++", "--", #Compound arithmetic assignment operators
|
| 45 |
+
"&=", "|=", "^=", "<<=", ">>=", #Compound bitwise assignment operators
|
| 46 |
+
"==", "!=", "<", "<=", ">", ">=", #Comparison operators
|
| 47 |
+
"?", "&&", "||", "!", #Logical operators
|
| 48 |
+
"(", ")", "{", "}", "[", "]", "->",
|
| 49 |
+
";", ","] #Others
|
| 50 |
+
#CPP56 KEYWORDS
|
| 51 |
+
keywords= ["if", "else", "for", "while",
|
| 52 |
+
"switch",
|
| 53 |
+
"enum", "int", "char", "short", "long",
|
| 54 |
+
"float", "double", "bool"]
|
| 55 |
+
#CPP SYNONYMS
|
| 56 |
+
synonyms = {"and": "&&", "or": "||", "not": "!"}
|
| 57 |
+
|
| 58 |
+
token_dict = {}
|
| 59 |
+
for _i, _op in enumerate(operators + keywords):
|
| 60 |
+
token_dict[_op] = _i
|
| 61 |
+
print(f"Token set of {len(token_dict)} tokens is constructed")
|
| 62 |
+
for _syn, _orig in synonyms.items():
|
| 63 |
+
token_dict[_syn] = token_dict[_orig]
|
| 64 |
+
print(f"Additionally it has {len(synonyms)} synonym tokens")
|
| 65 |
+
return token_dict
|
| 66 |
+
|
| 67 |
+
#Dictionary of tokens and their indicies
|
| 68 |
+
token_set = makeTokenSet()
|
| 69 |
+
|
| 70 |
+
def tokenizeFile(filename, tokenizer):
|
| 71 |
+
"""
|
| 72 |
+
Tokenize a given file
|
| 73 |
+
Parameters:
|
| 74 |
+
- filename -- name of source code file to tokenize
|
| 75 |
+
- tokenizer -- path to tokenizer executable
|
| 76 |
+
Returns:
|
| 77 |
+
- a list of integer token values representing the source code file
|
| 78 |
+
"""
|
| 79 |
+
#Name of temporary file for tokenized source code
|
| 80 |
+
TMP_TOKENIZATION = "./t_o_k_e_n_s.o_u_t"
|
| 81 |
+
#Tokenization command ignoring macros
|
| 82 |
+
#tokenize_cmd = tokenizer + " -wcmcsv"
|
| 83 |
+
#Tokenization command tokenising macros
|
| 84 |
+
tokenize_cmd = tokenizer + " -wmcsv"
|
| 85 |
+
if os.system(f"{tokenize_cmd} -o {TMP_TOKENIZATION} {filename}"):
|
| 86 |
+
sys.exit(f"Tokenization error in file {filename}")
|
| 87 |
+
tokens = []
|
| 88 |
+
with open(TMP_TOKENIZATION, newline='',
|
| 89 |
+
encoding="ISO-8859-1") as csvfile:
|
| 90 |
+
token_reader = csv.reader(csvfile)
|
| 91 |
+
token_reader.__next__() #Skip csv header
|
| 92 |
+
for _, _, _tok_class, _tok_value in token_reader:
|
| 93 |
+
if _tok_class == "operator" or _tok_class == "keyword":
|
| 94 |
+
try:
|
| 95 |
+
tokens.append(token_set[_tok_value] + 1)
|
| 96 |
+
except KeyError:
|
| 97 |
+
#ignore tokens that are not in the tokens set
|
| 98 |
+
pass
|
| 99 |
+
return tokens
|
| 100 |
+
|
| 101 |
+
def makeDataset(source, test, tokenizer):
|
| 102 |
+
"""
|
| 103 |
+
Make tensorflow dataset
|
| 104 |
+
for predicting similarity of testset samples with Simaese DNN
|
| 105 |
+
Parameters:
|
| 106 |
+
- source -- path to directory with source code files
|
| 107 |
+
to analyze similarity
|
| 108 |
+
- test -- path to the testsetrfile specifying pairs
|
| 109 |
+
of source code file to analyze similarity
|
| 110 |
+
- tokenizer -- path to tokenizer executable
|
| 111 |
+
Returns:
|
| 112 |
+
- dataset as list of two numpy arrays.
|
| 113 |
+
Each numpy array represets set of token sequences for one input of DNN
|
| 114 |
+
"""
|
| 115 |
+
tokenizations = {}
|
| 116 |
+
samples = []
|
| 117 |
+
max_code_len = 0
|
| 118 |
+
with open(test, newline='') as csvfile:
|
| 119 |
+
test_reader = csv.reader(csvfile)
|
| 120 |
+
test_reader.__next__() #Skip csv header
|
| 121 |
+
for _num, fn1, fn2 in test_reader:
|
| 122 |
+
try:
|
| 123 |
+
tok_seq1 = tokenizations[fn1]
|
| 124 |
+
except KeyError:
|
| 125 |
+
tok_seq1 = tokenizeFile(source + '/' + fn1, tokenizer)
|
| 126 |
+
tokenizations[fn1] = tok_seq1
|
| 127 |
+
max_code_len = max(max_code_len, len(tok_seq1))
|
| 128 |
+
try:
|
| 129 |
+
tok_seq2 = tokenizations[fn2]
|
| 130 |
+
except KeyError:
|
| 131 |
+
tok_seq2 = tokenizeFile(source + '/' + fn2, tokenizer)
|
| 132 |
+
tokenizations[fn2] = tok_seq2
|
| 133 |
+
max_code_len = max(max_code_len, len(tok_seq2))
|
| 134 |
+
samples.append((tok_seq1, tok_seq2))
|
| 135 |
+
np_ds1 = np.zeros(shape=(len(samples), max_code_len),
|
| 136 |
+
dtype=np.int32)
|
| 137 |
+
np_ds2 = np.zeros(shape=(len(samples), max_code_len),
|
| 138 |
+
dtype=np.int32)
|
| 139 |
+
for _i, _s in enumerate(samples):
|
| 140 |
+
tok_seq1, tok_seq2 = _s
|
| 141 |
+
np_ds1[_i][0:len(tok_seq1)] = np.asarray(tok_seq1, dtype=np.int32)
|
| 142 |
+
np_ds2[_i][0:len(tok_seq2)] = np.asarray(tok_seq2, dtype=np.int32)
|
| 143 |
+
print(f"Dataset of {len(samples)} samples is constructed")
|
| 144 |
+
return [np_ds1, np_ds2]
|
| 145 |
+
|
| 146 |
+
def loadLabels(filename):
|
| 147 |
+
"""
|
| 148 |
+
Load ground truth lables if they exist
|
| 149 |
+
Parameters:
|
| 150 |
+
- filename -- Path to labels file
|
| 151 |
+
Returns:
|
| 152 |
+
- numpy array with labels to compare with the predicted similarity
|
| 153 |
+
or None if no ground truth lables are provided
|
| 154 |
+
"""
|
| 155 |
+
if filename is None:
|
| 156 |
+
print("Labels of test samples are not specified")
|
| 157 |
+
print("Accuracy of DNN on this test cannot be evaluated")
|
| 158 |
+
return None
|
| 159 |
+
if not os.path.exists(filename):
|
| 160 |
+
print(f"File {filename} with labels of test samples is not found")
|
| 161 |
+
print("Accuracy of DNN on this test cannot be evaluated")
|
| 162 |
+
return None
|
| 163 |
+
labels = []
|
| 164 |
+
with open(filename, newline='') as csvfile:
|
| 165 |
+
test_reader = csv.reader(csvfile)
|
| 166 |
+
test_reader.__next__() #Skip csv header
|
| 167 |
+
for _num, _lbl in test_reader:
|
| 168 |
+
labels.append(int(_lbl))
|
| 169 |
+
return np.asarray(labels)
|
| 170 |
+
|
| 171 |
+
def writePredictions(test, probabilities, filename):
|
| 172 |
+
"""
|
| 173 |
+
Write down similarity predictions
|
| 174 |
+
Parameters:
|
| 175 |
+
- test -- path to the testset file specifying pairs
|
| 176 |
+
of source code file to analyze similarity
|
| 177 |
+
- probabilities -- numpy array with probabilities of similarities
|
| 178 |
+
- filename -- filename to write predictions
|
| 179 |
+
"""
|
| 180 |
+
with open(test, newline='') as csvin,\
|
| 181 |
+
open(filename, 'w', newline='') as csvout:
|
| 182 |
+
test_reader = csv.reader(csvin)
|
| 183 |
+
writer = csv.writer(csvout, lineterminator=os.linesep)
|
| 184 |
+
test_reader.__next__() #Skip csv header
|
| 185 |
+
writer.writerow(["pair-id", "file1", "file2",
|
| 186 |
+
"confidence", "prediction"])
|
| 187 |
+
_i = 0
|
| 188 |
+
for _num, _fn1, _fn2 in test_reader:
|
| 189 |
+
writer.writerow([_num, _fn1, _fn2, probabilities[_i][0],
|
| 190 |
+
"Similar" if probabilities[_i][0] >= 0.5
|
| 191 |
+
else "Dissimilar"])
|
| 192 |
+
_i += 1
|
| 193 |
+
|
| 194 |
+
def main(args):
|
| 195 |
+
"""
|
| 196 |
+
Main function of program for predicting similarity testset samples
|
| 197 |
+
|
| 198 |
+
Parameters:
|
| 199 |
+
- args -- Parsed command line arguments
|
| 200 |
+
as object returned by ArgumentParser
|
| 201 |
+
"""
|
| 202 |
+
if not os.path.exists(args.source_code):
|
| 203 |
+
sys.exit(f"Directory {args.source_code} with source code is not found")
|
| 204 |
+
if not os.path.exists(args.test):
|
| 205 |
+
sys.exit(f"File {args.test} with test pairs is not found")
|
| 206 |
+
if not os.path.exists(args.tokenizer):
|
| 207 |
+
sys.exit(f"Tokenizer {args.tokenizer} is not found")
|
| 208 |
+
if not os.path.exists(args.dnn):
|
| 209 |
+
sys.exit(f"Check point with dnn model {args.dnn} is not found")
|
| 210 |
+
ds = makeDataset(args.source_code, args.test, args.tokenizer)
|
| 211 |
+
labels = loadLabels(args.labels)
|
| 212 |
+
#Load trained DNN from TF checkpoint
|
| 213 |
+
dnn = tf.keras.models.load_model(args.dnn)
|
| 214 |
+
if labels is not None:
|
| 215 |
+
if ds[0].shape[0] == labels.shape[0]:
|
| 216 |
+
#Evaluate DNN accuracy on the testset
|
| 217 |
+
loss, acc = dnn.evaluate(ds, labels, verbose = args.progress)
|
| 218 |
+
print("\nEvaluation accuracy is {:5.2f}%".format(acc * 100))
|
| 219 |
+
print("Evaluation loss is {:5.2f}".format(loss))
|
| 220 |
+
else:
|
| 221 |
+
print(f"Numers of labels {labels.shape[0]} " +
|
| 222 |
+
f"and samples {ds[0].shape[0]} is different ")
|
| 223 |
+
print("Accuracy of DNN on this test cannot be evaluated")
|
| 224 |
+
#Compute probabilities of similarity predicted by DNN
|
| 225 |
+
prob = dnn.predict(ds, verbose = args.progress)
|
| 226 |
+
writePredictions(args.test, prob, args.predictions)
|
| 227 |
+
##############################################################################
|
| 228 |
+
# Program arguments are described below
|
| 229 |
+
##############################################################################
|
| 230 |
+
if __name__ == '__main__':
|
| 231 |
+
print("\nPREDICTING SIMILARITY OF TESTSET SAMPLES")
|
| 232 |
+
#Handle command-line arguments
|
| 233 |
+
parser = argparse.ArgumentParser("TestSetEval")
|
| 234 |
+
parser.add_argument("source_code", type=str,
|
| 235 |
+
help="directory with source code files to analyze similarity")
|
| 236 |
+
parser.add_argument("test", type=str,
|
| 237 |
+
help="file with sample pairs to analyze similarity")
|
| 238 |
+
parser.add_argument("--labels", type=str, default = None,
|
| 239 |
+
help="file with similarity labels of test samples")
|
| 240 |
+
parser.add_argument("--dnn", default = "./dnn_ckpt",
|
| 241 |
+
type=str, help="checkpoint file with trained dnn")
|
| 242 |
+
parser.add_argument("--tokenizer", default = "tokenize",
|
| 243 |
+
type=str, help="path to tokenizer of source code files")
|
| 244 |
+
parser.add_argument("--predictions", default = "./predictions.csv",
|
| 245 |
+
type=str, help="file to write similarity predictions")
|
| 246 |
+
parser.add_argument("--batch", default=400, type=int,
|
| 247 |
+
help="batch size")
|
| 248 |
+
parser.add_argument('--progress', default=1, type=int,
|
| 249 |
+
choices=[0, 1, 2],
|
| 250 |
+
help="mode of Keras training progress bar")
|
| 251 |
+
args = parser.parse_args()
|
| 252 |
+
|
| 253 |
+
print("Program arguments used:")
|
| 254 |
+
for k,v in sorted(vars(args).items()):
|
| 255 |
+
print("{}: {}".format(k,v))
|
| 256 |
+
|
| 257 |
+
main(args)
|
| 258 |
+
|
| 259 |
+
|
Contest/ExampleSimAnalysis/test_eval.sh
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
#Evaluating contest testset with DNN source code similarity analyzer:
|
| 3 |
+
#Parameters:
|
| 4 |
+
# $1 -- directory with source code files
|
| 5 |
+
# $2 -- csv file with sample pairs to analyze
|
| 6 |
+
# $3 -- csv file with ground truth labels
|
| 7 |
+
DATA=$1
|
| 8 |
+
TEST=$2
|
| 9 |
+
TOKENIZER=/Volume1/AI4CODE/bin/tokenize
|
| 10 |
+
DNN=dnn_ckpt
|
| 11 |
+
if test $# -gt 2; then
|
| 12 |
+
echo "Evaluating DNN accuracy on test set"
|
| 13 |
+
python TestSetEval.py $DATA $TEST --labels $3 --tokenizer $TOKENIZER --dnn $DNN --predictions ./predictions_2.csv --batch 400
|
| 14 |
+
fi
|
| 15 |
+
echo "Computing predictions of source code similarity"
|
| 16 |
+
python TestSetEval.py $DATA $TEST --tokenizer $TOKENIZER --dnn $DNN --predictions ./predictions_1.csv --batch 400
|
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Project CodeNet
|
| 2 |
+
|
| 3 |
+
[](https://zenodo.org/badge/latestdoi/363800912)
|
| 4 |
+
|
| 5 |
+
The goal of Project CodeNet is to provide the *AI-for-Code* research community with a large scale, diverse, and high quality curated dataset to drive innovation in AI techniques.
|
| 6 |
+
|
| 7 |
+
## Table of Contents
|
| 8 |
+
|
| 9 |
+
* [Introduction](#introduction)
|
| 10 |
+
* [Differentiation](#differentiation)
|
| 11 |
+
* [Benchmarks](#benchmarks)
|
| 12 |
+
* [Potential use cases](#potential-use-cases)
|
| 13 |
+
* [Usability](#usability)
|
| 14 |
+
* [Models and experiments](#models-and-experiments)
|
| 15 |
+
* [Relevant links](#relevant-links)
|
| 16 |
+
* [Download the dataset](#download-the-dataset)
|
| 17 |
+
* [Dataset overview](#dataset-overview)
|
| 18 |
+
* [Dataset statistics](#dataset-statistics)
|
| 19 |
+
* [Data](#data)
|
| 20 |
+
* [Metadata](#metadata)
|
| 21 |
+
* [Metadata at the dataset level](#metadata-at-the-dataset-level)
|
| 22 |
+
* [Metadata at the problem level](#metadata-at-the-problem-level)
|
| 23 |
+
* [Directory structure and naming convention](#directory-structure-and-naming-convention)
|
| 24 |
+
* [Relationships among the metadata and data](#relationships-among-the-metadata-and-data)
|
| 25 |
+
* [Example of getting the source file for a particular submission](#example-of-getting-the-source-file-for-a-particular-submission)
|
| 26 |
+
* [Example of getting the metadata for a particular source file](#example-of-getting-the-metadata-for-a-particular-source-file)
|
| 27 |
+
* [Tools to process source files](#tools-to-process-source-files)
|
| 28 |
+
* [Statistics](#statistics)
|
| 29 |
+
* [Access and selection](#access-and-selection)
|
| 30 |
+
* [Pre-processing](#pre-processing)
|
| 31 |
+
* [Contributors](#contributors)
|
| 32 |
+
|
| 33 |
+
## Introduction
|
| 34 |
+
|
| 35 |
+
A decade ago, Marc Andreessen [famously wrote](https://a16z.com/2011/08/20/why-software-is-eating-the-world/) that "software is eating the world." Software now permeates every part of our existence; Google services combine for [2 billion lines of code](https://www.wired.com/2015/09/google-2-billion-lines-codeand-one-place/), and a modern vehicle [contains around](https://www.technologyreview.com/2012/12/03/181350/many-cars-have-a-hundred-million-lines-of-code/) 100 million lines of code. It's a monumental challenge to create, debug, maintain, and update these complex software systems. Recently, a fast-growing discipline known as AI for Code aims to help software developers improve their productivity by automating the software engineering process. AI for Code researchers have been leveraging technologies like NLP and augmenting them with code analysis and compilation techniques to perform a myriad of practical tasks, such as code search, summarization, and completion, as well as code-to-code translation. The discipline isn't limited to academic research either: Ruchir Puri, IBM Research's chief research scientist, discussed in a recent [podcast](https://open.spotify.com/episode/7gHPbVBHEgSdrACTow7Gql) how technologies from AI for Code are being used to modernize legacy software by helping migrate monolithic applications to microservices for IBM's enterprise clients.
|
| 36 |
+
|
| 37 |
+
AI for Code is poised to transition from proof-of-concept to widespread adoption. To provide a catalyst for such a tipping point, researchers at IBM Research have introduced Project CodeNet, a large-scale dataset for benchmarking and experimentation. Project CodeNet has many characteristics (large scale, diveristy, etc.) similar to ImageNet, a huge dataset for imagery that had a dramatic impact on the field of computer vision research. Project CodeNet is a large scale dataset with approximately 14 million code samples, each of which is an intended solution to one of 4000 coding problems. Project CodeNet aims to do for AI for Code what ImageNet did for computer vision.
|
| 38 |
+
|
| 39 |
+
### Differentiation
|
| 40 |
+
|
| 41 |
+
There are a few differentiating features of Project CodeNet when compared to other similar efforts. In addition to the size of the dataset, the code samples are written in over 50 programming languages, though the dominant languages are C++, C, Python, and Java. The code samples in Project CodeNet are annotated with a rich set of information, such as the code size, memory footprint, CPU run time, and status, which indicates acceptance or error types. Over 90% of the problems come with the respective problem description, which contains a concise problem statement, specification of the input format and the output format. When available, we also extracted from the problem description sample input and output, and provide them as part of the dataset. Users can execute the accepted codes samples (over 50% of the submissions are accepted) to extract additional metadata and verify outputs from generative AI models for correctness.
|
| 42 |
+
|
| 43 |
+
Another area that Project CodeNet addressed is the quality of the data samples. From a [paper](https://arxiv.org/pdf/1812.06469.pdf) by Allamanis, we learned that quite a large number of frequently used AI for Code datasets have duplicate or near-duplicate code samples, which can inflate performance metrics as much as 100%. In addition, we found that problem-submission style datasets from online judging systems can contain clusters of identical problems, which will certainly skew the performance metrics. One example is [POJ-104](https://sites.google.com/site/treebasedcnn/), in which problems 26 and 62 are identical. Therefore we identified the near-duplicates and the identical problem clusters in Project CodeNet and provide these information for the benefit of the users.
|
| 44 |
+
|
| 45 |
+
### Benchmarks
|
| 46 |
+
|
| 47 |
+
In light of these issues, we have extracted several benchmark datasets from CodeNet for users to perform code classification and code similarity experiments. They have been filtered to remove identical problem clusters and near-duplicate code samples, so that performance metrics can be measured on training and test data samples with the appropriate statistics. There are two C++ benchmark datasets that are similar to the popular POJ-104 but are approximately ten times in size. We felt that the size increase is necessary, since [98% accuracy](https://github.com/zhangj111/astnn) has been already achieved in code classification on POJ-104. An order of magnitude larger dataset will leave ample room to advance the state of the art with more complex neural networks and algorithms. The other two benchmark datasets are in Python and Java, which provides a different flavor because the frequent use of library functions.
|
| 48 |
+
|
| 49 |
+
### Potential use cases
|
| 50 |
+
|
| 51 |
+
The rich metadata and diversity open Project CodeNet to a plethora of uses cases. The problem-submission relationship in Project CodeNet corresponds to [type-4 similarity](https://escholarship.org/uc/item/45r2308g) and can be used for code search and clone detection. The code samples in Project CodeNet are labeled with their acceptance status and we can explore AI techniques to distinguish correct codes from problematic ones. Project CodeNet's metadata also enables the tracking of how a submission evolves from problematic to accepted, which could be used for exploring automatic code correction. Each code sample is labeled with CPU run time and memory footprint, which can be used for regression studies and prediction. Given its wealth of programs written in a multitude of languages, Project CodeNet may serve as a valuable benchmark dataset for source-to-source translation.
|
| 52 |
+
|
| 53 |
+
### Usability
|
| 54 |
+
|
| 55 |
+
To facilitate creation of customized benchmarks and dataset, we provide a set of productivity tools to aggregate codes samples based on user criteria. We are also releasing pre-processing tools to transform code samples into [token sequences](tools/tokenizer), [simplified parse trees](tools/spt-generator) and other [code graphs](tools/analysis-graph-generator).
|
| 56 |
+
|
| 57 |
+
## Models and experiments
|
| 58 |
+
|
| 59 |
+
We have performed numerous experiments on the CodeNet dataset. The goal of these experiments is to produce a set of baseline models and results for users of the CodeNet dataset to gauge their research. The run scripts and training scripts are available in the model-experiments directory. The classification and similarity experiments use the benchmark datasets we extracted from CodeNet as training and test datasets. In addition to experiments based on token sequences, we also have experiments leveraging graph neural networks (GNN). For the convenience of the users interested in GNN's, we have included the simplified parse tree (SPT) representation of the code samples for each benchmark dataset. The experiment on Masked Language Model has a companion Jupyter notebook in the notebooks directory.
|
| 60 |
+
|
| 61 |
+
## Problem Descriptions
|
| 62 |
+
|
| 63 |
+
For the vast majority of problem classes, short problem descriptions are available in
|
| 64 |
+
'doc/problem_descriptions.tar.gz', a small html file for each problem.
|
| 65 |
+
|
| 66 |
+
## Relevant links
|
| 67 |
+
|
| 68 |
+
- [Project CodeNet full dataset: Project_CodeNet.tar.gz](https://codait-cos-dax.s3.us.cloud-object-storage.appdomain.cloud/dax-project-codenet/1.0.0/Project_CodeNet.tar.gz) (7.8GB)
|
| 69 |
+
- Project CodeNet metadata: Project_CodeNet_metadata.tar.gz. Unfortunately this dataset is no longer available as a separate tar file;
|
| 70 |
+
It does however form part of the full dataset listed above.
|
| 71 |
+
- [Project CodeNet paper: Arxiv paper](https://arxiv.org/abs/2105.12655)
|
| 72 |
+
|
| 73 |
+
## Download the dataset
|
| 74 |
+
|
| 75 |
+
Download the full dataset from the link listed above, then use
|
| 76 |
+
|
| 77 |
+
`tar -zxf Project_CodeNet.tar.gz`
|
| 78 |
+
to uncompress and untar. The directory structure and how the code samples are organized are explained [here](README.md#directory-structure-and-naming-convention).
|
| 79 |
+
|
| 80 |
+
The 4 benchmark datasets, Project_CodeNet_C++1000, Project_CodeNet_C++1400,
|
| 81 |
+
Project_CodeNet_Python800, and Project_CodeNet_Java250 are included in the
|
| 82 |
+
full dataset.
|
| 83 |
+
They can be used for code classification and code similarity research as a replacement of or in addition to the dataset [POJ-104](https://sites.google.com/site/treebasedcnn/).
|
| 84 |
+
|
| 85 |
+
## Dataset overview
|
| 86 |
+
|
| 87 |
+
The Project CodeNet Dataset consists of a very large collection of source files, extensive metadata, tooling to access the dataset and make tailored selections, and documentation.
|
| 88 |
+
|
| 89 |
+
The basis of the dataset is the data available on two online judge web sites:
|
| 90 |
+
|
| 91 |
+
1. [AIZU Online Judge](https://onlinejudge.u-aizu.ac.jp/home)
|
| 92 |
+
2. [AtCoder](https://atcoder.jp/)
|
| 93 |
+
|
| 94 |
+
An online judge website offers programmers an opportunity to test their skills by posing programming problems in the form of courses or contests. Users may submit their solution which is then judged by an automatic review mechanism. The outcome is reported back to the user. Both problem descriptions, user submissions and associated metadata are available for study via various REST APIs.
|
| 95 |
+
|
| 96 |
+
The first step in constructing Project CodeNet is downloading the problem descriptions and the source code submissions from the websites mentioned above, followed by reshaping and consolidating the metadata and cleaning up the inconsistencies, omissions, and
|
| 97 |
+
mistakes in the source data itself.
|
| 98 |
+
|
| 99 |
+
### Dataset statistics
|
| 100 |
+
|
| 101 |
+
The dataset comprises 13,916,868 submissions, divided into 4053 problems (of which 5 are empty). Of the submissions 53.6% (7,460,588) are *accepted*, 29.5% are marked as *wrong answer* and the remaining suffer from one of the possible rejection causes. The data contains submissions in 55 different languages, although 95% of them are coded in the six most common languages (C++, Python, Java, C, Ruby, C#). C++ is the most common language with 8,008,527 submissions (57% of the total) of which 4,353,049 are *accepted*. Here are 2 pie charts depicting submissions and status distribution of Project CodeNet.
|
| 102 |
+
|
| 103 |
+
<table><tr>
|
| 104 |
+
<td> <img src="./assets/Project_CodeNet_subs.png" alt="Drawing" style="width: 250px;"/> </td>
|
| 105 |
+
<td> <img src="./assets/Project_CodeNet_status.png" alt="Drawing" style="width: 250px;"/> </td>
|
| 106 |
+
</tr></table>
|
| 107 |
+
|
| 108 |
+
A detailed overview of the dataset statistics can be found in this [spreadsheet](assets/Project_CodeNet_statistics.xlsx).
|
| 109 |
+
|
| 110 |
+
## Data
|
| 111 |
+
|
| 112 |
+
The data consist of complete programs in a particular programming language. Each program is contained in a single file. The file will have a name with an extension that denotes the programming language used. (More details about the specific programming language and the version of the compiler/interpreter used, can be found in the metadata.)
|
| 113 |
+
|
| 114 |
+
Each program attempts to solve a certain programming task or problem. There are many problems and each problem might have many solutions in different languages. We refer to each program as a submission instead of a solution since it might not be complete and correct. Solutions are the accepted submissions that are compilable and executable, and at least correctly produce the expected results on all provided test cases. (Of course, according to the late Dijkstra, tests are no proof of correctness.)
|
| 115 |
+
|
| 116 |
+
## Metadata
|
| 117 |
+
|
| 118 |
+
The metadata provides properties of interest about the problems and their submissions. Foremost it formalizes the organization of the data and the relationship between problems, languages, and the source code files. The metadata allows for queries about the data and to make specific selections among the large collection of problems, languages, and source files.
|
| 119 |
+
|
| 120 |
+
Metadata is made available in comma-separated value (CSV) files. This allows for easy processing, even with simple command-line tools. Some of the fields in the csv files might be empty, and for submissions that are not accepted, some fields might have invalid entries such as negative numbers for CPU time. Extra checking needs to be implemented in parsing these files.
|
| 121 |
+
|
| 122 |
+
The metadata is hierarchically organized on 2 levels: the first level is the dataset level that relates to all the different problems defined by the various dataset sources. The second level is the problem level that relates to all source code submissions pertaining to a single problem or task.
|
| 123 |
+
|
| 124 |
+
Metadata and data are deliberately kept fully separated within the file system.
|
| 125 |
+
|
| 126 |
+
### Metadata at the dataset level
|
| 127 |
+
|
| 128 |
+
At the dataset level there is a single CSV file (`problem_list.csv`) listing all the different problems. Additionally, for each problem there is a more extensive description that sets the problem and any further requirements and constraints and often provides examples of data input and expected output.
|
| 129 |
+
|
| 130 |
+
The fields and their format of this CSV file are captured by the following table:
|
| 131 |
+
|
| 132 |
+
name of column | data type | unit | description
|
| 133 |
+
-- | -- | -- | --
|
| 134 |
+
id | string | none | unique anonymized id of the problem
|
| 135 |
+
name | string | none | short name of the problem
|
| 136 |
+
dataset | string | none | original dataset, AIZU or AtCoder
|
| 137 |
+
time_limit | int | millisecond | maximum time allowed for a submission
|
| 138 |
+
memory_limit | int | KB | maximum memory allowed for a submission
|
| 139 |
+
rating | int | none | rating, i.e., difficulty of the problem
|
| 140 |
+
tags | string | none | list of tags separated by "\|"; not used
|
| 141 |
+
complexity | string | none | degree of difficulty of the problem; not used
|
| 142 |
+
|
| 143 |
+
### Metadata at the problem level
|
| 144 |
+
|
| 145 |
+
At the problem level there is a CSV file per problem and all content of these files is of course organized under one and the same header.
|
| 146 |
+
|
| 147 |
+
The fields and their format of this CSV file are captured by the following table:
|
| 148 |
+
|
| 149 |
+
name of column | data type | unit | description
|
| 150 |
+
-- | -- | -- | --
|
| 151 |
+
submission_id | string | none | unique anonymized id of the submission
|
| 152 |
+
problem_id | string | none | anonymized id of the problem
|
| 153 |
+
user_id | string | none | anonymized user id of the submission
|
| 154 |
+
date | int | seconds | date and time of submission in the Unix timestamp format (seconds since the epoch)
|
| 155 |
+
language | string | none | mapped language of the submission (ex: C++14 -> C++)
|
| 156 |
+
original_language | string | none | original language specification
|
| 157 |
+
filename_ext | string | none | extension of the filename that indicates the programming language used
|
| 158 |
+
status | string | none | acceptance status, or error type
|
| 159 |
+
cpu_time | int | millisecond | execution time
|
| 160 |
+
memory | int | KB | memory used
|
| 161 |
+
code_size | int | bytes | size of the submission source code in bytes
|
| 162 |
+
accuracy | string | none | number of tests passed; *Only for AIZU
|
| 163 |
+
|
| 164 |
+
Here is a table of all the possible status values. The “abbreviation” and “numeric code” are sometimes seen in the original metadata on the websites; it is listed here for reference and completeness. These fields do not occur in the Project CodeNet metadata.
|
| 165 |
+
|
| 166 |
+
status | abbreviation | numeric code
|
| 167 |
+
-- | -- | --
|
| 168 |
+
Compile Error | CE | 0
|
| 169 |
+
Wrong Answer | WA | 1
|
| 170 |
+
Time Limit Exceeded | TLE | 2
|
| 171 |
+
Memory Limit Exceeded | MLE | 3
|
| 172 |
+
Accepted | AC | 4
|
| 173 |
+
Judge Not Available | JNA | 5
|
| 174 |
+
Output Limit Exceeded | OLE | 6
|
| 175 |
+
Runtime Error | RE | 7
|
| 176 |
+
WA: Presentation Error | PE | 8
|
| 177 |
+
Waiting for Judging | WJ |
|
| 178 |
+
Waiting for Re-judging | WR |
|
| 179 |
+
Internal Error | IE |
|
| 180 |
+
Judge System Error | |
|
| 181 |
+
|
| 182 |
+
## Directory structure and naming convention
|
| 183 |
+
|
| 184 |
+
The data and metadata are organized in a rigorous directory structure. At the top level sits the `Project CodeNet` directory with several sub-directories, `data`, `metadata`, and `problem_descriptions`:
|
| 185 |
+
|
| 186 |
+
- `data` is further subdivided into a directory per problem and within each problem directory, directories for each language. The language directory contains all the source files supposed to be written in that particular programming or scripting language. When there are no submissions for a particular language, there will be no directory for it, but the problem directory will always be there, even if there are no submissions at all.
|
| 187 |
+
|
| 188 |
+
The name of the directory for a programming language is the common name for the language using proper capitalization and special characters. This name is the consolidation of the names used in the metadata. Information is available about how the original language designations are mapped into the directory names and how these more general and common names are mapped to the submission file name extensions. As an example, a source could be designated c++14, which is mapped into the directory `C++` (notice the capital C) and will get the extension `.cpp`.
|
| 189 |
+
- `derived` holds information about near-duplicates, identical problem clusters, sample input and output for each problem, as well as the benchmarks.
|
| 190 |
+
- `metadata` holds all the problem CSV files and the `problem_list.csv` file.
|
| 191 |
+
- `problem_descriptions` holds HTML files for most problems, giving an extensive description of the problem, often accompanied with some sample input and expected output.
|
| 192 |
+
|
| 193 |
+
For the sake of creating a uniform set of metadata across all data sources, and to hide any sensitive information, some metadata fields are anonymized by randomly (but uniquely and consistently) renumbering problem, submission, and user identifiers (ids). The identifiers we use are defined by simple regular expressions:
|
| 194 |
+
|
| 195 |
+
- problem ids are anonymized and follow this pattern: `p[0-9]{5}` (a `p` followed by exactly 5 digits).
|
| 196 |
+
- submission ids are anonymized and follow this pattern: `s[0-9]{9}` (an `s` followed by exactly 9 digits).
|
| 197 |
+
- user ids are anonymized and follow this pattern: `u[0-9]{9}` (a `u` followed by exactly 9 digits).
|
| 198 |
+
|
| 199 |
+
## Relationships among the metadata and data
|
| 200 |
+
|
| 201 |
+
The main relationship between problem metadata and data is the fact that each metadata record (a non-header row in a problem CSV file) describes one source file and provides all information about its location. The directory structure and naming convention as stated above are implicitly assumed.
|
| 202 |
+
|
| 203 |
+
### Example of getting the source file for a particular submission
|
| 204 |
+
|
| 205 |
+
Starting at a CSV metadata entry for a particular submission, here is how to get to the corresponding source file. Say that the submission id is `s300682070`. Either we know this is a submission to problem `p00001` upfront or we can grep through all `Project_CodeNet/metadata/p?????.csv` files to learn that. We get a brief description of this problem by looking at the `p00001` entry in the `Project_CodeNet/metadata/problem_list.csv`:
|
| 206 |
+
|
| 207 |
+
```console
|
| 208 |
+
p00001,List of Top 3 Hills,AIZU,1000,131072,,,
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
We can get a more verbose description of this problem by reading `Project_CodeNet/problem_descriptions/p00001.html`.
|
| 212 |
+
|
| 213 |
+
The `Project_CodeNet/metadata/p00001.csv` file provides the info on all submissions. For our selected submission we find:
|
| 214 |
+
|
| 215 |
+
```console
|
| 216 |
+
s300682070,p00001,u558442027,1480319506,JavaScript,JavaScript,js,Accepted,60,15496,219,4/4
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
We see it is an `Accepted` submission in the language `JavaScript` with file extension `.js`.
|
| 220 |
+
|
| 221 |
+
The source file path therefore is: `Project_CodeNet/data/p00001/JavaScript/s300682070.js`
|
| 222 |
+
|
| 223 |
+
### Example of getting the metadata for a particular source file
|
| 224 |
+
|
| 225 |
+
Likewise, we can play the reverse game of finding the metadata entry for a given submission source file. Say the source file is `Project_CodeNet/data/p00001/JavaScript/s300682070.js`.
|
| 226 |
+
|
| 227 |
+
Encoded in this file name path we see the problem id `p00001` and language `JavaScript` and of course the submission id `s300682070`. We find the metadata CSV file to be: `Project_CodeNet/metadata/p00001.csv`. Opening that file and searching for the submission id we find the entry:
|
| 228 |
+
|
| 229 |
+
```console
|
| 230 |
+
s300682070,p00001,u558442027,1480319506,JavaScript,JavaScript,js,Accepted,60,15496,219,4/4
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
## Tools to process source files
|
| 234 |
+
|
| 235 |
+
The source files of Project CodeNet represent examples of some 50+ different programming and scripting languages. Of course not all languages are equally represented: most submissions are written in the more popular languages C, C++, Java, and Python.
|
| 236 |
+
|
| 237 |
+
To complement our large dataset of source code, a suite of tools and utilities will be provided. These tools target several purposes:
|
| 238 |
+
|
| 239 |
+
- derive statistics from the dataset
|
| 240 |
+
- access the dataset files to make selections
|
| 241 |
+
- preprocess the source files to extract certain information
|
| 242 |
+
- facilitate conversions between popular formats
|
| 243 |
+
|
| 244 |
+
### Statistics
|
| 245 |
+
|
| 246 |
+
Since Project CodeNet uses the file system as storage and uses a rigorous directory structure, many (Linux) command-line utilities can be directly used to extract interesting statistics about the dataset. Utilities like `ls`, `wc` and `grep` are very useful. The CSV metadata can best be browsed using [`csvkit`](https://csvkit.readthedocs.io/en/latest/) components like `csvstat`.
|
| 247 |
+
|
| 248 |
+
More elaborate statistics about the dataset can easily be retrieved using SQL queries on a database representation of the metadata. [HSQLDB](http://hsqldb.org/) is a database that runs off a CSV file. Our CSV problem metadata files are simply stripped of their headers and concatenated. A suite of useful SQL queries is available. A separate [document](doc/HSQLDB.md) explains the necessary steps.
|
| 249 |
+
|
| 250 |
+
### Access and selection
|
| 251 |
+
|
| 252 |
+
As described above, it should be easy to create specific subsets of the
|
| 253 |
+
dataset merely by copying (or symlinking) relevant files and/or
|
| 254 |
+
directories. For more elaborate selections based on a subset or range of
|
| 255 |
+
problems, a subset of languages, statuses, and code sizes, several Bash
|
| 256 |
+
scripts are available to accomplish that. These scripts reside in the
|
| 257 |
+
`tools/aggregation-scripts` directory and are separately documented in this [README](tools/aggregation-scripts/README.md).
|
| 258 |
+
|
| 259 |
+
### Pre-processing
|
| 260 |
+
|
| 261 |
+
We provide tools to convert code samples into a representation that can be consumed by AI algorithms
|
| 262 |
+
- generate stream of tokens [tokenizer](tools/tokenizer)
|
| 263 |
+
- parsing to tree/abstract syntax tree [AST generation](tools/spt-generator)
|
| 264 |
+
- control and data flow graph construction [code analysis](tools/analysis-graph-generator)
|
| 265 |
+
|
| 266 |
+
Whether and to what extent the above steps can successfully be applied to any given source file depends on several factors. Obviously, if the submission is not of `Accepted` status, it is to be expected that even simple tokenization will fail because of malformed lexical elements. But the situation for `Accepted` submissions is not always better: programmers might have used certain non-standard features of the language that happen to be accepted by a certain compiler or interpreter. Simple cases are the use of a dollar sign as part of a C identifier. For languages like C and C++ that use a pre-processor, use of macros and conditional defines can hugely change how the code ultimately looks like.
|
| 267 |
+
|
| 268 |
+
### Contributors
|
| 269 |
+
|
| 270 |
+
Ruchir Puri, David S. Kung, Geert Janssen, Wei Zhang, Giacomo Domeniconi, Vladimir Zolotov, Julian Dolby, Jie Chen, Mihir Choudhury, Lindsey Decker, Veronika Thost, Luca Buratti, Saurabh Pujar, Shyam Ramji, Ulrich Finkler, Susan Malaika, Frederick Reiss.
|
assets/Project_CodeNet_statistics.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47f56f9cc9dde3290b11e235770577390de9d38f4f6c08be86d0ca1a38dc239d
|
| 3 |
+
size 185503
|
assets/Project_CodeNet_status.png
ADDED
|
Git LFS Details
|
assets/Project_CodeNet_subs.png
ADDED
|
Git LFS Details
|
assets/tiny.png
ADDED
|
Git LFS Details
|
doc/HSQLDB.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Access Project CodeNet through SQL Queries
|
| 2 |
+
|
| 3 |
+
## Table of Contents
|
| 4 |
+
|
| 5 |
+
* [Introduction](#introduction)
|
| 6 |
+
* [Installation](#installation)
|
| 7 |
+
* [Creating a sqltool.rc file](#creating-a-sqltoolrc-file)
|
| 8 |
+
* [Prepare Project CodeNet for use with HSQLDB](#prepare-project-codenet-for-use-with-hsqldb)
|
| 9 |
+
* [Define the table schemas](#define-the-table-schemas)
|
| 10 |
+
* [A few simple SQL queries](#a-few-simple-sql-queries)
|
| 11 |
+
|
| 12 |
+
## Introduction
|
| 13 |
+
|
| 14 |
+
Project CodeNet metadata is available as CSV files in a rigid directory
|
| 15 |
+
structure. To abstract away from this structure and the peculiarities
|
| 16 |
+
of the metadata organization, we can use a database approach to the
|
| 17 |
+
metadata that allows for generic SQL queries to retrieve all kinds of
|
| 18 |
+
statistics but more importantly select file names of submissions
|
| 19 |
+
depending on all kinds of criteria.
|
| 20 |
+
|
| 21 |
+
One particular database is ideally suited to work with CSV files:
|
| 22 |
+
[*HyperSQL Database* (HSQLDB)](http://hsqldb.org). HSQLDB uses the CSV
|
| 23 |
+
files as persistent
|
| 24 |
+
storage and uses memory caches to speed up the queries.
|
| 25 |
+
|
| 26 |
+
HSQLDB is a simple but complete database software
|
| 27 |
+
implemented in Java. The main attractive feature is that it can link to
|
| 28 |
+
CSV files as tables and use them as persistent storage. This implies
|
| 29 |
+
that SQL queries can directly run off existing (even read-only) CSV
|
| 30 |
+
files without any modifications.
|
| 31 |
+
|
| 32 |
+
## Installation
|
| 33 |
+
|
| 34 |
+
Here we explain how to install and set up HSQLDB to work with the
|
| 35 |
+
Project CodeNet dataset. We assume `$PREFIX` to be a suitable system directory
|
| 36 |
+
like e.g. `/usr/local` and `$HOME` to expand to a user's home directory.
|
| 37 |
+
|
| 38 |
+
This brief guide is in no way a substitute for the excellent and
|
| 39 |
+
extensive [documentation](http://hsqldb.org/web/hsqlDocsFrame.html)
|
| 40 |
+
and [howtos](http://hsqldb.org/web/howto.html) that accompany HSQLDB.
|
| 41 |
+
|
| 42 |
+
We assume the use of (the latest as of writing) version 2.6.0 of HSQLDB.
|
| 43 |
+
(Any future newer version will probably work just as well).
|
| 44 |
+
|
| 45 |
+
The required software can be downloaded from
|
| 46 |
+
<http://www.hsqldb.org/download/hsqldb_260_jdk8/>.
|
| 47 |
+
That website offers the 2 files `hsqldb-2.6.0-jdk8.jar` and
|
| 48 |
+
`sqltool-2.6.0-jdk8.jar`. Rename the files to
|
| 49 |
+
`hsqldb.jar` and `sqltool.jar`, respectively.
|
| 50 |
+
|
| 51 |
+
Important files and their use are:
|
| 52 |
+
|
| 53 |
+
>`hsqldb.jar`
|
| 54 |
+
: The jar file containing all classes of the database engine proper.
|
| 55 |
+
Typically resides in some system accessible directory, like:
|
| 56 |
+
`$PREFIX/lib/hsqldb-2.6.0/hsqldb/lib/`
|
| 57 |
+
|
| 58 |
+
>`sqltool.jar`
|
| 59 |
+
: The jar file that provides an interactive command-line user interface (CLI)
|
| 60 |
+
to the database. Resides next to `hsqldb.jar`.
|
| 61 |
+
|
| 62 |
+
>`sqltool`
|
| 63 |
+
: A wrapper around `sqltool.jar` that calls the Java JVM and starts the
|
| 64 |
+
CLI. Typically to be found in a `bin` directory, like `$PREFIX/bin/`.
|
| 65 |
+
Its contents could be something like:
|
| 66 |
+
```bash
|
| 67 |
+
#!/usr/bin/env bash
|
| 68 |
+
|
| 69 |
+
HSQLDB_HOME=$PREFIX/lib/hsqldb-2.6.0/hsqldb
|
| 70 |
+
|
| 71 |
+
# allow csv to reside anywhere (and not just inside db directory)
|
| 72 |
+
java -Dtextdb.allow_full_path=false -jar $HSQLDB_HOME/lib/sqltool.jar "$@"
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
>`sqltool.rc`
|
| 76 |
+
The configuration file consulted by `sqltool`.
|
| 77 |
+
To be located in the user's home directory, e.g.
|
| 78 |
+
`$HOME/sqltool.rc`
|
| 79 |
+
|
| 80 |
+
>`DatabaseManagerSwing`
|
| 81 |
+
: A wrapper around `hsqldb.jar` that provides a graphical interface (GUI) to
|
| 82 |
+
the database. Can be found in the same bin directory as `sqltool`.
|
| 83 |
+
|
| 84 |
+
## Creating a `sqltool.rc` file
|
| 85 |
+
|
| 86 |
+
This configuration file specifies the various databases via URLs and
|
| 87 |
+
access rights. For simplicity we here assume a single user who is the
|
| 88 |
+
database administrator using the default user name `SA` without a
|
| 89 |
+
password. This is expressed as follows in `sqltool.rc`:
|
| 90 |
+
|
| 91 |
+
```
|
| 92 |
+
urlid .+
|
| 93 |
+
username SA
|
| 94 |
+
password
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
Assume we create the database (a collection of CSV files that become
|
| 98 |
+
the database tables) in a directory `$HOME\DB`. This is made known to
|
| 99 |
+
HSQLDB as follows and added to `sqltool.rc`:
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
urlid project_codenet
|
| 103 |
+
url jdbc:hsqldb:file:${user.home}/DB/project_codenet;shutdown=true
|
| 104 |
+
transiso TRANSACTION_READ_COMMITTED
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
Make sure that the directory exists: `mkdir -p $HOME/DB`.
|
| 108 |
+
With the configuration file in place, we can test our set up so far by
|
| 109 |
+
running `sqltool` and doing a few simple queries:
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
# Not really necessary, but for convenience, go to the DB directory:
|
| 113 |
+
$ cd $HOME/DB
|
| 114 |
+
|
| 115 |
+
# Start the sqltool program and make it use the (empty) project_codenet db:
|
| 116 |
+
# (You will get a message and eventually the sql> prompt.)
|
| 117 |
+
$ sqltool project_codenet
|
| 118 |
+
SqlTool v. 6140.
|
| 119 |
+
...
|
| 120 |
+
sql>
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
You can explore some of the commands and browse the system tables.
|
| 124 |
+
Here are a few examples:
|
| 125 |
+
|
| 126 |
+
```bash
|
| 127 |
+
# Get help about \ commands:
|
| 128 |
+
sql> \?
|
| 129 |
+
# Get a list of user tables (result is none):
|
| 130 |
+
sql> \dt
|
| 131 |
+
# Get a list of system tables:
|
| 132 |
+
sql> \dS
|
| 133 |
+
# Get the list of known users (only 1: SA):
|
| 134 |
+
sql> select * from information_schema.system_users;
|
| 135 |
+
# Quit the program (\q or simply ^D in a Linux shell):
|
| 136 |
+
sql> \q
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
This will leave behind the files `project_codenet.properties` and
|
| 140 |
+
`project_codenet.script` in the `DB` directory. These are the files used by
|
| 141 |
+
HSQLDB to record the database properties, the table schemas, etc.
|
| 142 |
+
In general you should not delete them.
|
| 143 |
+
|
| 144 |
+
## Prepare Project CodeNet for use with HSQLDB
|
| 145 |
+
|
| 146 |
+
HSQLDB equates a database table with a CSV file. In Project CodeNet we have a
|
| 147 |
+
CSV per problem which is not very convenient. It is better to merge
|
| 148 |
+
all problem metadata (`p?????.csv`) into a single CSV file. Note
|
| 149 |
+
however that each problem CSV has its own header; these need to be
|
| 150 |
+
stripped off first. Since the dataset is read-only we must make a copy
|
| 151 |
+
of the metadata directory. As an example we show the necessary steps:
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
# Make sure we are in the database directory:
|
| 155 |
+
$ cd $HOME/DB
|
| 156 |
+
|
| 157 |
+
# Copy the metadata from Project CodeNet:
|
| 158 |
+
$ cp -r Project_CodeNet/metadata .
|
| 159 |
+
|
| 160 |
+
# Move the problem_list out and rename:
|
| 161 |
+
$ mv metadata/problem_list.csv problems.csv
|
| 162 |
+
|
| 163 |
+
# Get a separate header file:
|
| 164 |
+
$ head -n1 metadata/p00000.csv > submissions_header.csv
|
| 165 |
+
|
| 166 |
+
# Strip off all headers:
|
| 167 |
+
$ find metadata -type f -exec sed -i -e '1d' {} \;
|
| 168 |
+
|
| 169 |
+
# Create a single CSV file:
|
| 170 |
+
$ cat submissions_header.csv metadata/p?????.csv > submissions.csv
|
| 171 |
+
|
| 172 |
+
# For safety make the CSV files read-only:
|
| 173 |
+
$ chmod 444 problems.csv submissions.csv
|
| 174 |
+
|
| 175 |
+
# The metadata copy and submissions_header are no longer needed:
|
| 176 |
+
$ rm -rf metadata submissions_header.csv
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
Now we can create HSQLDB tables for `problems.csv` and `submissions.csv`.
|
| 180 |
+
|
| 181 |
+
## Define the table schemas
|
| 182 |
+
|
| 183 |
+
To create a database table we need to specify its columns, the type of
|
| 184 |
+
value in each column and optionally some specific constraints or
|
| 185 |
+
properties for that column. All this is specified in an SQL
|
| 186 |
+
create table statement. Run `sqltool` and enter the following SQL statements
|
| 187 |
+
to accomplish the table creation and linking to the corresponding CSV files:
|
| 188 |
+
|
| 189 |
+
```bash
|
| 190 |
+
$ cd $HOME/DB
|
| 191 |
+
$ sqltool project_codenet
|
| 192 |
+
```
|
| 193 |
+
```sql
|
| 194 |
+
sql> CREATE TEXT TABLE problems(
|
| 195 |
+
id VARCHAR( 6) PRIMARY KEY NOT NULL,
|
| 196 |
+
name VARCHAR(64),
|
| 197 |
+
dataset VARCHAR(16) NOT NULL,
|
| 198 |
+
time_limit INTEGER,
|
| 199 |
+
memory_limit INTEGER,
|
| 200 |
+
rating INTEGER,
|
| 201 |
+
tags VARCHAR(64),
|
| 202 |
+
complexity VARCHAR(32)
|
| 203 |
+
);
|
| 204 |
+
|
| 205 |
+
SET TABLE problems READ ONLY;
|
| 206 |
+
|
| 207 |
+
SET TABLE problems SOURCE 'problems.csv;encoding=UTF-8;\
|
| 208 |
+
cache_rows=50000;cache_size=10240000;ignore_first=true;\
|
| 209 |
+
fs=,;qc=\quote';
|
| 210 |
+
|
| 211 |
+
sql> CREATE TEXT TABLE submissions(
|
| 212 |
+
submission_id VARCHAR(10) PRIMARY KEY NOT NULL,
|
| 213 |
+
problem_id VARCHAR( 6) NOT NULL,
|
| 214 |
+
user_id VARCHAR(10) NOT NULL,
|
| 215 |
+
date BIGINT NOT NULL,
|
| 216 |
+
language VARCHAR(16) NOT NULL,
|
| 217 |
+
original_language VARCHAR(16) NOT NULL,
|
| 218 |
+
filename_ext VARCHAR(16) NOT NULL,
|
| 219 |
+
status VARCHAR(32) NOT NULL,
|
| 220 |
+
cpu_time INTEGER NOT NULL,
|
| 221 |
+
memory INTEGER NOT NULL,
|
| 222 |
+
code_size INTEGER NOT NULL,
|
| 223 |
+
accuracy VARCHAR(16)
|
| 224 |
+
);
|
| 225 |
+
|
| 226 |
+
SET TABLE submissions READ ONLY;
|
| 227 |
+
|
| 228 |
+
SET TABLE submissions SOURCE 'submissions.csv;encoding=UTF-8;\
|
| 229 |
+
cache_rows=50000;cache_size=10240000;ignore_first=true;\
|
| 230 |
+
fs=,;qc=\quote';
|
| 231 |
+
|
| 232 |
+
sql> commit;
|
| 233 |
+
sql> \q
|
| 234 |
+
```
|
| 235 |
+
|
| 236 |
+
Note the `commit` command (abbreviated as `\=`); this is absolutely
|
| 237 |
+
vital: it commits all the changes to the database. Without it all our
|
| 238 |
+
effort would get lost as soon as we quit. The commit of the
|
| 239 |
+
submissions table will take a while (maybe several minutes) because
|
| 240 |
+
the large `submissions.csv` file has to be read and converted into an
|
| 241 |
+
internal format. So be patient.
|
| 242 |
+
|
| 243 |
+
## A few simple SQL queries
|
| 244 |
+
|
| 245 |
+
```sql
|
| 246 |
+
sql> -- How many distinct programming languages are used:
|
| 247 |
+
sql> select count(distinct language) from submissions;
|
| 248 |
+
|
| 249 |
+
sql> -- How many submissions per language:
|
| 250 |
+
sql> select language, count(*) as nr_submissions
|
| 251 |
+
from submissions group by language
|
| 252 |
+
order by nr_submissions desc;
|
| 253 |
+
|
| 254 |
+
sql> -- how many accepted submissions with code size >= 500 per language:
|
| 255 |
+
sql> select language, count(*) as accepted_submissions
|
| 256 |
+
from submissions
|
| 257 |
+
where status = 'Accepted' and code_size >= 500
|
| 258 |
+
group by language order by accepted_submissions desc;
|
| 259 |
+
|
| 260 |
+
sql> -- How many problems with >= 200 accepted submissions per language:
|
| 261 |
+
sql> select language, count(*) as problems
|
| 262 |
+
from (select problem_id, language, count(*) as accepted
|
| 263 |
+
from submissions where status = 'Accepted'
|
| 264 |
+
group by problem_id, language
|
| 265 |
+
having count(*) >= 200)
|
| 266 |
+
group by language order by problems desc;
|
| 267 |
+
```
|
doc/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Documentation on Tools
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
This directory contain detailed documentation on various tools that
|
| 6 |
+
can be used to manipulate the source files available in the Project CodeNet
|
| 7 |
+
dataset.
|
| 8 |
+
|
| 9 |
+
It also contains working documents on proposals and ideas for tools,
|
| 10 |
+
formats, and applications.
|
| 11 |
+
|
| 12 |
+
## HSQLDB
|
| 13 |
+
|
| 14 |
+
HSQLDB is a simple but complete database software that can use CSV files as
|
| 15 |
+
persistent storage. This [document](./HSQLDB.md) describes how to convert the
|
| 16 |
+
Project CodeNet metadata to be used with HSQLDB.
|
| 17 |
+
|
| 18 |
+
## srcml
|
| 19 |
+
|
| 20 |
+
srcML is a tool for the analysis of programming language source code.
|
| 21 |
+
The [document](./srcml.md) describes typical use cases.
|
| 22 |
+
|
| 23 |
+
## Syntax-correct Tokenstream
|
| 24 |
+
|
| 25 |
+
It is possible to obtain a token (class) stream from a source code file such
|
| 26 |
+
that the result is still syntactically correct. This
|
| 27 |
+
[document](./syntax-correct-tokenstream.md) shows how.
|
| 28 |
+
|
| 29 |
+
## Universal Tokens
|
| 30 |
+
|
| 31 |
+
Some thoughts and a proposal to normalize the token classes for various
|
| 32 |
+
programming languages are presented [here](./universal_tokens.md).
|
doc/problem_descriptions.tar.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8b631ae168ba84dce69c7d8e1b6c632256e0155858c2664c6493a5f001b45fdd
|
| 3 |
+
size 3492211
|
doc/srcml.md
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Some Experiments using the srcML Tool
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
[srcML](https://www.srcml.org) is a tool for the analysis of programming
|
| 6 |
+
language source code.
|
| 7 |
+
It is unique in that it presents its results in the form of an annotation
|
| 8 |
+
(using XML elements and attributes) of the original source code in a lossless
|
| 9 |
+
manner. Like in compression, lossless here means that the original source code
|
| 10 |
+
can be fully retrieved, inclusive lay-out in the form of white-space
|
| 11 |
+
and indentation.
|
| 12 |
+
|
| 13 |
+
The provided annotation reflects a simple Abstract Syntax Tree (AST) of the
|
| 14 |
+
"program". The program need not necessarily be a complete program in the sense
|
| 15 |
+
of the syntax of the programming language; it might as well be a well-formed
|
| 16 |
+
code snippet, like a declaration, a function definition, or a block of
|
| 17 |
+
statements, or an expression. Unlike with other parsers that would need to
|
| 18 |
+
know a grammar start symbol, with srcML there is no need to make this known:
|
| 19 |
+
srcML will figure out by itself how to process the snippet.
|
| 20 |
+
The programming languages supported by srcML are: C, C++, C#,
|
| 21 |
+
and Java. Each language has its own unique XML elements together with a common
|
| 22 |
+
shared set for similar language constructs.
|
| 23 |
+
This is documented [here](https://www.srcml.org/doc/srcMLElements.html).
|
| 24 |
+
|
| 25 |
+
### Example
|
| 26 |
+
|
| 27 |
+
The XML annotation is demonstrated here with a tiny C source code example:
|
| 28 |
+
|
| 29 |
+
[tiny.c]
|
| 30 |
+
```C
|
| 31 |
+
#include <stdio.h>
|
| 32 |
+
|
| 33 |
+
int main(int argc, char *argv[]) {
|
| 34 |
+
printf("args: %d\n", argc);
|
| 35 |
+
return 0;
|
| 36 |
+
}
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
The following command turns the C code into the annotated XML:
|
| 40 |
+
```console
|
| 41 |
+
$ srcml tiny.c -o tiny.xml
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
This generates the following XML. Mind that we manually edited the result
|
| 45 |
+
so that it fits on the page in this document without truncation of long lines.
|
| 46 |
+
(Of course this destroys the preserved lay-out of the original C source.)
|
| 47 |
+
|
| 48 |
+
```xml
|
| 49 |
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
| 50 |
+
<unit xmlns="http://www.srcML.org/srcML/src"
|
| 51 |
+
xmlns:cpp="http://www.srcML.org/srcML/cpp"
|
| 52 |
+
revision="0.9.5" language="C" filename="tiny.c">
|
| 53 |
+
<cpp:include>#<cpp:directive>include</cpp:directive>
|
| 54 |
+
<cpp:file><stdio.h></cpp:file>
|
| 55 |
+
</cpp:include>
|
| 56 |
+
|
| 57 |
+
<function><type><name>int</name></type> <name>main</name>
|
| 58 |
+
<parameter_list>(<parameter><decl><type><name>int</name></type>
|
| 59 |
+
<name>argc</name></decl></parameter>,
|
| 60 |
+
<parameter><decl><type><name>char</name> <modifier>*</modifier></type>
|
| 61 |
+
<name><name>argv</name><index>[]</index></name></decl></parameter>
|
| 62 |
+
)</parameter_list>
|
| 63 |
+
|
| 64 |
+
<block>{
|
| 65 |
+
<expr_stmt><expr><call><name>printf</name>
|
| 66 |
+
<argument_list>(
|
| 67 |
+
<argument><expr><literal type="string">"args: %d\n"</literal></expr>
|
| 68 |
+
</argument>,
|
| 69 |
+
<argument><expr><name>argc</name></expr></argument>
|
| 70 |
+
)</argument_list></call></expr>;</expr_stmt>
|
| 71 |
+
<return>return <expr><literal type="number">0</literal></expr>;</return>
|
| 72 |
+
}</block></function>
|
| 73 |
+
</unit>
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
To restore the original C code, run this:
|
| 77 |
+
```console
|
| 78 |
+
$ srcml tiny.xml
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
To remove the enclosing `<unit>` element use the `--output-srcml-inner` option.
|
| 82 |
+
To render the output XML in a nicely formatted form you can use this filter:
|
| 83 |
+
`| tidy -xml -i -q -`.
|
| 84 |
+
(Obviously you will lose the original white-space lay-out.)
|
| 85 |
+
|
| 86 |
+
There are various tools to render the parse tree as an image. A simple one is
|
| 87 |
+
DrawTag that accept any XML as input.
|
| 88 |
+
See figure 1 for a visualization of the tiny.xml file.
|
| 89 |
+
|
| 90 |
+

|
| 91 |
+
|
| 92 |
+
The srcML program has many options:
|
| 93 |
+
|
| 94 |
+
```console
|
| 95 |
+
GENERAL OPTIONS:
|
| 96 |
+
-h [ --help ] arg display this help and exit. USAGE: help or
|
| 97 |
+
help [module name]. MODULES: src2srcml,
|
| 98 |
+
srcml2src
|
| 99 |
+
-V [ --version ] display version number and exit
|
| 100 |
+
-v [ --verbose ] conversion and status information to stderr
|
| 101 |
+
-q [ --quiet ] suppress status messages
|
| 102 |
+
--list list all files in the srcML archive and
|
| 103 |
+
exit
|
| 104 |
+
-i [ --info ] display most metadata except srcML file
|
| 105 |
+
count and exit
|
| 106 |
+
-L [ --longinfo ] display all metadata including srcML file
|
| 107 |
+
count and exit
|
| 108 |
+
--max-threads arg (=4) set the maximum number of threads srcml can
|
| 109 |
+
spawn
|
| 110 |
+
-o [ --output ] arg (=stdout://-) write ouput to a file
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
CREATING SRCML:
|
| 114 |
+
-l [ --language ] arg set the language to C, C++, or Java
|
| 115 |
+
--register-ext arg register file extension EXT for
|
| 116 |
+
source-code language LANG. arg format
|
| 117 |
+
EXT=LANG
|
| 118 |
+
--src-encoding arg set the input source encoding
|
| 119 |
+
--files-from arg read list of source file names to form a
|
| 120 |
+
srcML archive
|
| 121 |
+
-X [ --output-xml ] output in XML instead of text
|
| 122 |
+
-r [ --archive ] store output in a srcML archive, default
|
| 123 |
+
for multiple input files
|
| 124 |
+
--in-order enable strict output ordering
|
| 125 |
+
-t [ --text ] arg raw string text to be processed
|
| 126 |
+
|
| 127 |
+
MARKUP OPTIONS:
|
| 128 |
+
--position include line/column attributes, namespace
|
| 129 |
+
'http://www.srcML.org/srcML/position'
|
| 130 |
+
--tabs [=arg(=8)] set tabs arg characters apart. Default
|
| 131 |
+
is 8
|
| 132 |
+
--cpp enable preprocessor parsing and markup
|
| 133 |
+
for Java and non-C/C++ languages
|
| 134 |
+
--cpp-markup-if0 markup cpp #if 0 regions
|
| 135 |
+
--cpp-nomarkup-else leave cpp #else regions as text
|
| 136 |
+
|
| 137 |
+
XML FORM:
|
| 138 |
+
-x [ --xml-encoding ] arg (=UTF-8) set output XML encoding. Default is UTF-8
|
| 139 |
+
--no-xml-declaration do not output the XML declaration
|
| 140 |
+
--no-namespace-decl do not output any namespace declarations
|
| 141 |
+
--xmlns arg set the default namespace to arg
|
| 142 |
+
--xmlns: arg set the namespace. arg format PREFIX=URI
|
| 143 |
+
|
| 144 |
+
METADATA OPTIONS:
|
| 145 |
+
-f [ --filename ] arg set the filename attribute
|
| 146 |
+
--url arg set the url attribute
|
| 147 |
+
-s [ --src-version ] arg set the version attribute
|
| 148 |
+
--hash add hash to srcml output
|
| 149 |
+
--timestamp add timestamp to srcml output
|
| 150 |
+
-p [ --prefix ] arg display prefix of namespace given by URI
|
| 151 |
+
arg and exit
|
| 152 |
+
--show-language display source language and exit
|
| 153 |
+
--show-url display source url name and exit
|
| 154 |
+
--show-filename display source filename and exit
|
| 155 |
+
--show-src-version display source version and exit
|
| 156 |
+
--show-timestamp display timestamp and exit
|
| 157 |
+
--show-hash display hash and exit
|
| 158 |
+
--show-encoding display xml encoding and exit
|
| 159 |
+
--show-unit-count display number of srcML files and exit
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
EXTRACTING SOURCE CODE:
|
| 163 |
+
-S [ --output-src ] output in text instead of XML
|
| 164 |
+
--to-dir arg extract all files from srcML and create them in the
|
| 165 |
+
filesystem
|
| 166 |
+
|
| 167 |
+
TRANSFORMATIONS:
|
| 168 |
+
--apply-root apply an xslt program or xpath query to the root
|
| 169 |
+
element
|
| 170 |
+
--relaxng arg output individual units that match RELAXNG file or URI
|
| 171 |
+
--xpath arg apply XPATH expression to each individual unit
|
| 172 |
+
--xslt arg apply XSLT file or URI transformation to each
|
| 173 |
+
individual unit
|
| 174 |
+
--attribute arg add attribute to xpath query
|
| 175 |
+
--element arg add element to xpath query
|
| 176 |
+
-U [ --unit ] arg extract individual unit number from srcML
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
For instance, the XML markup can be enhanced with line and column coordinates.
|
| 180 |
+
Notice also that srcML has built-in capabilities to query and manipulate the
|
| 181 |
+
XML. Queries can be done with XPath expressions. General transformations can
|
| 182 |
+
be executed with XSLT. By the way, there is no need to first convert the
|
| 183 |
+
source to XML; the built-in queries capabilities work also directly off the
|
| 184 |
+
source code.
|
| 185 |
+
|
| 186 |
+
Here are a few examples of useful operations:
|
| 187 |
+
|
| 188 |
+
- Get all function and method definition names:
|
| 189 |
+
```console
|
| 190 |
+
$ srcml --xpath="//src:function/src:name" program.java
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
- Count the number of conditions:
|
| 194 |
+
```console
|
| 195 |
+
$ srcml --xpath='count(//src:condition)' program.c
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
- Output all line comments:
|
| 199 |
+
```console
|
| 200 |
+
$ srcml --xpath='//src:comment[@type="line"]' program.cpp
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
Much more versatile and powerful tools to process any XML are
|
| 204 |
+
[`xidel`](http://videlibri.sourceforge.net/xidel.html) and
|
| 205 |
+
[`xmlstarlet`](http://xmlstar.sourceforge.net/).
|
| 206 |
+
|
| 207 |
+
If you prefer JSON over XML, then use `jtm` to convert the srcML output:
|
| 208 |
+
|
| 209 |
+
```console
|
| 210 |
+
jtm -i2 tiny.xml > tiny.json
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
## Using srcML to extract a Function Call Graph
|
| 214 |
+
|
| 215 |
+
A neat application of the combination of srcML and xmlstarlet is to use
|
| 216 |
+
them in a script to produce the call graph of a program as a
|
| 217 |
+
JSON-Graph.
|
| 218 |
+
It is easy to extract the actual function
|
| 219 |
+
definitions, i.e., the source text, of all functions mentioned in the
|
| 220 |
+
call graph.
|
| 221 |
+
|
| 222 |
+
Here we briefly sketch the main steps. Details can be found in the
|
| 223 |
+
actual Bash scripts provided in [this](../tools/aggregation-scripts) directory.
|
| 224 |
+
|
| 225 |
+
1. We start with using srcML to get all function definitions from a
|
| 226 |
+
source file: (This will ignore any pre-processor directives, any global
|
| 227 |
+
variables, and typedefs.)
|
| 228 |
+
`srcml --xpath="//src:function" source.c -o source.xml`
|
| 229 |
+
|
| 230 |
+
2. Given the `NAME` of a function we then look up its definition in the
|
| 231 |
+
`source.xml` file and using `xmlstarlet` retrieve all names mentioned in
|
| 232 |
+
function calls present in the body of that function definition:
|
| 233 |
+
`xmlstarlet -t -v "//function[name=\"NAME\"]//call/name" source.xml`
|
| 234 |
+
|
| 235 |
+
3. Using the capability of step 2, starting from some root function
|
| 236 |
+
name supplied by a cmdline argument or defaulting to `main` we build a
|
| 237 |
+
graph of nodes that represent functions and directed edges that
|
| 238 |
+
represent the function calls.
|
| 239 |
+
|
| 240 |
+
Notice that the call graph can have cycles. These are caused by direct
|
| 241 |
+
recursive or mutual recursive functions.
|
| 242 |
+
Once we have the graph, traversing it in reverse depth-first
|
| 243 |
+
order enumerates all function definitions in the proper
|
| 244 |
+
define-before-use order and can hence be retrieved from the
|
| 245 |
+
`source.xml` file, again using srcML to convert them back to source code.
|
doc/syntax-correct-tokenstream.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# A Syntactically Correct Token Stream
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
With some ingenuity in terms of defining token classes and the symbols that
|
| 6 |
+
represent them, it is possible to tokenize source code input of certain
|
| 7 |
+
programming languages such that the token stream itself is a syntactically
|
| 8 |
+
correct program. By the latter we mean that the token stream can be correctly
|
| 9 |
+
parsed as a sentence of the language grammar. Of course, all semantic aspects
|
| 10 |
+
such as use of identifiers (uniquely declared within a scope), application of
|
| 11 |
+
operators to the correctly typed values, etc. are no longer valid.
|
| 12 |
+
|
| 13 |
+
Apart from being an interesting curiosity,
|
| 14 |
+
being syntactically correct makes it possible to read the program as a
|
| 15 |
+
template: the complete grammatical structure is still clearly present,
|
| 16 |
+
especially if we present the tokenized program text in a pretty-printed form.
|
| 17 |
+
|
| 18 |
+
The following sections will show the details of the tokenization process as
|
| 19 |
+
applied to the programming language C. It should be obvious how a similar
|
| 20 |
+
approach can be developed for most imperative programming languages such as
|
| 21 |
+
C++, Java, and Python (pretty-printing Python might be a bit of a challenge).
|
| 22 |
+
|
| 23 |
+
## Approach
|
| 24 |
+
|
| 25 |
+
So how can we tokenize C source code in such a way that the result is still
|
| 26 |
+
syntactically correct?
|
| 27 |
+
|
| 28 |
+
The trick to achieve this is to choose the right representative for each
|
| 29 |
+
token class, i.e., the symbol used to designate a certain token class is a
|
| 30 |
+
correct literal that belongs to that token class, a representative.
|
| 31 |
+
Instead of the usual class names like number, operator, punctuator,
|
| 32 |
+
we choose representative literals for those classes.
|
| 33 |
+
|
| 34 |
+
Another subtle detail is to choose the least number of representatives of
|
| 35 |
+
operators to ensure that expressions and other constructs involving operators
|
| 36 |
+
will remain syntactically correct after the transformation. To represent any
|
| 37 |
+
operator we therefore choose the asterisk symbol (`*`) which can either be
|
| 38 |
+
used as a unary or an infix operator and moreover allows pointers to be
|
| 39 |
+
correctly declared. Unfortunately, replacing all minus signs (`-`) with `*`
|
| 40 |
+
might lead to errors in case of negative numbers, hence we make an exception
|
| 41 |
+
of it and will add the minus sign as an additional explicit operator token.
|
| 42 |
+
All other operators are not further distinguished (they all appear as `*`).
|
| 43 |
+
|
| 44 |
+
For strings and character literals we make sure that their representatives do
|
| 45 |
+
not contain a space character. As is commonly the case, we reserve the space
|
| 46 |
+
character as the separator between tokens. That way simply splitting the input
|
| 47 |
+
at white-space can fully reconstruct the individual tokens when needed.
|
| 48 |
+
|
| 49 |
+
Putting all tokens on a single line might cause problems for certain tools
|
| 50 |
+
that have some input line length limit. Moreover, the C pre-processor
|
| 51 |
+
directives are not free-format and require to be put on a single (logical)
|
| 52 |
+
line. To overcome this problem one could simply discard all pre-processor
|
| 53 |
+
directives or have the tokenizer respect newlines. It depends on the back-end
|
| 54 |
+
processing which solution is to be desired.
|
| 55 |
+
|
| 56 |
+
## Token class definitions
|
| 57 |
+
|
| 58 |
+
Here we define the various token classes and suggest a representative for
|
| 59 |
+
each. On the outset we require that the vocabulary of all tokens is closed,
|
| 60 |
+
i.e., we prefer a fixed set of token instances. For that reason we let every
|
| 61 |
+
keyword represent itself since their class is closed. We will distinguish
|
| 62 |
+
between user identifiers and standard identifiers. The former will
|
| 63 |
+
collectively be represented by a single class element, say `id`. The latter
|
| 64 |
+
must be one of a large set of over 300 names of functions and standard
|
| 65 |
+
variables defined by a typical collection of C header files residing in
|
| 66 |
+
`/usr/include` and also includes C pre-processor names like `include`,
|
| 67 |
+
`define`, `ifdef`, etc. We assume that programmers will not use any of the
|
| 68 |
+
standard identifiers for purposes other than their intended meaning,
|
| 69 |
+
although this is not in any way required by the language.
|
| 70 |
+
|
| 71 |
+
The following table summarizes the set of token representatives.
|
| 72 |
+
|
| 73 |
+
|Representative: | Represents:
|
| 74 |
+
|--------------------------|-----------
|
| 75 |
+
| `strcpy`, `malloc`, etc. | the standard identifiers (over 300)
|
| 76 |
+
| `id` | any identifier
|
| 77 |
+
| `[ ] ( ) { } < >` | any of these punctuators
|
| 78 |
+
| `; ? : :: , . ...` | any of these punctuators (`::` only for C++)
|
| 79 |
+
| `=` | any assignment operator (`+=`, `*=`, etc.)
|
| 80 |
+
| `++ --` | auto-increment, auto-decrement
|
| 81 |
+
| `-` | exception to better handle negative numbers
|
| 82 |
+
| `*` | any other operator (`*` covers more cases than `+`)
|
| 83 |
+
| `0` | the number `0`
|
| 84 |
+
| `1` | the number `1`
|
| 85 |
+
| `123` | any integer number except `0` and `1`
|
| 86 |
+
| `3.14` | any floating-point number
|
| 87 |
+
| `""` | any string literal
|
| 88 |
+
| `'A`' | any character literal
|
| 89 |
+
| `#` | the preprocessor symbol `#`
|
| 90 |
+
| `##` | the preprocessor symbol `##` (very rare)
|
| 91 |
+
|
| 92 |
+
## Example
|
| 93 |
+
|
| 94 |
+
We will now demonstrate the tokenization of a small C program using the above
|
| 95 |
+
suggested scheme. As an example we use the following complete and compilable C
|
| 96 |
+
program (`test1.c`) that exhibits many of the different token types.
|
| 97 |
+
|
| 98 |
+
```C
|
| 99 |
+
#include <stdio.h>
|
| 100 |
+
|
| 101 |
+
#define N 10
|
| 102 |
+
|
| 103 |
+
/* Compute factorial recursively. */
|
| 104 |
+
static int factorial(int i)
|
| 105 |
+
{
|
| 106 |
+
if (i == 0)
|
| 107 |
+
return 1;
|
| 108 |
+
else
|
| 109 |
+
return i * factorial(i - 1);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
int main(int argc, char *argv[])
|
| 113 |
+
{
|
| 114 |
+
fprintf(stdout, "fac(%d) = %d\n", N, factorial(N));
|
| 115 |
+
return 0;
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
We tokenize this to CSV format. To save space we only show the first 20 lines
|
| 120 |
+
of output: from `tokenize -m csv test1.c`:
|
| 121 |
+
|
| 122 |
+
```CSV
|
| 123 |
+
line,column,class,token
|
| 124 |
+
1,0,preprocessor,#
|
| 125 |
+
1,1,identifier,include
|
| 126 |
+
1,9,operator,<
|
| 127 |
+
1,10,identifier,stdio
|
| 128 |
+
1,15,operator,.
|
| 129 |
+
1,16,identifier,h
|
| 130 |
+
1,17,operator,>
|
| 131 |
+
3,0,preprocessor,#
|
| 132 |
+
3,1,identifier,define
|
| 133 |
+
3,8,identifier,N
|
| 134 |
+
3,10,integer,10
|
| 135 |
+
6,0,keyword,static
|
| 136 |
+
6,7,keyword,int
|
| 137 |
+
6,11,identifier,factorial
|
| 138 |
+
6,20,operator,(
|
| 139 |
+
6,21,keyword,int
|
| 140 |
+
6,25,identifier,i
|
| 141 |
+
6,26,operator,)
|
| 142 |
+
7,0,operator,{
|
| 143 |
+
8,2,keyword,if
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
This output is then filtered by a simple AWK script (`filter5.awk`) to turn it
|
| 147 |
+
into a stream of the above defined token classes. Here we will use `\` to
|
| 148 |
+
indicate line continuations; these are not present in the actual output though.
|
| 149 |
+
|
| 150 |
+
```console
|
| 151 |
+
# include < id . id > # define id 123 static int id ( int id ) { if \
|
| 152 |
+
( id * 0 ) return 1 ; else return id * id ( id - 1 ) ; } int main ( \
|
| 153 |
+
int argc , char * argv [ ] ) { fprintf ( stdout , "" , id , id ( id \
|
| 154 |
+
) ) ; return 0 ; }
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Unfortunately, the C pretty-printer that we use, is not able to correctly
|
| 158 |
+
handle the token stream on a single line because of the pre-processor
|
| 159 |
+
directives. Our tokenizer however is able to preserve newlines. So using that
|
| 160 |
+
option we get the following filtered token stream (`test1.toks`):
|
| 161 |
+
|
| 162 |
+
```console
|
| 163 |
+
$ tokenize -n -m csv test1.c | ./filter5.awk -v ORS=" "
|
| 164 |
+
# include < id . id >
|
| 165 |
+
|
| 166 |
+
# define id 123
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
static int id ( int id )
|
| 170 |
+
{
|
| 171 |
+
if ( id * 0 )
|
| 172 |
+
return 1 ;
|
| 173 |
+
else
|
| 174 |
+
return id * id ( id - 1 ) ;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
int main ( int argc , char * argv [ ] )
|
| 178 |
+
{
|
| 179 |
+
fprintf ( stdout , "" , id , id ( id ) ) ;
|
| 180 |
+
return 0 ;
|
| 181 |
+
}
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
Now this output can easily be pretty-printed to this:
|
| 185 |
+
|
| 186 |
+
```C
|
| 187 |
+
# include < id . id >
|
| 188 |
+
|
| 189 |
+
# define id 123
|
| 190 |
+
|
| 191 |
+
static int id (int id)
|
| 192 |
+
{
|
| 193 |
+
if (id * 0)
|
| 194 |
+
return 1;
|
| 195 |
+
else
|
| 196 |
+
return id * id (id - 1);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
int main (int argc, char *argv [])
|
| 200 |
+
{
|
| 201 |
+
fprintf (stdout, "", id, id (id));
|
| 202 |
+
return 0;
|
| 203 |
+
}
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
# Conclusion
|
| 207 |
+
|
| 208 |
+
A tokenizer followed by a simple AWK filter can render a token stream that
|
| 209 |
+
when pretty-printed resembles a template for the original source code.
|
doc/universal_tokens.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Proposal, considerations and rationale for a "Universal tokenizer output stream specification"
|
| 2 |
+
|
| 3 |
+
## What is a tokenizer?
|
| 4 |
+
|
| 5 |
+
A tokenizer is a procedure usually implemented as a computer program that
|
| 6 |
+
splits an input text in smaller pieces that have a certain significance. One
|
| 7 |
+
typical application is to split a sentence in its constituting words and
|
| 8 |
+
punctuation symbols. In the realm of programming languages a tokenizer is used
|
| 9 |
+
by almost every compiler and interpreter to split the input program text in
|
| 10 |
+
chunks that make up the atomic terminal symbols of the language grammar.
|
| 11 |
+
These chunks are called tokens.
|
| 12 |
+
There are 2 broad classes of tokens
|
| 13 |
+
|
| 14 |
+
1. tokens with a fixed prescribed representation
|
| 15 |
+
2. tokens that are defined by rules (e.g. by a regular expression)
|
| 16 |
+
|
| 17 |
+
The former class typically consists of operator symbols and reserved words;
|
| 18 |
+
the latter class allows for user-defined identifiers and the notation of
|
| 19 |
+
specific numeric constants and string literals.
|
| 20 |
+
|
| 21 |
+
## Purpose of tokens
|
| 22 |
+
|
| 23 |
+
The main purpose of tokens depends on the application. A compiler or
|
| 24 |
+
interpreter typically would be happy with a stream of tokens that ignores all
|
| 25 |
+
white-space and comments in the input text. Other uses might prefer to keep
|
| 26 |
+
the comments. For instance a syntax highlighting program would use a
|
| 27 |
+
particular font and color to render comments.
|
| 28 |
+
|
| 29 |
+
So the first question is: do we discard white-space and comments or not?
|
| 30 |
+
A troubling aspect of comments is that it includes block comments that can
|
| 31 |
+
stretch over several physical input lines. A token output format (to be
|
| 32 |
+
discussed in more detail below) can thus not be simply line based in that case.
|
| 33 |
+
|
| 34 |
+
A nice and preferred aspect of the definition of a token would be that its
|
| 35 |
+
literal text string fits on a single line of output irrespective of the actual
|
| 36 |
+
output format chosen. For instance XML has no problem with multi-line text;
|
| 37 |
+
in contrast JSON strings must fit on a single line but allow for embedded
|
| 38 |
+
escaped newlines.
|
| 39 |
+
|
| 40 |
+
So an important second question is: do we enforce that tokens are output 1 per
|
| 41 |
+
line?
|
| 42 |
+
|
| 43 |
+
This is convenient for many Unix text utilities that process their input line
|
| 44 |
+
by line.
|
| 45 |
+
|
| 46 |
+
## Aspects of tokens
|
| 47 |
+
|
| 48 |
+
One way of proceeding is to look at how each supported programming language
|
| 49 |
+
defines its tokens and try to find a common intersection of token classes.
|
| 50 |
+
Here we work from the other end, and first look at some general aspects that
|
| 51 |
+
we might like to know about the tokens.
|
| 52 |
+
|
| 53 |
+
What are aspects of a token (assume we already have precise definitions) that
|
| 54 |
+
could be of general interest:
|
| 55 |
+
|
| 56 |
+
1. Obviously we want to know the literal token text itself.
|
| 57 |
+
2. Although maybe redundant, the length in bytes of the token text could be
|
| 58 |
+
useful.
|
| 59 |
+
3. Some indication of the location of the token in the text is deemed useful.
|
| 60 |
+
These coordinates could be an absolute position, or a (line,column)
|
| 61 |
+
combination, or both.
|
| 62 |
+
4. A classification of the token in a category (token class).
|
| 63 |
+
|
| 64 |
+
Additionally some more context could be of use, like
|
| 65 |
+
|
| 66 |
+
5. What is the name of the source file, and
|
| 67 |
+
6. explicit token stream begin and end indicators when multiple files are
|
| 68 |
+
processed.
|
| 69 |
+
7. We may even go beyond the lexical level: the same token literal
|
| 70 |
+
may be used in different contexts, with different meanings. Think of
|
| 71 |
+
`*` as the multiplication operator and `*` as the _pointer-to_
|
| 72 |
+
symbol in a type definition. Should the token class convey these
|
| 73 |
+
distinctions? Are we willing to fully parse the source input to
|
| 74 |
+
derive these semantic annotations?
|
| 75 |
+
|
| 76 |
+
### token classes
|
| 77 |
+
|
| 78 |
+
Here we assume that a token class is defined at the lexical level;
|
| 79 |
+
there is no need to know the grammar of the language and do a parse to
|
| 80 |
+
derive this classification.
|
| 81 |
+
Some reasonable token class names, used and applicable across many languages
|
| 82 |
+
are:
|
| 83 |
+
|
| 84 |
+
- identifier
|
| 85 |
+
- reserved word/keyword (does not include standard functions etc.)
|
| 86 |
+
- number (lump all numbers together?), or split up like:
|
| 87 |
+
* integer number (no fraction; make distinction on notation?)
|
| 88 |
+
* floating-point number
|
| 89 |
+
- single quoted (character) literal (at least 1 character?)
|
| 90 |
+
- double quoted (string) literal
|
| 91 |
+
- operator
|
| 92 |
+
* punctuation (hard to distinguish from operator sometimes)
|
| 93 |
+
- language-specific special tokens like # and ## for CPP in C/C++
|
| 94 |
+
|
| 95 |
+
Suggestion for generic token class names:
|
| 96 |
+
|
| 97 |
+
| Class: | Description:
|
| 98 |
+
|--------------|------------
|
| 99 |
+
| identifier | any identifier
|
| 100 |
+
| keyword | a reserved word
|
| 101 |
+
| integer | integer number irrespective of notation
|
| 102 |
+
| floating | a floating-point number
|
| 103 |
+
| string | a double-quoted string (maybe empty)
|
| 104 |
+
| character | a single-quoted character (or string)
|
| 105 |
+
| operator | any symbol used to operate on values
|
| 106 |
+
| punctuator | any symbol used for punctuation
|
| 107 |
+
| preprocessor | either # or ##
|
| 108 |
+
| filename | pseudo token: start of a new file
|
| 109 |
+
| newline | pseudo token: end of logical line
|
| 110 |
+
|
| 111 |
+
Quite often, too much specialization will be hard to undo;
|
| 112 |
+
additional specialization will be easy to implement by some post-processing
|
| 113 |
+
filter program using sed or awk.
|
| 114 |
+
For instance,
|
| 115 |
+
identifiers can be checked against a list of standard function names and
|
| 116 |
+
hence separated in these and user identifiers.
|
| 117 |
+
Operator symbols are easily grouped in various sub-classes like arithmetic,
|
| 118 |
+
logical, relational, etc. or just unary and binary. But the roles of
|
| 119 |
+
some symbols cannot be correctly distinguished without proper semantic
|
| 120 |
+
annotation, e.g.. the symbol `<` could be part of a template
|
| 121 |
+
definition in C++ or merely the less-than operator.
|
| 122 |
+
|
| 123 |
+
Suggestion for a set of punctuator symbols:
|
| 124 |
+
```console
|
| 125 |
+
[ ] ( ) { } . , ? : :: ; ... @
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Suggestion for a set of operator symbols:
|
| 129 |
+
```console
|
| 130 |
+
-> ->* .* ++ -- * / % + - << >>
|
| 131 |
+
== != < > <= >= <=>
|
| 132 |
+
~ ! | || & && ^
|
| 133 |
+
= *= /= %= += -= <<= >>= >>>= &= ^==
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Output formats
|
| 137 |
+
|
| 138 |
+
An important guideline for the choice of an output format is its flexibility
|
| 139 |
+
of use. The output should be easy to post-process preferable by standard
|
| 140 |
+
open-source tools. We identify 3 formats that come to mind and fit the bill:
|
| 141 |
+
|
| 142 |
+
1. **CSV**: simple line-based format that is easily parsed by many available
|
| 143 |
+
utilities like `csvkit`. Requires that we have the same number of fields per
|
| 144 |
+
token of course. Mind that we need to observe the definition of quoted text in
|
| 145 |
+
CSV and encode tokens accordingly. This is something we need to do for most
|
| 146 |
+
other formats too.
|
| 147 |
+
2. **JSON**: very popular and not line-based.
|
| 148 |
+
3. **XML**: diminishing popularity but a solid and standardized format.
|
| 149 |
+
|
| 150 |
+
Both JSON and XML are very flexible and also offer the possibility of
|
| 151 |
+
validating the format against a schema. Both are of course much more verbose
|
| 152 |
+
than simple CSV.
|
| 153 |
+
|
| 154 |
+
Many tools use a proprietary format that is tailored to their needs.
|
| 155 |
+
Examples are Python's syntax highlighter
|
| 156 |
+
[pygmentize](https://pygments.org/docs/tokens/#module-pygments.token)
|
| 157 |
+
and the [ANTLR4](https://www.antlr.org/api/Java/org/antlr/v4/runtime/Token.html) lexer tokens output format.
|
| 158 |
+
|
| 159 |
+
## Proposal for CSV
|
| 160 |
+
|
| 161 |
+
Every token will occupy one CSV record, i.e., one physical line.
|
| 162 |
+
The various fields are separated by commas. Care has to be taken to
|
| 163 |
+
escape special characters: a comma itself has to be enclosed in double
|
| 164 |
+
quotes; double quoted strings must have their double quotes doubled.
|
| 165 |
+
|
| 166 |
+
Header: `line,column,class,token`
|
| 167 |
+
|
| 168 |
+
## Proposal for JSON
|
| 169 |
+
|
| 170 |
+
If we choose to represent each token on a single line, it is best to adopt the
|
| 171 |
+
JSON Lines specification, i.e., have a single JSON object per line. Officially
|
| 172 |
+
such a file is not valid JSON, but each line is.
|
| 173 |
+
|
| 174 |
+
Object keys: `line`, `column`, `class`, `token`
|
| 175 |
+
|
| 176 |
+
A more compact but less descriptive alternative is to simply use an
|
| 177 |
+
array per token with a fixed number of assigned elements. For instance
|
| 178 |
+
the first element would be the line number, the second the column
|
| 179 |
+
number, the third the token class and the fourth the token string.
|
| 180 |
+
|
| 181 |
+
## Proposal for XML
|
| 182 |
+
|
| 183 |
+
In XML we have the option of storing data in either attributes of elements or
|
| 184 |
+
as the text contents of the element. Simple-typed data is best stored as
|
| 185 |
+
attributes. Free text and longer strings should become the text node of an
|
| 186 |
+
element. It makes sense to have an element per token and collect all token
|
| 187 |
+
elements under some root element.
|
| 188 |
+
|
| 189 |
+
Elements: `<tokens>`, `<token>`
|
| 190 |
+
|
| 191 |
+
Attributes: `line`, `column` `class`
|
| 192 |
+
|
| 193 |
+
## Question summary
|
| 194 |
+
|
| 195 |
+
- output white-space and comments or not?
|
| 196 |
+
- continue in case of errors or not?
|
| 197 |
+
- what format to use? all on single line?
|
| 198 |
+
- what character encoding to use?
|
| 199 |
+
- distinguish operator and punctuation symbols?
|
| 200 |
+
- several (a hierarchy of) operator classes?
|
| 201 |
+
- annotate with semantic information gleaned from parse tree?
|
| 202 |
+
- distinguish integer and floating-point numbers?
|
| 203 |
+
- even further distinction in octal, decimal, hexadecimal?
|
| 204 |
+
- absolute position, line/column, or both?
|
| 205 |
+
- apart from token literal, class, and coordinates anything else?
|
| 206 |
+
|
| 207 |
+
## References
|
| 208 |
+
|
| 209 |
+
> <a id="1">[1]</a>
|
| 210 |
+
[Tokenizers: How machines read](https://blog.floydhub.com/tokenization-nlp/)
|
| 211 |
+
|
| 212 |
+
> <a id="2">[2]</a>
|
| 213 |
+
Daniel P Delorey, Charles Knutson, Mark Davies,
|
| 214 |
+
[Mining Programming Language Vocabularies from Source Code](https://www.researchgate.net/publication/228825985_Mining_Programming_Language_Vocabularies_from_Source_Code),
|
| 215 |
+
December 2008
|
metadata/Project_CodeNet.tar.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae987bdcff5bda069fe7fedd8509da9ce5a2c213692a6dbf714d378be8f6177c
|
| 3 |
+
size 323
|
model-experiments/gnn-based-experiments/.gitignore
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
build/
|
| 3 |
+
dist/
|
| 4 |
+
*.egg-info/
|
| 5 |
+
dataset/
|
| 6 |
+
*.swp
|
| 7 |
+
*.vscode
|
| 8 |
+
*.DS_Store
|
| 9 |
+
*.pt
|
| 10 |
+
*.so
|
| 11 |
+
|
| 12 |
+
# Byte-compiled / optimized / DLL files
|
| 13 |
+
__pycache__/
|
| 14 |
+
*.py[cod]
|
| 15 |
+
*$py.class
|
| 16 |
+
|
| 17 |
+
# C extensions
|
| 18 |
+
*.so
|
| 19 |
+
|
| 20 |
+
# Distribution / packaging
|
| 21 |
+
.Python
|
| 22 |
+
build/
|
| 23 |
+
develop-eggs/
|
| 24 |
+
dist/
|
| 25 |
+
downloads/
|
| 26 |
+
eggs/
|
| 27 |
+
.eggs/
|
| 28 |
+
lib/
|
| 29 |
+
lib64/
|
| 30 |
+
parts/
|
| 31 |
+
sdist/
|
| 32 |
+
var/
|
| 33 |
+
wheels/
|
| 34 |
+
pip-wheel-metadata/
|
| 35 |
+
share/python-wheels/
|
| 36 |
+
*.egg-info/
|
| 37 |
+
.installed.cfg
|
| 38 |
+
*.egg
|
| 39 |
+
MANIFEST
|
| 40 |
+
|
| 41 |
+
# PyInstaller
|
| 42 |
+
# Usually these files are written by a python script from a template
|
| 43 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 44 |
+
*.manifest
|
| 45 |
+
*.spec
|
| 46 |
+
|
| 47 |
+
# Installer logs
|
| 48 |
+
pip-log.txt
|
| 49 |
+
pip-delete-this-directory.txt
|
| 50 |
+
|
| 51 |
+
# Unit test / coverage reports
|
| 52 |
+
htmlcov/
|
| 53 |
+
.tox/
|
| 54 |
+
.nox/
|
| 55 |
+
.coverage
|
| 56 |
+
.coverage.*
|
| 57 |
+
.cache
|
| 58 |
+
nosetests.xml
|
| 59 |
+
coverage.xml
|
| 60 |
+
*.cover
|
| 61 |
+
*.py,cover
|
| 62 |
+
.hypothesis/
|
| 63 |
+
.pytest_cache/
|
| 64 |
+
|
| 65 |
+
# Translations
|
| 66 |
+
*.mo
|
| 67 |
+
*.pot
|
| 68 |
+
|
| 69 |
+
# Django stuff:
|
| 70 |
+
*.log
|
| 71 |
+
local_settings.py
|
| 72 |
+
db.sqlite3
|
| 73 |
+
db.sqlite3-journal
|
| 74 |
+
|
| 75 |
+
# Flask stuff:
|
| 76 |
+
instance/
|
| 77 |
+
.webassets-cache
|
| 78 |
+
|
| 79 |
+
# Scrapy stuff:
|
| 80 |
+
.scrapy
|
| 81 |
+
|
| 82 |
+
# Sphinx documentation
|
| 83 |
+
docs/_build/
|
| 84 |
+
|
| 85 |
+
# PyBuilder
|
| 86 |
+
target/
|
| 87 |
+
|
| 88 |
+
# Jupyter Notebook
|
| 89 |
+
.ipynb_checkpoints
|
| 90 |
+
|
| 91 |
+
# IPython
|
| 92 |
+
profile_default/
|
| 93 |
+
ipython_config.py
|
| 94 |
+
|
| 95 |
+
# pyenv
|
| 96 |
+
.python-version
|
| 97 |
+
|
| 98 |
+
# pipenv
|
| 99 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 100 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 101 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 102 |
+
# install all needed dependencies.
|
| 103 |
+
#Pipfile.lock
|
| 104 |
+
|
| 105 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
| 106 |
+
__pypackages__/
|
| 107 |
+
|
| 108 |
+
# Celery stuff
|
| 109 |
+
celerybeat-schedule
|
| 110 |
+
celerybeat.pid
|
| 111 |
+
|
| 112 |
+
# SageMath parsed files
|
| 113 |
+
*.sage.py
|
| 114 |
+
|
| 115 |
+
# Environments
|
| 116 |
+
.env
|
| 117 |
+
.venv
|
| 118 |
+
env/
|
| 119 |
+
venv/
|
| 120 |
+
ENV/
|
| 121 |
+
env.bak/
|
| 122 |
+
venv.bak/
|
| 123 |
+
|
| 124 |
+
# Spyder project settings
|
| 125 |
+
.spyderproject
|
| 126 |
+
.spyproject
|
| 127 |
+
|
| 128 |
+
# Rope project settings
|
| 129 |
+
.ropeproject
|
| 130 |
+
|
| 131 |
+
# mkdocs documentation
|
| 132 |
+
/site
|
| 133 |
+
|
| 134 |
+
# mypy
|
| 135 |
+
.mypy_cache/
|
| 136 |
+
.dmypy.json
|
| 137 |
+
dmypy.json
|
| 138 |
+
|
| 139 |
+
# Pyre type checker
|
| 140 |
+
.pyre/
|
model-experiments/gnn-based-experiments/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Graph Neural Network Baseline Experiments on Project CodeNet
|
| 2 |
+
|
| 3 |
+
The goal of this project is to investigate the source code classification capabilities of standard graph neural networks (GNNs).
|
| 4 |
+
We use the (slightly adapted) training procedures and models provided by the Open Graph Benchmark [1] with the example experiments on source code.
|
| 5 |
+
The code contains two GNNs, GCN [2] and GIN [3], including their extensions with virtual nodes.
|
| 6 |
+
## Example
|
| 7 |
+
|
| 8 |
+
### Graph Representation of Source Code
|
| 9 |
+
|
| 10 |
+

|
| 11 |
+
|
| 12 |
+
We transform the source code into graphs as in the picture, where the **simplified parse tree (SPT)** (see Section 6 [in the paper](./../../ProjectCodeNet.pdf)) is extended by **next-token edges**.
|
| 13 |
+
Each node is represented by five features:
|
| 14 |
+
(1) node type (token or parsing rule);
|
| 15 |
+
(2) token type (e.g., an identifier);
|
| 16 |
+
(3) parsing rule type (e.g., an expression);
|
| 17 |
+
(4) whether it represents a reserved word; and
|
| 18 |
+
(5) its depth in the tree.
|
| 19 |
+
|
| 20 |
+
Note that we actually consider the graph edges to be bi-directional at runtime in order to improve the learning capabilities of our models.
|
| 21 |
+
|
| 22 |
+
### Graph Representation Learning
|
| 23 |
+
|
| 24 |
+
**Graph neural networks (GNNs)** learn a graph representation by exploiting the graph structure as inductive bias.
|
| 25 |
+
Most GNNs follow the architecture proposed in [4]. In a nutshell, they first compute a node representation for every graph node by iteratively **aggregating** its neighbor nodes and **combining** this aggregated representation with the current node representation.
|
| 26 |
+
Then, the node representations are **pooled** to obtain a final representation for the entire graph.
|
| 27 |
+
The different models vary primarily in the way they do the aggregation, combination, and pooling.
|
| 28 |
+
|
| 29 |
+
The code contains two popular GNNs:
|
| 30 |
+
the **graph convolutional network (GCN)** [2], one of the first and most common GNNs,
|
| 31 |
+
and the **graph isomorphism network (GIN)** [3], which is more powerful since it pools not only the final node representations but those from all iterations.
|
| 32 |
+
In addition, we provide the **option for using virtual nodes**, which means that an artificial node is added to each graph and bi-directionally connected to all graph nodes to improve the aggregation phase.
|
| 33 |
+
|
| 34 |
+
Finally, note that you can easily integrate any graph classification model written in Pytorch Geometric. For an introduction to Pytorch Geometric, see [here](https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html).
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
### The Task
|
| 38 |
+
|
| 39 |
+
In our experiments, we do program classification as follows.
|
| 40 |
+
Each problem in the Project Codenet benchmark is one class,
|
| 41 |
+
and a code sample belongs to a class if it is a submission to the corresponding problem.
|
| 42 |
+
Hence, **we use the graph representation of a code sample computed by the GNN to predict its problem class**.
|
| 43 |
+
|
| 44 |
+
## Installation
|
| 45 |
+
|
| 46 |
+
Tested with Python 3.8, PyTorch 1.8.1, and PyTorch Geometric 1.6.3.
|
| 47 |
+
- Set up an Anaconda environment: `./setup.sh`
|
| 48 |
+
(before running, edit pytorch installation command and set variables; see comment in file)
|
| 49 |
+
- Alternatively, install the above and the packages listed in requirements.txt
|
| 50 |
+
|
| 51 |
+
## Data
|
| 52 |
+
|
| 53 |
+
The project contains a self-contained data sample directory `small` to test the installation. Note that `small` directory contains two sub-directories `raw` and `splits/random`. The `raw` directory contains the SPT data (8 CSV files each in .gz format) and `splits/random` directory contains the training/validation/testing split files (in both CSV and its .gz format). We also published the splits files that we used in our paper [here](https://github.com/IBM/Project_CodeNet/blob/main/ProjectCodeNet_NeurIPS2021.pdf). To repeat the large scale JAVA/Python/C++ experiments as mentioned in the paper, one simply needs to download the Project CodeNet benchmark SPT datasets in graph format [here](https://developer.ibm.com/exchanges/data/all/project-codenet/) (e.g., Project_CodeNet_Java250_spts.tar.gz, which contains 8 CSV files that represent the encoding of the SPT graph) and convert each CSV file to its .gz format and put them into the corresponding data directory (e.g., data/Java250/raw) before launching the run script. Please refer to `small` directory for the file format and directory layout.
|
| 54 |
+
|
| 55 |
+
## Experiments
|
| 56 |
+
|
| 57 |
+
* The script to run the experiments is `./run.sh`
|
| 58 |
+
* By default, the script will run `GCN` over `small`. To change these settings, see the comments in the script. To repeat the JAVA/Python/C++ experiments as mentioned in our paper, one just needs to put the raw data in the corresponding directory (see above) and change the `DATASET` to one of the 4 options: Java250, Python800, C++1000, and C++1400.
|
| 59 |
+
* You can change the dataset, data directory, and other variables in the script as needed.
|
| 60 |
+
* Note that we did not do hyperparamter tuning. For all our experiments, we used the parameters from the script.
|
| 61 |
+
* When running the first time with a new dataset, the code will first preprocess the data. It will reuse these files with later runs.
|
| 62 |
+
|
| 63 |
+
## Results
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
| | Java250 | Python800 | C++1000 | C++1400 |
|
| 67 |
+
| ----| --------|-------- |------- | --------|
|
| 68 |
+
| MLP w/ bag of tokens|71.87 | 67.84| 68.23 | 64.73 |
|
| 69 |
+
| CNN w/ token sequence | 90.96 | 89.49| 94.27| 94.10 |
|
| 70 |
+
| C-BERT | 97.60| 97.30 | 93.00 | 90.00 |
|
| 71 |
+
| **GCN** | 92.70 ± 0.25 | 93.82 ± 0.16 | 95.76 ± 0.12 | 95.26 ± 0.13|
|
| 72 |
+
| **GCN-V** | 93.02 ± 0.81 | 94.30 ± 0.15 | 96.09 ± 0.17 | 95.73 ± 0.07 |
|
| 73 |
+
| **GIN** | 93.26 ± 0.23 | 94.17 ± 0.19 | 96.34 ± 0.15 | 95.95 ± 0.13 |
|
| 74 |
+
| **GIN-V** | 92.77 ± 0.66 | 94.54 ± 0.12 | 96.64 ± 0.10 | 96.36 ± 0.10 |
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
## References
|
| 80 |
+
|
| 81 |
+
* [1] Hu et al. [Open Graph Benchmark: Datasets for Machine Learning on Graphs](https://arxiv.org/pdf/2005.00687.pdf), NeurIPS 2020.
|
| 82 |
+
* [2] Kipf and Welling. [Semi-Supervised Classification with Graph Convolutional Networks](https://arxiv.org/pdf/1609.02907.pdf), ICLR 2017.
|
| 83 |
+
* [3] Xu et al. [How Powerful are Graph Neural Networks?](https://arxiv.org/pdf/1810.00826.pdf), ICLR 2019.
|
| 84 |
+
* [4] Gilmer et al. [Neural Message Passing for Quantum Chemistry](https://arxiv.org/pdf/1704.01212.pdf), ICML 2017.
|
| 85 |
+
|
| 86 |
+
Please leave an issue if you have any trouble running the code.
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
Author: Veronika Thost
|
model-experiments/gnn-based-experiments/data/C++1000/raw/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore everything in this directory
|
| 2 |
+
*
|
| 3 |
+
# Except this file
|
| 4 |
+
!.gitignore
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/test.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:863176076af9965e4d21a8a5d0238e30b612572ccff7202d00d16815b1a7b168
|
| 3 |
+
size 313900
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/train.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:49ad6a1e10d22f6ee4f15eac7dc0cd701dbcc34db44ca4332e4edd7597bdf97e
|
| 3 |
+
size 939493
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/valid.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1000/split/random/valid.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:84c82c098be4d33d7e2ac03745e1f6fc68b43f6cef9918efbdcbfe0dfc7cd985
|
| 3 |
+
size 314030
|
model-experiments/gnn-based-experiments/data/C++1400/raw/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore everything in this directory
|
| 2 |
+
*
|
| 3 |
+
# Except this file
|
| 4 |
+
!.gitignore
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/test.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c2b259af0f5014ea51b8cf6678be764f36b78f13c507f4e6f2dff2eb01b98f86
|
| 3 |
+
size 260835
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/train.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37e214f1336702b9768c3df8129109b69d0cd9dd5da4dd166fd6ad2390828954
|
| 3 |
+
size 780550
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/valid.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/C++1400/split/random/valid.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9a9295eda0bd543d4b4c498c0f47670f204bc1879a9cdf5a0a5d18ebeb63494
|
| 3 |
+
size 260977
|
model-experiments/gnn-based-experiments/data/Java250/raw/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore everything in this directory
|
| 2 |
+
*
|
| 3 |
+
# Except this file
|
| 4 |
+
!.gitignore
|
model-experiments/gnn-based-experiments/data/Java250/split/random/test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Java250/split/random/test.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd1cd2684506c26c9827876b8713c02d70690f0431ab4af8217e1f08930c35fa
|
| 3 |
+
size 41281
|
model-experiments/gnn-based-experiments/data/Java250/split/random/train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Java250/split/random/train.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8edb0cab6b6a4c8c87caebb650d9ec0731632219c894317406f8d8a35c7b2e2e
|
| 3 |
+
size 121386
|
model-experiments/gnn-based-experiments/data/Java250/split/random/valid.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Java250/split/random/valid.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b89573f326eeb4fb6db777c011434fbf96f730bfd8ae052ae5860f4610c539d9
|
| 3 |
+
size 41340
|
model-experiments/gnn-based-experiments/data/Python800/raw/.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore everything in this directory
|
| 2 |
+
*
|
| 3 |
+
# Except this file
|
| 4 |
+
!.gitignore
|
model-experiments/gnn-based-experiments/data/Python800/split/random/test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Python800/split/random/test.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:85f1c4f7ef842002c5205f9a10aee6a843c20817d7415a7b177ab3c5c9016c98
|
| 3 |
+
size 144048
|
model-experiments/gnn-based-experiments/data/Python800/split/random/train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Python800/split/random/train.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dfcaa84252f80a28d19b7cfdd22c8454f3410ca1139c4ceb0b4b7ab89b21bf4f
|
| 3 |
+
size 430015
|
model-experiments/gnn-based-experiments/data/Python800/split/random/valid.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-experiments/gnn-based-experiments/data/Python800/split/random/valid.csv.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47f3e35b3d236f2a6b6ed501b85a350abdd564b8c0f80edd276417504101c0b8
|
| 3 |
+
size 144076
|