wcg / keyword-extractor
A Laravel package for keyword extraction
This package's canonical repository appears to be gone and the package has been frozen as a result.
README
The Keyword Extractor Laravel package helps in extracting keywords from a given description text.
Installation
-
Install the package via Composer:
composer require wcg/keyword-extractor
-
Publish the configuration file:
php artisan vendor:publish --provider="Wcg\KeywordExtractor\KeywordExtractorServiceProvider" --tag=keyword-extractor-config
This will publish the package configuration file to
config/keyword-extractor.php
. You can modify the configuration as needed. -
Configure the package:
Update
config/keyword-extractor.php
to set the appropriate stopword source and languages. -
(Optional) Setup stopword database source:
If using a database as the stopword source, configure the database connection and create one table 'stopwords'.
Table Name:
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 |
Example Data
| 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 |
Configuration
The package allows for basic customization via the configuration file. The config/keyword-extractor.php
file contains options such as supported languages and other settings.
Usage
-
Import the
KeywordExtractor
class:use Wcg\KeywordExtractor\KeywordExtractor;
-
Create an instance of the
KeywordExtractor
:$extractor = new KeywordExtractor();
-
Extract keywords from a description:
$description = "A fantastic opportunity to purchase a private detached charming country residence..."; $language = 'en'; $keywords = $extractor->extractKeywords($description,$language);
Replace
$description
with the actual description from which you want to extract keywords. -
Use the extracted keywords as needed:
// Example: Display extracted keywords print_r($keywords);
License
This package is open-source and licensed under the MIT License. See the LICENSE file for details.