Crowd Knowledge Answer Generator. Feel free to try our tool. For more details about the technique, please check our paper.
To provide comprehensive solutions for daily programming tasks containing code examples and succinct explanations (limited to Java in this initial vesion).
- Input: API related query in natural language.
- Output: Code examples containing explanations.
CROKAGE receives as input a query written in natural language and uses state-of-art text retrieval models combined with three state-of-art API recommender tools to retrieve the most related Stack Overflow answers to that query, sorted by relevance. CROKAGE then uses natural language processing to extract the code and relevant sentences to compose a summary containing the solution for the query.
- AnswerBot is limited as it does not provide code.
- BIKER is limited as its documentation is limited to JAVA SE and does not provide code for every query.
- CROKAGE address both limitations by providing relevant code and explanations in form of summaries.
Note: all the experiments were conducted over a server equipped with 32 GB RAM, 3.1 GHz on four cores and 64-bit Linux Mint Cinnamon operating system. We strongly recommend a similar or better hardware environment. The operating system however could be changed.
Softwares:
- Java 1.8
- Postgres 9.4 - Configure your DB to accept local connections. An example of pg_hba.conf configuration:
...
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
...
-
PgAdmin (we used PgAdmin 4) but feel free to use any DB tool for PostgreSQL.
-
Maven 3. Assert Maven is correctly installed. In a Terminal enter with the command:
mvn --version
. This should return the version of Maven.
Download CROKAGE files here and place in a folder preferable in your home folder, ex /home/user/crokage-replication-package.
Check your instalation. Make sure your crokage folder (ex /home/user/crokage-replication-package) contains this structure:
..
./data
./tmp (4 files)
./soContentWordVec.txt
./bigMap.txt
./soIDFVocabulary.txt
./soUpvotedPostsWithCodeAPIsMap.txt
crokage.jar
main.properties
Note: for now we only provide the replication package. The complete source code will be released soon.
-
Download the Dump of SO here (Dump of June 2018). This is a preprocessed dump, downloaded from the official web site containing the main tables we use (we only consider Java posts in this initial version). Postsmin table (representing posts table) has extra columns with the preprocessed data used by CROKAGE (processedtitle, processedbody, code, processedcode).
-
On your DB tool, create a new database named stackoverflow2018crokagereplicationpackage. This is a query example:
CREATE DATABASE stackoverflow2018crokagereplicationpackage
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8'
CONNECTION LIMIT = -1;
- Restore the downloaded dump to the created database. PgAdmin has this feature. Right click on the created database -> Restore... select the dump (dump2018crokagereplicationpackage.backup).
Obs: restoring this dump would require at least 10 Gb of free space. If your operating system runs in a partition with insufficient free space, create a tablespace pointing to a larger partition and associate the database to it by replacing the "TABLESPACE" value to the new tablespace name: TABLESPACE = tablespacename
.
- Assert the database is sound. Execute the following SQL command:
select id, title,body,processedtitle,processedbody,code, processedcode from postsmin po limit 10
. The return should list the main fields for 10 posts.
Edit main.properties
and set the required following parameters:
CROKAGE_HOME
= the root folder of the project (ex /home/user/CROKAGE-replication-package) where you must place the jar and main.properties
.
TMP_DIR
= the folder location of the models. This folder is the tmp folder from previous step (ex /home/user/crokage-replication-package/tmp).
spring.datasource.username
= your db user
spring.datasource.password=
= your db password
action
= you have 2 main options. action=runApproach
: run the retrieval mechanism and output metrics for our ground truth. CROKAGE will show metrics for the chosen data set (below). action=extractAnswers
: build the summaries containing the solutions.
dataSet
= You also have 2 main options. dataSet=selectedqueries-test48
: test (48 queries). dataSet=selectedqueries-training49
: training (49 queries).
The other parameters are optional:
subAction
= The set of the API extractors separated by '|'. Ex: rack|biker|NLP2Api|
.
numberOfComposedAnswers
= number of answers used to compose summaries. (Default=3)
If you want to reproduce other baselines except CROKAGE, please refer to our paper to more details about how to set the weights.
Open a terminal, go to the project folder and run the following command: java -Xms1024M -Xmx32g -jar crokage.jar --spring.config.location=./main.properties
. This command uses the file main.properties
to overwrite the default parameters which must be set as described above.
The results are displayed in the terminal/console but also stored in the database in tables metricsresults. The following query should return the results: ย
select * from metricsresults
We provide a REST interface to enable other researchers to use CROKAGE as a baseline or repeat, improve or refute our results. If you are interested in obtaining the solutions for your programming tasks, you can call this interface from within your applications. For this, make a POST request to http://isel.ufu.br:8080/crokage/query/getsolutions, set in the header the "Content-Type" to "application/json" and pass the parameters in JSON format as follows:
{
"numberOfComposedAnswers":10,
"queryText":"how to insert an element array in a given position"
}
This is an example of making a REST call to CROKAGE using the RESTED plugin for Chrome.
The result is a JSON containing the answers with explanations.
We provide a Java implementation for invoking the rest interface. For this, follow the following steps:
-
Clone this project into your local machine: git clone https://github.com/muldon/CROKAGE-replication-package.git
-
Import the maven project into your IDE (i.e., Eclipse).
-
Right click on CrokageInitializer.java on Package Explorer-> Run As -> Java Application.
If you desire to change the parameters, access application.properties
file under src/main/resources/config/
. Once you run the application, the demo client will invoke the remove REST api and obtain the solutions for the queries in the list.
We implemented our approach in form of a tool to assist developers with their daily programming issues. The figure below shows the tool architecture. We follow a REST (Representational State Transfer) architecture. The tool is in beta version and only provide solutions for Java language, but we expect to release the full version soon.
If you intend to use this work, please cite us:
@inproceedings{silva2019recommending,
title={Recommending comprehensive solutions for programming tasks by mining crowd knowledge},
author={Silva, Rodrigo FG and Roy, Chanchal K and Rahman, Mohammad Masudur and Schneider, Kevin A and Paixao, Klerisson and de Almeida Maia, Marcelo},
booktitle={Proceedings of the 27th International Conference on Program Comprehension},
pages={358--368},
year={2019},
organization={IEEE Press}
}
This project is licensed under the MIT License - see the LICENSE file for details