Skip to content

Commit

Permalink
Fix Hepburn styles, add Nihon-shiki and Kunrei-shiki romanji styles.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleigh committed Nov 4, 2015
1 parent 791b5b6 commit 6dd7c50
Show file tree
Hide file tree
Showing 37 changed files with 1,505 additions and 640 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ before_script:
script:
- ./install-php-mecab.sh

install: composer install

env:
- DIC_DIRECTORY=
install: composer install
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Install Limelight.
composer require nihongodera/limelight
```

Copy the **.env.example** file to **.env**. If your MeCab install requires a dictionary directory, set **DIC_DIRECTORY** to your MeCab dictionary directory path. Otherwise, leave it as it is.

Make a Limelight instance.
```php
$limelight = new Limelight();
Expand Down Expand Up @@ -89,7 +87,7 @@ Once installed and working, install Limelight through composer.
composer require nihongodera/limelight
```

After installation, copy the **.env.example** file to **.env**. If your MeCab install requires a dictionary directory, set **DIC_DIRECTORY** to your MeCab dictionary directory path. Otherwise, leave it as it is.
If your install of MeCab requires a dictionary directory, set the dictionary directory path in config.php under options->PhpMecab->dictionary.

## Usage
- [Parsing Strings](#parsing-strings)
Expand Down Expand Up @@ -603,6 +601,10 @@ A plugin template with some example code can be found in Limelight/Plugins.
[Top](#contents)

## Change Log

Nov. 2, 2015: Version 1.2.1
- Added Modified Hepburn Romanji
- Rewrote romanji plugin engine

Nov. 1, 2015: Version 1.2.0
- Added Romanji plugin
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
}
},
"require": {
"vlucas/phpdotenv": "~1.0"

}
}
53 changes: 3 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions limelight_console
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ use Limelight\Limelight;
require __DIR__ . '/vendor/autoload.php';

$limelight = new Limelight();

$results = $limelight->parse('東京に行きます');

var_dump($results);
12 changes: 6 additions & 6 deletions src/Classes/LimelightResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function __construct($text, array $words, $pluginData)
/**
* Call generator if invoked as function.
*
* @return generator
* @return function
*/
public function __invoke()
{
return $this->next();
return $this->getNext();
}

/**
Expand Down Expand Up @@ -94,8 +94,8 @@ public function getResultString()

/**
* Get all lemmas combined as a string.
*
* @return [type] [description]
*
* @return string
*/
public function getLemmaString()
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getNext()
}

/**
* Get single word by word.
* Get single word, by word.
*
* @param string $string
*
Expand All @@ -153,7 +153,7 @@ public function getByWord($string)
/**
* Get single word by index.
*
* @param int $position
* @param int $index
*
* @return Limelight\Classes\LimelightWord
*/
Expand Down
15 changes: 4 additions & 11 deletions src/Classes/LimelightWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function __get($name)

/**
* Call methods for plugin items.
*
* @param string $name
* @param array $arguments
*
*
* @param string $name
* @param array $arguments
*
* @return $this
*/
public function __call($name, $arguments)
Expand Down Expand Up @@ -269,13 +269,6 @@ public function toKatakana()
return $this;
}

public function toRomanji()
{


return $this;
}

/**
* Append value to end of property.
*
Expand Down
30 changes: 30 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Config
{
/**
* config.php
*
* @var array
*/
private $configFile;
Expand Down Expand Up @@ -94,6 +96,34 @@ public function make($interface)
}
}

/**
* Reset config values to those defined in config file.
*/
public function resetConfig()
{
$this->configFile = include dirname(__DIR__).'/config.php';
}

/**
* Dynamically set config values.
*
* @param string $value
* @param string $key1
* @param string $key1
*
* @return bool
*/
public function set($value, $key1, $key2)
{
if (isset($this->configFile[$key1]) && isset($this->configFile[$key1][$key2])) {
$this->configFile[$key1][$key2] = $value;

return true;
}

throw new LimelightInvalidInputException('Key not found in config file.');
}

/**
* Get full class namespace from bindings array.
*
Expand Down
26 changes: 0 additions & 26 deletions src/Config/Setup.php

This file was deleted.

23 changes: 17 additions & 6 deletions src/Limelight.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Limelight;

use Limelight\Config\Setup;
use Limelight\Parse\Parser;
use Limelight\Config\Config;
use Limelight\Parse\Tokenizer;
Expand All @@ -11,7 +10,7 @@
class Limelight
{
/**
* @var implements Limelight\Mecab\Mecab
* @var Limelight\Mecab\Mecab
*/
private $mecab;

Expand All @@ -20,10 +19,6 @@ class Limelight
*/
public function __construct()
{
$setup = new Setup();

$setup->boot();

$config = Config::getInstance();

$this->mecab = $config->make('Limelight\Mecab\Mecab');
Expand Down Expand Up @@ -94,4 +89,20 @@ public function mecabSplit($string)
{
return $this->mecab->split($string);
}

/**
* Dynamically set config values.
*
* @param string $value
* @param string $key1
* @param string $key1
*
* @return bool
*/
public function setConfig($value, $key1, $key2)
{
$config = Config::getInstance();

$config->set($value, $key1, $key2);
}
}
8 changes: 7 additions & 1 deletion src/Mecab/PhpMecab/PhpMecab.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
class PhpMecab implements Mecab
{
/**
* @var implements Limelight\Mecab\Mecab
* MeCab.
*
* @var Limelight\Mecab\Mecab
*/
private $mecab;

/**
* Options array pulled from config.php.
*
* @var array
*/
private $options;
Expand All @@ -27,6 +31,8 @@ class PhpMecab implements Mecab

/**
* Construct.
*
* @param array $options
*/
public function __construct($options)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Plugins/Library/Furigana/Furigana.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Limelight\Plugins\Library\Furigana;

use Limelight\Config\Config;
use Limelight\Plugins\Plugin;

class Furigana extends Plugin
Expand Down Expand Up @@ -335,7 +336,9 @@ private function addToWord($wordObject, $word)
*/
private function setTags()
{
$tags = $this->config->get('Furigana');
$config = Config::getInstance();

$tags = $config->get('Furigana');

foreach ($tags as $name => $tag) {
$openClose = explode('{{}}', $tag);
Expand Down
Loading

0 comments on commit 6dd7c50

Please sign in to comment.