guesslang: guess programming language
Guesslang detects the programming language of a given source code:
echo '
package main
import "fmt"
func main() {
fmt.Println("My mascot is a gopher and Google loves me. Who am I?")
}
' | guesslang
# ⟶ Programming language: Go
Guesslang supports 30 programming languages:
|
Languages |
|
|
|
|
|
Batchfile |
C |
C# |
C++ |
CSS |
|
CoffeeScript |
Erlang |
Go |
HTML |
Haskell |
|
Java |
JavaScript |
Jupyter Notebook |
Lua |
Markdown |
|
Matlab |
Objective-C |
PHP |
Perl |
PowerShell |
|
Python |
R |
Ruby |
Rust |
SQL |
|
Scala |
Shell |
Swift |
TeX |
TypeScript |
With a guessing accuracy higher than 90%.
Guesslang command line
-
Show all available options
guesslang --help
usage: guesslang [-h] [-p] [-l] [--train TRAINING_DIRECTORY]
[--steps TRAINING_STEPS] [--model MODEL_DIR] [-d]
[filename]
Guess the programming language of a given source code
positional arguments:
filename source code file. Reads from the standard input (stdin)
if no file is given
optional arguments:
-h, --help show this help message and exit
-p, --probabilities show match probability of a given source code with each
of the supported programming languages
-l, --list-supported list the supported programming languages
--train TRAINING_DIRECTORY
train from a directory containing source code files.
The source files should be split in 3 directories
named: train, valid, test. --model and --steps values
should be provided when using --train
--steps TRAINING_STEPS
number of steps training steps. The model accuracy and
the training time increase with the number of steps
--model MODEL_DIR custom Guesslang trained model directory
-d, --debug show debug messages
-
Detect the programming language of /bin/which:
guesslang /bin/which
# ⟶ Programming language: Shell
-
Detect the programming language of a given text:
echo '
/** Turn command line arguments to uppercase */
object Main {
def main(args: Array[String]) {
val res = for (a <- args) yield a.toUpperCase
println("Arguments: " + res.toString)
}
}
' | guesslang
# ⟶ Programming language: Scala
-
Show the detection probabilities for a given source code:
echo "
def qsort(items):
if not items:
return []
else:
pivot = items[0]
less = [x for x in items if x < pivot]
more = [x for x in items[1:] if x >= pivot]
return qsort(less) + [pivot] + qsort(more)
if __name__ == '__main__':
items = [1, 4, 2, 7, 9, 3]
print(f'Sorted: {qsort(items)}')
" | guesslang --probabilities
# Language name Probability
# Python 80.53%
# Batchfile 6.16%
# CoffeeScript 2.18%
# Markdown 1.66%
# JavaScript 1.47%
# ...
Documentation
-
Guesslang documentation is available at https://guesslang.readthedocs.io/en/latest/
-
Guesslang language detection explained here https://guesslang.readthedocs.io/en/latest/how.html
No comments to display
No comments to display