项目作者: maxim5

项目描述 :
Programming language detector algorithm
高级语言: Python
项目地址: git://github.com/maxim5/code-inspector.git
创建时间: 2017-12-24T15:33:02Z
项目社区:https://github.com/maxim5/code-inspector

开源协议:Apache License 2.0

下载


Code Inspector

Programming language detector algorithm.

Key feature: the algorithm is aimed on classifying short and possibly incomplete code snippets,
without any prior knowledge of file extension, context, keywords, etc.

Currently recognized languages:
c, c++, c#, clojure, coffeescript, css, erlang, f#, go, html, java, javascript, lua, matlab, objective c,
pascal, perl, php, python, r, ruby, scala, shell, sql, swift, typescript, visual basic.

Snippets examples

Java

  1. BigInteger value = bd.unscaledValue();
  2. char[] buffer = value.abs().toString().toCharArray();
  3. int numDigitsLeft = buffer.length - 1;
  4. int endPosition = numDigitsLeft % 2;
  5. int length = (precision + 2) / 2;

JavaScript

  1. var _a = this, source = _a.source, count = _a.count;
  2. if (count === 0) {
  3. return _super.prototype.error.call(this, err);
  4. }

C++

  1. unsigned int mw = 0;
  2. int support = -1;
  3. if (hnvml) {
  4. support = nvml_get_power_usage(hnvml, gpu->gpu_id, &mw);
  5. }

C

  1. BOOL ret;
  2. DWORD err;
  3. if (!PyArg_ParseTuple(args, F_HANDLE "O", &handle, &bufobj))
  4. return NULL;

Python

  1. self.path = base_path
  2. self.target = spec['target_name']
  3. self.type = spec['type']
  4. self.toolset = spec['toolset']

PHP

  1. {
  2. $adapter = new Ftp($this->options + ['systemType' => 'unknown']);
  3. $adapter->listContents();
  4. }

Clearly, not all languages can be distinguished within a short snippet, see for example C and C++, that’s why
the model outputs a probability distribution. The larger the snippet, the more confident the model is.

License

Apache 2.0