-
Notifications
You must be signed in to change notification settings - Fork 28
LimelightWord
LimelightWord objects contain all information gained from the Limelight parse() method. Each LimelightWord object holds information for exactly one word. Unlike LimelightResults methods which are plural, LimelightWord methods are all singular.
All examples in this section will use the following text.
$results = $limelight->parse('イギリス人のことを 「ライム野郎 (limey)」 と呼びます。');
- convert()
- furigana()
- get()
- grammar()
- lemma()
- parsed()
- parseLemma()
- partOfSpeech()
- plugin()
- pronunciation()
- rawMecab()
- reading()
- romaji()
- toArray()
- toHiragana()
- toJson()
- toKatakana()
- word()
Convert word properties to hiragana or katakana.
$word = $results->pull(0);
$katakanaOutput = $word->word();
// 'イギリス人'
$coverted = $word->convert('hiragana');
$hiraganaOutput = $word->convert('hiragana')->word();
// 'いぎりす人'
Get furigana.
$word = $results->pluck(12);
$output = $word->furigana();
// '<ruby>呼<rt>よ</rt></ruby>びます'
Get the word.
$word = $results->pull(0);
$output = $word->get();
// 'イギリス人'
Get any grammar notes for the word. Most words do not yet have grammar notes.
$word = $results->pull(0);
$output = $word->grammar();
// Grammar, if any
Get the word's lemma (dictionary form).
$word = $results->pull(12);
$output = $word->lemma();
// '呼ぶ'
Returns true if word was successfully parsed, false if it was not. Occasionally, words are not able to be parsed by MeCab either because they are rare, slang, or written in uncommon way (e.g. kana instead of kanji).
$word = $results->pull(0);
$output = $word->parsed();
// true
Parse the lemma with Limelight to get lemma readings, furigana, romaji etc. Returns a LimelightWord instance.
$word = $results->pull(12);
$output = $word->parseLemma()->reading();
// 'ヨブ'
Get the word's part of speech.
$word = $results->pull(0);
$output = $word->partOfSpeech();
// 'proper noun'
Get plugin data by plugin name.
$word = $results->pull(6);
$output = $word->plugin('romaji');
// 'yarō'
Get the word's pronunciation. Long vowels are denoted by 'ー'.
$word = $results->pull(6);
$output = $word->pronunciation();
// 'ヤロー'
Get the word's Mecab tokens. Output will be an array of token arrays.
$word = $results->pull(5);
$output = $word->rawMecab();
// [
// 0 => [
// 'type' => 'parsed',
// 'literal' => 'ライム',
// 'partOfSpeech1' => 'meishi',
// 'partOfSpeech2' => '一般',
// 'partOfSpeech3' => '*',
// 'partOfSpeech4' => '*',
// 'inflectionType' => '*',
// 'inflectionForm' => '*',
// 'lemma' => 'ライム',
// 'reading' => 'ライム',
// 'pronunciation' => 'ライム'
// ]
// ]
Get the word's reading.
$word = $results->pull(6);
$output = $word->reading();
// 'ヤロウ'
Get romaji.
$word = $results->pull(0);
$output = $word->romaji();
// 'Igirisujin'
Get the objects public properties as an array.
$word = $results->pull(6);
$output = $word->toArray();
// [
// 'rawMecab' => [
// 0 => [
// 'type => 'parsed',
// 'literal' => '野郎',
// 'partOfSpeech1' => 'meishi',
// 'partOfSpeech2' => '一般',
// 'partOfSpeech3' => '*',
// 'partOfSpeech4' => '*',
// 'inflectionType' => '*',
// 'inflectionForm' => '*',
// 'lemma' => '野郎',
// 'reading' => 'ヤロウ',
// 'pronunciation' => 'ヤロー'
// ]
// ],
// 'word' => '野郎',
// 'lemma' => '野郎',
// 'reading' => 'ヤロウ',
// 'pronunciation' => 'ヤロー',
// 'partOfSpeech' => 'noun',
// 'grammar' => 'NULL',
// 'parsed' => true,
// 'pluginData' => [
// 'Furigana' => '<ruby><rb>野郎</rb><rp>(</rp><rt>やろう</rt><rp>)</rp></ruby>',
// 'Romaji' => 'yarō'
// ]
// ]
Convert all kana to hiragana.
$word = $results->pull(0);
$output = $word->toHiragana()->reading();
// 'いぎりすじん'
Convert the object to its JSON representation.
$word = $results->pull(1);
$output = $word->toJson();
// '{"rawMecab":[{"type":"parsed","literal":"\u306e","partOfSpeech1":"joshi","partOfSpeech2":"rentaika","partOfSpeech3":"*","partOfSpeech4":"*","inflectionType":"*","inflectionForm":"*","lemma":"\u306e","reading":"\u30ce","pronunciation":"\u30ce"}],"word":"\u306e","lemma":"\u306e","reading":"\u30ce","pronunciation":"\u30ce","partOfSpeech":"postposition","grammar":null,"parsed":true,"pluginData":{"Furigana":"\u306e","Romaji":"no"}}'
Convert all kana to katakana.
$word = $results->pull(12);
$output = $word->toKatakana()->word();
// '呼ビマス'
Get the word.
$word = $results->pull(0);
$output = $word->word();
// 'イギリス人'