Created
October 23, 2012 10:31
-
-
Save farico/3938084 to your computer and use it in GitHub Desktop.
Linksniavimas LT vardu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Lietuviškų vardų linksniai. | |
* | |
* @author Maug Lee <[email protected]> | |
* @copyright Copyleft (ↄ) 2011, Maug Lee | |
* @version 0.3 | |
* @package Vardai | |
*/ | |
class Linksniai { | |
function __construct ( $encoding = 'UTF-8' ) { | |
mb_internal_encoding($encoding) ; | |
// kilmininkas (ko?) | |
$this->kil = array( | |
'a' => 'os', | |
'as' => 'o', | |
'ė' => 'ės', | |
'tis' => 'čio', | |
'dis' => 'džio', | |
'is' => 'io', | |
'us' => 'aus', | |
'tys' => 'čio', | |
'dys' => 'džio', | |
'ys' => 'io' | |
) ; | |
// naudininkas (kam?) | |
$this->nau = array( | |
'a' => 'ai', | |
'as' => 'ui', | |
'ė' => 'ei', | |
'tis' => 'čiui', | |
'dis' => 'džiui', | |
'is' => 'iui', | |
'us' => 'ui', | |
'tys' => 'čiui', | |
'dys' => 'džiui', | |
'ys' => 'iui' | |
) ; | |
// galininkas (ką?) | |
$this->gal = array( | |
'a' => 'ą', | |
'as' => 'ą', | |
'ė' => 'ę', | |
'is' => 'į', | |
'us' => 'ų', | |
'ys' => 'į' | |
) ; | |
// įnagininkas (kuo?) | |
$this->ina = array( | |
'a' => 'a', | |
'as' => 'u', | |
'ė' => 'e', | |
'tis' => 'čiu', | |
'dis' => 'džiu', | |
'is' => 'iu', | |
'us' => 'u', | |
'tys' => 'čiu', | |
'dys' => 'džiu', | |
'ys' => 'iu' | |
) ; | |
// vietininkas (kur? kame?) | |
$this->vie = array( | |
'a' => 'oje', | |
'as' => 'e', | |
'ė' => 'ėje', | |
'is' => 'yje', | |
'us' => 'uje', | |
'ys' => 'yje' | |
) ; | |
// šauksmininkas | |
$this->sau = array( | |
'a' => 'a', | |
'as' => 'ai', | |
'ė' => 'e', | |
'is' => 'i', | |
'us' => 'au', | |
'ys' => 'y' | |
) ; | |
} | |
/** | |
* Vardų transformacija | |
* | |
* @param string $vardas lietuviškas vardas arba pavardė | |
* @param string $linksnis sutrumpintas linksnio pavadinimas: kil, nau, gal, ina, vie, sau | |
* @return string | |
*/ | |
function getName ( $vardas, $linksnis = 'sau' ) { | |
$vardai = explode( ' ', $this->sanitizeName($vardas) ) ; | |
$vardaiL = array() ; | |
foreach ( $vardai as $v ) { | |
$vardaiL[] = $this->getLinksnis( $v, $linksnis ) ; | |
} | |
return count($vardaiL) ? implode(' ', $vardaiL) : $vardas ; | |
} | |
/** | |
* Vardų sanitarija | |
* | |
* @param string $vardas lietuviškas vardas arba pavardė | |
* @return string | |
*/ | |
function sanitizeName ( $vardas ) { | |
$vardas = mb_eregi_replace('[^a-ž]', ' ', $vardas) ; | |
$vardas = mb_eregi_replace('\s+', ' ', $vardas) ; | |
$vardas = trim($vardas) ; | |
$vardas = mb_convert_case($vardas, MB_CASE_TITLE) ; | |
return $vardas ; | |
} | |
/** | |
* Vardas linksnyje | |
* | |
* @param string $vardas lietuviškas vardas arba pavardė | |
* @param string $linksnis sutrumpintas linksnio pavadinimas: kil, nau, gal, ina, vie, sau | |
* @return string | |
*/ | |
function getLinksnis ( $vardas, $linksnis = 'sau' ) { | |
$return = $vardas ; | |
foreach ( $this->$linksnis as $from=>$to ) { | |
if ( mb_substr( $return, -mb_strlen($from) ) == $from ) { | |
$return = mb_substr( $return, 0, -mb_strlen($from) ) ; | |
$return .= $to ; | |
break ; | |
} | |
} | |
return $return ; | |
} | |
} | |
$l = new Linksniai ; | |
echo $l->getName(' antANAS Saulys Janis saulė_ petronėlė-golubauskienė ---___') ; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labai gerai