wcg / keyword-extractor
用于关键词提取的Laravel包
1.1
2024-02-21 13:39 UTC
README
Keyword Extractor Laravel包可以帮助从给定的描述文本中提取关键词。
安装
-
使用Composer安装包
composer require wcg/keyword-extractor
-
发布配置文件
php artisan vendor:publish --provider="Wcg\KeywordExtractor\KeywordExtractorServiceProvider" --tag=keyword-extractor-config
这将发布包配置文件到
config/keyword-extractor.php
。您可以根据需要修改配置。 -
配置包
更新
config/keyword-extractor.php
以设置适当的停用词来源和语言。 -
(可选) 设置停用词数据库源
如果使用数据库作为停用词源,配置数据库连接并创建一个名为'stopwords'的表。
表名:
stopwords
| Column Name | Data Type | Description | |-------------|-----------|------------------------------| | id | int | Primary key | | language | string | Language code (e.g., 'en') | | word | string | Stopword | | created_at | timestamp | Timestamp of creation | | updated_at | timestamp | Timestamp of last update |
示例数据
| id | language | word | created_at | updated_at | |----|----------|-----------|----------------------|----------------------| | 1 | en | the | 2023-09-15 12:34:56 | 2023-09-15 12:34:56 | | 2 | en | and | 2023-09-15 12:34:57 | 2023-09-15 12:34:57 | | 3 | fr | le | 2023-09-15 12:34:58 | 2023-09-15 12:34:58 | | 4 | fr | la | 2023-09-15 12:34:59 | 2023-09-15 12:34:59 |
配置
该包允许通过配置文件进行基本定制。config/keyword-extractor.php
文件包含支持的语言和其他设置等选项。
用法
-
导入
KeywordExtractor
类use Wcg\KeywordExtractor\KeywordExtractor;
-
创建
KeywordExtractor
的实例$extractor = new KeywordExtractor();
-
从描述中提取关键词
$description = "A fantastic opportunity to purchase a private detached charming country residence..."; $language = 'en'; $keywords = $extractor->extractKeywords($description,$language);
将
$description
替换为您想要提取关键词的实际描述。 -
根据需要使用提取的关键词
// Example: Display extracted keywords print_r($keywords);
许可证
此包为开源软件,采用MIT许可证。有关详细信息,请参阅LICENSE文件。