tgerbet / babelfish
A file programming language detector
0.1.0
2019-01-05 15:02 UTC
Requires
- php: ^7.2
Requires (Dev)
- doctrine/coding-standard: ^5.0
- phpunit/phpunit: ^7.3
- symfony/yaml: ^4.1
- vimeo/psalm: ^3.0
This package is auto-updated.
Last update: 2024-10-28 14:43:51 UTC
README
Babelfish is a file programming language detector based on github/linguist and src-d/enry.
Examples
$source_file = new ContentFile('Babelfish.php', \file_get_contents(__DIR__ . '/src/Babelfish/Babelfish.php')); $language = Babelfish::getWithDefaultStrategies()->getLanguage($source_file); if ($language !== null) { echo 'Language detected: ' . $language->getName(); }
How Babelfish works?
The language is determined by using an ordered set of strategies. Each strategy will either identify the precise language or reduce the number of likely languages for the next strategy. The default set of strategies is:
- Vim or Emacs modeline
- commonly used filename
- shell shebang
- file extension
- XML header
- heuristics
- naïve Bayesian classification
See also How Linguist works.