teon / text-extraction
文本提取库
该软件包的官方仓库似乎已消失,因此该软件包已被冻结。
v0.2.0
2015-12-01 03:15 UTC
Requires
- php: >=5.3.0
- smalot/pdfparser: ~0.9
- teon/base: ~0.2
This package is not auto-updated.
Last update: 2024-01-20 14:43:15 UTC
README
PHP 库,使用各种驱动程序和策略从各种文档中提取文本。
支持每种文件扩展名/媒体类型的多个提取器。
使用方法
库有两种操作模式,两种子模式。模式:1.) 使用一种提取策略并让库完成所有工作(需要 fileinfo PHP 扩展);或 2.) 获取您的文件类型提取器(通过明确指定媒体类型或文件扩展名)并手动使用它们。
子模式:a) 使用文件路径操作,或 b) 使用字符串中的文件内容操作
使用 composer 安装
composer require teon/text-extraction
通用使用方法
1.) 完全自动模式
// Instantiate $TextExtraction = new \Teon\Text\Extraction\Extraction(); // Submode a): $text1 = $TextExt->fromFile($filePath); // Submode b): $text2 = $TextExt->fromString($fileContent);
2.) 手动提取器选择模式
// Instantiate $TextExtraction = new \Teon\Text\Extraction\ExtractorRegistry(); $ExtractorRegistry = $TextExtraction->getRegistry(); // Get appropriate extractors $extractors1 = $ExtractorRegistry->getByMediaType($fileMediaType); $extractors2 = $ExtractorRegistry->getByExtension($fileExtension); // Do your magic to decide which extractor to use $Extractor1 = $extractors1[0]; $Extractor2 = $extractors2[0]; // Submode a): $text1 = $Extractor1->fromFile($filePath); // Submode b): $text2 = $Extractor2->fromString($fileContent);
在使用之前,您可以重新配置它
// Get default configuration $config = \Teon\Text\Extraction\Extraction::getDefaultConfiguration(); // Adjust it $config['strategy']['class'] = "\\My\\Super\\Dooper\\TextExtractionStrategy" // Instantiate with adjusted configuration $TextExtraction = new \Teon\Text\Extraction\Extraction($config); // Start using it // ...
在框架中使用:Symfony
使用上面描述的方法安装 composer
composer require teon/text-extraction
调整配置设置(app/config/config.yml 或 parameters.yml)
teon_text_extraction: strategy: class: ConcatOutput extractor: pdfocr: enabled: true command: my-convert-pdf-to-tiff-and-run-tesseract.sh
查看 Resources/config/config.yml 文件了解可调整的内容,或打印默认配置。
注册捆绑包
/* * FILE: app/AppKernel.php */ // ... public function registerBundles() { $bundles = array( // ... new Teon\Text\Extraction\TeonTextExtractionBundle(), // ... ); return $bundles; } // ...
在控制器中使用
/* * FILE: src/YourApp/Controller/TextExtractionController.php */ // ... public function extractAction () { // Get service $TextExtraction = $this->get('teon_text_extraction'); // See section "General usage" above // ... } // ...