function write(phpMorphy_Dict_Source_Interface $source) { $this->getObserver()->onStart(); try { $source = phpMorphy_Dict_Source_Normalized_Ancodes::wrap($source); $xml_opts = $this->getXmlOptions(); $writer = $this->createXmlWriter($this->path); $validator = new phpMorphy_Dict_Writer_Utils_Validator(); $validator->setAncodes($source->getAncodesNormalized()); $this->validator = $validator; $writer->startDocument($xml_opts['xml_version'], $xml_opts['xml_encoding']); $writer->writeDtd('phpmorphy', $xml_opts['dtd_pub_id'], $xml_opts['dtd_sys_id']); $writer->writeComment('This file generated with ' . __CLASS__ . ' at ' . date('r')); // morphy $writer->startElement('phpmorphy'); $this->writeOptions($writer, $source); $this->writePoses($writer, $source->getPoses()); $this->writeGrammems($writer, $source->getGrammems()); $this->writeAncodes($writer, $source->getAncodesNormalized()); $validator->setFlexiasCount($this->writeFlexias($writer, $source->getFlexiasNormalized())); $validator->setPrefixesCount($this->writePrefixes($writer, $source->getPrefixes())); $this->writeLemmas($writer, $source->getLemmasNormalized()); $writer->endElement(); $writer->endDocument(); } catch (Exception $e) { $this->getObserver()->onEnd(); throw $e; } $this->getObserver()->onEnd(); }
protected function loadLemmas(phpMorphy_Dict_Source_Normalized_Ancodes $source, $context, $dictId) { //$stmt = $this->engine->prepareInsert('lemmas', array('dict_id', 'base_str', 'flexia_id', 'accent_id', 'prefix_id', 'common_ancode_id')); $inserter = $this->engine->getBulkInserter('lemmas', array('dict_id', 'base_str', 'flexia_id', 'accent_id', 'prefix_id', 'common_ancode_id')); $flexias_map = $context->getFlexiasMap(); $ancodes_map = $context->getAncodesMap(); $prefixes_map = $context->getPrefixesMap(); $i = 0; foreach ($source->getLemmas() as $lemma) { if ($i % self::COMMIT_EVERY_LEMMA == 0) { $this->log("Flush packet of inserts"); $inserter->execute(); } if ($i % self::DUMP_EVERY_LEMMA == 0) { $this->log("{$i} lemmas done"); } $ancode_id = $lemma->hasAncodeId() ? $ancodes_map->resolve($lemma->getAncodeId()) : null; $prefix_id = $lemma->hasPrefixId() ? $prefixes_map->resolve($lemma->getPrefixId()) : null; $accent_id = null; $flexia_model_id = $flexias_map->resolve($lemma->getFlexiaId()); $base = $this->trim($lemma->getBase(), 64); $inserter->add(array($dictId, $base, $flexia_model_id, $accent_id, $prefix_id, $ancode_id)); $i++; } $inserter->execute(); }