Skip to content
Zach Leigh edited this page Apr 26, 2016 · 8 revisions

Contents

Parse Text

Make a new instance of Limelight\Limelight. Limelight takes no arguments.

$limelight = new Limelight();

Use the parse() method on the Limelight object to parse Japanese text.

$results = $limelight->parse('庭でライムを育てています。');

The returned object is an instance of Limelight\Classes\LimelightResults.

Get Results

Get results for the entire text using methods available on LimelightResults.

$results = $limelight->parse('庭でライムを育てています。');

echo 'Words: ' . $results->string('word') . "\n";
echo 'Readings: ' . $results->string('reading') . "\n";
echo 'Pronunciations: ' . $results->string('pronunciation') . "\n";
echo 'Lemmas: ' . $results->string('lemma') . "\n";
echo 'Parts of speech: ' . $results->string('partOfSpeech') . "\n";
echo 'Hiragana: ' . $results->toHiragana()->string('word') . "\n";
echo 'Katakana: ' . $results->toKatakana()->string('word') . "\n";
echo 'Romaji: ' . $results->string('romaji', ' ') . "\n";
echo 'Furigana: ' . $results->string('furigana') . "\n";

Output:
Words: 庭でライムを育てています。
Readings: ニワデライムヲソダテテイマス。
Pronunciations: ニワデライムヲソダテテイマス。
Lemmas: 庭でライムを育てる。
Parts of speech: noun postposition noun postposition verb symbol
Hiragana: にわでらいむをそだてています。
Katakana: ニワデライムヲソダテテイマス。
Romaji: niwa de raimu o sodateteimasu.
Furigana: (にわ)でライムを(そだ)てています。

Alter the collection of words however you like using the library of collection methods.

Get individual words off the LimelightResults object by using one of several applicable collection methods. Use methods available on the returned LimelightWord object.

$results = $limelight->parse('庭でライムを育てています。');

$word1 = $results->pull(2);

$word2 = $results->where('word', '');

echo $word1->string('romaji') . "\n";

echo $word2->string('furigana') . "\n";

Output:
raimu
にわ

Methods on the LimelightResults object and the LimelightWord object follow the same conventions, but LimelightResults methods are plural (words()) while LimelightWord methods are singular (word()).

Alternatively, loop through all the words on the LimelightResults object.

$results = $limelight->parse('庭でライムを育てています。');

foreach ($results as $word) {
    echo $word->word() . ' is a ' . $word->partOfSpeech() . ' read like ' . $word->reading() . "\n";
}

Output:
庭 is a noun read like ニワ
で is a postposition read like デ
ライム is a noun read like ライム
を is a postposition read like ヲ
育てています is a verb read like ソダテテイマス
。 is a symbol read like 。