Skip to content

Commit

Permalink
Add get method to LimelightResults and LimelightWord.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleigh committed Apr 11, 2016
1 parent 3364ad2 commit 66afd00
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
Binary file removed .composer.json.swp
Binary file not shown.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ echo 'Furigana: ' . $results->toFurigana()->words() . "\n";
> Hiragana: にわでらいむをそだてています。
> Katakana: ニワデライムヲソダテテイマス。
> Romaji: Niwa de raimu o sodateteimasu.
> Furigana: <ruby><rb>庭</rb><rp>(</rp><rt>にわ</rt><rp>)</rp></ruby>でライムを<ruby><rb>育</rb><rp>(</rp><rt>そだ</rt><rp>)</rp></ruby>てています。
> Furigana: <ruby><rb>庭</rb><rp>(</rp><rt>にわ</rt><rp>)</rp></ruby>でライムを<ruby><rb>育</rb><rp>(</rp><rt>そだ</rt><rp>)</rp></ruby>てています。
Note: instead of calling words() you can call get().
```
$results->toRomaji()->get();
```

Get individual words off the LimelightResults object by selecting them by either word or index and using methods available on the returned [LimelightWord](https://github.com/nihongodera/limelight/wiki/LimelightWord) object.
```php
Expand All @@ -104,6 +109,11 @@ echo $word2->toFurigana()->word() . "\n";
> <ruby>庭<rt>にわ</rt></ruby>
Notice that methods on the LimelightResults object and the LimelightWord object follow the same conventions, but LimelightResults methods are plural (word**s**()) while LimelightWord methods are singular (word()).

Note: instead of calling word() you can call get().
```
$word1->toRomaji()->get();
```

Alternatively, loop through all the words on the LimelightResults object using the next() method.
```php
Expand Down
34 changes: 31 additions & 3 deletions src/Classes/LimelightResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ public function original()
/**
* Get all words combined as a string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function get($spaces = false, $divider = ' ')
{
return $this->words($spaces, $divider);
}

/**
* Get all words combined as a string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function words($spaces = false, $divider = ' ')
Expand All @@ -110,6 +126,9 @@ public function words($spaces = false, $divider = ' ')
/**
* Get all lemmas combined as a string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function lemmas($spaces = false, $divider = ' ')
Expand All @@ -120,6 +139,9 @@ public function lemmas($spaces = false, $divider = ' ')
/**
* Get all readings combined as a string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function readings($spaces = false, $divider = ' ')
Expand All @@ -130,6 +152,9 @@ public function readings($spaces = false, $divider = ' ')
/**
* Get all pronunciations combined as a string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function pronunciations($spaces = false, $divider = ' ')
Expand All @@ -140,6 +165,9 @@ public function pronunciations($spaces = false, $divider = ' ')
/**
* Get all partsOfSpeech combined as a space sseerated string.
*
* @param bool $spaces [put divider between words]
* @param string $divider
*
* @return string
*/
public function partsOfSpeech($spaces = true, $divider = ' ')
Expand Down Expand Up @@ -209,7 +237,7 @@ public function next()
$count = count($this->words);

for ($i = 0; $i < $count; ++$i) {
yield ($this->words[$i]);
yield $this->words[$i];
}
}

Expand Down Expand Up @@ -314,8 +342,8 @@ private function shouldTrim($word, $string, $property)
/**
* Cut last char if its is divider.
*
* @param string $string
* @param string $divider
* @param string $string
* @param string $divider
*
* @return string
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Classes/LimelightWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ public function rawMecab()
return $this->rawMecab;
}

/**
* Get word.
*
* @return string
*/
public function get()
{
return $this->word();
}

/**
* Get word.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/LimelightResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public function it_can_build_a_word_string_from_words()
$this->AssertEquals('音楽を聴きます。', $string);
}

/**
* @test
*/
public function it_can_build_a_word_string_from_words_when_get_is_called()
{
$string = self::$results->get();

$this->AssertEquals('音楽を聴きます。', $string);
}

/**
* @test
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/LimelightWordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ public function it_can_get_word()
$this->assertEquals('東京', $word);
}

/**
* @test
*/
public function it_can_get_word_when_get_called()
{
$word = self::$results->findIndex(0)->get();

$this->assertEquals('東京', $word);
}

/**
* @test
*/
Expand Down
2 changes: 1 addition & 1 deletion travis-php-mecab.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -ex
wget https://github.com/rsky/php-mecab/archive/master.zip
wget https://github.com/nihongodera/php-mecab/archive/master.zip
unzip master.zip
cd php-mecab-master/mecab && phpize && ./configure --with-php-config=/usr/bin/php-config --with-mecab-config=/usr/bin/mecab-config && make && sudo make install
echo "extension=<extension>.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

0 comments on commit 66afd00

Please sign in to comment.