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(); }
function write(phpMorphy_Dict_Source_Interface $source) { $source = phpMorphy_Dict_Source_Normalized_Ancodes::wrap($source); $context = $this->createContext(); $tables = $this->getTablesToProcess(); $old_time_limit = ini_get('max_execution_time'); set_time_limit(0); $b = microtime(true); $restore_keys_stmt = new phpMorphy_Dict_Writer_Sql_StatementsBundle($this->engine); $e = null; try { $old_state = $this->engine->initState(); try { // drop keys foreach ($tables as $table_name) { $restore_keys_stmt->prepend($this->engine->dropKeys($table_name)); } $this->engine->begin(); // protect transaction try { $context->setDictId($this->createNewDict($source)); foreach ($tables as $table) { $this->loadSection($table, $source, $context); } $this->engine->commit(); } catch (Exception $e) { $this->engine->rollback(); throw $e; } } catch (Exception $e) { } // restore keys if (!$restore_keys_stmt->safeExecute()) { $message = "An error occured while restore keys: " . implode(', ', $restore_keys_stmt->getLastErrors()); if (isset($e)) { $message .= ' (prev. error = ' . $e->getMessage(); } throw new phpMorphy_Dict_Writer_Sql_Exception($message); } $this->engine->restoreState($old_state); if (isset($e)) { throw $e; } } catch (Exception $e) { } set_time_limit($old_time_limit); $this->log(sprintf("Total time taken = %0.2f", microtime(true) - $b)); if (isset($e)) { throw $e; } return $context->getDictId(); }