<commit_before><?php

/*
 +--------------------------------------------------------------------+
 | YASS                                                               |
 +--------------------------------------------------------------------+
 | Copyright ARMS Software LLC (c) 2011-2012                          |
 +--------------------------------------------------------------------+
 | This file is a part of YASS.                                       |
 |                                                                    |
 | YASS is free software; you can copy, modify, and distribute it     |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007.                                       |
 |                                                                    |
 | YASS 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.        |
 |                                                                    |
 | Additional permissions may be granted. See LICENSE.txt for         |
 | details.                                                           |
 +--------------------------------------------------------------------+
*/

require_once 'YASS/ILocalDataStore.php';
require_once 'YASS/Replica.php';

/**
 * Store localized versions of YASS entities (eg yass_conflict, yass_mergelog)
 */
class YASS_LocalDataStore_GenericSQL implements YASS_ILocalDataStore {

    /**
     * @var array(entityType => ARMS_Select)
     */
    var $queries;

    /**
     * 
     */
    public function __construct(YASS_Replica $replica, $entityWeights = FALSE) {
        arms_util_include_api('array');
        arms_util_include_api('query');
        $this->replica = $replica;
        
        if (! $entityWeights) {
            $types = array(
                'contact', 'activity', 'testentity', 'irrelevant',
                'civicrm_contact', 'civicrm_address', 'civicrm_phone', 'civicrm_email', 'civicrm_website',
                'civicrm_activity','civicrm_activity_assignment','civicrm_activity_target',
                'yass_conflict', 'yass_mergelog',
            );
            $entityWeights = array();
            foreach ($types as $type) {
                $entityWeights[$type] = '10';
            }
        }
        
        $this->entityWeights = $entityWeights;
        
        
    }
    
    /**
     *
     * @return array(entityType)
     */
    function getEntityTypes() {
        return array_keys($this->getEntityWeights());
    }

    /**
     * Detremine the order in which entities should be written to DB.
     *
     * Low-weight items are inserted before high-weight items.
     * High-weight items are deleted before low-weight items.
     *
     * @return array(entityType => weight)
     */
    function getEntityWeights() {
        return $this->entityWeights;
    }

    /**
     * Read a batch of entities
     *
     * @var $lids array(entityGuid => lid)
     * @return array(entityGuid => YASS_Entity)
     */<commit_msg>YASS_LocalDataStore_GenericSQL - Allow for empty list of weights<commit_after><?php

/*
 +--------------------------------------------------------------------+
 | YASS                                                               |
 +--------------------------------------------------------------------+
 | Copyright ARMS Software LLC (c) 2011-2012                          |
 +--------------------------------------------------------------------+
 | This file is a part of YASS.                                       |
 |                                                                    |
 | YASS is free software; you can copy, modify, and distribute it     |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007.                                       |
 |                                                                    |
 | YASS 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.        |
 |                                                                    |
 | Additional permissions may be granted. See LICENSE.txt for         |
 | details.                                                           |
 +--------------------------------------------------------------------+
*/

require_once 'YASS/ILocalDataStore.php';
require_once 'YASS/Replica.php';

/**
 * Store localized versions of YASS entities (eg yass_conflict, yass_mergelog)
 */
class YASS_LocalDataStore_GenericSQL implements YASS_ILocalDataStore {

    /**
     * @var array(entityType => ARMS_Select)
     */
    var $queries;

    /**
     * 
     */
    public function __construct(YASS_Replica $replica, $entityWeights = NULL) {
        arms_util_include_api('array');
        arms_util_include_api('query');
        $this->replica = $replica;
        
        if (! is_array($entityWeights)) {
            $types = array(
                'contact', 'activity', 'testentity', 'irrelevant',
                'civicrm_contact', 'civicrm_address', 'civicrm_phone', 'civicrm_email', 'civicrm_website',
                'civicrm_activity','civicrm_activity_assignment','civicrm_activity_target',
                'yass_conflict', 'yass_mergelog',
            );
            $entityWeights = array();
            foreach ($types as $type) {
                $entityWeights[$type] = '10';
            }
        }
        
        $this->entityWeights = $entityWeights;
        $this->entityTypes = array_keys($entityWeights);
    }
    
    /**
     *
     * @return array(entityType)
     */
    function getEntityTypes() {
        return $this->entityTypes;
    }

    /**
     * Detremine the order in which entities should be written to DB.
     *
     * Low-weight items are inserted before high-weight items.
     * High-weight items are deleted before low-weight items.
     *
     * @return array(entityType => weight)
     */
    function getEntityWeights() {
        return $this->entityWeights;
    }

    /**
     * Read a batch of entities
     *
     * @var $lids array(entityGuid => lid)
     * @return array(entityGuid => YASS_Entity)
     */
{'fraction_non_alphanumeric': 0.1696867321867322, 'fraction_numerical': 0.005221130221130221, 'mean_word_length': 1.1877729257641922, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6940018', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1533, 'n_words': 400}