Skip to content

Commit

Permalink
Merge pull request #11 from stevenay/master
Browse files Browse the repository at this point in the history
PHP: Add user guide and demo.
  • Loading branch information
sffc authored Jun 7, 2018
2 parents 7e0ae7c + 5afab59 commit fd70856
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clients/php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This documentation is for PHP specific usage of *Myanmar Tools*. For general doc

Prerequisites: PHP >=7.0 and composer >= 1.0

Add the dependency to your project: (Pending)
Add the dependency to your project:

```bash
$ composer install myanmar-tools
```

To detect Zawgyi, create an instance of ZawgyiDetector, and call `getZawgyiProbability` with your string. Generally, if the score is greater than or equal to 0.95, you can assume the string is Zawgyi. If the score is lower or equal to 0.05, you can assume it is Unicode.
To detect Zawgyi, create an instance of ZawgyiDetector, and call `getZawgyiProbability` with your string. Generally, if the score is greater than or equal to 0.95, you can generally assume the string is Zawgyi. If the score is lower or equal to 0.05, you can assume it is Unicode.

```
$autoload = __DIR__.'/vendor/autoload.php';
Expand Down Expand Up @@ -47,15 +47,15 @@ Rabbit::zg2uni("သီဟိုဠ္မွ ဉာဏ္ႀကီးရွင္
// output is now "သီဟိုဠ်မှ ဉာဏ်ကြီးရှင်သည် အာယုဝဍ်ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေးဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။"
```

For a complete working example, see [samples/php/demo.rb](../../samples/php/demo.php).
For a complete working example, see [samples/php/Demo.php](../../samples/php/Demo.php).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/googlei18n/myanmar-tools . This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.

## License

The gem is available as open source under the terms of the [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0).
The package is available as open source under the terms of the [Apache-2.0 License](http://www.apache.org/licenses/LICENSE-2.0).

## Code of Conduct

Expand Down
33 changes: 33 additions & 0 deletions samples/php/Demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// include autoload
$autoload = join(DIRECTORY_SEPARATOR, [__DIR__, "vendor", "autoload.php"]);
if (!file_exists($autoload))
exit("Need Composer!");
require $autoload;

use Googlei18n\MyanmarTools\ZawgyiDetector;

$detector = new ZawgyiDetector();

// Unicode string
$unicodeInput = 'အပြည်ပြည်ဆိုင်ရာ လူ့အခွင့်အရေး ကြေညာစာတမ်း';

// Zawgyi string
$zawgyiInput = 'အျပည္ျပည္ဆိုင္ရာ လူ႔အခြင့္အေရး ေၾကညာစာတမ္း';

$unicodeScore = $detector->getZawgyiProbability($unicodeInput);
$zawgyiScore = $detector->getZawgyiProbability($zawgyiInput);

assert($unicodeScore < 0.001);
assert($zawgyiScore > 0.999);

printf("Unicode Score: %.6f", $unicodeScore);
echo "<br />";
printf("Zawgyi Score: %.6f", $zawgyiScore);

echo "<br />";

// Convert the second string to Unicode:
$zawgyi2UniConverted = Rabbit::zg2uni($zawgyiInput);
assert($unicodeInput === $zawgyi2UniConverted, "Converted string is equal to unicode");
printf("Converted Text: %s\n", $zawgyi2UniConverted);
19 changes: 19 additions & 0 deletions samples/php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "googlei18n/myanmar-tools-sample",
"description": "Sample for how to use myanmar-tools detector",
"license": "MIT",
"keywords": [
"sample"
],
"homepage": "https://developers.google.com/international",
"authors": [
{
"name": "googlei18n",
"email": "[email protected]"
}
],
"type": "project",
"require": {
"googlei18n/myanmar-tools": ">=0.1.0"
}
}

0 comments on commit fd70856

Please sign in to comment.