wcg/keyword-extractor

用于关键词提取的Laravel包

1.1 2024-02-21 13:39 UTC

This package is auto-updated.

Last update: 2024-09-23 13:16:28 UTC


README

Keyword Extractor Laravel包可以帮助从给定的描述文本中提取关键词。

安装

  1. 使用Composer安装包

    composer require wcg/keyword-extractor
  2. 发布配置文件

    php artisan vendor:publish --provider="Wcg\KeywordExtractor\KeywordExtractorServiceProvider" --tag=keyword-extractor-config

    这将发布包配置文件到config/keyword-extractor.php。您可以根据需要修改配置。

  3. 配置包

    更新config/keyword-extractor.php以设置适当的停用词来源和语言。

  4. (可选) 设置停用词数据库源

    如果使用数据库作为停用词源,配置数据库连接并创建一个名为'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文件包含支持的语言和其他设置等选项。

用法

  1. 导入KeywordExtractor

    use Wcg\KeywordExtractor\KeywordExtractor;
  2. 创建KeywordExtractor的实例

    $extractor = new KeywordExtractor();
  3. 从描述中提取关键词

    $description = "A fantastic opportunity to purchase a private detached charming country residence...";
    $language = 'en';
    $keywords = $extractor->extractKeywords($description,$language);

    $description替换为您想要提取关键词的实际描述。

  4. 根据需要使用提取的关键词

    // Example: Display extracted keywords
    print_r($keywords);

许可证

此包为开源软件,采用MIT许可证。有关详细信息,请参阅LICENSE文件。