bitandblack/german-words

This library provides a huge dataset of german words and their grammar rules

0.5.1 2019-11-25 10:27 UTC

This package is auto-updated.

Last update: 2020-02-25 11:43:57 UTC


README

PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License composer.lock

German Words

This library provides a huge dataset of german words and their grammar rules.

It is taken from gambolputty/german-nouns. More info about the different columns can be found here. Original source is WiktionaryDE with license Creative Commons Attribution-ShareAlike 3.0 Unported.

Installation

Run $ composer install bitandblack/german-words and $ composer update to install.

Usage

Set up a Words object and give it the file loaded by the CSV loader:

<?php 

use BitAndBlack\File\CSV;
use BitAndBlack\Words;

$datasetFull = 'data/words.csv';
$fullLoader = new CSV($datasetFull, 0);
$words = new Words($fullLoader);

You can access the words now by calling get(), for example:

<?php 

$articleWord = $words->get('Hose')->getArticle(true);
var_dump($articleWord);

This will dump die Hose.

Performance

Cache

The dataset is very huge and takes a long time to load, that's why you can set up a cache. All the loaded words will stored in this file then. The full dataset will only load then if there's a request for a word which isn't found in the cached dataset file. To use the cache function, set up like that:

<?php 

use BitAndBlack\Cache\Cache;
use BitAndBlack\File\CSV;
use BitAndBlack\Words;

$datasetFull = 'data/words.csv';
$datasetCached = 'data/words-cached.csv';

$fullLoader = new CSV($datasetFull, 0);
$cacheLoader = new CSV($datasetCached, 0);

$words = new Words(
    $fullLoader, 
    new Cache($cacheLoader)
);

Ignore Words

When words don't exist in the cache the script will always load the dataset. If words don't exist there neither, you can store them in a list of ignored words. Whenever a word appears on this list has() will return false without loading the whole dataset.

Set up like that:

<?php 

use BitAndBlack\Cache\Cache;
use BitAndBlack\File\CSV;
use BitAndBlack\Words;
use BitAndBlack\IgnoredWords\IgnoredWords;

$datasetFull = 'data/words.csv';
$datasetCached = 'data/words-cached.csv';
$datasetIgnored = 'data/words-ignored.csv';

$fullLoader = new CSV($datasetFull, 0);
$cacheLoader = new CSV($datasetCached, 0);
$ignoredLoader = new CSV($datasetIgnored, 0);

$words = new Words(
    $fullLoader, 
    new Cache($cacheLoader),
    new IgnoredWords($ignoredLoader)
);

Help

If you have any questions feel free to contact us under german-words@bitandblack.com.