├── .gitignore ├── AUTHORS ├── CHANGES ├── COPYING ├── INSTALL ├── README ├── bin ├── bench.php ├── create-user-dict.php ├── dev │ ├── generate-bat-files.php │ ├── generate-decorators.php │ ├── generate-fsa-access.php │ ├── generate-graminfo.php │ ├── generate-gramtab-cpp.php │ ├── generate-gramtab-php.php │ ├── generate-phpunit.php │ ├── reorganize-classes-to-zf-layout.php │ └── update-copyleft.php ├── dict-build │ ├── build-dict.php │ ├── extract-ancodes-map.php │ ├── extract-ancodes.php │ ├── extract-graminfo-header.php │ └── extract-gramtab.php ├── dict-processing │ ├── bench_explode.php │ ├── convert-mrd2xml.php │ ├── convert-russian-jo.php │ ├── convert-xml2csv.php │ ├── dump-xml-dict-paradigms.php │ ├── extract-gramtab.php │ ├── morphy-structure.sql │ └── remove-graminfo.php └── print-paradigm.php ├── dicts └── __put_dicts_here__ ├── examples ├── example-0.3.x.php └── example.php ├── src ├── common.php ├── gramtab_consts.php ├── phpMorphy.php └── phpMorphy │ ├── AncodesResolver │ ├── AncodesResolverInterface.php │ ├── AsIs.php │ ├── Decorator.php │ ├── Proxy.php │ ├── ToDialingAncodes.php │ └── ToText.php │ ├── AnnotDecoder │ ├── AnnotDecoderAbstract.php │ ├── AnnotDecoderInterface.php │ ├── Common.php │ ├── Factory.php │ └── Predict.php │ ├── Aot │ ├── GramTab │ │ ├── Exception.php │ │ ├── File.php │ │ ├── GramInfo.php │ │ ├── GramInfo │ │ │ └── Empty.php │ │ ├── GramInfoFactory.php │ │ ├── GramInfoHelper │ │ │ ├── English.php │ │ │ ├── German.php │ │ │ └── Russian.php │ │ ├── GramInfoHelperAbstract.php │ │ ├── GramInfoHelperInterface.php │ │ └── Reader.php │ ├── Mrd │ │ ├── Exception.php │ │ ├── File.php │ │ ├── Section │ │ │ ├── Accents.php │ │ │ ├── Flexias.php │ │ │ ├── Lemmas.php │ │ │ ├── Prefixes.php │ │ │ └── Sessions.php │ │ └── SectionAbstract.php │ ├── MrdManager.php │ ├── Mwz │ │ ├── Exception.php │ │ └── File.php │ └── Rml │ │ ├── Exception.php │ │ └── IniFile.php │ ├── DecoratorInterface.php │ ├── Dict │ ├── AccentModel.php │ ├── Ancode.php │ ├── Flexia.php │ ├── FlexiaDecorator.php │ ├── FlexiaModel.php │ ├── FlexiaModelDecorator.php │ ├── GramTab │ │ ├── ConstStorage.php │ │ └── ConstStorage │ │ │ ├── Factory.php │ │ │ ├── Loader.php │ │ │ ├── Specials.php │ │ │ └── data │ │ │ ├── eng.xml │ │ │ ├── ger.xml │ │ │ ├── lang_map.php │ │ │ ├── rus.xml │ │ │ ├── specials.xml │ │ │ └── unk.xml │ ├── Grammem.php │ ├── Lemma.php │ ├── LemmaDecorator.php │ ├── ModelsFormatter.php │ ├── PartOfSpeech.php │ ├── PrefixSet.php │ ├── Source │ │ ├── Decorator.php │ │ ├── Mrd.php │ │ ├── Mutable.php │ │ ├── Mutable │ │ │ └── Container.php │ │ ├── NormalizedAncodes.php │ │ ├── NormalizedAncodes │ │ │ ├── Ancode.php │ │ │ ├── AncodesManager.php │ │ │ ├── DecoratingIterator.php │ │ │ ├── Flexia.php │ │ │ ├── FlexiaModel.php │ │ │ └── Lemma.php │ │ ├── NormalizedAncodesInterface.php │ │ ├── SourceInterface.php │ │ ├── ValidatingSource.php │ │ ├── ValidatingSource │ │ │ ├── Iterator.php │ │ │ ├── Validator.php │ │ │ ├── ValidatorInterface.php │ │ │ └── ValidatorSection.php │ │ ├── Xml.php │ │ └── Xml │ │ │ ├── Section │ │ │ ├── Ancodes.php │ │ │ ├── Flexias.php │ │ │ ├── Grammems.php │ │ │ ├── Lemmas.php │ │ │ ├── Options.php │ │ │ ├── Poses.php │ │ │ └── Prefixes.php │ │ │ └── SectionAbstract.php │ └── Writer │ │ ├── Csv.php │ │ ├── Decorator.php │ │ ├── Observer │ │ ├── Empty.php │ │ ├── ObserverInterface.php │ │ └── Standart.php │ │ ├── WriterAbstract.php │ │ ├── WriterInterface.php │ │ └── Xml.php │ ├── Exception.php │ ├── FilesBundle.php │ ├── Finder │ ├── FinderAbstract.php │ ├── FinderInterface.php │ └── Fsa │ │ ├── Finder.php │ │ ├── PredictByDatabase.php │ │ └── PredictBySuffix.php │ ├── Fsa │ ├── Decorator.php │ ├── FsaAbstract.php │ ├── FsaInterface.php │ ├── Link.php │ ├── LinkAbstract.php │ ├── LinkAnnot.php │ ├── Proxy.php │ ├── Sparse │ │ ├── File.php │ │ ├── Mem.php │ │ └── Shm.php │ ├── State.php │ ├── Tree │ │ ├── File.php │ │ ├── Mem.php │ │ └── Shm.php │ ├── WordsCollector.php │ └── WordsCollector │ │ └── ForPrediction.php │ ├── Generator │ ├── Decorator │ │ ├── Generator.php │ │ ├── HandlerDefault.php │ │ ├── HandlerInterface.php │ │ ├── PhpDocHelper.php │ │ └── PhpDocHelperHeader.php │ ├── Fsa.php │ ├── Fsa │ │ ├── HelperAbstract.php │ │ ├── HelperSparse.php │ │ ├── HelperTree.php │ │ └── tpl │ │ │ ├── Sparse │ │ │ ├── extra_funcs.tpl.php │ │ │ ├── extra_props.tpl.php │ │ │ ├── find_char_in_state.tpl.php │ │ │ ├── read_state.tpl.php │ │ │ └── unpack_trans.tpl.php │ │ │ ├── Tree │ │ │ ├── extra_funcs.tpl.php │ │ │ ├── extra_props.tpl.php │ │ │ ├── find_char_in_state.tpl.php │ │ │ ├── read_state.tpl.php │ │ │ └── unpack_trans.tpl.php │ │ │ └── fsa.tpl.php │ ├── GramInfo.php │ ├── GramInfo │ │ ├── Helper.php │ │ └── tpl │ │ │ └── graminfo.tpl.php │ ├── GramTab.php │ ├── GramTab │ │ ├── HelperPhp.php │ │ └── tpl │ │ │ ├── cpp │ │ │ ├── declaration.tpl.php │ │ │ └── definition.tpl.php │ │ │ └── php │ │ │ └── gramtab.tpl.php │ ├── HelperAbstract.php │ ├── Lexer.php │ ├── PhpFileParser.php │ ├── PhpFileParser │ │ ├── ClassDescriptor.php │ │ ├── Exception.php │ │ ├── FileDescriptor.php │ │ └── phpDoc.php │ ├── ReflectionHelper.php │ ├── StorageHelper │ │ ├── File.php │ │ ├── Mem.php │ │ └── Shm.php │ ├── StorageHelperInterface.php │ └── Template.php │ ├── GramInfo │ ├── AncodeCache.php │ ├── Decorator.php │ ├── File.php │ ├── GramInfoAbstract.php │ ├── GramInfoInterface.php │ ├── HeaderCache.php │ ├── Mem.php │ ├── Proxy.php │ ├── RuntimeCache.php │ └── Shm.php │ ├── GramTab │ ├── Decorator.php │ ├── Empty.php │ ├── GramTab.php │ ├── GramTabInterface.php │ ├── Proxy.php │ └── gramtab_consts.php │ ├── GrammemsProvider │ ├── Decorator.php │ ├── Empty.php │ ├── Factory.php │ ├── ForFactoryAbstract.php │ ├── GrammemsProviderAbstract.php │ ├── GrammemsProviderInterface.php │ └── ru │ │ └── RU.php │ ├── Helper.php │ ├── Loader.php │ ├── Morphier │ ├── Bulk.php │ ├── Common.php │ ├── Empty.php │ ├── MorphierAbstract.php │ ├── MorphierInterface.php │ ├── PredictByDatabase.php │ └── PredictBySuffix.php │ ├── MorphyInterface.php │ ├── MorphyNative.php │ ├── Paradigm │ ├── ArrayBased.php │ ├── Collection.php │ ├── CollectionSerializer.php │ ├── Formatter.php │ ├── FsaBased.php │ └── ParadigmInterface.php │ ├── Semaphore │ ├── Empty.php │ ├── Nix.php │ ├── SemaphoreFactory.php │ ├── SemaphoreInterface.php │ └── Win.php │ ├── Shm │ ├── Cache.php │ ├── CacheInterface.php │ ├── FileDescriptor.php │ └── Header.php │ ├── Source │ ├── Dba.php │ ├── Fsa.php │ ├── SourceFactory.php │ └── SourceInterface.php │ ├── Storage │ ├── Decorator.php │ ├── Factory.php │ ├── File.php │ ├── Mem.php │ ├── Proxy.php │ ├── Shm.php │ ├── StorageAbstract.php │ └── StorageInterface.php │ ├── UnicodeHelper │ ├── MultiByteFixed.php │ ├── Singlebyte.php │ ├── UnicodeHelperAbstract.php │ ├── UnicodeHelperInterface.php │ ├── Utf16.php │ └── Utf8.php │ ├── UserDict │ ├── EditCommand │ │ ├── Add.php │ │ ├── CommandAbstract.php │ │ ├── Delete.php │ │ └── Update.php │ ├── EncodingConverter.php │ ├── Exception.php │ ├── GrammarIdentifier.php │ ├── Log │ │ ├── CLI.php │ │ ├── ErrorsHandlerException.php │ │ ├── ErrorsHandlerInterface.php │ │ └── ErrorsHandlerPass.php │ ├── LogInterface.php │ ├── Pattern.php │ ├── PatternMatcher.php │ ├── PatternMatcher │ │ ├── AmbiguityException.php │ │ └── BaseException.php │ ├── VisitorInterface.php │ ├── XmlDiff │ │ ├── Command │ │ │ ├── Add.php │ │ │ ├── CommandAbstract.php │ │ │ ├── Delete.php │ │ │ └── Edit.php │ │ ├── Generator.php │ │ ├── ParadigmContainer.php │ │ └── ParadigmSaver.php │ └── XmlLoader.php │ ├── Util │ ├── Collection │ │ ├── ArrayBased.php │ │ ├── CollectionInterface.php │ │ ├── Decorator.php │ │ ├── Immutable.php │ │ └── Typed.php │ ├── Fs.php │ ├── Hunspell │ │ ├── AffixAbstract.php │ │ ├── AffixFile.php │ │ ├── AffixFileReader.php │ │ ├── AffixFlagAbstract.php │ │ ├── DictFile.php │ │ ├── DictFileReader.php │ │ ├── Exception.php │ │ ├── Prefix.php │ │ ├── PrefixFlag.php │ │ ├── Suffix.php │ │ └── SuffixFlag.php │ ├── Iterator │ │ ├── ArrayAccessAdapter.php │ │ ├── Decorator.php │ │ ├── Filter.php │ │ ├── Iconv.php │ │ └── Transform.php │ ├── MbstringOverloadFixer.php │ └── String.php │ └── WordForm │ ├── WithFormNo.php │ ├── WordForm.php │ └── WordFormInterface.php └── tests ├── bootstrap.php ├── functional └── commonTest.php ├── phpunit.xml └── unit ├── Collection ├── ArrayBasedTest.php └── TypedTest.php ├── Paradigm └── ArrayBasedTest.php ├── UserDict ├── phpMorphy_UserDict_EncodingConverterTest.php ├── phpMorphy_UserDict_GrammarIdentifierTest.php └── phpMorphy_UserDict_PatternTest.php └── WordForm └── MutableTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | dicts/*/ 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Kamaev Vladimir developer 2 | 3 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heromantor/phpmorphy/45204ee423290ab7d278bd7ac5d74f07aacd987c/COPYING -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | For proper work you need phpMorphy library and one of dictionaries. 2 | Download each one from http://sourceforge.net/projects/phpmorphy/ 3 | 4 | -- INSTALL LIBRARY 5 | - untar archive and include ./src/common.php in your script 6 | 7 | -- INSTALL DICTIONARY 8 | - untar archive with dict to any directory(i suggest ./dicts directory in phpMorphy dir). Use this directory when create 9 | dict descriptor(phpMorphy_FilesBundle) in script. 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | phpMorphy -- morphological analyzer library for Russisan, English and German languages 2 | 3 | Website (in russian): http://phpmorphy.sourceforge.net/ 4 | SF project: http://sourceforge.net/projects/phpmorphy 5 | 6 | 7 | This library allow retireve follow morph information for any word: 8 | - Base(normal) form 9 | - All forms 10 | - Grammatical(part of speech, grammems) information 11 | 12 | ------------ SPEED ------------- 13 | *-------------------* 14 | | Single word mode: | 15 | *-----------------------------------------------------------* 16 | | mode | base form | all forms | all forms with gram. info | 17 | |-----------------------------------------------------------| 18 | | FILE | 1000 | 800 | 600 | 19 | |-----------------------------------------------------------| 20 | | SHM | 2200 | 1100 | 800 | 21 | |-----------------------------------------------------------| 22 | | MEM | 2500 | 1200 | 900 | 23 | *-----------------------------------------------------------* 24 | 25 | *------------* 26 | | Bulk mode: | 27 | *-----------------------------------------------------------* 28 | | mode | base form | all forms | all forms with gram. info | 29 | |-----------------------------------------------------------| 30 | | FILE | 1700 | 800 | 700 | 31 | |-----------------------------------------------------------| 32 | | SHM | 3200 | 800 | 700 | 33 | |-----------------------------------------------------------| 34 | | MEM | 3500 | 800 | 700 | 35 | *-----------------------------------------------------------* 36 | 37 | Note: 38 | All values are words per second speed. 39 | Test platform: PHP 5.2.3, AMD Duron 800 with 512Mb memory, WinXP 40 | 41 | ------------ INSTALLATION ------------- 42 | See INSTALL file in current directory 43 | 44 | ------------ USAGE ------------- 45 | See example in ./examples directory 46 | -------------------------------------------------------------------------------- /bin/create-user-dict.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | PHPMORPHY_STORAGE_MEM, 21 | 'predict_by_suffix' => true, 22 | 'predict_by_db' => true, 23 | ); 24 | 25 | return new phpMorphy($dir, $lang, $opts); 26 | } 27 | 28 | $morphy = createMorphy($morphy_dict_dir, $morphy_dict_lang); 29 | 30 | $encoding_converter = new phpMorphy_UserDict_EncodingConverter( 31 | $morphy->getEncoding(), $morphy->isInUpperCase() ? MB_CASE_UPPER : MB_CASE_LOWER, 32 | 'utf-8', MB_CASE_UPPER 33 | ); 34 | 35 | //$errors_handler = new phpMorphy_UserDict_Log_ErrorsHandlerException(); 36 | $errors_handler = new phpMorphy_UserDict_Log_ErrorsHandlerPass(); 37 | 38 | $observer = new phpMorphy_UserDict_Log_CLI( 39 | $verbose, 40 | $errors_handler, 41 | $encoding_converter 42 | ); 43 | 44 | $b = microtime(true); 45 | 46 | if(1) { 47 | phpMorphy_UserDict_XmlDiff_Generator::convertFromXmlToXml( 48 | $user_dict_xml, 49 | $outXmlFilePath, 50 | $morphy, 51 | $observer, 52 | $encoding_converter 53 | ); 54 | } 55 | 56 | $e = microtime(true); 57 | 58 | printf("Time taken: %0.2f\n", $e - $b); 59 | -------------------------------------------------------------------------------- /bin/dev/generate-bat-files.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 2 ? (string)$argv[2] : DEFAULT_TESTS_DIR . '/unit'; 18 | ////////////////////////////////////////////////////////////////////////////// 19 | ////////////////////////////////////////////////////////////////////////////// 20 | 21 | $output_dir = realpath($output_dir); 22 | $output_dir = rtrim($output_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; 23 | 24 | $classes = PHPUnit_Util_File::getClassesInFile($input_file); 25 | foreach($classes as $class_name => $class_descriptor) { 26 | echo "==> Generate test for $class_name class\n"; 27 | 28 | $stripped_class_name = substr($class_name, strlen($remove_class_prefix)); 29 | 30 | $test_class_path = phpMorphy_Loader::classNameToFilePath($stripped_class_name); 31 | 32 | $test_file_path = 33 | $output_dir . 34 | preg_replace('/\.php$/u', '', $test_class_path) . 35 | 'Test.php'; 36 | 37 | $test_class_name = 'test_' . $stripped_class_name; 38 | 39 | $args = array( 40 | '--skeleton-test', 41 | $class_name, 42 | $input_file, 43 | $test_class_name, 44 | $test_file_path 45 | ); 46 | 47 | $cmd = 48 | $phpunit_bin . ' ' . 49 | ('' !== $phpunit_args ? ($phpunit_args . ' ') : '') . 50 | implode(' ', array_map('escapeshellarg', $args)); 51 | 52 | @mkdir(dirname($test_file_path)); 53 | 54 | passthru($cmd); 55 | } 56 | -------------------------------------------------------------------------------- /bin/dev/update-copyleft.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License as published by the Free Software Foundation; either 17 | * version 2 of the License, or (at your option) any later version. 18 | * 19 | * This library is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | * Lesser General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU Lesser General Public 25 | * License along with this library; if not, write to the 26 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 27 | * Boston, MA 02111-1307, USA. 28 | */ 29 | 30 | EOS; 31 | 32 | phpMorphy_Util_Fs::applyToEachFile( 33 | getcwd(), 34 | '~\.php$~', 35 | function($path) use($copyright_text, $marker_text) { 36 | $content = file_get_contents($path); 37 | if(substr($content, 0, 5) !== '<' . '?php' || strpos($content, $marker_text) !== false) { 38 | echo "Skip $path\n"; 39 | return; 40 | } 41 | 42 | $content = '<' . '?php' . PHP_EOL . $copyright_text . substr($content, 5);; 43 | file_put_contents($path, $content); 44 | }, 45 | true 46 | ); -------------------------------------------------------------------------------- /bin/dict-build/extract-graminfo-header.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | create(PHPMORPHY_STORAGE_FILE, $file, false), false); 17 | 18 | $out_file = $out_dir . '/morph_data_header_cache.' . strtolower($graminfo->getLocale()) . '.bin'; 19 | 20 | file_put_contents( 21 | $out_file, 22 | '<' . "?php" . PHP_EOL . "return " . 23 | var_export( 24 | $graminfo->getHeader(), 25 | true 26 | ) . 27 | ";" . PHP_EOL 28 | ); 29 | } catch (Exception $e) { 30 | echo $e; 31 | exit(1); 32 | } 33 | -------------------------------------------------------------------------------- /bin/dict-processing/bench_explode.php: -------------------------------------------------------------------------------- 1 | getLanguage() . ".xml"; 19 | 20 | $writer = new phpMorphy_Dict_Writer_Xml($out); 21 | $writer->setObserver(new phpMorphy_Dict_Writer_Observer_Standart('log_msg')); 22 | $writer->write($source); 23 | } catch (Exception $e) { 24 | echo $e; 25 | exit(1); 26 | } 27 | 28 | function log_msg($msg) { 29 | echo $msg, PHP_EOL; 30 | } 31 | -------------------------------------------------------------------------------- /bin/dict-processing/convert-russian-jo.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getLanguage() . ".xml"; 19 | $writer = new phpMorphy_Dict_Writer_Csv( 20 | get_abs_filename('part_of_speech.csv'), 21 | get_abs_filename('grammems.csv'), 22 | get_abs_filename('ancodes.csv'), 23 | get_abs_filename('flexia_models.csv'), 24 | get_abs_filename('prefixes.csv'), 25 | get_abs_filename('lemmas.csv') 26 | ); 27 | 28 | $writer->setObserver(new phpMorphy_Dict_Writer_Observer_Standart('log_msg')); 29 | $writer->write($source); 30 | } catch (Exception $e) { 31 | die((string)$e); 32 | } 33 | 34 | function get_abs_filename($name) { 35 | return $GLOBALS['out_dir'] . DIRECTORY_SEPARATOR . $name; 36 | } 37 | 38 | function log_msg($msg) { 39 | echo $msg, PHP_EOL; 40 | } 41 | -------------------------------------------------------------------------------- /bin/dict-processing/dump-xml-dict-paradigms.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getFlexias()); 16 | $ancodes = remap_to_ids($source->getAncodes()); 17 | $prefixes = remap_to_ids($source->getPrefixes()); 18 | 19 | echo "$xml: {", PHP_EOL; 20 | 21 | $para_no = 1; 22 | /** @var phpMorphy_Dict_Lemma $lemma */ 23 | foreach($source->getLemmas() as $lemma) { 24 | $common_grammems = array(); 25 | if($lemma->hasAncodeId()) { 26 | /** @var phpMorphy_Dict_Ancode $common_ancode */ 27 | $common_ancode = $ancodes[$lemma->getAncodeId()]; 28 | $common_grammems = $common_ancode->getGrammems(); 29 | } 30 | 31 | $flexia_model = $flexias[$lemma->getFlexiaId()]; 32 | $paradigm = new phpMorphy_Paradigm_ArrayBased(false); 33 | 34 | /** @var phpMorphy_Dict_Flexia $flexia */ 35 | foreach($flexia_model as $flexia) { 36 | /** @var phpMorphy_Dict_Ancode $ancode */ 37 | $ancode = $ancodes[$flexia->getAncodeId()]; 38 | 39 | $wf = new phpMorphy_WordForm_WordForm(); 40 | $wf->setBase($lemma->getBase()); 41 | $wf->setFormPrefix($flexia->getPrefix()); 42 | $wf->setSuffix($flexia->getSuffix()); 43 | $wf->setCommonGrammems($common_grammems); 44 | $wf->setPartOfSpeech($ancode->getPartOfSpeech()); 45 | $wf->setFormGrammems($ancode->getGrammems()); 46 | 47 | $paradigm->append($wf); 48 | } 49 | 50 | printf(" Paradigm %2d.\n%s", $para_no++, $formatter->format($paradigm, ' ')); 51 | } 52 | 53 | echo '}' . PHP_EOL; 54 | 55 | function remap_to_ids($ary) { 56 | $result = array(); 57 | 58 | foreach($ary as $value) { 59 | $result[$value->getId()] = $value; 60 | } 61 | 62 | return $result; 63 | } -------------------------------------------------------------------------------- /bin/dict-processing/remove-graminfo.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getFlexias() as $flexia_model) { 17 | $hash = ''; 18 | 19 | foreach($flexia_model->getFlexias() as $flexia) { 20 | $prefix = $flexia->getPrefix(); 21 | $suffix = $flexia->getSuffix(); 22 | 23 | $hash .= "<$prefix>$suffix|"; 24 | } 25 | 26 | $mapping[$hash] = 1; 27 | ++$total_models; 28 | 29 | echo "$total_models done\n"; 30 | } 31 | 32 | echo "orig = $total_models, new = " . count($mapping) . PHP_EOL; 33 | } catch (Exception $e) { 34 | echo $e; 35 | exit(1); 36 | } 37 | -------------------------------------------------------------------------------- /bin/print-paradigm.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | 2 ? $argv[2] : 'ru_RU'; 15 | 16 | $dir = __DIR__ . '/../dicts/'; 17 | $dir .= $argc > 3 ? "/{$argv[3]}" : 'utf-8'; 18 | 19 | $opts = array( 20 | 'storage' => PHPMORPHY_STORAGE_FILE, 21 | 'predict_by_suffix' => true, 22 | 'predict_by_db' => true, 23 | ); 24 | 25 | $morphy = new phpMorphy($dir, $lang, $opts); 26 | $encoding = $morphy->getEncoding(); 27 | $formatter = new phpMorphy_Paradigm_Formatter(); 28 | 29 | $word = iconv('utf-8', $encoding, $word); 30 | $word = mb_strtoupper($word, $encoding); 31 | $result = $morphy->findWord($word); 32 | 33 | $predict_text = 'DICT'; 34 | if($morphy->getLastPredictionType() == phpMorphy::PREDICT_BY_DB) { 35 | $predict_text = 'PREDICT_BY_DB'; 36 | } else if($morphy->getLastPredictionType() == phpMorphy::PREDICT_BY_SUFFIX) { 37 | $predict_text = 'PREDICT_BY_SUFFIX'; 38 | } 39 | 40 | echo "Paradigms for $word($predict_text):" . PHP_EOL; 41 | if(false === $result) { 42 | echo 'NOT FOUND' . PHP_EOL; 43 | exit(WORD_NOT_FOUND); 44 | } 45 | 46 | $para_no = 1; 47 | foreach($result as $paradigm) { 48 | printf(" Paradigm %2d.\n%s", $para_no++, $formatter->format($paradigm, ' ')); 49 | } 50 | -------------------------------------------------------------------------------- /dicts/__put_dicts_here__: -------------------------------------------------------------------------------- 1 | When you download dict for particular language untar it to this directory -------------------------------------------------------------------------------- /src/common.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'phpMorphy.php'); 24 | -------------------------------------------------------------------------------- /src/gramtab_consts.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | require_once(dirname(__FILE__) . '/phpMorphy/GramTab/gramtab_consts.php'); 24 | -------------------------------------------------------------------------------- /src/phpMorphy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | if(!defined('PHPMORPHY_DIR')) { 24 | define('PHPMORPHY_DIR', __DIR__); 25 | } 26 | 27 | require_once(PHPMORPHY_DIR . '/phpMorphy/Loader.php'); 28 | 29 | spl_autoload_register(array(new phpMorphy_Loader(PHPMORPHY_DIR), 'loadClass')); 30 | 31 | if(extension_loaded('morphy')) { 32 | throw new phpMorphy_Exception("todo: php extension not implemented"); 33 | } else { 34 | class phpMorphy extends phpMorphy_MorphyNative { 35 | } 36 | } 37 | 38 | define('PHPMORPHY_STORAGE_FILE', phpMorphy::STORAGE_FILE); 39 | define('PHPMORPHY_STORAGE_MEM', phpMorphy::STORAGE_MEM); 40 | define('PHPMORPHY_STORAGE_SHM', phpMorphy::STORAGE_SHM); 41 | -------------------------------------------------------------------------------- /src/phpMorphy/AncodesResolver/AncodesResolverInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_AncodesResolver_AncodesResolverInterface { 24 | /** 25 | * @abstract 26 | * @param int|string $ancodeId 27 | * @return string 28 | */ 29 | function resolve($ancodeId); 30 | 31 | /** 32 | * @abstract 33 | * @param string $ancode 34 | * @return string 35 | */ 36 | function unresolve($ancode); 37 | } -------------------------------------------------------------------------------- /src/phpMorphy/AncodesResolver/AsIs.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_AncodesResolver_AsIs implements phpMorphy_AncodesResolver_AncodesResolverInterface { 24 | // This ctor for ReflectionClass::newInstanceArgs($args) with $args = array() 25 | function __construct() { 26 | } 27 | 28 | function resolve($ancodeId) { 29 | return $ancodeId; 30 | } 31 | 32 | function unresolve($ancode) { 33 | return $ancode; 34 | } 35 | } -------------------------------------------------------------------------------- /src/phpMorphy/AncodesResolver/Proxy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_AncodesResolver_Proxy extends phpMorphy_AncodesResolver_Decorator { 24 | private 25 | /** @var string */ 26 | $class, 27 | /** @var array */ 28 | $args; 29 | 30 | /** 31 | * @param string $class 32 | * @param array $ctorArgs 33 | */ 34 | function __construct($class, array $ctorArgs) { 35 | $this->class = (string)$class; 36 | $this->args = $ctorArgs; 37 | 38 | $this->actAsProxy(); 39 | } 40 | 41 | protected function proxyInstantiate() { 42 | $result = $this->instantiateClass($this->class, $this->args); 43 | unset($this->args); 44 | unset($this->class); 45 | return $result; 46 | } 47 | } -------------------------------------------------------------------------------- /src/phpMorphy/AncodesResolver/ToText.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_AncodesResolver_ToText implements phpMorphy_AncodesResolver_AncodesResolverInterface { 24 | protected $gramtab; 25 | 26 | function __construct(phpMorphy_GramTab_GramTabInterface $gramtab) { 27 | $this->gramtab = $gramtab; 28 | } 29 | 30 | function resolve($ancodeId) { 31 | if(!isset($ancodeId)) { 32 | return null; 33 | } 34 | 35 | return $this->gramtab->ancodeToString($ancodeId); 36 | } 37 | 38 | function unresolve($ancode) { 39 | return $this->gramtab->stringToAncode($ancode); 40 | //throw new phpMorphy_Exception("Can`t convert grammar info in text into ancode id"); 41 | } 42 | } -------------------------------------------------------------------------------- /src/phpMorphy/AnnotDecoder/AnnotDecoderInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_AnnotDecoder_AnnotDecoderInterface { 24 | /** 25 | * @abstract 26 | * @param string $annotsRaw 27 | * @param bool $withBase 28 | * @return array 29 | */ 30 | function decode($annotsRaw, $withBase); 31 | } -------------------------------------------------------------------------------- /src/phpMorphy/AnnotDecoder/Common.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_AnnotDecoder_Common extends phpMorphy_AnnotDecoder_AnnotDecoderAbstract { 24 | protected function getUnpackString() { 25 | return 'Voffset/vcplen/vplen/vflen/vcommon_ancode/vforms_count/vpacked_forms_count/vaffixes_size/vform_no/vpos_id'; 26 | // return 'Voffset/vcplen/vplen/vflen/vcommon_ancode/vforms_count/vpacked_forms_count/vaffixes_size/vpos_id'; 27 | } 28 | 29 | protected function getUnpackBlockSize() { 30 | return 22; 31 | } 32 | } -------------------------------------------------------------------------------- /src/phpMorphy/AnnotDecoder/Predict.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_AnnotDecoder_Predict extends phpMorphy_AnnotDecoder_Common { 24 | protected function getUnpackString() { 25 | // return 'Voffset/vcplen/vplen/vflen/vcommon_ancode/vforms_count/vpacked_forms_count/vaffixes_size/vform_no/vpos_id/vfreq'; 26 | return parent::getUnpackString() . '/vfreq'; 27 | } 28 | 29 | protected function getUnpackBlockSize() { 30 | return parent::getUnpackBlockSize() + 2; 31 | } 32 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_GramTab_Exception extends Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/GramInfo/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_GramTab_GramInfo_Empty extends phpMorphy_Aot_GramTab_GramInfo { 24 | function __construct($ancode) { 25 | //parent::__construct('*', '', $ancode); 26 | parent::__construct('UNKNOWN', 'unknown, grammems', $ancode, true); 27 | } 28 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/GramInfoHelper/English.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_GramTab_GramInfoHelper_English 24 | extends phpMorphy_Aot_GramTab_GramInfoHelperAbstract 25 | { 26 | /** 27 | * @param string $partOfSpeech 28 | * @param string[] $grammems 29 | * @return string 30 | */ 31 | function convertPartOfSpeech($partOfSpeech, $grammems) { 32 | return $partOfSpeech; 33 | } 34 | 35 | /** 36 | * @param string $partOfSpeech 37 | * @return bool 38 | */ 39 | function isPartOfSpeechProductive($partOfSpeech) { 40 | static $map = array( 41 | "NOUN" => 1, 42 | "VERB" => 1, 43 | "ADJECTIVE" => 1, 44 | "ADVERB" => 1, 45 | ); 46 | 47 | return isset($map[$partOfSpeech]); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/GramInfoHelper/German.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_GramTab_GramInfoHelper_German 24 | extends phpMorphy_Aot_GramTab_GramInfoHelperAbstract 25 | { 26 | /** 27 | * @param string $partOfSpeech 28 | * @param string[] $grammems 29 | * @return string 30 | */ 31 | function convertPartOfSpeech($partOfSpeech, $grammems) { 32 | return $partOfSpeech; 33 | } 34 | 35 | /** 36 | * @param string $partOfSpeech 37 | * @return bool 38 | */ 39 | function isPartOfSpeechProductive($partOfSpeech) { 40 | static $map = array( 41 | "SUB" => 1, 42 | "VER" => 1, 43 | "ADJ" => 1, 44 | "ADV" => 1, 45 | ); 46 | 47 | return isset($map[$partOfSpeech]); 48 | } 49 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/GramInfoHelperAbstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | abstract class phpMorphy_Aot_GramTab_GramInfoHelperAbstract 24 | implements phpMorphy_Aot_GramTab_GramInfoHelperInterface 25 | { 26 | /** 27 | * @static 28 | * @throws phpMorphy_Exception 29 | * @param $language 30 | * @return phpMorphy_Aot_GramTab_GramInfoHelperInterface 31 | */ 32 | static function createByLanguage($language) { 33 | switch(strtolower($language)) { 34 | case 'russian': 35 | return new phpMorphy_Aot_GramTab_GramInfoHelper_Russian(); 36 | case 'english': 37 | return new phpMorphy_Aot_GramTab_GramInfoHelper_English(); 38 | case 'german': 39 | return new phpMorphy_Aot_GramTab_GramInfoHelper_German(); 40 | default: throw new phpMorphy_Exception("Unknown '$language' language"); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/GramTab/GramInfoHelperInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Aot_GramTab_GramInfoHelperInterface { 24 | /** 25 | * @param string $partOfSpeech 26 | * @param string[] $grammems 27 | * @return string 28 | */ 29 | function convertPartOfSpeech($partOfSpeech, $grammems); 30 | 31 | /** 32 | * @param string $partOfSpeech 33 | * @return bool 34 | */ 35 | function isPartOfSpeechProductive($partOfSpeech); 36 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mrd/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mrd_Exception extends Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mrd/Section/Accents.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mrd_Section_Accents extends phpMorphy_Aot_Mrd_SectionAbstract { 24 | const UNKNOWN_ACCENT_VALUE = 255; 25 | 26 | protected function processLine($line) { 27 | if(substr($line, -1, 1) == ';') { 28 | $line = substr($line, 0, -1); 29 | } 30 | 31 | $result = new phpMorphy_Dict_AccentModel($this->getPosition()); 32 | $result->import( 33 | new ArrayIterator( 34 | array_map( 35 | array($this, 'processAccentValue'), 36 | explode(';', $line) 37 | ) 38 | ) 39 | ); 40 | 41 | return $result; 42 | } 43 | 44 | protected function processAccentValue($item) { 45 | $item = (int)$item; 46 | 47 | if($item == self::UNKNOWN_ACCENT_VALUE) { 48 | $item = null; 49 | } 50 | 51 | return $item; 52 | } 53 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mrd/Section/Lemmas.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mrd_Section_Lemmas extends phpMorphy_Aot_Mrd_SectionAbstract { 24 | protected function processLine($line) { 25 | //if(6 != count($tokens = array_map('trim', explode(' ', $line)))) { 26 | $line = $this->iconv($line); 27 | 28 | if(6 != count($tokens = explode(' ', $line))) { 29 | throw new phpMorphy_Aot_Mrd_Exception("Invalid lemma str('$line'), too few tokens"); 30 | } 31 | 32 | $base = trim($tokens[0]); 33 | 34 | if($base === '#') { 35 | $base = ''; 36 | } 37 | 38 | $lemma = new phpMorphy_Dict_Lemma( 39 | $base, //$this->iconv(trim($tokens[0])), // base 40 | (int)$tokens[1], // flexia_id 41 | (int)$tokens[2] // accent_id 42 | ); 43 | 44 | if('-' !== $tokens[4]) { 45 | $lemma->setAncodeId($tokens[4]); 46 | } 47 | 48 | if('-' !== $tokens[5]) { 49 | $lemma->setPrefixId((int)$tokens[5]); 50 | } 51 | 52 | return $lemma; 53 | } 54 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mrd/Section/Prefixes.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mrd_Section_Prefixes extends phpMorphy_Aot_Mrd_SectionAbstract { 24 | protected function processLine($line) { 25 | $line = $this->iconv($line); 26 | 27 | $result = new phpMorphy_Dict_PrefixSet($this->getPosition()); 28 | 29 | $result->import( 30 | new ArrayIterator( 31 | array_map('trim', explode(',', $line)) 32 | ) 33 | ); 34 | 35 | return $result; 36 | } 37 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mrd/Section/Sessions.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mrd_Section_Sessions extends phpMorphy_Aot_Mrd_SectionAbstract { 24 | } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Mwz/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Mwz_Exception extends Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/Aot/Rml/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Aot_Rml_Exception extends Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/DecoratorInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_DecoratorInterface { 24 | /** 25 | * @abstract 26 | * @return mixed 27 | */ 28 | public function getDecorateeObject(); 29 | } 30 | -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Flexia.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Flexia { 24 | protected 25 | $prefix, 26 | $suffix, 27 | $ancode_id; 28 | 29 | function __construct($prefix, $suffix, $ancodeId) { 30 | //phpMorphy_Dict_Ancode::checkAncodeId($ancodeId, "Invalid ancode specified for flexia"); 31 | 32 | $this->setPrefix($prefix); 33 | $this->setSuffix($suffix); 34 | $this->setAncodeId($ancodeId); 35 | } 36 | 37 | function setPrefix($prefix) { $this->prefix = (string)$prefix; } 38 | function setSuffix($suffix) { $this->suffix = (string)$suffix; } 39 | function setAncodeId($id) { $this->ancode_id = $id; } 40 | 41 | function getPrefix() { return $this->prefix; } 42 | function getSuffix() { return $this->suffix; } 43 | function getAncodeId() { return $this->ancode_id; } 44 | 45 | function __toString() { 46 | return phpMorphy_Dict_ModelsFormatter::create()->formatFlexia($this); 47 | } 48 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/FlexiaModel.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_FlexiaModel extends phpMorphy_Util_Collection_ArrayBased/*_Typed */{ 24 | protected 25 | $id; 26 | 27 | function __construct($id) { 28 | parent::__construct(/*$this->createStorageCollection(), 'phpMorphy_Dict_Flexia'*/); 29 | 30 | $this->setId($id); 31 | 32 | } 33 | 34 | function setId($id) { 35 | $this->id = $id; 36 | } 37 | 38 | function getId() { 39 | return $this->id; 40 | } 41 | 42 | function getFlexias() { 43 | return $this->getData(); 44 | } 45 | 46 | /* 47 | protected function createStorageCollection() { 48 | return new phpMorphy_Util_Collection_ArrayBased(); 49 | } 50 | */ 51 | 52 | function __toString() { 53 | return phpMorphy_Dict_ModelsFormatter::create()->formatFlexiaModel($this); 54 | } 55 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/GramTab/ConstStorage/Specials.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_GramTab_ConstStorage_Specials extends phpMorphy_Dict_GramTab_ConstStorage { 24 | function getDeletedTagName() { 25 | return 'DELETED'; 26 | } 27 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/GramTab/ConstStorage/data/lang_map.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | return array( 24 | 'ru_ru' => 'rus.xml', 25 | 'rus' => 'rus.xml', 26 | 27 | 'en_en' => 'eng.xml', 28 | 'eng' => 'eng.xml', 29 | 30 | 'de_de' => 'ger.xml', 31 | 'ger' => 'ger.xml', 32 | 33 | 'specials' => 'specials.xml', 34 | 35 | // for all others 36 | false => 'unk.xml' 37 | ); 38 | -------------------------------------------------------------------------------- /src/phpMorphy/Dict/GramTab/ConstStorage/data/specials.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Special 5 | SPECIAL 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/phpMorphy/Dict/GramTab/ConstStorage/data/unk.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Unknown 5 | U 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Grammem.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Grammem { 24 | private 25 | $id, 26 | $name, 27 | $shift; 28 | 29 | function __construct($id, $name, $shift) { 30 | $this->id = (int)$id; 31 | $this->shift = (int)$shift; 32 | $this->name = (string)$name; 33 | } 34 | 35 | function getName() { 36 | return $this->name; 37 | } 38 | 39 | function getId() { 40 | return $this->id; 41 | } 42 | 43 | function getShift() { 44 | return $this->shift; 45 | } 46 | 47 | function __toString() { 48 | return phpMorphy_Dict_ModelsFormatter::create()->formatGrammem($this); 49 | } 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/PartOfSpeech.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_PartOfSpeech { 24 | private 25 | $id, 26 | $name, 27 | $is_predict; 28 | 29 | function __construct($id, $name, $isPredict) { 30 | $this->id = (int)$id; 31 | $this->is_predict = (bool)$isPredict; 32 | $this->name = (string)$name; 33 | } 34 | 35 | function getName() { 36 | return $this->name; 37 | } 38 | 39 | function getId() { 40 | return $this->id; 41 | } 42 | 43 | function isPredict() { 44 | return $this->is_predict; 45 | } 46 | 47 | function __toString() { 48 | return phpMorphy_Dict_ModelsFormatter::create()->formatPartOfSpeech($this); 49 | } 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/PrefixSet.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_PrefixSet extends phpMorphy_Util_Collection_ArrayBased/*_Typed*/ { 24 | protected 25 | $id; 26 | 27 | function __construct($id) { 28 | parent::__construct(/*$this->createStorageCollection(), 'string'*/); 29 | 30 | $this->setId($id); 31 | } 32 | 33 | function setId($id) { 34 | $this->id = $id; 35 | } 36 | 37 | function getId() { 38 | return $this->id; 39 | } 40 | 41 | /** 42 | * @param bool $extendIfEmpty 43 | * @return string[] 44 | */ 45 | function getPrefixes($extendIfEmpty = false) { 46 | if($extendIfEmpty && !$this->count()) { 47 | return array(''); 48 | } else { 49 | return $this->getData(); 50 | } 51 | } 52 | 53 | /* 54 | protected function createStorageCollection() { 55 | return new phpMorphy_Util_Collection_ArrayBased(); 56 | } 57 | */ 58 | 59 | function __toString() { 60 | return phpMorphy_Dict_ModelsFormatter::create()->formatPrefixSet($this); 61 | } 62 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodes/Ancode.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_NormalizedAncodes_Ancode { 25 | private 26 | $id, 27 | $name, 28 | $pos_id, 29 | $grammems_ids 30 | ; 31 | 32 | function __construct($id, $name, $posId, $grammemsIds) { 33 | $this->id = (int)$id; 34 | $this->pos_id = (int)$posId; 35 | $this->grammems_ids = array_map('intval', (array)$grammemsIds); 36 | $this->name = (string)$name; 37 | } 38 | 39 | function getId() { 40 | return $this->id; 41 | } 42 | 43 | function getPartOfSpeechId() { 44 | return $this->pos_id; 45 | } 46 | 47 | function getGrammemsIds() { 48 | return $this->grammems_ids; 49 | } 50 | 51 | function getName() { 52 | return $this->name; 53 | } 54 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodes/DecoratingIterator.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_NormalizedAncodes_DecoratingIterator extends IteratorIterator { 25 | protected 26 | $manager, 27 | $new_class; 28 | 29 | function __construct(Traversable $it, phpMorphy_Dict_Source_NormalizedAncodes_AncodesManager $manager, $newClass) { 30 | parent::__construct($it); 31 | 32 | $this->manager = $manager; 33 | $this->new_class = $newClass; 34 | } 35 | 36 | function current() { 37 | return $this->decorate(parent::current()); 38 | } 39 | 40 | protected function decorate($object) { 41 | $new_class = $this->new_class; 42 | 43 | return new $new_class($this->manager, $object); 44 | } 45 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodes/Flexia.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_NormalizedAncodes_Flexia extends phpMorphy_Dict_FlexiaDecorator { 25 | protected 26 | $manager; 27 | 28 | function __construct(phpMorphy_Dict_Source_NormalizedAncodes_AncodesManager $manager, phpMorphy_Dict_Flexia $inner) { 29 | parent::__construct($inner); 30 | $this->manager = $manager; 31 | } 32 | 33 | function getAncodeId() { return $this->manager->resolveAncode(parent::getAncodeId()); } 34 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodes/FlexiaModel.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_NormalizedAncodes_FlexiaModel extends phpMorphy_Dict_FlexiaModelDecorator { 25 | protected $manager; 26 | 27 | function __construct(phpMorphy_Dict_Source_NormalizedAncodes_AncodesManager $manager, phpMorphy_Dict_FlexiaModel $inner) { 28 | parent::__construct($inner); 29 | $this->manager = $manager; 30 | } 31 | 32 | function getIterator() { 33 | $that = $this; 34 | 35 | return new phpMorphy_Util_Iterator_Transform( 36 | parent::getIterator(), 37 | function(phpMorphy_Dict_Flexia $flexia) use ($that) { 38 | return $that->__decorate($flexia); 39 | } 40 | ); 41 | } 42 | 43 | function offsetGet($offset) { 44 | return $this->__decorate(parent::offsetGet($offset)); 45 | } 46 | 47 | function __decorate(phpMorphy_Dict_Flexia $flexia) { 48 | return new phpMorphy_Dict_Source_NormalizedAncodes_Flexia($this->manager, $flexia); 49 | } 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodes/Lemma.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_NormalizedAncodes_Lemma extends phpMorphy_Dict_LemmaDecorator { 25 | protected 26 | $manager; 27 | 28 | function __construct(phpMorphy_Dict_Source_NormalizedAncodes_AncodesManager $manager, phpMorphy_Dict_Lemma $inner) { 29 | parent::__construct($inner); 30 | $this->manager = $manager; 31 | } 32 | 33 | function getAncodeId() { 34 | return $this->manager->resolveAncode(parent::getAncodeId()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/NormalizedAncodesInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | interface phpMorphy_Dict_Source_NormalizedAncodesInterface { 26 | function getPoses(); 27 | function getGrammems(); 28 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/SourceInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Dict_Source_SourceInterface { 24 | /** 25 | * @return string 26 | */ 27 | function getName(); 28 | /** 29 | * ISO3166 country code separated by underscore(_) from ISO639 language code 30 | * ru_RU, uk_UA for example 31 | * @return string 32 | */ 33 | function getLanguage(); 34 | /** 35 | * Any string 36 | * @return string 37 | */ 38 | function getDescription(); 39 | 40 | /** 41 | * @return Iterator over objects of phpMorphy_Dict_Ancode 42 | */ 43 | function getAncodes(); 44 | /** 45 | * @return Iterator over objects of phpMorphy_Dict_FlexiaModel 46 | */ 47 | function getFlexias(); 48 | /** 49 | * @return Iterator over objects of phpMorphy_Dict_PrefixSet 50 | */ 51 | function getPrefixes(); 52 | /** 53 | * @return Iterator over objects of phpMorphy_Dict_AccentModel 54 | */ 55 | function getAccents(); 56 | /** 57 | * @return Iterator over objects of phpMorphy_Dict_Lemma 58 | */ 59 | function getLemmas(); 60 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/ValidatingSource/Iterator.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Dict_Source_ValidatingSource_Iterator extends IteratorIterator { 25 | /** @var Closure */ 26 | private $callback; 27 | 28 | function __construct($iterator, $callback) { 29 | parent::__construct(is_array($iterator) ? new ArrayIterator($iterator) : $iterator); 30 | $this->callback = $callback; 31 | } 32 | 33 | function current() { 34 | $value = parent::current(); 35 | 36 | $fn = $this->callback; 37 | $fn($value); 38 | 39 | return $value; 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/ValidatingSource/ValidatorInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | interface phpMorphy_Dict_Source_ValidatingSource_ValidatorInterface { 26 | function validateFlexiaId($id); 27 | function validateAccentId($id); 28 | function validateSessionId($id); 29 | function validatePrefixId($id); 30 | function validateAncodeId($id); 31 | function validatePartOfSpeechId($id); 32 | function validateGrammemId($id); 33 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/ValidatingSource/ValidatorSection.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | class phpMorphy_Dict_Source_ValidatingSource_ValidatorSection implements Countable{ 26 | protected $map = array(); 27 | 28 | function insertId($id) { 29 | if($this->hasId($id)) { 30 | return true; 31 | } 32 | 33 | $this->map[$id] = true; 34 | return false; 35 | } 36 | 37 | function hasId($id) { 38 | return isset($this->map[$id]); 39 | } 40 | 41 | public function count() { 42 | return count($this->map); 43 | } 44 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/Xml/Section/Grammems.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Source_Xml_Section_Grammems extends phpMorphy_Dict_Source_Xml_SectionAbstract { 24 | protected 25 | $current; 26 | 27 | protected function getSectionName() { 28 | return 'grammems'; 29 | } 30 | 31 | function rewind() { 32 | $this->current = null; 33 | 34 | parent::rewind(); 35 | } 36 | 37 | protected function readNext(XMLReader $reader) { 38 | do { 39 | if($this->isStartElement('grammem')) { 40 | $this->current = array( 41 | 'id' => (int)$reader->getAttribute('id'), 42 | 'name' => $reader->getAttribute('name') 43 | ); 44 | 45 | $this->read(); 46 | 47 | break; 48 | } 49 | } while($this->read()); 50 | } 51 | 52 | protected function getCurrentKey() { 53 | return $this->current['id']; 54 | } 55 | 56 | protected function getCurrentValue() { 57 | return $this->current; 58 | } 59 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Source/Xml/Section/Options.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Source_Xml_Section_Options extends phpMorphy_Dict_Source_Xml_SectionAbstract { 24 | protected 25 | $current; 26 | 27 | protected function getSectionName() { 28 | return 'options'; 29 | } 30 | 31 | protected function readNext(XMLReader $reader) { 32 | do { 33 | if($this->isStartElement('locale')) { 34 | if(!$this->current = $reader->getAttribute('name')) { 35 | throw new Exception('Empty locale name found'); 36 | } 37 | 38 | $this->read(); 39 | 40 | break; 41 | } 42 | } while($this->read()); 43 | } 44 | 45 | function rewind() { 46 | $this->current = null; 47 | 48 | parent::rewind(); 49 | } 50 | 51 | protected function getCurrentKey() { 52 | return 'locale'; 53 | } 54 | 55 | protected function getCurrentValue() { 56 | return $this->current; 57 | } 58 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Writer/Observer/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Writer_Observer_Empty implements phpMorphy_Dict_Writer_Observer_ObserverInterface { 24 | function onStart() { } 25 | function onLog($message) { } 26 | function onEnd() { } 27 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Writer/Observer/ObserverInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Dict_Writer_Observer_ObserverInterface { 24 | function onStart(); 25 | function onLog($message); 26 | function onEnd(); 27 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Writer/Observer/Standart.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Dict_Writer_Observer_Standart implements phpMorphy_Dict_Writer_Observer_ObserverInterface { 24 | protected 25 | $start_time; 26 | 27 | function __construct($callback) { 28 | if(!is_callable($callback)) { 29 | throw new Exception("Invalid callback"); 30 | } 31 | 32 | $this->callback = $callback; 33 | } 34 | 35 | function onStart() { 36 | $this->start_time = microtime(true); 37 | } 38 | 39 | function onEnd() { 40 | $this->writeMessage(sprintf("Total time = %f", microtime(true) - $this->start_time)); 41 | } 42 | 43 | function onLog($message) { 44 | $this->writeMessage(sprintf("+%0.2f %s", microtime(true) - $this->start_time, $message)); 45 | } 46 | 47 | protected function writeMessage($msg) { 48 | call_user_func($this->callback, $msg); 49 | } 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Writer/WriterAbstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | abstract class phpMorphy_Dict_Writer_WriterAbstract implements phpMorphy_Dict_Writer_WriterInterface { 24 | private $observer; 25 | 26 | function __construct() { 27 | $this->setObserver(new phpMorphy_Dict_Writer_Observer_Empty()); 28 | } 29 | 30 | function setObserver(phpMorphy_Dict_Writer_Observer_ObserverInterface $observer) { 31 | $this->observer = $observer; 32 | } 33 | 34 | function hasObserver() { 35 | return isset($this->observer); 36 | } 37 | 38 | function getObserver() { 39 | return $this->observer; 40 | } 41 | 42 | protected function log($message) { 43 | if($this->hasObserver()) { 44 | $this->getObserver()->onLog($message); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/phpMorphy/Dict/Writer/WriterInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Dict_Writer_WriterInterface { 24 | function write(phpMorphy_Dict_Source_SourceInterface $source); 25 | } -------------------------------------------------------------------------------- /src/phpMorphy/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Exception extends Exception { 24 | } -------------------------------------------------------------------------------- /src/phpMorphy/Finder/FinderInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Finder_FinderInterface { 24 | /** 25 | * @abstract 26 | * @param string $word 27 | * @return void 28 | */ 29 | function findWord($word); 30 | 31 | /** 32 | * @abstract 33 | * @param string $raw 34 | * @param bool $withBase 35 | * @return array 36 | */ 37 | function decodeAnnot($raw, $withBase); 38 | 39 | /** 40 | * @abstract 41 | * @return phpMorphy_AnnotDecoder_AnnotDecoderInterface 42 | */ 43 | function getAnnotDecoder(); 44 | } -------------------------------------------------------------------------------- /src/phpMorphy/Finder/Fsa/Finder.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | class phpMorphy_Finder_Fsa_Finder extends phpMorphy_Finder_FinderAbstract { 26 | protected 27 | $fsa, 28 | $root; 29 | 30 | function __construct(phpMorphy_Fsa_FsaInterface $fsa, phpMorphy_AnnotDecoder_AnnotDecoderInterface $annotDecoder) { 31 | parent::__construct($annotDecoder); 32 | 33 | $this->fsa = $fsa; 34 | $this->root = $this->fsa->getRootTrans(); 35 | } 36 | 37 | function getFsa() { 38 | return $this->fsa; 39 | } 40 | 41 | protected function doFindWord($word) { 42 | $result = $this->fsa->walk($this->root, $word); 43 | 44 | if(!$result['result'] || null === $result['annot']) { 45 | return false; 46 | } 47 | 48 | return $result['annot']; 49 | } 50 | } -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/Link.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Fsa_Link extends phpMorphy_Fsa_LinkAbstract { 24 | function isAnnotation() { return false; } 25 | 26 | function getDest() { return $this->trans['dest']; } 27 | function getAttr() { return $this->trans['attr']; } 28 | 29 | function getTargetState() { 30 | return $this->createState($this->trans['dest']); 31 | } 32 | 33 | protected function createState($index) { 34 | return new phpMorphy_Fsa_State($this->fsa, $index); 35 | } 36 | } -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/LinkAbstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | abstract class phpMorphy_Fsa_LinkAbstract { 24 | protected 25 | $fsa, 26 | $trans, 27 | $raw_trans; 28 | 29 | function phpMorphy_Fsa_LinkAbstract(phpMorphy_Fsa_FsaInterface $fsa, $trans, $rawTrans) { 30 | $this->fsa = $fsa; 31 | $this->trans = $trans; 32 | $this->raw_trans = $rawTrans; 33 | } 34 | 35 | function isAnnotation() { } 36 | function getTrans() { return $this->trans; } 37 | function getFsa() { return $this->fsa; } 38 | function getRawTrans() { return $this->raw_trans; } 39 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/LinkAnnot.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Fsa_LinkAnnot extends phpMorphy_Fsa_LinkAbstract { 24 | function isAnnotation() { return true; } 25 | 26 | function getAnnotation() { 27 | return $this->fsa->getAnnot($this->raw_trans); 28 | } 29 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/Proxy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Fsa_Proxy extends phpMorphy_Fsa_Decorator { 24 | /** @var phpMorphy_Storage_StorageInterface */ 25 | private $storage; 26 | 27 | /** 28 | * @param phpMorphy_Storage_StorageInterface $storage 29 | */ 30 | function __construct(phpMorphy_Storage_StorageInterface $storage) { 31 | $this->storage = $storage; 32 | $this->actAsProxy(); 33 | } 34 | 35 | protected function proxyInstantiate() { 36 | $result = phpMorphy_Fsa_FsaAbstract::create($this->storage, false); 37 | unset($this->storage); 38 | 39 | return $result; 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/State.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Fsa_State { 24 | protected 25 | $fsa, 26 | $transes, 27 | $raw_transes; 28 | 29 | function phpMorphy_Fsa_State(phpMorphy_Fsa_FsaInterface $fsa, $index) { 30 | $this->fsa = $fsa; 31 | 32 | $this->raw_transes = $fsa->readState($index); 33 | $this->transes = $fsa->unpackTranses($this->raw_transes); 34 | } 35 | 36 | function getLinks() { 37 | $result = array(); 38 | 39 | for($i = 0, $c = count($this->transes); $i < $c; $i++) { 40 | $trans = $this->transes[$i]; 41 | 42 | if(!$trans['term']) { 43 | $result[] = $this->createNormalLink($trans, $this->raw_transes[$i]); 44 | } else { 45 | $result[] = $this->createAnnotLink($trans, $this->raw_transes[$i]); 46 | } 47 | } 48 | 49 | return $result; 50 | } 51 | 52 | function getSize() { return count($this->transes); } 53 | 54 | protected function createNormalLink($trans, $raw) { 55 | return new phpMorphy_Fsa_Link($this->fsa, $trans, $raw); 56 | } 57 | 58 | protected function createAnnotLink($trans, $raw) { 59 | return new phpMorphy_Fsa_LinkAnnot($this->fsa, $trans, $raw); 60 | } 61 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Fsa/WordsCollector.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Fsa_WordsCollector { 24 | protected 25 | $items = array(), 26 | $limit; 27 | 28 | function __construct($collectLimit) { 29 | $this->limit = $collectLimit; 30 | } 31 | 32 | function collect($word, $annot) { 33 | if(count($this->items) < $this->limit) { 34 | $this->items[$word] = $annot; 35 | return true; 36 | } else { 37 | return false; 38 | } 39 | } 40 | 41 | function getItems() { return $this->items; } 42 | function clear() { $this->items = array(); } 43 | function getCallback() { return array($this, 'collect'); } 44 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Sparse/extra_funcs.tpl.php: -------------------------------------------------------------------------------- 1 | function getAlphabetNum() { 2 | if(!isset($this->alphabet_num)) { 3 | $this->alphabet_num = array_map('ord', $this->getAlphabet()); 4 | } 5 | 6 | return $this->alphabet_num; 7 | } 8 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Sparse/extra_props.tpl.php: -------------------------------------------------------------------------------- 1 | protected $alphabet_num; -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Sparse/find_char_in_state.tpl.php: -------------------------------------------------------------------------------- 1 | // sparse version 2 | $result = true; 3 | out($helper->seekTrans('$trans', '$char'), ';'); ?> 4 | list(, $trans) = readTrans('$trans', '$char') ?>; 5 | 6 | if(checkEmpty('$trans') ?> || getChar('$trans') ?> != $char) { 7 | $result = false; 8 | } 9 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Sparse/read_state.tpl.php: -------------------------------------------------------------------------------- 1 | $start_offset = getOffsetInFsa($helper->idx2offset('$index')) ?>; 2 | 3 | // first try read annot transition 4 | out($helper->getStorage()->seek('$start_offset'), ';'); ?> 5 | list(, $trans) = unpackTrans($helper->getStorage()->read('$start_offset', $helper->getTransSize())) ?>; 6 | 7 | if(checkTerm('$trans') ?>) { 8 | $result[] = $trans; 9 | } 10 | 11 | // read rest 12 | $start_offset += getTransSize() ?>; 13 | foreach($this->getAlphabetNum() as $char) { 14 | idx2offset('$char') ?> 15 | out($helper->getStorage()->seek($offset), ';'); ?> 16 | list(, $trans) = unpackTrans($helper->getStorage()->read($offset, $helper->getTransSize())) ?>; 17 | 18 | // if(!checkEmpty('$trans') ?> && getChar('$trans') ?> == $char) { 19 | // TODO: check term and empty flags at once i.e. $trans & 0x0300 20 | if(!(checkEmpty('$trans') ?> || checkTerm('$trans') ?>) && getChar('$trans') ?> == $char) { 21 | 22 | $result[] = $trans; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Sparse/unpack_trans.tpl.php: -------------------------------------------------------------------------------- 1 | array( 2 | 'term' => checkTerm('$rawTrans') ?> ? true : false, 3 | 'empty' => checkEmpty('$rawTrans') ?> ? true : false, 4 | 'attr' => getChar('$rawTrans') ?>, 5 | 'dest' => getDest('$rawTrans') ?>, 6 | ) -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Tree/extra_funcs.tpl.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heromantor/phpmorphy/45204ee423290ab7d278bd7ac5d74f07aacd987c/src/phpMorphy/Generator/Fsa/tpl/Tree/extra_funcs.tpl.php -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Tree/extra_props.tpl.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heromantor/phpmorphy/45204ee423290ab7d278bd7ac5d74f07aacd987c/src/phpMorphy/Generator/Fsa/tpl/Tree/extra_props.tpl.php -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Tree/read_state.tpl.php: -------------------------------------------------------------------------------- 1 | $offset = getOffsetInFsa($helper->idx2offset('$index')) ?>; 2 | 3 | // read first trans 4 | out($helper->getStorage()->seek('$offset'), ';'); ?> 5 | list(, $trans) = unpackTrans($helper->getStorage()->read('$offset', $helper->getTransSize())) ?>; 6 | 7 | // check if first trans is pointer to annot, and not single in state 8 | if(checkTerm('$trans') ?> && !(checkLLast('$trans') ?> || checkRLast('$trans') ?>)) { 9 | $result[] = $trans; 10 | 11 | list(, $trans) = unpackTrans($helper->getStorage()->read('$offset', $helper->getTransSize())) ?>; 12 | $offset += getTransSize(); ?>; 13 | } 14 | 15 | // read rest 16 | for($expect = 1; $expect; $expect--) { 17 | if(!checkLLast('$trans') ?>) $expect++; 18 | if(!checkRLast('$trans') ?>) $expect++; 19 | 20 | $result[] = $trans; 21 | 22 | if($expect > 1) { 23 | list(, $trans) = unpackTrans($helper->getStorage()->read('$offset', $helper->getTransSize())) ?>; 24 | $offset += getTransSize(); ?>; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Fsa/tpl/Tree/unpack_trans.tpl.php: -------------------------------------------------------------------------------- 1 | array( 2 | 'term' => checkTerm('$rawTrans') ?> ? true : false, 3 | 'llast' => checkLLast('$rawTrans') ?> ? true : false, 4 | 'rlast' => checkRLast('$rawTrans') ?> ? true : false, 5 | 'attr' => getChar('$rawTrans') ?>, 6 | 'dest' => getDest('$rawTrans') ?>, 7 | ) -------------------------------------------------------------------------------- /src/phpMorphy/Generator/GramInfo.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_GramInfo { 24 | /** 25 | * @param string $outputDirectory 26 | * @return void 27 | */ 28 | static function generate($outputDirectory) { 29 | $storage_ary = array('File', 'Mem', 'Shm'); 30 | 31 | $tpl = new phpMorphy_Generator_Template(__DIR__ . '/GramInfo/tpl'); 32 | $helper_class = "phpMorphy_Generator_TemplateHelper_Fsa"; 33 | 34 | foreach($storage_ary as $storage_name) { 35 | $storage_class = "phpMorphy_Generator_StorageHelper_" . ucfirst($storage_name); 36 | $helper = new phpMorphy_Generator_GramInfo_Helper($tpl, new $storage_class()); 37 | 38 | $result = $tpl->get('graminfo', array('helper' => $helper)); 39 | 40 | $file_path = 41 | $outputDirectory . DIRECTORY_SEPARATOR . 42 | phpMorphy_Loader::classNameToFilePath($helper->getClassName()); 43 | 44 | @mkdir(dirname($file_path), 0744, true); 45 | file_put_contents($file_path, $result); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/GramInfo/Helper.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_GramInfo_Helper extends phpMorphy_Generator_HelperAbstract { 24 | /** 25 | * @return string 26 | */ 27 | function getParentClassName() { 28 | return 'phpMorphy_GramInfo_GramInfoAbstract'; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | function getClassName() { 35 | $storage_type = ucfirst($this->storage->getType()); 36 | 37 | return "phpMorphy_GramInfo_$storage_type"; 38 | } 39 | 40 | /** 41 | * @return string 42 | */ 43 | function prolog() { 44 | return $this->storage->prolog(); 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | function getInfoHeaderSize() { 51 | return 20; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | function getStartOffset() { 58 | return '0x100'; 59 | } 60 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/GramTab/tpl/cpp/declaration.tpl.php: -------------------------------------------------------------------------------- 1 | // This file is autogenerated at , don`t change it! 2 | #ifndef _MORPHY_LIBMORPHY_GRAMTAB_HPP 3 | #define _MORPHY_LIBMORPHY_GRAMTAB_HPP 4 | 5 | #include 6 | #include "morph_data.hpp" 7 | 8 | namespace morphy { namespace libmorphy { namespace GramTab { 9 | 10 | using morphy::libmorphy::MorphData::BitString; 11 | 12 | 13 | namespace getLanguage(), MB_CASE_TITLE, 'utf-8'); ?> { 14 | namespace PartOfSpeech { 15 | getPosesMap() as $item): ?> 16 | LIBMORPHY_API extern const uint16_t ; // name => 17 | 18 | } // namespace PartOfSpeech { 19 | 20 | namespace Grammem { 21 | getGrammemsMap() as $item): ?> 22 | LIBMORPHY_API extern const BitString ; // name => 23 | 24 | 25 | getMetaGrammemsMap() as $item): ?> 26 | LIBMORPHY_API extern const BitString ; 27 | 28 | } // namespace Grammem { 29 | 30 | namespace g = Grammem; 31 | namespace p = PartOfSpeech; 32 | } // namespace 33 | 34 | 35 | 36 | } } } // namespace morphy { namespace libmorphy { namespace GramTab { 37 | #endif _MORPHY_LIBMORPHY_GRAMTAB_HPP 38 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/GramTab/tpl/cpp/definition.tpl.php: -------------------------------------------------------------------------------- 1 | // This file is autogenerated at , don`t change it! 2 | #include "" 3 | 4 | namespace morphy { namespace libmorphy { namespace GramTab { 5 | 6 | static BitString init_bitstring(size_t shift) { 7 | BitString bs; 8 | bs.set(shift, 1); 9 | return bs; 10 | }; 11 | 12 | 13 | namespace getLanguage(), MB_CASE_TITLE, 'utf-8'); ?> { 14 | namespace PartOfSpeech { 15 | getPosesMap() as $item): ?> 16 | const uint16_t = ; 17 | 18 | } // namespace PartOfSpeech { 19 | 20 | namespace Grammem { 21 | getGrammemsMap() as $item): ?> 22 | const BitString = init_bitstring(); 23 | 24 | 25 | getMetaGrammemsMap() as $item): ?> 26 | const BitString = ; 27 | 28 | } // namespace Grammem { 29 | } // namespace 30 | 31 | 32 | 33 | } } } // namespace morphy { namespace libmorphy { namespace GramTab { 34 | -------------------------------------------------------------------------------- /src/phpMorphy/Generator/HelperAbstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | abstract class phpMorphy_Generator_HelperAbstract { 24 | /* @var phpMorphy_Generator_Template */ 25 | protected $tpl; 26 | /* @var phpMorphy_Generator_StorageHelperInterface */ 27 | protected $storage; 28 | 29 | /** 30 | * @param phpMorphy_Generator_Template $tpl 31 | * @param phpMorphy_Generator_StorageHelperInterface $storage 32 | */ 33 | function __construct(phpMorphy_Generator_Template $tpl, phpMorphy_Generator_StorageHelperInterface $storage) { 34 | $this->tpl = $tpl; 35 | $this->storage = $storage; 36 | } 37 | 38 | /** 39 | * @return phpMorphy_Generator_StorageHelperInterface 40 | */ 41 | function getStorage() { 42 | return $this->storage; 43 | } 44 | 45 | /** 46 | * @param string $str 47 | * @param string $suffix 48 | * @return void 49 | */ 50 | function out($str, $suffix) { 51 | if(strlen($str)) { 52 | echo $str, $suffix; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/PhpFileParser/ClassDescriptor.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Generator_PhpFileParser_ClassDescriptor { 25 | const IS_INTERFACE = 'interface'; 26 | const IS_CLASS = 'class'; 27 | 28 | public 29 | /** @var string */ 30 | $namespace, 31 | /** @var IS_INTERFACE|IS_CLASS */ 32 | $type, 33 | /** @var string */ 34 | $name, 35 | /** @var int */ 36 | $startLine, 37 | /** @var int */ 38 | $endLine, 39 | /** @var phpMorphy_Generator_PhpFileParser_phpDoc */ 40 | $phpDoc; 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/PhpFileParser/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Generator_PhpFileParser_Exception extends Exception { 25 | function __construct($msg, array $token = null) { 26 | $msg = null === $token ? $msg : $msg . ', at ' . $token[2] . ' line'; 27 | 28 | parent::__construct($msg); 29 | } 30 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/PhpFileParser/FileDescriptor.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_PhpFileParser_FileDescriptor { 24 | public 25 | /** @var phpMorphy_Generator_PhpFileParser_ClassDescriptor[] */ 26 | $classes = array(), 27 | /** @var phpMorphy_Generator_PhpFileParser_phpDoc */ 28 | $phpDoc; 29 | 30 | function finalize() { 31 | if(null !== $this->phpDoc) { 32 | foreach($this->classes as $class) { 33 | if( 34 | null !== $class->phpDoc && 35 | $class->phpDoc->startLine === $this->phpDoc->startLine && 36 | $class->phpDoc->endLine === $this->phpDoc->endLine 37 | ) { 38 | $this->phpDoc = null; 39 | } 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/PhpFileParser/phpDoc.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_PhpFileParser_phpDoc { 24 | public 25 | /** @var string */ 26 | $text, 27 | /** @var int */ 28 | $startLine, 29 | /** @var int */ 30 | $endLine; 31 | 32 | /** 33 | * @param array $token 34 | */ 35 | function __construct($token) { 36 | $this->startLine = $token[2]; 37 | $this->endLine = $this->startLine + substr_count($token[1], "\n"); 38 | $this->text = $token[1]; 39 | } 40 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/StorageHelper/File.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_StorageHelper_File implements phpMorphy_Generator_StorageHelperInterface { 24 | /** 25 | * @return string 26 | */ 27 | function getType() { 28 | return 'file'; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | function prolog() { return '$__fh = $this->resource'; } 35 | 36 | /** 37 | * @return string 38 | */ 39 | function seek($offset) { return 'fseek($__fh, ' . $offset . ')'; } 40 | 41 | /** 42 | * @return string 43 | */ 44 | function read($offset, $len) { return "fread(\$__fh, $len)"; } 45 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/StorageHelper/Mem.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_StorageHelper_Mem implements phpMorphy_Generator_StorageHelperInterface { 24 | /** 25 | * @return string 26 | */ 27 | function getType() { 28 | return 'mem'; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | function prolog() { return '$__mem = $this->resource'; } 35 | 36 | /** 37 | * @return string 38 | */ 39 | function seek($offset) { return ''; } 40 | 41 | /** 42 | * @return string 43 | */ 44 | function read($offset, $len) { return "\$GLOBALS['__phpmorphy_substr'](\$__mem, $offset, $len)"; } 45 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/StorageHelper/Shm.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_StorageHelper_Shm implements phpMorphy_Generator_StorageHelperInterface { 24 | /** 25 | * @return string 26 | */ 27 | function getType() { 28 | return 'shm'; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | function prolog() { return '$__shm = $this->resource[\'shm_id\']; $__offset = $this->resource[\'offset\']'; } 35 | 36 | /** 37 | * @return string 38 | */ 39 | function seek($offset) { return ''; } 40 | 41 | /** 42 | * @return string 43 | */ 44 | function read($offset, $len) { return "shmop_read(\$__shm, \$__offset + ($offset), $len)"; } 45 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/StorageHelperInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Generator_StorageHelperInterface { 24 | /** 25 | * @return string 26 | */ 27 | function getType(); 28 | 29 | /** 30 | * @return string 31 | */ 32 | function prolog(); 33 | 34 | /** 35 | * @return string 36 | */ 37 | function seek($offset); 38 | 39 | /** 40 | * @return string 41 | */ 42 | function read($offset, $len); 43 | } -------------------------------------------------------------------------------- /src/phpMorphy/Generator/Template.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Generator_Template { 24 | /* @var string */ 25 | protected $template_dir; 26 | 27 | /** 28 | * @param string $dir 29 | */ 30 | function __construct($dir) { 31 | $this->template_dir = (string)$dir; 32 | } 33 | 34 | /** 35 | * @param string $templateFile 36 | * @param array $opts 37 | * @return string 38 | */ 39 | function get($templateFile, $opts) { 40 | ob_start(); 41 | 42 | extract($opts); 43 | 44 | $template_path = $this->template_dir . DIRECTORY_SEPARATOR . "$templateFile.tpl.php"; 45 | if(!file_exists($template_path)) { 46 | throw new phpMorphy_Exception("Template '$template_path' not found"); 47 | } 48 | 49 | include($template_path); 50 | 51 | $content = ob_get_contents(); 52 | if(!ob_end_clean()) { 53 | throw new phpMorphy_Exception("Can`t invoke ob_end_clean()"); 54 | } 55 | 56 | return $content; 57 | } 58 | }; -------------------------------------------------------------------------------- /src/phpMorphy/GramInfo/AncodeCache.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GramInfo_AncodeCache extends phpMorphy_GramInfo_Decorator { 24 | public 25 | $hits = 0, 26 | $miss = 0; 27 | 28 | protected 29 | $cache; 30 | 31 | function __construct(phpMorphy_GramInfo_GramInfoInterface $inner, $resource) { 32 | parent::__construct($inner); 33 | 34 | if(false === ($this->cache = unserialize($resource->read(0, $resource->getFileSize())))) { 35 | throw new phpMorphy_Exception("Can`t read ancodes cache"); 36 | } 37 | } 38 | 39 | function readAncodes($info) { 40 | $offset = $info['offset']; 41 | 42 | if(isset($this->cache[$offset])) { 43 | $this->hits++; 44 | 45 | return $this->cache[$offset]; 46 | } else { 47 | // in theory misses never occur 48 | $this->miss++; 49 | 50 | return parent::readAncodes($info); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/phpMorphy/GramInfo/Proxy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GramInfo_Proxy extends phpMorphy_GramInfo_Decorator { 24 | /** @var phpMorphy_Storage_StorageInterface */ 25 | private $storage; 26 | 27 | /** 28 | * @param phpMorphy_Storage_StorageInterface $storage 29 | */ 30 | function __construct(phpMorphy_Storage_StorageInterface $storage) { 31 | $this->storage = $storage; 32 | $this->actAsProxy(); 33 | } 34 | 35 | protected function proxyInstantiate() { 36 | $result = phpMorphy_GramInfo_GramInfoAbstract::create($this->storage, false); 37 | unset($this->storage); 38 | 39 | return $result; 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/GramInfo/RuntimeCache.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GramInfo_RuntimeCache extends phpMorphy_GramInfo_Decorator { 24 | protected 25 | $flexia = array(); 26 | 27 | function readFlexiaData($info) { 28 | $offset = $info['offset']; 29 | 30 | if(!isset($this->flexia[$offset])) { 31 | $this->flexia[$offset] = parent::readFlexiaData($info); 32 | } 33 | 34 | return $this->flexia[$offset]; 35 | } 36 | } -------------------------------------------------------------------------------- /src/phpMorphy/GramTab/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GramTab_Empty implements phpMorphy_GramTab_GramTabInterface { 24 | function getGrammems($ancodeId) { return array(); } 25 | function getPartOfSpeech($ancodeId) { return 0; } 26 | function resolveGrammemIds($ids) { return is_array($ids) ? array() : ''; } 27 | function resolvePartOfSpeechId($id) { return ''; } 28 | function includeConsts() { } 29 | function ancodeToString($ancodeId, $commonAncode = null) { return ''; } 30 | function stringToAncode($string) { return null; } 31 | function toString($partOfSpeechId, $grammemIds) { return ''; } 32 | } -------------------------------------------------------------------------------- /src/phpMorphy/GramTab/Proxy.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GramTab_Proxy extends phpMorphy_GramTab_Decorator { 24 | /** @var phpMorphy_Storage_StorageInterface */ 25 | private $storage; 26 | 27 | /** 28 | * @param phpMorphy_Storage_StorageInterface $storage 29 | */ 30 | function __construct(phpMorphy_Storage_StorageInterface $storage) { 31 | $this->storage = $storage; 32 | $this->actAsProxy(); 33 | } 34 | 35 | protected function proxyInstantiate() { 36 | $result = phpMorphy_GramTab_GramTab::create($this->storage); 37 | unset($this->storage); 38 | 39 | return $result; 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/GrammemsProvider/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GrammemsProvider_Empty extends phpMorphy_GrammemsProvider_GrammemsProviderAbstract { 24 | function getAllGrammemsGrouped() { 25 | return array(); 26 | } 27 | 28 | function getGrammems($partOfSpeech) { 29 | return false; 30 | } 31 | } -------------------------------------------------------------------------------- /src/phpMorphy/GrammemsProvider/Factory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_GrammemsProvider_Factory { 24 | protected static $included = array(); 25 | 26 | static function create(phpMorphy_MorphyInterface $morphy) { 27 | $locale = $GLOBALS['__phpmorphy_strtolower']($morphy->getLocale()); 28 | 29 | if(!isset(self::$included[$locale])) { 30 | $class = "phpMorphy_GrammemsProvider_$locale"; 31 | 32 | if(!class_exists($class)) { 33 | self::$included[$locale] = call_user_func(array($class, 'instance'), $morphy); 34 | } else { 35 | self::$included[$locale] = new phpMorphy_GrammemsProvider_Empty($morphy); 36 | } 37 | } 38 | 39 | 40 | return self::$included[$locale]; 41 | } 42 | } -------------------------------------------------------------------------------- /src/phpMorphy/GrammemsProvider/GrammemsProviderInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_GrammemsProvider_GrammemsProviderInterface { 24 | /** 25 | * @abstract 26 | * @param string $partOfSpeech 27 | * @return array 28 | */ 29 | function getGrammems($partOfSpeech); 30 | } -------------------------------------------------------------------------------- /src/phpMorphy/Morphier/Common.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Morphier_Common extends phpMorphy_Morphier_MorphierAbstract { 24 | function __construct(phpMorphy_Fsa_FsaInterface $fsa, phpMorphy_Helper $helper) { 25 | parent::__construct( 26 | new phpMorphy_Finder_Fsa_Finder( 27 | $fsa, 28 | $this->createAnnotDecoder($helper) 29 | ), 30 | $helper 31 | ); 32 | } 33 | 34 | protected function createAnnotDecoder(phpMorphy_Helper $helper) { 35 | return phpMorphy_AnnotDecoder_Factory::instance($helper->getEndOfString())->getCommonDecoder(); 36 | } 37 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Morphier/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Morphier_Empty implements phpMorphy_Morphier_MorphierInterface { 24 | function getAnnot($word) { return false; } 25 | function getBaseForm($word) { return false; } 26 | function getAllForms($word) { return false; } 27 | function getAllFormsWithGramInfo($word) { return false; } 28 | function getPseudoRoot($word) { return false; } 29 | function getPartOfSpeech($word) { return false; } 30 | function getParadigmCollection($word) { return false; } 31 | function getAllFormsWithAncodes($word) { return false; } 32 | function getAncode($word) { return false; } 33 | function getGrammarInfoMergeForms($word) { return false; } 34 | function getGrammarInfo($word) { return false; } 35 | function castFormByGramInfo($word, $partOfSpeech, $grammems, $returnWords = false, $callback = null) { return false; } 36 | } -------------------------------------------------------------------------------- /src/phpMorphy/Morphier/MorphierInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Morphier_MorphierInterface { 24 | function getAnnot($word); 25 | function getBaseForm($word); 26 | function getAllForms($word); 27 | function getPseudoRoot($word); 28 | function getPartOfSpeech($word); 29 | function getParadigmCollection($word); 30 | function getAllFormsWithAncodes($word); 31 | function getAncode($word); 32 | function getGrammarInfoMergeForms($word); 33 | function getGrammarInfo($word); 34 | } -------------------------------------------------------------------------------- /src/phpMorphy/Morphier/PredictByDatabase.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Morphier_PredictByDatabase extends phpMorphy_Morphier_MorphierAbstract { 24 | function __construct(phpMorphy_Fsa_FsaInterface $fsa, phpMorphy_Helper $helper) { 25 | parent::__construct( 26 | new phpMorphy_Finder_Fsa_PredictByDatabase( 27 | $fsa, 28 | $this->createAnnotDecoder($helper), 29 | $helper->getEncoding(), 30 | $helper->getGramInfo(), 31 | 2, 32 | 32 33 | ), 34 | $helper 35 | ); 36 | } 37 | 38 | protected function createAnnotDecoder(phpMorphy_Helper $helper) { 39 | return phpMorphy_AnnotDecoder_Factory::instance($helper->getEndOfString())->getPredictDecoder(); 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/Morphier/PredictBySuffix.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Morphier_PredictBySuffix extends phpMorphy_Morphier_MorphierAbstract { 24 | function __construct(phpMorphy_Fsa_FsaInterface $fsa, phpMorphy_Helper $helper) { 25 | parent::__construct( 26 | new phpMorphy_Finder_Fsa_PredictBySuffix( 27 | $fsa, 28 | $this->createAnnotDecoder($helper), 29 | $helper->getGramInfo()->getEncoding(), 30 | 4 31 | ), 32 | $helper 33 | ); 34 | } 35 | 36 | protected function createAnnotDecoder(phpMorphy_Helper $helper) { 37 | return phpMorphy_AnnotDecoder_Factory::instance($helper->getEndOfString())->getCommonDecoder(); 38 | } 39 | } -------------------------------------------------------------------------------- /src/phpMorphy/Paradigm/Collection.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Paradigm_Collection extends phpMorphy_Util_Collection_Typed { 24 | function __construct() { 25 | parent::__construct( 26 | new phpMorphy_Util_Collection_ArrayBased(), 27 | 'phpMorphy_Paradigm_ParadigmInterface' 28 | ); 29 | } 30 | 31 | /** 32 | * @param string|string[] $poses 33 | * @return phpMorphy_Paradigm_ParadigmInterface[] 34 | */ 35 | function getByPartOfSpeech($poses) { 36 | $result = array(); 37 | settype($poses, 'array'); 38 | 39 | foreach($this as $paradigm) { 40 | if($paradigm->hasPartOfSpeech($poses)) { 41 | $result[] = $paradigm; 42 | } 43 | } 44 | 45 | return $result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/phpMorphy/Paradigm/ParadigmInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Paradigm_ParadigmInterface extends Countable, ArrayAccess, IteratorAggregate { 24 | /** 25 | * Alias for getLemma() 26 | * @see phpMorphy_Paradigm_ParadigmInterface::getLemma() 27 | * @abstract 28 | * @return string 29 | */ 30 | function getBaseForm(); 31 | 32 | /** 33 | * Returns lemma for this paradigm 34 | * @abstract 35 | * @return string 36 | */ 37 | function getLemma(); 38 | 39 | /** 40 | * Returns longest common substring for all word forms in this paradigm 41 | * @abstract 42 | * @return string 43 | */ 44 | function getPseudoRoot(); 45 | 46 | /** 47 | * Returns all unique word forms for this paradigm 48 | * @abstract 49 | * @return string[] 50 | */ 51 | function getAllForms(); 52 | 53 | /** 54 | * Returns word form at given position in paradigm 55 | * @abstract 56 | * @param int $index 57 | * @return void 58 | */ 59 | function getWordForm($index); 60 | } -------------------------------------------------------------------------------- /src/phpMorphy/Semaphore/Empty.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Semaphore_Empty implements phpMorphy_Semaphore_SemaphoreInterface { 24 | function lock() { } 25 | function unlock() { } 26 | function remove() { } 27 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Semaphore/Nix.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Semaphore_Nix implements phpMorphy_Semaphore_SemaphoreInterface { 24 | const DEFAULT_PERM = 0644; 25 | 26 | private $sem_id = false; 27 | 28 | function __construct($key) { 29 | if(false === ($this->sem_id = sem_get($key, 1, self::DEFAULT_PERM, true))) { 30 | throw new phpMorphy_Exception("Can`t get semaphore for '$key' key"); 31 | } 32 | } 33 | 34 | function lock() { 35 | if(false === sem_acquire($this->sem_id)) { 36 | throw new phpMorphy_Exception("Can`t acquire semaphore"); 37 | } 38 | } 39 | 40 | function unlock() { 41 | if(false === sem_release($this->sem_id)) { 42 | throw new phpMorphy_Exception("Can`t release semaphore"); 43 | } 44 | } 45 | 46 | function remove() { 47 | sem_remove($this->sem_id); 48 | } 49 | } -------------------------------------------------------------------------------- /src/phpMorphy/Semaphore/SemaphoreFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | abstract class phpMorphy_Semaphore_SemaphoreFactory { 24 | /** 25 | * @static 26 | * @param string $key 27 | * @param bool $createEmpty 28 | * @return phpMorphy_Semaphore_SemaphoreInterface 29 | */ 30 | static function create($key, $createEmpty = false) { 31 | if(!$createEmpty) { 32 | if (0 == strcasecmp($GLOBALS['__phpmorphy_substr'](PHP_OS, 0, 3), 'WIN')) { 33 | return new phpMorphy_Semaphore_Win($key); 34 | } else { 35 | return new phpMorphy_Semaphore_Nix($key); 36 | } 37 | } else { 38 | return new phpMorphy_Semaphore_Empty($key); 39 | } 40 | } 41 | }; -------------------------------------------------------------------------------- /src/phpMorphy/Semaphore/SemaphoreInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Semaphore_SemaphoreInterface { 24 | function lock(); 25 | function unlock(); 26 | } -------------------------------------------------------------------------------- /src/phpMorphy/Shm/CacheInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Shm_CacheInterface { 24 | function close(); 25 | function get($filePath); 26 | function clear(); 27 | function delete($filePath); 28 | function reload($filePath); 29 | function reloadIfExists($filePath); 30 | function free(); 31 | } -------------------------------------------------------------------------------- /src/phpMorphy/Shm/FileDescriptor.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Shm_FileDescriptor { 24 | private 25 | $shm_id, 26 | $file_size, 27 | $offset; 28 | 29 | function __construct($shmId, $fileSize, $offset) { 30 | $this->shm_id = $shmId; 31 | $this->file_size = $fileSize; 32 | $this->offset = $offset; 33 | } 34 | 35 | function getShmId() { return $this->shm_id; } 36 | function getFileSize() { return $this->file_size; } 37 | function getOffset() { return $this->offset; } 38 | } -------------------------------------------------------------------------------- /src/phpMorphy/Source/Fsa.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Source_Fsa implements phpMorphy_Source_SourceInterface { 24 | protected 25 | /** @var phpMorphy_Fsa_FsaInterface */ 26 | $fsa, 27 | /** @var int */ 28 | $root; 29 | 30 | /** 31 | * @param phpMorphy_Fsa_FsaInterface $fsa 32 | */ 33 | function __construct(phpMorphy_Fsa_FsaInterface $fsa) { 34 | $this->fsa = $fsa; 35 | $this->root = $fsa->getRootTrans(); 36 | } 37 | 38 | /** 39 | * @return phpMorphy_Fsa_FsaInterface 40 | */ 41 | function getFsa() { 42 | return $this->fsa; 43 | } 44 | 45 | /** 46 | * @param string $key 47 | * @return string|false 48 | */ 49 | function getValue($key) { 50 | if(false === ($result = $this->fsa->walk($this->root, $key, true)) || !$result['annot']) { 51 | return false; 52 | } 53 | 54 | return $result['annot']; 55 | } 56 | } -------------------------------------------------------------------------------- /src/phpMorphy/Source/SourceFactory.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Source_SourceFactory { 24 | const SOURCE_FSA = 'fsa'; 25 | const SOURCE_DBA = 'dba'; 26 | const SOURCE_SQL = 'sql'; 27 | } -------------------------------------------------------------------------------- /src/phpMorphy/Source/SourceInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Source_SourceInterface { 24 | /** 25 | * Find value by $key key 26 | * @abstract 27 | * @param string $key 28 | * @return string|false 29 | */ 30 | function getValue($key); 31 | } -------------------------------------------------------------------------------- /src/phpMorphy/Storage/File.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Storage_File extends phpMorphy_Storage_StorageAbstract { 24 | function getType() { return phpMorphy_Storage_Factory::STORAGE_FILE; } 25 | 26 | function getFileSize() { 27 | if(false === ($stat = fstat($this->resource))) { 28 | throw new phpMorphy_Exception('Can`t invoke fstat for ' . $this->file_name . ' file'); 29 | } 30 | 31 | return $stat['size']; 32 | } 33 | 34 | function readUnsafe($offset, $len) { 35 | if(0 !== fseek($this->resource, $offset)) { 36 | throw new phpMorphy_Exception("Can`t seek to $offset offset"); 37 | } 38 | 39 | return fread($this->resource, $len); 40 | } 41 | 42 | function open($fileName) { 43 | if(false === ($fh = fopen($fileName, 'rb'))) { 44 | throw new phpMorphy_Exception("Can`t open $this->file_name file"); 45 | } 46 | 47 | return $fh; 48 | } 49 | } -------------------------------------------------------------------------------- /src/phpMorphy/Storage/Mem.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Storage_Mem extends phpMorphy_Storage_StorageAbstract { 24 | function getType() { return phpMorphy_Storage_Factory::STORAGE_MEM; } 25 | 26 | function getFileSize() { 27 | return $GLOBALS['__phpmorphy_strlen']($this->resource); 28 | } 29 | 30 | function readUnsafe($offset, $len) { 31 | return $GLOBALS['__phpmorphy_substr']($this->resource, $offset, $len); 32 | } 33 | 34 | function open($fileName) { 35 | if(false === ($string = file_get_contents($fileName))) { 36 | throw new phpMorphy_Exception("Can`t read $fileName file"); 37 | } 38 | 39 | return $string; 40 | } 41 | } -------------------------------------------------------------------------------- /src/phpMorphy/Storage/Shm.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Storage_Shm extends phpMorphy_Storage_StorageAbstract { 24 | protected 25 | $descriptor; 26 | 27 | function __construct($fileName, $shmCache) { 28 | $this->cache = $shmCache; 29 | 30 | parent::__construct($fileName); 31 | } 32 | 33 | function getFileSize() { 34 | return $this->descriptor->getFileSize(); 35 | } 36 | 37 | function getType() { return phpMorphy_Storage_Factory::STORAGE_SHM; } 38 | 39 | function readUnsafe($offset, $len) { 40 | return shmop_read($this->resource['shm_id'], $this->resource['offset'] + $offset, $len); 41 | } 42 | 43 | function open($fileName) { 44 | $this->descriptor = $this->cache->get($fileName); 45 | 46 | return array( 47 | 'shm_id' => $this->descriptor->getShmId(), 48 | 'offset' => $this->descriptor->getOffset() 49 | ); 50 | } 51 | } -------------------------------------------------------------------------------- /src/phpMorphy/Storage/StorageInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_Storage_StorageInterface { 24 | /** 25 | * Returns name of file 26 | * @return string 27 | */ 28 | function getFileName(); 29 | 30 | /** 31 | * Returns size of file in bytes 32 | * @abstract 33 | * @return int 34 | */ 35 | function getFileSize(); 36 | 37 | /** 38 | * Returns resource of this storage 39 | * @return mixed 40 | */ 41 | function getResource(); 42 | 43 | /** 44 | * Returns type of this storage 45 | * @return string 46 | */ 47 | function getTypeAsString(); 48 | 49 | /** 50 | * Reads $len bytes from $offset offset 51 | * 52 | * @throws phpMorphy_Exception 53 | * @param int $offset Read from this offset 54 | * @param int $length How many bytes to read 55 | * @param bool $exactLength If this set to true, then exception thrown when we read less than $len bytes 56 | * @return string 57 | */ 58 | function read($offset, $length, $exactLength = true); 59 | } -------------------------------------------------------------------------------- /src/phpMorphy/UnicodeHelper/Singlebyte.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_UnicodeHelper_Singlebyte extends phpMorphy_UnicodeHelper_UnicodeHelperAbstract { 24 | function getFirstCharSize($str) { 25 | return 1; 26 | } 27 | 28 | function strrev($str) { 29 | return strrev($str); 30 | } 31 | 32 | function clearIncompleteCharsAtEnd($str) { 33 | return $str; 34 | } 35 | 36 | protected function strlenImpl($str) { 37 | return $GLOBALS['__phpmorphy_strlen']($str); 38 | } 39 | } -------------------------------------------------------------------------------- /src/phpMorphy/UnicodeHelper/UnicodeHelperInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | interface phpMorphy_UnicodeHelper_UnicodeHelperInterface { 24 | /** 25 | * @abstract 26 | * @param string $string 27 | * @return int 28 | */ 29 | function getFirstCharSize($string); 30 | 31 | /** 32 | * @abstract 33 | * @param string $string 34 | * @return string 35 | */ 36 | function strrev($string); 37 | 38 | /** 39 | * @abstract 40 | * @param string $string 41 | * @return string 42 | */ 43 | function clearIncompleteCharsAtEnd($string); 44 | 45 | /** 46 | * @abstract 47 | * @param string $string 48 | * @return int 49 | */ 50 | function strlen($string); 51 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/EditCommand/Add.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_UserDict_EditCommand_Add extends phpMorphy_UserDict_EditCommand_CommandAbstract { 25 | 26 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/EditCommand/CommandAbstract.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | abstract class phpMorphy_UserDict_EditCommand_CommandAbstract { 25 | /** @var phpMorphy_UserDict_PatternMatcher */ 26 | protected $pattern_matcher; 27 | 28 | function __construct(phpMorphy_UserDict_PatternMatcher $matcher) { 29 | $this->pattern_matcher = $matcher; 30 | } 31 | 32 | /** 33 | * @param phpMorphy_Paradigm_MutableDecorator $paradigm 34 | * @return void 35 | */ 36 | abstract function apply(phpMorphy_Paradigm_MutableDecorator $paradigm); 37 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/EditCommand/Update.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_UserDict_EditCommand_Update extends phpMorphy_UserDict_EditCommand_CommandAbstract { 25 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_UserDict_Exception extends phpMorphy_Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/Log/ErrorsHandlerException.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | class phpMorphy_UserDict_Log_ErrorsHandlerException 26 | implements phpMorphy_UserDict_Log_ErrorsHandlerInterface { 27 | 28 | function handle($message) { 29 | throw new phpMorphy_UserDict_Exception($message); 30 | } 31 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/Log/ErrorsHandlerInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | interface phpMorphy_UserDict_Log_ErrorsHandlerInterface { 26 | /** 27 | * @param string $message 28 | */ 29 | function handle($message); 30 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/Log/ErrorsHandlerPass.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | class phpMorphy_UserDict_Log_ErrorsHandlerPass 26 | implements phpMorphy_UserDict_Log_ErrorsHandlerInterface { 27 | 28 | function handle($message) { } 29 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/PatternMatcher/BaseException.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_UserDict_PatternMatcher_BaseException extends 25 | phpMorphy_UserDict_Exception 26 | { 27 | } -------------------------------------------------------------------------------- /src/phpMorphy/UserDict/VisitorInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | interface phpMorphy_UserDict_VisitorInterface { 25 | /** 26 | * @param string $lexem 27 | * @param phpMorphy_UserDict_Pattern $pattern 28 | */ 29 | function addLexem($lexem, phpMorphy_UserDict_Pattern $pattern); 30 | 31 | /** 32 | * @param phpMorphy_UserDict_Pattern $pattern 33 | * @param bool $deleteFromInternal 34 | * @param bool $deleteFromExternal 35 | */ 36 | function deleteLexem(phpMorphy_UserDict_Pattern $pattern, $deleteFromInternal, $deleteFromExternal); 37 | 38 | /** 39 | * 40 | */ 41 | function editLexem(phpMorphy_UserDict_XmlDiff_Command_Edit $command); 42 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Collection/CollectionInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | interface phpMorphy_Util_Collection_CollectionInterface extends 25 | IteratorAggregate, ArrayAccess, Countable 26 | { 27 | /** 28 | * @abstract 29 | * @param Traversable $values 30 | * @return void 31 | */ 32 | function import($values); 33 | 34 | /** 35 | * @abstract 36 | * @param mixed $value 37 | * @return void 38 | */ 39 | function append($value); 40 | 41 | /** 42 | * @abstract 43 | * @return void 44 | */ 45 | function clear(); 46 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Collection/Immutable.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Util_Collection_Immutable extends phpMorphy_Util_Collection_Decorator { 25 | function import($values) { 26 | throw new phpMorphy_Exception("Collection is immutable"); 27 | } 28 | 29 | function append($value) { 30 | throw new phpMorphy_Exception("Collection is immutable"); 31 | } 32 | 33 | function clear() { 34 | throw new phpMorphy_Exception("Collection is immutable"); 35 | } 36 | 37 | function offsetSet($offset, $value) { 38 | throw new phpMorphy_Exception("Collection is immutable"); 39 | } 40 | 41 | function offsetUnset($offset) { 42 | throw new phpMorphy_Exception("Collection is immutable"); 43 | } 44 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/AffixFileReader.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_AffixFileReader extends IteratorIterator { 24 | function __construct($fileName, $defaultEncoding) { 25 | parent::__construct($this->createIterators($this->createIterators($fileName))); 26 | 27 | $this->setEncoding($defaultEncoding); 28 | } 29 | 30 | function setEncoding($enc) { 31 | $this->getInnerIterator()->setEncoding($enc); 32 | } 33 | 34 | protected function createIterators($fileName) { 35 | return new phpMorphy_Util_Iterator_Iconv( 36 | new phpMorphy_Util_Iterator_Filter( 37 | new SplFileObject($fileName), 38 | function($item) { 39 | return strlen($item) > 0; 40 | } 41 | ) 42 | ); 43 | } 44 | 45 | function current() { 46 | return explode( 47 | ' ', 48 | preg_replace('~\s{2,}~', ' ', trim(parent::current())) 49 | ); 50 | } 51 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/Exception.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_Exception extends Exception { } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/Prefix.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_Prefix extends phpMorphy_Util_Hunspell_AffixAbstract { 24 | protected function getRegExp($find) { 25 | return "~^{$find}~iu"; 26 | } 27 | 28 | function generateWord($word) { 29 | if(!$this->isMatch($word)) { 30 | return false; 31 | } 32 | 33 | if($this->remove_len && mb_strlen($word) >= $this->remove_len) { 34 | $word = mb_substr($word, $this->remove_len); 35 | } 36 | 37 | return "{$this->append}$word"; 38 | } 39 | 40 | protected function simpleMatch($word) { 41 | return mb_substr($word, 0, $this->find_len) == $this->find; 42 | } 43 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/PrefixFlag.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_PrefixFlag extends phpMorphy_Util_Hunspell_AffixFlagAbstract { 24 | protected function createAffix($find, $remove, $append, $morph) { 25 | return new phpMorphy_Util_Hunspell_Prefix( 26 | $find, 27 | $remove, 28 | $append, 29 | $morph 30 | ); 31 | } 32 | 33 | function isSuffix() { return false; } 34 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/Suffix.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_Suffix extends phpMorphy_Util_Hunspell_AffixAbstract { 24 | protected function getRegExp($find) { 25 | //return $find; 26 | return "~{$find}$~iu"; 27 | } 28 | 29 | function generateWord($word) { 30 | if(!$this->isMatch($word)) { 31 | return false; 32 | } 33 | 34 | if($this->remove_len && mb_strlen($word) >= $this->remove_len) { 35 | $tail = mb_substr($word, -$this->remove_len); 36 | 37 | if($tail != $this->remove) { 38 | vd("Try to remove $tail from $word"); 39 | vd($this); 40 | exit; 41 | } 42 | 43 | $word = mb_substr($word, 0, -$this->remove_len); 44 | } 45 | 46 | return "$word{$this->append}"; 47 | } 48 | 49 | protected function simpleMatch($word) { 50 | return mb_substr($word, -$this->find_len) == $this->find; 51 | } 52 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Hunspell/SuffixFlag.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | class phpMorphy_Util_Hunspell_SuffixFlag extends phpMorphy_Util_Hunspell_AffixFlagAbstract { 24 | protected function createAffix($find, $remove, $append, $morph) { 25 | return new phpMorphy_Util_Hunspell_Suffix( 26 | $find, 27 | $remove, 28 | $append, 29 | $morph 30 | ); 31 | } 32 | 33 | function isSuffix() { return true; } 34 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Iterator/Filter.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | 25 | class phpMorphy_Util_Iterator_Filter extends FilterIterator { 26 | /** @var Closure */ 27 | private $callback; 28 | 29 | /** 30 | * @param Iterator $iterator 31 | * @param $function 32 | */ 33 | public function __construct(Iterator $iterator, $function) { 34 | parent::__construct($iterator); 35 | $this->callback = $function; 36 | } 37 | 38 | public function accept() { 39 | $fn = $this->callback; 40 | return $fn(parent::current(), parent::key()); 41 | } 42 | } -------------------------------------------------------------------------------- /src/phpMorphy/Util/Iterator/Transform.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_Util_Iterator_Transform extends IteratorIterator { 25 | /** @var Closure */ 26 | private $function; 27 | 28 | public function __construct(Traversable $iterator, $function) { 29 | parent::__construct($iterator); 30 | $this->function = $function; 31 | } 32 | 33 | function current() { 34 | $fn = $this->function; 35 | return $fn(parent::current()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/phpMorphy/WordForm/WithFormNo.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | 24 | class phpMorphy_WordForm_WithFormNo extends phpMorphy_WordForm_WordForm { 25 | /** @var int */ 26 | protected $form_no; 27 | 28 | /** 29 | * @param int $form_no 30 | */ 31 | function __construct($form_no) { 32 | $this->form_no = (int)$form_no; 33 | } 34 | 35 | function getFormNo() { 36 | return $this->form_no; 37 | } 38 | } -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | ./functional 4 | 5 | 6 | ./unit 7 | 8 | -------------------------------------------------------------------------------- /tests/unit/UserDict/phpMorphy_UserDict_EncodingConverterTest.php: -------------------------------------------------------------------------------- 1 | object = new phpMorphy_UserDict_EncodingConverter( 24 | self::MORPHY_ENCODING, 25 | self::MORPHY_CASE, 26 | self::INTERNAL_ENCODING, 27 | self::INTERNAL_CASE 28 | ); 29 | } 30 | 31 | /** 32 | * Tears down the fixture, for example, closes a network connection. 33 | * This method is called after a test is executed. 34 | */ 35 | protected function tearDown() 36 | { 37 | } 38 | 39 | public function testToMorphy() 40 | { 41 | $this->assertEquals( 42 | iconv(self::INTERNAL_ENCODING, self::MORPHY_ENCODING, 'АБВ'), 43 | $this->object->toMorphy('абв') 44 | ); 45 | } 46 | 47 | public function testToInternal() 48 | { 49 | $this->assertEquals( 50 | 'абв', 51 | $this->object->toInternal(iconv(self::INTERNAL_ENCODING, self::MORPHY_ENCODING, 'АБВ')) 52 | ); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tests/unit/UserDict/phpMorphy_UserDict_PatternTest.php: -------------------------------------------------------------------------------- 1 | object = new phpMorphy_UserDict_Pattern( 20 | 'test', 21 | new phpMorphy_UserDict_GrammarIdentifier( 22 | 'pos', 23 | array('a', 'b') 24 | ) 25 | ); 26 | } 27 | 28 | /** 29 | * Tears down the fixture, for example, closes a network connection. 30 | * This method is called after a test is executed. 31 | */ 32 | protected function tearDown() 33 | { 34 | } 35 | 36 | public function testConstructFromString() 37 | { 38 | // word + part of speech + grammems 39 | $this->assertEquals( 40 | $this->object, 41 | phpMorphy_UserDict_Pattern::constructFromString(" test \t\t\t \t pos a , b") 42 | ); 43 | 44 | // only word 45 | $this->assertEquals( 46 | new phpMorphy_UserDict_Pattern('test', new phpMorphy_UserDict_GrammarIdentifier(null, array())), 47 | phpMorphy_UserDict_Pattern::constructFromString(" test \t\t\t ") 48 | ); 49 | } 50 | 51 | public function testMatchWord() 52 | { 53 | $this->assertTrue($this->object->matchWord('test')); 54 | } 55 | 56 | /** 57 | * @todo Implement testMatch(). 58 | */ 59 | public function testMatch() 60 | { 61 | $this->assertTrue( 62 | $this->object->match( 63 | 'test', 64 | 'pos', 65 | array('a', 'c', 'b') 66 | ) 67 | ); 68 | } 69 | } 70 | ?> 71 | --------------------------------------------------------------------------------