GitSocratic - Query your source code with Graql


#1

For those of you who like to use Graql for source code related mischief, I’d like to introduce you to a new multilingual source code query command line interface powered by Grakn. This CLI is called GitSocratic and GitSocratic is able to use Docker to automatically setup the entire environment necessary to parse, store, and query source code of various languages. GitSocratic is able to use Grakn’s powerful knowledge graph to answer complex queries related to the structure and semantic meaning of source code. With GitSocratic you can combine repositories of different languages and query them individually or together. GitSocratic’s goal is to facilitate the ability for anyone to create intelligent multilingual source code bots and more!

Languages currently supported: Go, Java, JavaScript, PHP, Python, Ruby

Project source code: https://github.com/CodeBrig/GitSocratic
Release distribution (v0.1-alpha): https://github.com/CodeBrig/GitSocratic/releases/tag/v0.1-alpha

Notes: This is an alpha release. It’s going to break on you. Please create an issue showing the code it failed on and I’ll provide a fix.

Setup

The following video shows me setting up GitSocratic on a newly created DigitalOcean droplet. I install Java, unzip, Docker, and finally GitSocratic. I also parse the GitHub repository bfergerson/same-program which has the same program in Java, Go, and JavaScript. In the video below I also show how these languages can be queried together or independently.

asciicast

Example usage

Find all for statements (language-agnostic)

$ ./gitsocratic query graql 'match $x isa FOR_STATEMENT; aggregate count;'
# Query: match $x isa FOR_STATEMENT; aggregate count;
# Result:
3

Find all Go methods named “main”

$ ./gitsocratic question "how many go methods are named main"
# Question: how many [language] methods are named [name]
# Result:
1

I understand this question idea isn’t very fleshed out. I liked the idea of being able to ask source code questions which led to the idea of having a FAQ command which would return results for commonly asked questions. This line of thinking also leads to the idea of having a dialog with source code about itself (meta. meta. meta), which would essentially be intelligent source code bots. So if the idea of AI-based pair programming interests you please let me know. I’m working on a project that brings this project together with IDE integration and would love to hear your ideas/opinions on this type of software.


#2

Well done, @BFergerson!! The @Grakn team is so proud to see your work!

We’ll be making a page for “Awesome Grakn” soon, and we’ll add GitSocratic to it. :slight_smile: