guillermobt/babelfish

一种文件编程语言检测器

dev-master 2023-03-19 11:11 UTC

This package is auto-updated.

Last update: 2024-09-21 13:41:39 UTC


README

Babelfish 是一个基于 github/linguistsrc-d/enry 的文件编程语言检测器。

示例

$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();
}

Babelfish 是如何工作的?

语言是通过使用一组有序的策略来确定的。每个策略要么能够精确识别语言,要么减少下一个策略可能的语言数量。默认的策略集包括:

另请参阅 Linguist 的工作原理