<commit_before><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2013, Dansk Bibliotekscenter a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
*/


require_once 'OLS_class_lib/memcache_class.php';

/**
 * \brief Class for formatting records from fedora object repository
 *   records are split according to record_blocking and send to one or more formating servers
 *
 * Usage: \n
*    $formater = new formatRecords($config_array, $namespace, $objconverter, $xmlconverter [, $timer]);
     $formatted_records = $formater->format($records, $param);
 *
 * Example:
 *   $formatRecords = new formatRecords($this->config->get_section('setup'), $this->xmlns['of'], $this->objconvert, $this->xmlconvert, $this->watch);
 *   $formatted = $formatRecords->format($form_req, $param);
 *
 * @author <NAME> - DBC
 */

class FormatRecords {
  protected $cache;                     ///< for caching formatted records
  protected $curl;                      ///< the curl connection
  protected $namespace;                 ///< the namespace for openformat
  protected $objconvert;                ///< OLS object to xml convert
  protected $xmlconvert;                ///< xml to OLS object convert
  protected $watch;                     ///< timer object
  protected $record_blocking = 1;       ///< block factor: number of records in each request to js_server
  protected $js_server_url = array();   ///< if more than one, the formatting requests will be split amongst them
  protected $rec_status = array();      ///< curl_status for each record formattet
  protected $timeout = 5;               ///< -

  /** \brief
  *  @param $setup object
  *  @param $namespace string
  *  @param $objconvert class 
  *  @param $xmlconvert class 
  *  @param $watch class optional
  */
  public function __construct($setup, $namespace, &$objconvert, &$xmlconvert, &$watch = NULL) {
    $this->curl = new curl();
    foreach ($setup['js_server'] as $url) {
      $this->js_server_url[] = $url;
    }
    if (!($this->timeout = (integer) $setup['curl_timeout'])) {
      $this->timeout = 5;
    }
  // Since the api for record_blocking is not defined, it will be set to 1
  //  if (!($this->record_blocking = (integer) $setup['record_blocking'])) {
      $this->record_blocking = 1;
  //  }
    $this->cache = new cache($setup['cache_host'], $setup['cache_port'], $setup['cache_expire']);

    $this->curl = new curl();
    $this->namespace = $namespace;
    $this->objconvert = $objconvert;
    $this->xmlconvert = $xmlconvert;
    $this->watch = $watch;
  }

  /** \brief
  *  @param $records array Records to format
  *  @param $param object User given parameters
  *  @retval array - of formatted records
  */
  public function format($records, $param) {
    static $dom;
    if (empty($dom)) {
      $dom = new DomDocument();
      $dom->preserveWhiteSpace = false;
    }
    $output_format = $param->outputFormat->_value;
    $form_req->formatSingleManifestationRequest->_value->agency = $param->agency;
    $form_req->formatSingleManifestationRequest->_value->holdBackEndDate = $param->holdBackEndDate;
    $form_req->formatSingleManifestationRequest->_value->language = $param->language;
    $form_req->formatSingleManifestationRequest->_value->outputFormat = $param->outputFormat;
    $form_req->formatSingleManifestationRequest->_value->trackingId = $param->trackingId;
    $ret = array();
    $ret_index = array();  // to make future caching easier<commit_msg>new on objects<commit_after><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2013, Dansk Bibliotekscenter a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
*/


require_once 'OLS_class_lib/memcache_class.php';

/**
 * \brief Class for formatting records from fedora object repository
 *   records are split according to record_blocking and send to one or more formating servers
 *
 * Usage: \n
*    $formater = new formatRecords($config_array, $namespace, $objconverter, $xmlconverter [, $timer]);
     $formatted_records = $formater->format($records, $param);
 *
 * Example:
 *   $formatRecords = new formatRecords($this->config->get_section('setup'), $this->xmlns['of'], $this->objconvert, $this->xmlconvert, $this->watch);
 *   $formatted = $formatRecords->format($form_req, $param);
 *
 * @author <NAME> - DBC
 */

class FormatRecords {
  protected $cache;                     ///< for caching formatted records
  protected $curl;                      ///< the curl connection
  protected $namespace;                 ///< the namespace for openformat
  protected $objconvert;                ///< OLS object to xml convert
  protected $xmlconvert;                ///< xml to OLS object convert
  protected $watch;                     ///< timer object
  protected $record_blocking = 1;       ///< block factor: number of records in each request to js_server
  protected $js_server_url = array();   ///< if more than one, the formatting requests will be split amongst them
  protected $rec_status = array();      ///< curl_status for each record formattet
  protected $timeout = 5;               ///< -

  /** \brief
  *  @param $setup object
  *  @param $namespace string
  *  @param $objconvert class 
  *  @param $xmlconvert class 
  *  @param $watch class optional
  */
  public function __construct($setup, $namespace, &$objconvert, &$xmlconvert, &$watch = NULL) {
    $this->curl = new curl();
    foreach ($setup['js_server'] as $url) {
      $this->js_server_url[] = $url;
    }
    if (!($this->timeout = (integer) $setup['curl_timeout'])) {
      $this->timeout = 5;
    }
  // Since the api for record_blocking is not defined, it will be set to 1
  //  if (!($this->record_blocking = (integer) $setup['record_blocking'])) {
      $this->record_blocking = 1;
  //  }
    $this->cache = new cache($setup['cache_host'], $setup['cache_port'], $setup['cache_expire']);

    $this->curl = new curl();
    $this->namespace = $namespace;
    $this->objconvert = $objconvert;
    $this->xmlconvert = $xmlconvert;
    $this->watch = $watch;
  }

  /** \brief
  *  @param $records array Records to format
  *  @param $param object User given parameters
  *  @retval array - of formatted records
  */
  public function format($records, $param) {
    static $dom;
    if (empty($dom)) {
      $dom = new DomDocument();
      $dom->preserveWhiteSpace = false;
    }
    $output_format = $param->outputFormat->_value;
    $form_req = new stdClass();
    $form_req->formatSingleManifestationRequest = new stdClass();
    $form_req->formatSingleManifestationRequest->_value = new stdClass();
    $form_req->formatSingleManifestationRequest->_value->agency = $param->agency;
    $form_req->formatSingleManifestationRequest->_value->holdBackEndDate = $param->holdBackEndDate;
    $form_req->formatSingleManifestationRequest->_value->language = $param->language;
    $form_req->formatSingleManifestationRequest->_value->outputFormat = $param->outputFormat;
    $form_req->formatSingleManifestationRequest->_value->trackingId = $param->trackingId;
    $ret = array();
    $ret_index = array();  // to make future caching easier
{'fraction_non_alphanumeric': 0.12565997888067582, 'fraction_numerical': 0.0058664789393406075, 'mean_word_length': 3.3137651821862346, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '299794', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2387, 'n_words': 774}