Siapa
Malay Name Parser: A simple script for parsing complex Malay names into their individual components.
- Salutation
- First Name
- Last Name
- Gender
Example Usage
$siapa = Siapa::name("Dato' Dr. Ir Hj. Hariadi Bin Hinta");
echo $siapa->salutation(); // Dato' Dr. Ir Hj.
echo $siapa->first(); // Hariadi
echo $siapa->last(); // Bin Hinta
echo $siapa->gender(); // MInstall
If you're using Composer to manage dependencies, you can include the following in your composer.json file:
`composer require hariadi/siapa`
Then, after running composer update or php composer.phar update, you can
load the class using Composer's autoloading:
require 'vendor/autoload.php';Otherwise, you can simply require the file directly:
require_once 'path/to/Siapa/src/Siapa.php';OO and Procedural
The library offers both OO method chaining with Hariadi\Siapa. An example
of the former is the following:
use Hariadi\Siapa;
echo Siapa::name('Hariadi Hinta', 'UTF-8')->first(); // HariadiMethods
Note: If $encoding is not given, it defaults to mb_internal_encoding().
salutation
$siapa->salutation()
Siapa::salutation()
Returns salutation from full name.
Siapa::name('Datuk Dr. Ir. Hariadi Hinta', 'UTF-8')->salutation(); // Datuk Dr. Ir.givenName
Siapa::givenName()
Returns the combine of first and last name without salutation and optional with or witout middle name.
Siapa::name('Dato\' Hariadi Bin Hinta', 'UTF-8')->givenName(false); // Hariadi Bin Hintafirst
Siapa::first()
Returns the first name.
Siapa::name('Hariadi Hinta', 'UTF-8')->first(); // Hariadilast
Siapa::last()
Returns the last name.
Siapa::name('Hariadi Hinta', 'UTF-8')->last(); // Hintagender
Siapa::gender(boolean $short)
Returns the gender of name. Default param is true for short gender (M for Male and F for Female).
Siapa::name('Hariadi Hinta', 'UTF-8')->gender(false); // MaleAlgorithm to detect malay name gender:
- Default gender is Male
- Check if
Binti,Bte.,Bte,Puan,Puan,Pn.,Bt.,Bt,A/Pexist in first name - If not found then we check for salutation if
Hajah,Hajjah,Hjh.,Puan,Pn.,Cikexist. - If not found then we check for common female malay name in
female.txtlibrary
Tests
- Clone the repository: git clone https://github.com/hariadi/Siapa.git
- From the project directory, tests can be ran using
phpunit
License
Released under the MIT License - see LICENSE.txt for details.