text:
<?php

require_once dirname(__FILE__) . '/../BaseSchemaParser.php';

/**
 * Pervasive database schema parser.
 *
 * @author     Thierry Blind
 * @version    $Revision$
 * @package    propel.generator.reverse.pervasive
 */
class PervasiveSchemaParser extends BaseSchemaParser
{

    /**
     * Map Pervasive native types to Propel types.
     *
     * @var array
     */
    // http://docs.pervasive.com/products/database/psqlv11/wwhelp/wwhimpl/js/html/wwhelp.htm#href=ODBC/SQLSysTb.12.3.html
    // http://docs.pervasive.com/products/database/psqlv11/wwhelp/wwhimpl/js/html/wwhelp.htm#href=ODBC/SQLDtype.10.2.html#134810
    private static $propelTypeMap = array(
        'AUTOINC2' => PropelTypes::SMALLINT, // Type code = 15
        'AUTOINC4' => PropelTypes::INTEGER, // Type code = 15
        'BFLOAT4' => PropelTypes::REAL, // Type code = 9
        'BFLOAT8' => PropelTypes::DOUBLE, // Type code = 9
        'CLOB/BLOB' => PropelTypes::LONGVARBINARY, // Type code = 21
        'CURRENCY' => PropelTypes::DECIMAL, // Type code = 19
        'DATE' => PropelTypes::DATE, // Type code = 3
        'DATETIME' => PropelTypes::TIMESTAMP, // Type code =  30 // TODO: Check...
        'DECIMAL' => PropelTypes::DECIMAL, // Type code = 5
        'REAL' => PropelTypes::REAL, // Type code = 2
        'DOUBLE' => PropelTypes::DOUBLE, // Type code = 2
        'GUID' => PropelTypes::LONGVARBINARY, // Type code = 27 // SQL_GUID (UNIQUEIDENTIFIER)
        'TINYINT' => PropelTypes::TINYINT, // Type code = 1
        'SMALLINT' => PropelTypes::SMALLINT, // Type code = 1
        'INTEGER' => PropelTypes::INTEGER, // Type code = 1
        'BIGINT' => PropelTypes::BIGINT, // Type code = 1 // TODO: PropelTypes::SQL_DECIMAL doesn't exist
        'MONEY' => PropelTypes::DECIMAL, // Type code = 6
        'NUMERIC' => PropelTypes::NUMERIC, // Type code = 8
        'NUMERICSA' => PropelTypes::NUMERIC, // Type code = 18
        'NUMERICSLB' => PropelTypes::NUMERIC, // Type code = 28
        'NUMERICSLS' => PropelTypes::NUMERIC, // Type code = 29
        'NUMERICSTB' => PropelTypes::NUMERIC, // Type code = 31
        'NUMERICSTS' => PropelTypes::NUMERIC, // Type code = 17
        'STRING' => PropelTypes::CHAR, // Type code = 0 // TODO: SQL_BINARY or SQL_CHAR ?
        'TIME' => PropelTypes::TIME, // Type code = 4
        'TIMESTAMP' => PropelTypes::TIMESTAMP, // Type code = 20
        'UNSIGNED1 BINARY' => PropelTypes::TINYINT, // Type code = 14
        'UNSIGNED2 BINARY' => PropelTypes::SMALLINT, // Type code = 14
        'UNSIGNED4 BINARY' => PropelTypes::INTEGER, // Type code = 14
        'UNSIGNED8 BINARY' => PropelTypes::DECIMAL, // Type code = 14
        // Type code = 25 or 26 not supported
        'VARCHAR' => PropelTypes::VARCHAR, // Type code = 11
        // http://docs.pervasive.com/products/database/psqlv11/pdac/wwhelp/wwhimpl/common/html/wwhelp.htm#href=pdacref.2.6.html&single=true
        'BIT' => PropelTypes::BOOLEAN, // Type code = 16 // TODO: SQL_BIT doesn't exist -> ftBoolean
        'LOGICAL' => PropelTypes::SMALLINT // Type code = 7 // TODO: SQL_BIT doesn't exist -> ftBoolean or ftSmallint ?
    );

    // TODO: Remove this hack...
    protected function cleanMethod($schemaName, Task $task)
    {
        if ($task instanceof PropelSchemaReverseTask && $task->isSamePhpName()) {
            return $schemaName;
        }

        $name = '';
        $regexp = '/([a-z0-9]+)/i';
        $matches = array();
        $first = true;
        if (preg_match_all($regexp, $schemaName, $matches)) {
            foreach ($matches[1] as $tok) {
                if ($first) {
                    $name = $tok;
                    $first = false;
                    continue;
                }
                $name .= NameGenerator::STD_SEPARATOR_CHAR . ucfirst($tok);
            }
        } else {
            return $schemaName;
        }

        // A variable name cannot start with a number:
        if (preg_match('/^[0-9]/', $name)) {
            $name = NameGenerator::STD_SEPARATOR_CHAR . $name;
        }

        return $name;
    }

    /**
     *
     * @see BaseSchemaParser::getTypeMapping()
     */
    protected function getTypeMapping()
    {
        return self::$propelTypeMap;
    }

    public function parse(Database $database, Task $task = null)
    {
        // ftp://ftp.agris.com/Pervasive/PVSW10.3/Books/SQL_Engine_Reference.pdf
        // http://cs.pervasive.com/forums/p/951/3357.aspx
        // See also: call psp_tables(null, null, 'User table')
        $stmt = $this->dbh->query('SELECT DISTINCT XF$NAME FROM X$FILE, X$FIELD WHERE XF$ID = XE$FILE AND XF$FLAGS & 16 <> 16 AND XE$DATATYPE NOT IN (227, 255) ORDER BY XF$NAME');

        // First load the tables (important that this happen before filling out details of tables)
        $tables = array();
        while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            array_walk($row, 'PervasiveSchemaParser::rtrim_to_utf8', $task);

            $name = $row[0];
            if ($name == $this->getMigrationTable()) {
                continue;
            }
            $table = new Table($name);
            // TODO: Remove...
            $table->setPhpName($this->cleanMethod($name, $task));
            $table->setIdMethod($database->getDefaultIdMethod());
            $database->addTable($table);
            $tables[] = $table;
        }

        // Now populate only columns.
        foreach ($tables as $table) {
            $this->addColumns($table, $task);
        }

        // Now add indexes and constraints.
        foreach ($tables as $table) {
            $this->addForeignKeys($table, $task);
            $this->addIndexes($table, $task);
            $this->addPrimaryKey($table, $task);
        }

        return count($tables);
    }

    public final static function rtrim_to_utf8(&$valeur, $key, Task $task)
    {
        if (is_string($valeur)) {
            if ($task instanceof PropelSchemaReverseTask) {
                $encoding = $task->getDbEncoding($key);
                if (trim($encoding) !== '') {
                    $valeur = mb_convert_encoding($valeur, 'UTF-8', array(
                        $encoding
                    ));
                }
            }
            $valeur = rtrim($valeur);
        }
    }

    // http://www.pervasive.com/portals/55/documents/psqlv11/Accessing_the_DDF_Files_Through_Views.pdf
    private function calculatePropelTypeKey(& $row)
    {
        switch ($row['DATATYPE']) {
        case '0':
            $row['PROPEL_TYPE_KEY'] = 'STRING';
            break;
        case '1':
            switch ($row['COL_SIZE']) {
            case '1':
                $row['PROPEL_TYPE_KEY'] = 'TINYINT';
                break;
            case '2':
                $row['PROPEL_TYPE_KEY'] = 'SMALLINT';
                break;
            case '4':
                $row['PROPEL_TYPE_KEY'] = 'INTEGER';
                break;
            case '8':
                $row['PROPEL_TYPE_KEY'] = 'BIGINT';
                break;
            default:
                $row['PROPEL_TYPE_KEY'] = 'UNKNOWN INTEGER';
                break;
            }
            break;
        case '2':
            switch ($row['COL_SIZE']) {
            case '4':
                $row['PROPEL_TYPE_KEY'] = 'REAL';
                break;
            case '8':
                $row['PROPEL_TYPE_KEY'] = 'DOUBLE';
                break;
            default:
                $row['PROPEL_TYPE_KEY'] = 'UNKNOWN REAL';
                break;
            }
            break;
        case '3':
            $row['PROPEL_TYPE_KEY'] = 'DATE';
            break;
        case '4':
            $row['PROPEL_TYPE_KEY'] = 'TIME';
            break;
        case '5':
            $row['PROPEL_TYPE_KEY'] = 'DECIMAL';
            break;
        case '6':
            $row['PROPEL_TYPE_KEY'] = 'MONEY';
            break;
        case '7':
            $row['PROPEL_TYPE_KEY'] = 'LOGICAL';
            break;
        case '8':
            $row['PROPEL_TYPE_KEY'] = 'NUMERIC';
            break;
        case '9':
            switch ($row['COL_SIZE']) {
            case '4':
                $row['PROPEL_TYPE_KEY'] = 'BFLOAT4';
                break;
            case '8':
                $row['PROPEL_TYPE_KEY'] = 'BFLOAT8';
                break;
            default:
                $row['PROPEL_TYPE_KEY'] = 'UNKNOWN BFLOAT';
                break;
            }
            break;
        case '11':
            $row['PROPEL_TYPE_KEY'] = 'VARCHAR';
            break;
        case '14':
            switch ($row['COL_SIZE']) {
            case '1':
                $row['PROPEL_TYPE_KEY'] = 'UNSIGNED1 BINARY';
                break;
            case '2':
                $row['PROPEL_TYPE_KEY'] = 'UNSIGNED2 BINARY';
                break;
            case '4':
                $row['PROPEL_TYPE_KEY'] = 'UNSIGNED4 BINARY';
                break;
            case '8':
                $row['PROPEL_TYPE_KEY'] = 'UNSIGNED8 BINARY';
                break;
            default:
                $row['PROPEL_TYPE_KEY'] = 'UNKNOWN UNSIGNED BINARY';
                break;
            }
            break;
        case '15':
            switch ($row['COL_SIZE']) {
            case '2':
                $row['PROPEL_TYPE_KEY'] = 'AUTOINC2';
                break;
            case '4':
                $row['PROPEL_TYPE_KEY'] = 'AUTOINC4';
                break;
            default:
                $row['PROPEL_TYPE_KEY'] = 'UNKNOWN AUTOINC';
                break;
            }
            break;
        case '16':
            $row['PROPEL_TYPE_KEY'] = 'BIT';
            break;
        case '17':
            $row['PROPEL_TYPE_KEY'] = 'NUMERICSTS';
            break;
        case '18':
            $row['PROPEL_TYPE_KEY'] = 'NUMERICSA';
            break;
        case '19':
            $row['PROPEL_TYPE_KEY'] = 'CURRENCY';
            break;
        case '20':
            $row['PROPEL_TYPE_KEY'] = 'TIMESTAMP';
            break;
        case '21':
            $row['PROPEL_TYPE_KEY'] = 'CLOB/BLOB';
            break;
        case '25':
            $row['PROPEL_TYPE_KEY'] = 'WSTRING';
            break;
        case '26':
            $row['PROPEL_TYPE_KEY'] = 'WZTRING';
            break;
        case '27':
            $row['PROPEL_TYPE_KEY'] = 'GUID';
            break;
        case '28':
            $row['PROPEL_TYPE_KEY'] = 'NUMERICSLB';
            break;
        case '29':
            $row['PROPEL_TYPE_KEY'] = 'NUMERICSLS';
            break;
        case '30':
            $row['PROPEL_TYPE_KEY'] = 'DATETIME';
            break;
        case '31':
            $row['PROPEL_TYPE_KEY'] = 'NUMERICSTB';
            break;
        default:
            $row['PROPEL_TYPE_KEY'] = 'DATATYPE UNKNOWN = ' . $row['DATATYPE'];
            break;
        }

        // The original query sometimes crashed our Pervasive servers,
        // so do all calculations on PHP-side now...
        // And generation is also much faster now...
/*
        // http://www.pervasive.com/portals/55/documents/psqlv11/Accessing_the_DDF_Files_Through_Views.pdf
        $query = '
     , CASE XE$DATATYPE
          WHEN 0 THEN \'STRING\'
          WHEN 1 THEN
             CASE XE$SIZE
                WHEN 1 THEN \'TINYINT\'
                WHEN 2 THEN \'SMALLINT\'
                WHEN 4 THEN \'INTEGER\'
                WHEN 8 THEN \'BIGINT\'
                ELSE \'UNKNOWN INTEGER\'
             END
          WHEN 2 THEN
             CASE XE$SIZE
                WHEN 4 THEN \'REAL\'
                WHEN 8 THEN \'DOUBLE\'
                ELSE \'UNKNOWN REAL\'
             END
          WHEN 3 THEN \'DATE\'
          WHEN 4 THEN \'TIME\'
          WHEN 5 THEN \'DECIMAL\'
          WHEN 6 THEN \'MONEY\' -- added
          WHEN 7 THEN \'LOGICAL\' -- added
          WHEN 8 THEN \'NUMERIC\'
          WHEN 9 THEN
             CASE XE$SIZE
                WHEN 4 THEN \'BFLOAT4\'
                WHEN 8 THEN \'BFLOAT8\'
                ELSE \'UNKNOWN BFLOAT\'
             END
          WHEN 11 THEN \'VARCHAR\'
          WHEN 14 THEN
             CASE XE$SIZE
                WHEN 1 THEN \'UNSIGNED1 BINARY\'
                WHEN 2 THEN \'UNSIGNED2 BINARY\'
                WHEN 4 THEN \'UNSIGNED4 BINARY\'
                WHEN 8 THEN \'UNSIGNED8 BINARY\'
                ELSE \'UNKNOWN UNSIGNED BINARY\'
             END
          WHEN 15 THEN
             CASE XE$SIZE
                WHEN 2 THEN \'AUTOINC2\'
                WHEN 4 THEN \'AUTOINC4\'
                ELSE \'UNKNOWN AUTOINC\'
             END
          WHEN 16 THEN \'BIT\'
          WHEN 17 THEN \'NUMERICSTS\'
          WHEN 18 THEN \'NUMERICSA\'
          WHEN 19 THEN \'CURRENCY\'
          WHEN 20 THEN \'TIMESTAMP\'
          WHEN 21 THEN \'CLOB/BLOB\'
          WHEN 25 THEN \'WSTRING\'
          WHEN 26 THEN \'WZTRING\'
          WHEN 27 THEN \'GUID\'
          WHEN 28 THEN \'NUMERICSLB\' -- added
          WHEN 29 THEN \'NUMERICSLS\' -- added
          WHEN 30 THEN \'DATETIME\'
          WHEN 31 THEN \'NUMERICSTB\' -- added
          ELSE CONCAT(\'DATATYPE UNKNOWN = \', CAST(XE$DATATYPE AS CHAR(3)))
       END PROPEL_TYPE_KEY
';
*/
    }

    /**
     * Adds Columns to the specified table.
     *
     * @param Table $table
     *            The Table model class to add columns to.
     */
    protected function addColumns(Table $table, Task $task = null)
    {
        // ftp://ftp.agris.com/Pervasive/PVSW10.3/Books/SQL_Engine_Reference.pdf
        // http://www.pervasive.com/portals/55/documents/psqlv11/Accessing_the_DDF_Files_Through_Views.pdf
        // http://support.pervasive.com/t5/tkb/articleprintpage/tkb-id/Database_KnowledgeBase/article-id/162
        // TODO: XE$OFFSET is NOT unique (per table), find ordering used by Pervasive Control Center.
        // Actually it's neither by XE$ID nor by XE$NAME, arbitrarily we will use XE$NAME.
        // See also: call psp_columns(null, '$table->getName()', null)
        $query = '
SELECT TAB.XF$NAME TABLE_NAME
     , COL.XE$NAME COLUMN_NAME
     , COL.XE$DATATYPE DATATYPE
     , COL.XE$SIZE COL_SIZE
     , COL.XE$SIZE CHAR_LEN
     , COL.XE$SIZE PRECISION
     , COL.XE$DEC SCALE
     , CASE
          WHEN COL.XE$FLAGS & 4 = 4 THEN \'YES\'
          ELSE \'NO\'
       END NULLABLE
     , CASE
          WHEN ATT.XA$ID IS NOT NULL AND ATT.XA$TYPE = \'D\' THEN \'YES\'
          ELSE \'NO\'
       END HAS_DEF_VAL
     , ATT.XA$ATTRS DEFAULT_VALUE
  FROM X$FILE AS TAB
 INNER JOIN X$FIELD AS COL
    ON COL.XE$FILE = TAB.XF$ID
  LEFT JOIN X$ATTRIB AS ATT
    ON ATT.XA$ID = COL.XE$ID
   AND ATT.XA$TYPE = \'D\'
 WHERE TAB.XF$FLAGS & 16 <> 16
   AND COL.XE$DATATYPE NOT IN (227, 255)
   AND TAB.XF$NAME = \'' . $table->getName() . '\'
 ORDER BY COL.XE$OFFSET
     , COL.XE$NAME
';
        $stmt = $this->dbh->query($query);

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            array_walk($row, 'PervasiveSchemaParser::rtrim_to_utf8', $task);

            $this->calculatePropelTypeKey($row);

            $name = $row['COLUMN_NAME'];
            $type = $row['PROPEL_TYPE_KEY'];
            $size = $row['CHAR_LEN'];
            $is_nullable = $row['NULLABLE'] === 'YES';
            $has_default = $row['HAS_DEF_VAL'] === 'YES';
            $default = $row['DEFAULT_VALUE'];
            //$precision = $row['PRECISION'];
            $scale = $row['SCALE'];
            $autoincrement = false;
            if (strpos($type, 'AUTOINC') !== false) {
                $autoincrement = true;
            }

            $propelType = $this->getMappedPropelType($type);
            if ($propelType === null) {
                $propelType = Column::DEFAULT_TYPE;
                $this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
            }

            $column = new Column($name);
            // TODO: Remove...
            $column->setPhpName($this->cleanMethod($name, $task));
            $column->setTable($table);
            $column->setDomainForType($propelType);
            // We may want to provide an option to include this:
            // $column->getDomain()->replaceSqlType($type);
            $column->getDomain()->replaceSize($size);
            $column->getDomain()->replaceScale($scale);
            if ($has_default) {
                $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, ColumnDefaultValue::TYPE_VALUE));
            }
            $column->setAutoIncrement($autoincrement);
            $column->setNotNull(! $is_nullable);

            $table->addColumn($column);
        }
    }

    /**
     * Load foreign keys for this table.
     */
    protected function addForeignKeys(Table $table, Task $task = null)
    {
        $database = $table->getDatabase();

        // ftp://ftp.agris.com/Pervasive/PVSW10.3/Books/SQL_Engine_Reference.pdf
        // See also: call psp_fkeys(null, '$table->getName()', null)
        $query = '
SELECT A.XR$NAME RULE_NAME
     , TABSRC.XF$NAME FKTABLE
     , IDXSRC.XI$PART FKPART
     , FLDSRC.XE$NAME FKCOLUMN
     , TABDEST.XF$NAME PKTABLE
     , IDXDEST.XI$PART PKPART
     , FLDDEST.XE$NAME PKCOLUMN
     , CASE
          WHEN A.XR$UPDATERULE = 1 THEN \'RESTRICT\'
          ELSE \'UNKNOWN\'
       END UPDATE_RULE
     , CASE
          WHEN A.XR$DELETERULE = 1 THEN \'RESTRICT\'
          WHEN A.XR$DELETERULE = 2 THEN \'CASCADE\'
          ELSE \'UNKNOWN\'
       END DELETE_RULE
  FROM X$RELATE A
     , X$FILE TABSRC
     , X$INDEX IDXSRC
     , X$FIELD FLDSRC
     , X$FILE TABDEST
     , X$INDEX IDXDEST
     , X$FIELD FLDDEST
 WHERE TABSRC.XF$ID = A.XR$PID
   AND IDXSRC.XI$FILE = TABSRC.XF$ID
   AND IDXSRC.XI$NUMBER = A.XR$INDEX
   AND FLDSRC.XE$ID = IDXSRC.XI$FIELD
   AND FLDSRC.XE$FILE = TABSRC.XF$ID
   AND TABDEST.XF$ID = A.XR$FID
   AND IDXDEST.XI$FILE = TABDEST.XF$ID
   AND IDXDEST.XI$NUMBER = A.XR$FINDEX
   AND IDXDEST.Xi$FLAGS & POWER(2,13) <> 0
   AND FLDDEST.XE$ID = IDXDEST.XI$FIELD
   AND FLDDEST.XE$FILE = TABDEST.XF$ID
   AND IDXDEST.XI$PART = IDXSRC.XI$PART
   AND TABDEST.XF$FLAGS & 16 <> 16
   AND TABDEST.XF$NAME = \'' . $table->getName() . '\'
 ORDER BY A.XR$NAME
     , IDXDEST.XI$PART
     , IDXSRC.XI$PART
';
        $stmt = $this->dbh->query($query);

        $foreignKeys = array(); // local store to avoid duplicates
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            array_walk($row, 'PervasiveSchemaParser::rtrim_to_utf8', $task);

            $name = $row['RULE_NAME'];
            $lcol = $row['PKCOLUMN'];
            $ftbl = $row['FKTABLE'];
            $fcol = $row['FKCOLUMN'];

            $foreignTable = $database->getTable($ftbl);
            $foreignColumn = $foreignTable->getColumn($fcol);
            $localColumn = $table->getColumn($lcol);

            if (! isset($foreignKeys[$name])) {
                $fk = new ForeignKey($name);
                $fk->setForeignTableCommonName($foreignTable->getCommonName());
                $fk->setForeignSchemaName($foreignTable->getSchema());
                $fk->setOnDelete($row['DELETE_RULE']);
                $fk->setOnUpdate($row['UPDATE_RULE']);
                $table->addForeignKey($fk);
                $foreignKeys[$name] = $fk;
            }
            $foreignKeys[$name]->addReference($localColumn, $foreignColumn);
        }
    }

    /**
     * Load indexes for this table
     */
    protected function addIndexes(Table $table, Task $task = null)
    {
        // ftp://ftp.agris.com/Pervasive/PVSW10.3/Books/SQL_Engine_Reference.pdf
        // See also: call psp_indexes(null, '$table->getName()')
        //
        // Final Note - not all indexes have names.  If the DDFs have been migrated forward
        // from older versions, there might be index definitions in X$Index that do not have
        // corresponding names in X$Field.  This is acceptable, from the engine's point of view.
        //
        // Use MOD(Xi$FLAGS,2) = 0 if you want to select only the named indexes.
        //
        // NB: XE$OFFSET *should* be unique (per index), so add DISTINCT to be sure.
        $query = '
SELECT DISTINCT
       COLIDX.XE$NAME INDEX_NAME
     , COL.XE$NAME COLUMN_NAME
     , CASE
          WHEN IDX.XI$FLAGS & 1 = 0 THEN \'YES\'
          ELSE \'NO\'
       END IS_UNIQUE
     , TAB.XF$NAME TABLE_NAME
     , IDX.XI$NUMBER INDEX_NUMBER
  FROM X$FILE AS TAB
     , X$INDEX AS IDX
     , X$FIELD AS COL
     , X$FIELD AS COLIDX
 WHERE TAB.XF$FLAGS & 16 <> 16
   AND TAB.XF$NAME = \'' . $table->getName() . '\'
   AND IDX.XI$FILE = TAB.XF$ID
   AND IDX.XI$FLAGS & POWER(2,13) = 0
   AND COL.XE$ID = IDX.XI$FIELD
   AND COLIDX.XE$FILE = TAB.XF$ID
   AND COLIDX.XE$DATATYPE IN (227, 255)
   AND COLIDX.XE$OFFSET = IDX.XI$NUMBER
 ORDER BY IDX.XI$NUMBER
     , IDX.XI$PART
';
        $stmt = $this->dbh->query($query);

        $indexes = array();
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            array_walk($row, 'PervasiveSchemaParser::rtrim_to_utf8', $task);

            $colName = $row['COLUMN_NAME'];
            $name = $row['INDEX_NAME'];
            // Not all indexes have names.
            if (! strlen($name)) {
                $name = 'unnamed_index_' . $row['TABLE_NAME'] . '_' . $row['INDEX_NUMBER'];
            } elseif (strpos($name, 'unnamed_index_') === 0) {
                $name = '_' . $name;
            }
            $unique = $row['IS_UNIQUE'] === 'YES';

            if (! isset($indexes[$name])) {
                if ($unique) {
                    $indexes[$name] = new Unique($this->cleanMethod($name, $task));
                } else {
                    $indexes[$name] = new Index($this->cleanMethod($name, $task));
                }
                $table->addIndex($indexes[$name]);
            }

            $indexes[$name]->addColumn($table->getColumn($colName));
        }
    }

    /**
     * Loads the primary key for this table.
     */
    protected function addPrimaryKey(Table $table, Task $task = null)
    {
        // ftp://ftp.agris.com/Pervasive/PVSW10.3/Books/SQL_Engine_Reference.pdf
        // See also: call psp_indexes(null, '$table->getName()')
        //
        // NB: XE$OFFSET *should* be unique (per index), so put it in an EXISTS clause to be sure.
        $query = '
SELECT COL.XE$NAME
  FROM X$FILE AS TAB
     , X$INDEX AS IDX
     , X$FIELD AS COL
 WHERE TAB.XF$FLAGS & 16 <> 16
   AND TAB.XF$NAME = \'' . $table->getName() . '\'
   AND IDX.XI$FILE = TAB.XF$ID
   AND IDX.XI$FLAGS & POWER(2,13) = 0
   AND COL.XE$ID = IDX.XI$FIELD
   AND EXISTS(
       SELECT 1
         FROM X$FIELD AS COLIDX
        WHERE COLIDX.XE$FILE = TAB.XF$ID
          AND COLIDX.XE$DATATYPE IN (227, 255)
          AND COLIDX.XE$OFFSET = IDX.XI$NUMBER
       )
   AND IDX.XI$FLAGS & 1 = 0
 ORDER BY IDX.XI$NUMBER
     , IDX.XI$PART
';
        $stmt = $this->dbh->query($query);

        // Loop through the returned results, grouping the same key_name together
        // adding each column for that key.
        while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            array_walk($row, 'PervasiveSchemaParser::rtrim_to_utf8', $task);

            $name = $row[0];
            $table->getColumn($name)->setPrimaryKey(true);
        }
    }

    /**
     * according to the identifier definition, we have to clean simple quote (') around the identifier name
     * returned by pervasive
     *
     * @see http://msdn.microsoft.com/library/ms175874.aspx
     *
     * @param string $identifier
     *
     * @return string
     */
    protected function cleanDelimitedIdentifiers($identifier)
    {
        return preg_replace('/^\'(.*)\'$/U', '$1', $identifier);
    }
}


text:
"""Compute class accuracy for manysstubs4j.
"""
import collections

from plur.eval import util as eval_util
from plur.eval.plur_eval import PlurEval
from plur.utils import util

class Manysstubs4jEval(PlurEval):
  """Eval class for manysstubs4j dataset."""

  def compute_metric_for_one_target(self, beam_prediction_lines, target_line):
    """Compute class accuracy between the prediction and target.

    We define manysstubs4j as a classification task. Currently there is
    no tool that has evaluations on this task, so for now we define the
    evaluation metric as the class accuracy. The target line is the ground truth
    bug type, ie. 'WRONG_FUNCTION_NAME'. The predictions should have the same
    format.

    Args:
      beam_prediction_lines: A list of prediction strings. Each string is a
        predicted class name.
      target_line: The ground truth line.
    Returns:
      A integer, 1 means that one of the predicted class is correct, and 0
      otherwise.
    """
    for line in beam_prediction_lines:
      if line == target_line:
        return 1
    return 0

  def evaluate_once(self, grouped_prediction_lines, target_lines):

    # Sum all numbers for predictions and compute the final metric.
    total_correct = 0
    total_attempts = 0
    for beam_prediction_lines, target_line in zip(
        grouped_prediction_lines, target_lines):
      total_correct += self.compute_metric_for_one_target(
          beam_prediction_lines, target_line)
      total_attempts += 1

    class_acc = util.safe_division(total_correct, total_attempts)

    metrics = collections.OrderedDict()
    metrics_format = collections.OrderedDict()

    metrics['class_acc'] = class_acc
    metrics_format['class_acc'] = '{:.5f}'

    return eval_util.Results(
        total=len(target_lines), metrics=metrics, metrics_format=metrics_format)

  def get_metric_as_string(self):
    return str(self.evaluate())

redpajama_set_name: RedPajamaGithub


text:
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry5.commons.util;

import java.util.regex.Pattern;

/**
 * Some utility methods used in different Tapestry subprojects.
 */
public class CommonsUtils
{

    private static final String SLASH = "/";

    private static final Pattern SLASH_PATTERN = Pattern.compile(SLASH);

    private static final Pattern COMMA_PATTERN = Pattern.compile("\\s*,\\s*");

    /**
     * Splits a path at each slash.
     */
    public static String[] splitPath(String path)
    {
        return SLASH_PATTERN.split(path);
    }

    /**
     * Splits a value around commas. Whitespace around the commas is removed, as is leading and trailing whitespace.
     *
     * @since 5.1.0.0
     */
    public static String[] splitAtCommas(String value)
    {
        if (isBlank(value))
            return EMPTY_STRING_ARRAY;

        return COMMA_PATTERN.split(value.trim());
    }

    /**
     * Returns true if the input is null, or is a zero length string (excluding leading/trailing whitespace).
     */

    public static boolean isBlank(String input)
    {
        return input == null || input.length() == 0 || input.trim().length() == 0;
    }

    public static final String[] EMPTY_STRING_ARRAY = new String[0];

}


text:
package tech.tablesaw.aggregate;

import tech.tablesaw.api.BooleanColumn;
import tech.tablesaw.api.ColumnType;

/**
 * Partial implementation of Aggregate function that returns a Double value when applied to a
 * BooleanColumn
 */
public abstract class BooleanDoubleAggregateFunction
    extends AggregateFunction<BooleanColumn, Double> {

  /**
   * Constructs a BooleanNumericFunction with the given name. The name may be used to name a column
   * in the output when this function is used by {@link Summarizer}
   */
  public BooleanDoubleAggregateFunction(String functionName) {
    super(functionName);
  }

  /** Returns a double that is the result of applying this function to the given column */
  @Override
  public abstract Double summarize(BooleanColumn column);

  /** {@inheritDoc} */
  @Override
  public boolean isCompatibleColumn(ColumnType type) {
    return type.equals(ColumnType.BOOLEAN);
  }

  /** {@inheritDoc} */
  @Override
  public ColumnType returnType() {
    return ColumnType.DOUBLE;
  }
}


text:
Chef::Resource::Execute.send(:include, Cygwin::Helpers)

directory node['cygwin']['download_path'] do
  recursive true
end

architecture = node['kernel']['machine'] =~ /x86_64/ ? "x86_64" : "x86"

remote_file "#{node['cygwin']['download_path']}/setup.exe" do
  source "http://cygwin.com/setup-#{architecture}.exe"
  action :create
end

execute "setup.exe" do
  cwd node['cygwin']['download_path']
  command "setup.exe -q -O -R #{node['cygwin']['home']} -s #{node['cygwin']['site']} #{proxy_command}"
  not_if { File.exists?("C:/cygwin/etc/passwd") }
end

windows_path "#{node['cygwin']['home']}/bin".gsub( /\//, "\\") do
  action :add
end

# Initially install a list of defined packages
node['cygwin']['packages'].each do |pkg|
    cygwin_package pkg do
        action :install
    end
end


text:
import React, {Component} from 'react'
import {observer, inject} from 'mobx-react';
import {List, InputItem, TextareaItem, Picker, Button, WhiteSpace, WingBlank, Toast} from 'antd-mobile';
import {HeadTitle} from './../../components/Index'
import {createForm} from 'rc-form';
import Qs from 'qs';

import {Protected} from "./../../components/Index";

@Protected
@inject('repairStore', 'generalStore', 'userStore')
@observer
class Index extends Component {

    state = {
        region: [],
        regionCols: 1,
        UserNameStatus: false
    };

    constructor(props) {
        super(props);
        this.store = {
            repairStore: props.repairStore,
            generalStore: props.generalStore,
            userStore: props.userStore
        };
    }

    componentDidMount() {
        this.store.repairStore.getRegion();
        this.store.generalStore.getCategory();
    }

    save(e) {
        if (e) e.preventDefault();
        let post = this.props.form.getFieldsValue();
        this.axios.post('/XRepair/BackEnd/public/service/general/addOrder', Qs.stringify(post)).then((res) => {
            let data = res.data;
            if (data.code == 200) {
                Toast.success(data.message, 1.5);
            } else {
                Toast.fail(data.message, 1.5);
            }
        }).catch((e) => {
            Toast.offline(e.message, 1.5)
        });
    }

    render() {
        const _this = this;
        const {getFieldProps} = this.props.form;
        const {regionList, regionCols} = this.store.repairStore;
        const {categoryList, categoryCols} = this.store.generalStore;
        const {userInfo} = this.store.userStore;
        return (
            <div id="general-index">
                <HeadTitle title="通用报修" subTitle="集合多种报修项目"/>

                <List renderHeader={() => '个人信息'}>
                    <InputItem
                        {...getFieldProps('name', {
                            initialValue: userInfo.name
                        })}
                        clear
                        placeholder="请输入你的姓名"
                    >姓名</InputItem>
                    <InputItem
                        {...getFieldProps('mobile', {
                            initialValue: userInfo.mobile
                        })}
                        clear
                        placeholder="请输入你的手机号码"
                    >手机号码</InputItem>
                </List>

                <List renderHeader={() => '报修信息'}>
                    <Picker data={regionList} cols={regionCols} {...getFieldProps('regions')}>
                        <List.Item arrow="horizontal">区域</List.Item>
                    </Picker>
                    <Picker data={categoryList} cols={categoryCols} {...getFieldProps('categorys')}>
                        <List.Item arrow="horizontal">选择报修项目</List.Item>
                    </Picker>
                </List>

                <List renderHeader={() => '故障描述'}>
                    <TextareaItem
                        placeholder="请描述一下你的故障情况!"
                        {...getFieldProps('desc')}
                        rows={5}
                        count={200}
                    />
                </List>

                <WhiteSpace size="lg"/>
                <WingBlank size="sm">
                    <Button className="btn" type="primary" onClick={_this.save.bind(_this)}>提交报修</Button>
                </WingBlank>
                <WhiteSpace size="lg"/>
            </div>
        );
    }
}

export default createForm()(Index);


text:
package org.wso2.siddhi.core.partition;

import org.wso2.siddhi.core.query.QueryRuntime;

import java.util.List;

/**
 * Class to represent each partition key instance. These will be created dynamically and will contain
 * {@link QueryRuntime}s belonging to that partition key.
 */
public class PartitionInstanceRuntime {
    private String key;
    private List<QueryRuntime> queryRuntimeList;

    public PartitionInstanceRuntime(String key, List<QueryRuntime> queryRuntimeList) {
        this.key = key;
        this.queryRuntimeList = queryRuntimeList;
    }

    public List<QueryRuntime> getQueryRuntimeList() {
        return queryRuntimeList;
    }

    public String getKey() {
        return key;
    }

}


text:
var run = require('./lib/index.js').default;

exports.handler = function(event, context) {
	run(function(data) {
		context.succeed(data);
	});
}


text:
package co.cask.cdap.common.stream.notification;

import com.google.common.base.Objects;

/**
 * Notification sent by the stream service when a stream has ingested a certain amount of data,
 * determined in the configuration of the stream.
 * The size is the absolute size of data ever ingested by the stream, in bytes.
 */
public class StreamSizeNotification {
  private final long timestamp;
  private final long size;

  public StreamSizeNotification(long timestamp, long size) {
    this.timestamp = timestamp;
    this.size = size;
  }

  public long getTimestamp() {
    return timestamp;
  }

  public long getSize() {
    return size;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    StreamSizeNotification that = (StreamSizeNotification) o;

    return Objects.equal(this.timestamp, that.timestamp) &&
      Objects.equal(this.size, that.size);
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(timestamp, size);
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
      .add("timestamp", timestamp)
      .add("size", size)
      .toString();
  }
}


text:
SimpleNavigation::Configuration.run do |navigation|
  # Specify a custom renderer if needed.
  # The default renderer is SimpleNavigation::Renderer::List which renders HTML lists.
  # The renderer can also be specified as option in the render_navigation call.
  # navigation.renderer = Your::Custom::Renderer

  # Specify the class that will be applied to active navigation items.
  # Defaults to 'selected' navigation.selected_class = 'your_selected_class'

  # Specify the class that will be applied to the current leaf of
  # active navigation items. Defaults to 'simple-navigation-active-leaf'
  # navigation.active_leaf_class = 'your_active_leaf_class'

  # Item keys are normally added to list items as id.
  # This setting turns that off
  # navigation.autogenerate_item_ids = false

  # You can override the default logic that is used to autogenerate the item ids.
  # To do this, define a Proc which takes the key of the current item as argument.
  # The example below would add a prefix to each key.
  # navigation.id_generator = Proc.new {|key| "my-prefix-#{key}"}

  # If you need to add custom html around item names, you can define a proc that
  # will be called with the name you pass in to the navigation.
  # The example below shows how to wrap items spans.
  # navigation.name_generator = Proc.new {|name, item| "<span>#{name}</span>"}

  # The auto highlight feature is turned on by default.
  # This turns it off globally (for the whole plugin)
  # navigation.auto_highlight = false

  # If this option is set to true, all item names will be considered as safe (passed through html_safe). Defaults to false.
  # navigation.consider_item_names_as_safe = false

  # Define the primary navigation
  navigation.renderer = SimpleNavigationRenderers::Bootstrap3

  navigation.items do |primary|

    primary.item :user_options, {icon: "glyphicon glyphicon-list", title: "Menu"}, if: -> { current_user } do |user_options|

      user_options.item :propiedades, 'Propiedades', '#', if: -> { current_user.is_a?(LeaseHolder) } do |propiedades|
        propiedades.item :mostrar, 'Mis Propiedades', user_properties_path(current_user.id)
        propiedades.item :agregar, 'Registrar Propiedad', new_user_property_path(current_user.id)
      end

      user_options.item :operaciones, 'Operaciones', '#', if: -> { current_user.is_a?(LeaseHolder) || current_user.is_a?(Consultant) } do |operaciones|
        operaciones.item :show, 'Mis Operaciones', '#'
        operaciones.item :show, 'Nueva Operación', new_user_operation_path(current_user.id)
      end

      user_options.item :usuarios, 'Usuarios', '#', if: -> { current_user.is_admin? } do |usuarios|
        usuarios.item :show, 'Listar', '#'
        usuarios.item :show_roles, 'Roles', '#'
      end

      user_options.item :lugares, 'Lugares', '#', if: -> { current_user.is_admin? } do |lugares|
        lugares.item :show, 'Cargar', new_location_path
        lugares.item :show_roles, 'Ver todos', '#'
      end

    end

    primary.dom_class = 'nav'

  end
end


text:
/**
 \file shape.h
 \author Dmitry Kozlov
 \version 1.0
 \brief Contains declaration of various shape types supported by the renderer.
 */
#pragma once

#include "math/float3.h"
#include "math/float2.h"
#include "math/matrix.h"
#include "math/bbox.h"
#include <memory>
#include <string>
#include <vector>

#include "scene_object.h"
#include "material.h"

namespace Baikal
{
    class Material;

    /**
     \brief Shape base interface.

     High-level interface all shape classes need to implement.
     */
    class Shape : public SceneObject
    {
    public:
        using Ptr = std::shared_ptr<Shape>;

        struct Visibility
        {
            enum VisibilityFlags
            {
                kPrimary = 0x1,
                kShadow = (0x1 << 15)
            };

            static VisibilityFlags VisibleForAll() { return (VisibilityFlags)0xffffffffu; }
            static VisibilityFlags InvisibleForAll() { return (VisibilityFlags)0x0u; }
            static VisibilityFlags VisibleForPrimary() { return kPrimary; }
            static VisibilityFlags VisibleForPrimaryShadow() { return kShadow; }
            static VisibilityFlags VisibleForBounce(int i) { return (VisibilityFlags)(kPrimary << i); }
            static VisibilityFlags VisibleForBounceShadow(int i) { return (VisibilityFlags)(kShadow << i); }
        };

        // Destructor
        virtual ~Shape() = 0;

        // Get and set material
        void SetMaterial(Material::Ptr material);
        Material::Ptr GetMaterial() const;

        // Get and set volume material
        void SetVolumeMaterial(VolumeMaterial::Ptr volume_mat);
        VolumeMaterial::Ptr GetVolumeMaterial() const;

        // Get and set transform
        void SetTransform(RadeonRays::matrix const& t);
        RadeonRays::matrix GetTransform() const;

        // Set whether a shape casts shadow or not
        void SetShadow(bool shadow);
        bool GetShadow() const;

        // Set visibility properties for a shape
        void SetVisibilityMask(std::uint32_t mask);
        std::uint32_t GetVisibilityMask() const;

        // Local AABB
        virtual RadeonRays::bbox GetLocalAABB() const = 0;
        RadeonRays::bbox GetWorldAABB() const;

        // Forbidden stuff
        Shape(Shape const&) = delete;
        Shape& operator = (Shape const&) = delete;

    protected:
        // Constructor
        Shape();

    private:
        // Material for the shape
        Material::Ptr m_material;
        // Volume material for the shape
        VolumeMaterial::Ptr m_volume;
        // Transform
        RadeonRays::matrix m_transform;
        // Visibility mask
        std::uint32_t m_visibility_mask;
    };

    /**
     \brief Triangle mesh class.

     Triangle mesh is a collection of indexed triangle.
     */
    class Mesh : public Shape
    {
    public:
        using Ptr = std::shared_ptr<Mesh>;
        static Ptr Create();

        // Set and get index array
        void SetIndices(std::uint32_t const* indices, std::size_t num_indices);
        void SetIndices(std::vector<std::uint32_t>&& indices);
        std::size_t GetNumIndices() const;
        std::uint32_t const* GetIndices() const;

        // Set and get vertex array
        void SetVertices(RadeonRays::float3 const* vertices, std::size_t num_vertices);
        void SetVertices(float const* vertices, std::size_t num_vertices);
        void SetVertices(std::vector<RadeonRays::float3>&& vertices);

        std::size_t GetNumVertices() const;
        RadeonRays::float3 const* GetVertices() const;

        // Set and get normal array
        void SetNormals(RadeonRays::float3 const* normals, std::size_t num_normals);
        void SetNormals(float const* normals, std::size_t num_normals);
        void SetNormals(std::vector<RadeonRays::float3>&& normals);

        std::size_t GetNumNormals() const;
        RadeonRays::float3 const* GetNormals() const;

        // Set and get UV array
        void SetUVs(RadeonRays::float2 const* uvs, std::size_t num_uvs);
        void SetUVs(float const* uvs, std::size_t num_uvs);
        void SetUVs(std::vector<RadeonRays::float2>&& uvs);
        std::size_t GetNumUVs() const;
        RadeonRays::float2 const* GetUVs() const;

        // Local space AABB
        RadeonRays::bbox GetLocalAABB() const override;

        // We need to override it since mesh changes trigger
        // m_aabb_cached flag reset
        void SetDirty(bool dirty) const override;

        // Forbidden stuff
        Mesh(Mesh const&) = delete;
        Mesh& operator = (Mesh const&) = delete;

    protected:
        Mesh();

    private:
        std::vector<RadeonRays::float3> m_vertices;
        std::vector<RadeonRays::float3> m_normals;
        std::vector<RadeonRays::float2> m_uvs;
        std::vector<std::uint32_t> m_indices;

        mutable RadeonRays::bbox m_aabb;
        mutable bool m_aabb_cached;
    };

    inline Shape::~Shape()
    {
    }

    inline Shape::Shape()
        : m_material(nullptr)
        , m_volume(nullptr)
        , m_visibility_mask(0xffffffffu)
    {
    }

    inline void Shape::SetMaterial(Material::Ptr material)
    {
        m_material = material;
        SetDirty(true);
    }

    inline Material::Ptr Shape::GetMaterial() const
    {
        return m_material;
    }

    inline void Shape::SetVolumeMaterial(VolumeMaterial::Ptr volume_mat)
    {
        m_volume = volume_mat;
        SetDirty(true);
    }

    inline VolumeMaterial::Ptr Shape::GetVolumeMaterial() const
    {
        return m_volume;
    }

    inline void Shape::SetTransform(RadeonRays::matrix const& t)
    {
        m_transform = t;
        SetDirty(true);
    }

    inline RadeonRays::matrix Shape::GetTransform() const
    {
        return m_transform;
    }

    inline void Shape::SetVisibilityMask(std::uint32_t mask)
    {
        m_visibility_mask = mask;
        SetDirty(true);
    }

    inline std::uint32_t Shape::GetVisibilityMask() const
    {
        return m_visibility_mask;
    }

    /**
    \brief Instance class.

    Instance references some mesh, but might have different transform and material.
    */
    class Instance : public Shape
    {
    public:
        using Ptr = std::shared_ptr<Instance>;
        static Ptr Create(Shape::Ptr base_shape);

        // Get and set base shape
        void SetBaseShape(Shape::Ptr base_shape);
        Shape::Ptr GetBaseShape() const;

        // Local space AABB
        RadeonRays::bbox GetLocalAABB() const override;

        // Forbidden stuff
        Instance(Instance const&) = delete;
        Instance& operator = (Instance const&) = delete;

    protected:
        Instance(Shape::Ptr base_shape = nullptr);

    private:
        Shape::Ptr m_base_shape;
    };

    inline Instance::Instance(Shape::Ptr base_shape)
        : m_base_shape(base_shape)
    {
    }

    inline void Instance::SetBaseShape(Shape::Ptr base_shape)
    {
        m_base_shape = base_shape;
        SetDirty(true);
    }

    inline Shape::Ptr Instance::GetBaseShape() const
    {
        return m_base_shape;
    }
}


text:
FOUNDATION_EXPORT double Pods_ObjcSwiftTest_TestsVersionNumber;
FOUNDATION_EXPORT const unsigned char Pods_ObjcSwiftTest_TestsVersionString[];


text:
{% include "includes/phase_banner_alpha.html" %}
{% extends "layout.html" %}
{% block page_title %}
  Water abstraction licence
{% endblock %}
{% block content %}

      ALPHA
    This is an Alpha prototype, details may be missing whilst we build the service. Your feedback will help us improve this service.

< Back to previous

{% endblock %}


text:
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.ml;

import com.facebook.presto.operator.aggregation.AggregationFunction;
import com.facebook.presto.operator.aggregation.CombineFunction;
import com.facebook.presto.operator.aggregation.InputFunction;
import com.facebook.presto.operator.aggregation.OutputFunction;
import com.facebook.presto.spi.block.BlockBuilder;
import com.facebook.presto.type.SqlType;
import io.airlift.slice.Slice;

import static com.facebook.presto.ml.type.ClassifierType.VARCHAR_CLASSIFIER;
import static com.facebook.presto.spi.type.StandardTypes.VARCHAR;

@AggregationFunction(value = "learn_libsvm_classifier", decomposable = false)
public final class LearnLibSvmVarcharClassifierAggregation
{
    private LearnLibSvmVarcharClassifierAggregation() {}

    @InputFunction
    public static void input(
            LearnState state,
            @SqlType(VARCHAR) Slice label,
            @SqlType("map<bigint,double>") Slice features,
            @SqlType(VARCHAR) Slice parameters)
    {
        state.getLabels().add((double) state.enumerateLabel(label.toStringUtf8()));
        FeatureVector featureVector = ModelUtils.toFeatures(features);
        state.addMemoryUsage(featureVector.getEstimatedSize());
        state.getFeatureVectors().add(featureVector);
        state.setParameters(parameters);
    }

    @CombineFunction
    public static void combine(LearnState state, LearnState otherState)
    {
        throw new UnsupportedOperationException("LEARN must run on a single machine");
    }

    @OutputFunction("Classifier<varchar>")
    public static void output(LearnState state, BlockBuilder out)
    {
        Dataset dataset = new Dataset(state.getLabels(), state.getFeatureVectors(), state.getLabelEnumeration().inverse());
        Model model = new StringClassifierAdapter(new ClassifierFeatureTransformer(new SvmClassifier(LibSvmUtils.parseParameters(state.getParameters().toStringUtf8())), new FeatureUnitNormalizer()));
        model.train(dataset);
        VARCHAR_CLASSIFIER.writeSlice(out, ModelUtils.serialize(model));
    }
}


text:
package org.apache.camel.builder.endpoint.dsl;

import javax.annotation.Generated;
import org.apache.camel.builder.EndpointConsumerBuilder;
import org.apache.camel.builder.EndpointProducerBuilder;
import org.apache.camel.builder.endpoint.AbstractEndpointBuilder;

/**
 * The solr component allows you to interface with an Apache Lucene Solr server.
 *
 * Generated by camel-package-maven-plugin - do not edit this file!
 */
@Generated("org.apache.camel.maven.packaging.EndpointDslMojo")
public interface SolrEndpointBuilderFactory {

    /**
     * Builder for endpoint for the Solr component.
     */
    public interface SolrEndpointBuilder extends EndpointProducerBuilder {
        default AdvancedSolrEndpointBuilder advanced() {
            return (AdvancedSolrEndpointBuilder) this;
        }
        /**
         * Server side must support gzip or deflate for this to have any effect.
         *
         * The option is a: java.lang.Boolean type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder allowCompression(Boolean allowCompression) {
            doSetProperty("allowCompression", allowCompression);
            return this;
        }
        /**
         * Server side must support gzip or deflate for this to have any effect.
         *
         * The option will be converted to a java.lang.Boolean
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder allowCompression(String allowCompression) {
            doSetProperty("allowCompression", allowCompression);
            return this;
        }
        /**
         * connectionTimeout on the underlying HttpConnectionManager.
         *
         * The option is a: java.lang.Integer type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder connectionTimeout(Integer connectionTimeout) {
            doSetProperty("connectionTimeout", connectionTimeout);
            return this;
        }
        /**
         * connectionTimeout on the underlying HttpConnectionManager.
         *
         * The option will be converted to a java.lang.Integer
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder connectionTimeout(String connectionTimeout) {
            doSetProperty("connectionTimeout", connectionTimeout);
            return this;
        }
        /**
         * maxConnectionsPerHost on the underlying HttpConnectionManager.
         *
         * The option is a: java.lang.Integer type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder defaultMaxConnectionsPerHost(
                Integer defaultMaxConnectionsPerHost) {
            doSetProperty("defaultMaxConnectionsPerHost", defaultMaxConnectionsPerHost);
            return this;
        }
        /**
         * maxConnectionsPerHost on the underlying HttpConnectionManager.
         *
         * The option will be converted to a java.lang.Integer
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder defaultMaxConnectionsPerHost(
                String defaultMaxConnectionsPerHost) {
            doSetProperty("defaultMaxConnectionsPerHost", defaultMaxConnectionsPerHost);
            return this;
        }
        /**
         * indicates whether redirects are used to get to the Solr server.
         *
         * The option is a: java.lang.Boolean type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder followRedirects(Boolean followRedirects) {
            doSetProperty("followRedirects", followRedirects);
            return this;
        }
        /**
         * indicates whether redirects are used to get to the Solr server.
         *
         * The option will be converted to a java.lang.Boolean
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder followRedirects(String followRedirects) {
            doSetProperty("followRedirects", followRedirects);
            return this;
        }
        /**
         * Whether the producer should be started lazy (on the first message).
         * By starting lazy you can use this to allow CamelContext and routes to
         * startup in situations where a producer may otherwise fail during
         * starting and cause the route to fail being started. By deferring this
         * startup to be lazy then the startup failure can be handled during
         * routing messages via Camel's routing error handlers. Beware that when
         * the first message is processed then creating and starting the
         * producer may take a little time and prolong the total processing time
         * of the processing.
         *
         * The option is a: boolean type.
         *
         * Default: false
         * Group: producer
         */
        default SolrEndpointBuilder lazyStartProducer(boolean lazyStartProducer) {
            doSetProperty("lazyStartProducer", lazyStartProducer);
            return this;
        }
        /**
         * Whether the producer should be started lazy (on the first message).
         * By starting lazy you can use this to allow CamelContext and routes to
         * startup in situations where a producer may otherwise fail during
         * starting and cause the route to fail being started. By deferring this
         * startup to be lazy then the startup failure can be handled during
         * routing messages via Camel's routing error handlers. Beware that when
         * the first message is processed then creating and starting the
         * producer may take a little time and prolong the total processing time
         * of the processing.
         *
         * The option will be converted to a boolean type.
         *
         * Default: false
         * Group: producer
         */
        default SolrEndpointBuilder lazyStartProducer(String lazyStartProducer) {
            doSetProperty("lazyStartProducer", lazyStartProducer);
            return this;
        }
        /**
         * Maximum number of retries to attempt in the event of transient
         * errors.
         *
         * The option is a: java.lang.Integer type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder maxRetries(Integer maxRetries) {
            doSetProperty("maxRetries", maxRetries);
            return this;
        }
        /**
         * Maximum number of retries to attempt in the event of transient
         * errors.
         *
         * The option will be converted to a java.lang.Integer
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder maxRetries(String maxRetries) {
            doSetProperty("maxRetries", maxRetries);
            return this;
        }
        /**
         * maxTotalConnection on the underlying HttpConnectionManager.
         *
         * The option is a: java.lang.Integer type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder maxTotalConnections(
                Integer maxTotalConnections) {
            doSetProperty("maxTotalConnections", maxTotalConnections);
            return this;
        }
        /**
         * maxTotalConnection on the underlying HttpConnectionManager.
         *
         * The option will be converted to a java.lang.Integer
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder maxTotalConnections(
                String maxTotalConnections) {
            doSetProperty("maxTotalConnections", maxTotalConnections);
            return this;
        }
        /**
         * Set the request handler to be used.
         *
         * The option is a: java.lang.String type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder requestHandler(String requestHandler) {
            doSetProperty("requestHandler", requestHandler);
            return this;
        }
        /**
         * Read timeout on the underlying HttpConnectionManager. This is
         * desirable for queries, but probably not for indexing.
         *
         * The option is a: java.lang.Integer type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder soTimeout(Integer soTimeout) {
            doSetProperty("soTimeout", soTimeout);
            return this;
        }
        /**
         * Read timeout on the underlying HttpConnectionManager. This is
         * desirable for queries, but probably not for indexing.
         *
         * The option will be converted to a java.lang.Integer
         * type.
         *
         * Group: producer
         */
        default SolrEndpointBuilder soTimeout(String soTimeout) {
            doSetProperty("soTimeout", soTimeout);
            return this;
        }
        /**
         * Set the queue size for the StreamingUpdateSolrServer.
         *
         * The option is a: int type.
         *
         * Default: 10
         * Group: producer
         */
        default SolrEndpointBuilder streamingQueueSize(int streamingQueueSize) {
            doSetProperty("streamingQueueSize", streamingQueueSize);
            return this;
        }
        /**
         * Set the queue size for the StreamingUpdateSolrServer.
         *
         * The option will be converted to a int type.
         *
         * Default: 10
         * Group: producer
         */
        default SolrEndpointBuilder streamingQueueSize(String streamingQueueSize) {
            doSetProperty("streamingQueueSize", streamingQueueSize);
            return this;
        }
        /**
         * Set the number of threads for the StreamingUpdateSolrServer.
         *
         * The option is a: int type.
         *
         * Default: 2
         * Group: producer
         */
        default SolrEndpointBuilder streamingThreadCount(
                int streamingThreadCount) {
            doSetProperty("streamingThreadCount", streamingThreadCount);
            return this;
        }
        /**
         * Set the number of threads for the StreamingUpdateSolrServer.
         *
         * The option will be converted to a int type.
         *
         * Default: 2
         * Group: producer
         */
        default SolrEndpointBuilder streamingThreadCount(
                String streamingThreadCount) {
            doSetProperty("streamingThreadCount", streamingThreadCount);
            return this;
        }
        /**
         * Sets password for basic auth plugin enabled servers.
         *
         * The option is a: java.lang.String type.
         *
         * Group: security
         */
        default SolrEndpointBuilder password(String password) {
            doSetProperty("password", password);
            return this;
        }
        /**
         * Sets username for basic auth plugin enabled servers.
         *
         * The option is a: java.lang.String type.
         *
         * Group: security
         */
        default SolrEndpointBuilder username(String username) {
            doSetProperty("username", username);
            return this;
        }
        /**
         * Set the collection name which the solrCloud server could use.
         *
         * The option is a: java.lang.String type.
         *
         * Group: solrCloud
         */
        default SolrEndpointBuilder collection(String collection) {
            doSetProperty("collection", collection);
            return this;
        }
        /**
         * Set the ZooKeeper host information which the solrCloud could use,
         * such as zkhost=localhost:8123.
         *
         * The option is a: java.lang.String type.
         *
         * Group: solrCloud
         */
        default SolrEndpointBuilder zkHost(String zkHost) {
            doSetProperty("zkHost", zkHost);
            return this;
        }
    }

    /**
     * Advanced builder for endpoint for the Solr component.
     */
    public interface AdvancedSolrEndpointBuilder
            extends
                EndpointProducerBuilder {
        default SolrEndpointBuilder basic() {
            return (SolrEndpointBuilder) this;
        }
        /**
         * Whether the endpoint should use basic property binding (Camel 2.x) or
         * the newer property binding with additional capabilities.
         *
         * The option is a: boolean type.
         *
         * Default: false
         * Group: advanced
         */
        default AdvancedSolrEndpointBuilder basicPropertyBinding(
                boolean basicPropertyBinding) {
            doSetProperty("basicPropertyBinding", basicPropertyBinding);
            return this;
        }
        /**
         * Whether the endpoint should use basic property binding (Camel 2.x) or
         * the newer property binding with additional capabilities.
         *
         * The option will be converted to a boolean type.
         *
         * Default: false
         * Group: advanced
         */
        default AdvancedSolrEndpointBuilder basicPropertyBinding(
                String basicPropertyBinding) {
            doSetProperty("basicPropertyBinding", basicPropertyBinding);
            return this;
        }
        /**
         * Sets whether synchronous processing should be strictly used, or Camel
         * is allowed to use asynchronous processing (if supported).
         *
         * The option is a: boolean type.
         *
         * Default: false
         * Group: advanced
         */
        default AdvancedSolrEndpointBuilder synchronous(boolean synchronous) {
            doSetProperty("synchronous", synchronous);
            return this;
        }
        /**
         * Sets whether synchronous processing should be strictly used, or Camel
         * is allowed to use asynchronous processing (if supported).
         *
         * The option will be converted to a boolean type.
         *
         * Default: false
         * Group: advanced
         */
        default AdvancedSolrEndpointBuilder synchronous(String synchronous) {
            doSetProperty("synchronous", synchronous);
            return this;
        }
    }

    public interface SolrBuilders {
        /**
         * Solr (camel-solr)
         * The solr component allows you to interface with an Apache Lucene Solr
         * server.
         *
         * Category: monitoring,search
         * Since: 2.9
         * Maven coordinates: org.apache.camel:camel-solr
         *
         * Syntax: solr:url
         *
         * Path parameter: url (required)
         * Hostname and port for the solr server
         */
        default SolrEndpointBuilder solr(String path) {
            return SolrEndpointBuilderFactory.solr(path);
        }
        /**
         * Solr (camel-solr)
         * The solr component allows you to interface with an Apache Lucene Solr
         * server.
         *
         * Category: monitoring,search
         * Since: 2.9
         * Maven coordinates: org.apache.camel:camel-solr
         *
         * Syntax: solrCloud:url
         *
         * Path parameter: url (required)
         * Hostname and port for the solr server
         */
        default SolrEndpointBuilder solrCloud(String path) {
            return SolrEndpointBuilderFactory.solrCloud(path);
        }
        /**
         * Solr (Secure) (camel-solr)
         * The solr component allows you to interface with an Apache Lucene Solr
         * server.
         *
         * Category: monitoring,search
         * Since: 2.9
         * Maven coordinates: org.apache.camel:camel-solr
         *
         * Syntax: solrs:url
         *
         * Path parameter: url (required)
         * Hostname and port for the solr server
         */
        default SolrEndpointBuilder solrs(String path) {
            return SolrEndpointBuilderFactory.solrs(path);
        }
        /**
         * Solr (camel-solr)
         * The solr component allows you to interface with an Apache Lucene Solr
         * server.
         *
         * Category: monitoring,search
         * Since: 2.9
         * Maven coordinates: org.apache.camel:camel-solr
         */
        default SolrEndpointBuilder solr(String scheme, String path) {
            return SolrEndpointBuilderFactory.solr(scheme,path);
        }
    }
    /**
     * Solr (camel-solr)
     * The solr component allows you to interface with an Apache Lucene Solr
     * server.
     *
     * Category: monitoring,search
     * Since: 2.9
     * Maven coordinates: org.apache.camel:camel-solr
     *
     * Syntax: solr:url
     *
     * Path parameter: url (required)
     * Hostname and port for the solr server
     */
    static SolrEndpointBuilder solr(String path) {
        return solr("solr", path);
    }
    /**
     * Solr (camel-solr)
     * The solr component allows you to interface with an Apache Lucene Solr
     * server.
     *
     * Category: monitoring,search
     * Since: 2.9
     * Maven coordinates: org.apache.camel:camel-solr
     *
     * Syntax: solrCloud:url
     *
     * Path parameter: url (required)
     * Hostname and port for the solr server
     */
    static SolrEndpointBuilder solrCloud(String path) {
        return solr("solrCloud", path);
    }
    /**
     * Solr (Secure) (camel-solr)
     * The solr component allows you to interface with an Apache Lucene Solr
     * server.
     *
     * Category: monitoring,search
     * Since: 2.9
     * Maven coordinates: org.apache.camel:camel-solr
     *
     * Syntax: solrs:url
     *
     * Path parameter: url (required)
     * Hostname and port for the solr server
     */
    static SolrEndpointBuilder solrs(String path) {
        return solr("solrs", path);
    }
    /**
     * Solr (camel-solr)
     * The solr component allows you to interface with an Apache Lucene Solr
     * server.
     *
     * Category: monitoring,search
     * Since: 2.9
     * Maven coordinates: org.apache.camel:camel-solr
     */
    static SolrEndpointBuilder solr(String scheme, String path) {
        class SolrEndpointBuilderImpl extends AbstractEndpointBuilder implements SolrEndpointBuilder, AdvancedSolrEndpointBuilder {
            public SolrEndpointBuilderImpl(String scheme, String path) {
                super(scheme, path);
            }
        }
        return new SolrEndpointBuilderImpl(scheme, path);
    }
}


text:
template<class T>
struct add_rval_ref {
  typedef T&& type;
};

template<>
struct add_rval_ref<void> {
  typedef void type;
};

template<class T>
typename add_rval_ref<T>::type create();

template<class T, class... Args>
decltype(T{create<Args>()...}, char()) f(int);

template<class, class...>
char (&f(...))[2];

static_assert(sizeof(f<int, void>(0)) != 1, "Error"); // #


text:
package com.terahorse.zp.client;

import com.terahorse.zp.converter.DeezerConverter;
import com.terahorse.zp.model.deezer.PlaylistDeezer;
import com.terahorse.zp.model.deezer.PlaylistsDeezer;
import com.terahorse.zp.model.zp.Playlist;
import com.terahorse.zp.model.zp.Playlists;

public class DeezerClient extends MusicClient {

    private static final String BASE_URL = "http://api.deezer.com";
    private static final String URL_PLAYLISTS = "/chart/0/playlists";
    private static final String URL_PLAYLIST = "/playlist";

    private DeezerConverter deezerConverter = new DeezerConverter();

    @Override
    public Playlists findPlaylists() {
        String url = BASE_URL + URL_PLAYLISTS;
        PlaylistsDeezer playlistsDeezer = sendRequest(url, PlaylistsDeezer.class);
        return deezerConverter.convertPlaylists(playlistsDeezer);
    }

    @Override
    public Playlist findPlaylist(Long id) {
        String url = BASE_URL + URL_PLAYLIST + "/" + id;
        PlaylistDeezer playlistDeezer = sendRequest(url, PlaylistDeezer.class);
        return deezerConverter.convertPlaylist(playlistDeezer);
    }

}


text:
using namespace OpenHome;
using namespace OpenHome::Media;
using namespace OpenHome::TestFramework;

static const TUint kTracksMax = 1000;
static const char* kProtocolInfo =
"http-get:*:audio/x-flac:*,"
"http-get:*:audio/wav:*,"
"http-get:*:audio/wave:*,"
"http-get:*:audio/x-wav:*,"
"http-get:*:audio/mpeg:*,"
"http-get:*:audio/x-mpeg:*,"
"http-get:*:audio/mp1:*,"
"http-get:*:audio/aiff:*,"
"http-get:*:audio/x-aiff:*,"
"http-get:*:audio/x-m4a:*,"
"http-get:*:audio/x-ms-wma:*,"
"rtsp-rtp-udp:*:audio/x-ms-wma:*,"
"http-get:*:audio/x-scpls:*,"
"http-get:*:audio/x-mpegurl:*,"
"http-get:*:audio/x-ms-asf:*,"
"http-get:*:audio/x-ms-wax:*,"
"http-get:*:audio/x-ms-wvx:*,"
"http-get:*:text/xml:*,"
"http-get:*:audio/aac:*,"
"http-get:*:audio/aacp:*,"
"http-get:*:audio/mp4:*,"
"http-get:*:audio/ogg:*,"
"http-get:*:audio/x-ogg:*,"
"http-get:*:application/ogg:*,"
"http-get:*:video/mpeg:*,"
"http-get:*:video/mp4:*,"
"http-get:*:video/quicktime:*,"
"http-get:*:video/webm:*,"
"http-get:*:video/x-ms-wmv:*,"
"http-get:*:video/x-ms-asf:*,"
"http-get:*:video/x-msvideo:*,"
"http-get:*:video/x-ms-wax:*,"
"http-get:*:video/x-ms-wvx:*,"
"http-get:*:video/x-m4v:*,"
"http-get:*:video/x-matroska:*,"
"http-get:*:application/octet-stream:*"
;

class StandbyHandler : public IStandbyHandler
{
public:
    virtual void SetStandby(TBool aValue);
};

void StandbyHandler::SetStandby(TBool aValue)
{
  Log::Print("Setting Standby: %d\n", aValue);
}

class SourceIndexHandler : public ISourceIndexHandler
{
public:
    virtual void SetSourceIndex(TUint aValue);
};

void SourceIndexHandler::SetSourceIndex(TUint aValue)
{
  Log::Print("Setting source: %d\n", aValue);
}

int main(int aArgc, char* aArgv[])
{
    OptionParser parser;

    OptionString optionRenderer("-r", "--renderer", Brn("dummy"), "Renderer module name.");
    parser.AddOption(&optionRenderer);

    if (!parser.Parse(aArgc, aArgv)) {
        return (1);
    }

    Net::InitialisationParams* initParams = Net::InitialisationParams::Create();

    Net::Library* lib = new Net::Library(initParams);

    Net::DvStack* dvStack = lib->StartDv();

    Brhz udn("device1");

    Net::DvDeviceStandard* device = new Net::DvDeviceStandard(*dvStack, udn);

    SourceIndexHandler* sourceIndexHandler = new SourceIndexHandler();
    StandbyHandler* standbyHandler = new StandbyHandler();

    IRenderer* renderer = NULL;
    if (0 == strcmp((const char*)optionRenderer.Value().Ptr(), "dummy"))
    {
      renderer = new Dummy(lib->Env());
    }
#ifdef HAVE_VLC_VLC_H
    else
    {
      renderer = new Vlc(lib->Env());
    }
#endif

    std::vector<OpenHome::NetworkAdapter*>* subnetList = lib->CreateSubnetList();
    TIpAddress adapter = (*subnetList)[0]->Address();
    OpenHome::Net::Library::DestroySubnetList(subnetList);

    char url[1024];
    char attributes[1024];

    sprintf(url, "%d.%d.%d.%d", adapter&0xff, (adapter>>8)&0xff, (adapter>>16)&0xff, (adapter>>24)&0xff);
    Config::GetInstance().GetAbout().SetUrl(url);
    sprintf(url, "http://%s:%s/", url, kHttpPort);
    sprintf(attributes, "Info Time App:Config=%s Volume", url);
    Config::GetInstance().GetAbout().SetVersion(VERSION);

    unsigned long long size;
    const char* res = getResource("/renderer.js", &size);
    Config::GetInstance().RegisterController(res, size);
    Config::GetInstance().GetDataMapper().Append("/data/renderer.json", "renderer");

    Player* player = new Player(
        renderer,
        *device,
        *standbyHandler,
        *sourceIndexHandler,
        true,
        attributes,
        "OpenHome",
        "OpenHome Consortium",
        "http://openhome.org",
        "",
        "OpenHome Media Player",
        "",
        "",
        "",
        Config::GetInstance().GetString("device", "room").c_str(),
        Config::GetInstance().GetString("device", "name").c_str(),
        "",
        url,
        "");

    SourcePlaylist* sourcePlaylist = new SourcePlaylist(*device, kTracksMax, kProtocolInfo, *player);

    player->AddSource(sourcePlaylist);

    device->SetEnabled();

    char c = '\0';
    while (c != 'q') {
        if(scanf("%c", &c))
          ;
    }

    Log::Print("Quiting...\n");

    delete sourcePlaylist;
    delete device;
    delete sourceIndexHandler;
    delete standbyHandler;
    delete player;

    Log::Print("Exit complete\n");

    return (0);
}


text:
layout: post
title: "随机矩阵理论(IX): 机器学习"
author: "李军"
categories: journal
tags: [RMT, machine learning, data analysis]
image:
  feature:
  teaser:
  credit:
  creditlink: ""
---

本文是随机矩阵理论系列的第九篇文章,讲述了随机矩阵在机器学习中的运用。

#### Random matrices in data analysis

#### Applications of random matrices in spectral computations and machine learning

#### Random matrices for machine learning on brain graphs

#### Random matrices in high-dimensional data analysis

#### Random matrix theory in statistics: A review

#### Random matrices meet machine learning: a large dimensional analysis of LS-SVM


text:
module Lita
  module Handlers
    class Ruby < Handler

      class StandardChat
        def initialize(response)
          @response = response
          @buffer = String.new
        end

        def write(string)
          @buffer << string
        end

        def puts(string)
          self.write string
          self.write "\n"
          flush
        end

        def flush
          @response.reply @buffer.strip
          @buffer.clear
        end
      end

      route %r{\Aruby(?: me)?\s+(.+)\Z}i, :evaluate,
        command: true,
        help: {
          'ruby EXPRESSION' => 'Evalutes EXPRESSION with a Ruby interpretor'
        }

      def evaluate(response)
        hijack_stdout_with(response) do
          begin
            eval(response.matches.first.first, binding, __FILE__, __LINE__)
          rescue => error
            puts error.inspect
          end
        end
      end

      private

      def hijack_stdout_with(response)
        original_stdout = $stdout
        $stdout = StandardChat.new(response)
        yield
        $stdout = original_stdout
      end
    end

    Lita.register_handler(Ruby)
  end
end


text:
from __future__ import unicode_literals, print_function

import json
import re
import sys
import unittest
import warnings

import twitter
import responses
from responses import GET

warnings.filterwarnings('ignore', category=DeprecationWarning)

DEFAULT_URL = re.compile(r'https?://.*\.twitter.com/1\.1/.*')

class ModelsChangesTest(unittest.TestCase):
    """Test how changes to tweets affect model creation"""

    def setUp(self):
        self.api = twitter.Api(
            consumer_key='test',
            consumer_secret='test',
            access_token_key='test',
            access_token_secret='test',
            sleep_on_rate_limit=False)

    @responses.activate
    def test_extended_in_compat_mode(self):
        """API is in compatibility mode, but we call GetStatus on a tweet that
        was written in extended mode.

        The tweet in question is exactly 140 characters and attaches a photo.

        """
        with open('testdata/3.2/extended_tweet_in_compat_mode.json') as f:
            resp_data = f.read()
        status = twitter.Status.NewFromJsonDict(json.loads(resp_data))
        self.assertTrue(status)
        self.assertEqual(status.id, 782737772490600448)
        self.assertEqual(status.text, "has more details about these changes.  Thanks for making more expressive!writing requirements to python_twitt pytho… https://t.co/et3OTOxWSa")
        self.assertEqual(status.tweet_mode, 'compatibility')
        self.assertTrue(status.truncated)

    @responses.activate
    def test_extended_in_extended_mode(self):
        """API is in extended mode, and we call GetStatus on a tweet that
        was written in extended mode.

        The tweet in question is exactly 140 characters and attaches a photo.

        """
        with open('testdata/3.2/extended_tweet_in_extended_mode.json') as f:
            resp_data = f.read()
        status = twitter.Status.NewFromJsonDict(json.loads(resp_data))
        self.assertTrue(status)
        self.assertEqual(status.id, 782737772490600448)
        self.assertEqual(status.full_text, "has more details about these changes.  Thanks for making more expressive!writing requirements to python_twitt python_twitter.egg-info/SOURCE https://t.co/JWSPztfoyt")
        self.assertEqual(status.tweet_mode, 'extended')
        self.assertFalse(status.truncated)


text:
package com.getbase.android.schema;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class CanaryTest {
  @Test
  public void canaryTest() throws Exception {
  }
}


text:
@implementation Product (UpdateProduct)

- (BOOL)updateProduct {
    // TODO: Make this run in the background
    BOOL success = NO;
    int result = SQLITE_OK;

    if (self.recordIsReady && self.recordNeedsSaving) {
        sqlite3_stmt *statement = NULL;

        const char *query =
            "UPDATE products SET "
                "product_name = ?, "
                "product_description = ?, "
                "product_regular_price = ?, "
                "product_sale_price = ?, "
                "product_photo = ?, "
                "product_colors = ?,"
                "product_stores = ?"
            "WHERE product_id = ?";

        // Prepare statement
        result = sqlite3_prepare_v2(self.db, query, -1, &statement, NULL);
        if (result != SQLITE_OK) {
            NSLog(@"Failed to prepare Update statement - Error: %s", sqlite3_errmsg(self.db));
        }
        else {
            // Bind statement parameters.
            // All String parameters must be marked SQLITE_TRANSIENT so SQLite
            // can handle memory appropriately
            sqlite3_bind_text(statement, 1, [self.productName UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_text(statement, 2, [self.productDescription UTF8String], -1, SQLITE_TRANSIENT);
            sqlite3_bind_double(statement, 3, self.productRegularPrice);
            sqlite3_bind_double(statement, 4, self.productSalePrice);

            // Prepare Photo data for its BLOB field and bind it
            NSData *productImageData = UIImagePNGRepresentation(self.productImage);
            sqlite3_bind_blob(statement, 5,  productImageData.bytes, (int)productImageData.length, NULL);

            // Convert Colors Array to String and bind it to the statement
            sqlite3_bind_text(statement, 6, [[self.productColors componentsJoinedByString:@","] UTF8String], -1, SQLITE_TRANSIENT);

            // Convert Stores Dictionary to JSON String and bind it to statement
            NSError *error = nil;

            NSData *jsonData = [
                NSJSONSerialization
                dataWithJSONObject:self.productStores
                options:0 //NSJSONWritingPrettyPrinted
                error:&error
            ];
            NSString *productStoresJSON = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
            sqlite3_bind_text(statement, 7, [productStoresJSON UTF8String], -1, SQLITE_TRANSIENT);

            // Bind record Id
            sqlite3_bind_int64(statement, 8, self.recordId);

            // Execute Update Query
            result = sqlite3_step(statement);
            if (result == SQLITE_DONE) {
                self.recordNeedsSaving = NO;
                success = YES;
                self.productWasUpdated = YES;
            }
            else {
                NSLog(@"Failed to Update Product Id: %ld - Error: %s", self.recordId, sqlite3_errmsg(self.db));
            }
        }
        sqlite3_finalize(statement);
    }
    return success;
}

@end


text:
package com.amazonaws.services.mediaconvert.model;

import javax.annotation.Generated;

/**
 * Optional. Specify how the service determines the pixel aspect ratio (PAR) for this output. The default behavior,
 * Follow source (INITIALIZE_FROM_SOURCE), uses the PAR from your input video for your output. To specify a different
 * PAR in the console, choose any value other than Follow source. To specify a different PAR by editing the JSON job
 * specification, choose SPECIFIED. When you choose SPECIFIED for this setting, you must also specify values for the
 * parNumerator and parDenominator settings.
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public enum Vp8ParControl {

    INITIALIZE_FROM_SOURCE("INITIALIZE_FROM_SOURCE"),
    SPECIFIED("SPECIFIED");

    private String value;

    private Vp8ParControl(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return this.value;
    }

    /**
     * Use this in place of valueOf.
     *
     * @param value
     *        real value
     * @return Vp8ParControl corresponding to the value
     *
     * @throws IllegalArgumentException
     *         If the specified value does not map to one of the known values in this enum.
     */
    public static Vp8ParControl fromValue(String value) {
        if (value == null || "".equals(value)) {
            throw new IllegalArgumentException("Value cannot be null or empty!");
        }

        for (Vp8ParControl enumEntry : Vp8ParControl.values()) {
            if (enumEntry.toString().equals(value)) {
                return enumEntry;
            }
        }

        throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
    }
}


text:
var aliases = {
  "CustomEvent": "CustomEvent",
  "Event": "Event",
  "Events": "Event",
  "HTMLEvents": "Event",
  "KeyboardEvent": "KeyboardEvent",
  "MessageEvent": "MessageEvent",
  "MouseEvent": "MouseEvent",
  "MouseEvents": "MouseEvent",
  "TouchEvent": "TouchEvent",
  "UIEvent": "UIEvent",
  "UIEvents": "UIEvent"
};


text:
all: html-split html-single css pdf dvi ps txt nroff local

html-split: build/_html-split.done
html-single: build/_html-single.done
css: build/_css.done
pdf: build/_pdf.done
dvi: build/_dvi.done
ps: build/_ps.done
txt: build/_txt.done
nroff: build/_nroff.done
meta: release/meta
local: build/_local.done

generated_sources = \
src/m_docid.ud meta/id \
src/m_pkg.ud   src/m_supp.ud \
src/m_title.ud meta/title_full \
src/footer.html src/header.html \
src/footer.txt src/header.txt \
src/main.tex

#----------------------------------------------------------------------
# meta

meta/id: mk-docid meta/id_prefix
	./mk-docid meta/id_prefix > meta/id.tmp && mv meta/id.tmp meta/id
src/m_docid.ud: mk-ud-docid meta/id
	./mk-ud-docid meta/id > src/m_docid.ud.tmp && mv src/m_docid.ud.tmp src/m_docid.ud
src/m_pkg.ud: mk-ud-pkg meta/pkg
	./mk-ud-pkg meta/pkg > src/m_pkg.ud.tmp && mv src/m_pkg.ud.tmp src/m_pkg.ud
src/m_supp.ud: mk-ud-supp
	./mk-ud-supp meta/supported > src/m_supp.ud.tmp && mv src/m_supp.ud.tmp src/m_supp.ud
meta/title_full: mk-title meta/pkg meta/title
	./mk-title meta/pkg meta/title > meta/title_full.tmp && mv meta/title_full.tmp meta/title_full
src/m_title.ud: mk-ud-title meta/title_full
	./mk-ud-title meta/title_full > src/m_title.ud.tmp && mv src/m_title.ud.tmp src/m_title.ud

#----------------------------------------------------------------------
# source generation

src/footer.html: meta/site meta/title_full mk-html-footer
	./mk-html-footer meta/site meta/title_full > src/footer.html.tmp && mv src/footer.html.tmp src/footer.html
src/header.html: meta/site meta/title_full mk-html-header
	./mk-html-header meta/site meta/title_full > src/header.html.tmp && mv src/header.html.tmp src/header.html
src/footer.txt: meta/site meta/title_full mk-txt-footer
	./mk-txt-footer meta/site meta/title_full > src/footer.txt.tmp && mv src/footer.txt.tmp src/footer.txt
src/header.txt: meta/site meta/title_full mk-txt-header
	./mk-txt-header meta/site meta/title_full > src/header.txt.tmp && mv src/header.txt.tmp src/header.txt
src/main.tex: meta/title_full mk-tex-code
	./mk-tex-code meta/title_full > src/main.tex.tmp && mv src/main.tex.tmp src/main.tex

#----------------------------------------------------------------------
# build targets

build/_html-split.done:\
meta/id src/main.ud release build build/_local.done $(generated_sources)
	(cd src && udoc-render \
		-c `head -n 1 ../conf/xh-toc` \
		-s `head -n 1 ../conf/xh-split` \
		-r xhtml main.ud ../build)
	cp build/*.html release
	touch build/_html-split.done

build/_html-single.done:\
meta/id src/main.ud release build build/_local.done $(generated_sources)
	(cd src && udoc-render \
		-c `head -n 1 ../conf/xh-toc` \
		-s 0 \
		-r xhtml main.ud ../build)
	cp build/0.html release/single.html
	touch build/_html-single.done

build/_css.done: src/main.css
	cp src/main.css build
	cp build/main.css release
	touch build/_css.done

build/_txt.done:\
meta/id meta/pkg src/main.ud pkg-name release build build/_local.done \
$(generated_sources)
	(cd src && udoc-render -r plain main.ud ../build)
	cp build/0.txt release/`./pkg-name meta/pkg`.txt
	touch build/_txt.done

build/_nroff.done:\
meta/id meta/pkg src/main.ud pkg-name release build build/_local.done \
$(generated_sources)
	(cd src && udoc-render -r nroff main.ud ../build)
	cp build/0.nrf release/`./pkg-name meta/pkg`.nrf
	touch build/_nroff.done

build/0.tex:\
meta/id meta/pkg src/main.ud release build build/_local.done conf/ctex-split \
$(generated_sources)
	(cd src && udoc-render \
		-s `head -n 1 ../conf/ctex-split` \
		-r context main.ud ../build)

build/_dvi.done:\
meta/id meta/pkg src/main.ud build/0.tex pkg-name release build \
build/_local.done $(generated_sources)
	(cd build && texexec --dvi 0.tex)
	cp build/0.dvi release/`./pkg-name meta/pkg`.dvi
	touch build/_dvi.done

build/_pdf.done:\
meta/id meta/pkg src/main.ud build/0.tex pkg-name release build \
build/_local.done $(generated_sources)
	(cd build && texexec --pdf 0.tex)
	cp build/0.pdf release/`./pkg-name meta/pkg`.pdf
	touch build/_pdf.done

build/_ps.done:\
meta/id meta/pkg src/main.ud build/0.pdf pkg-name release build \
build/_local.done $(generated_sources)
	(cd build && pdf2ps 0.pdf)
	cp build/0.ps release/`./pkg-name meta/pkg`.ps
	touch build/_ps.done

build/_local.done:\
local.sh
	./local.sh

release:
	mkdir release

build:
	mkdir build

release/meta: meta/id meta/title_full meta/pkg pkg-meta pkg-name
	./pkg-meta

package: meta pkg-make pkg-name meta/pkg
	./pkg-make

#----------------------------------------------------------------------

clean:
	rm -f $(generated_sources)
	rm -rf build
	rm -rf release

clean-all: clean


text:
package quizleague.domain.command

import quizleague.domain.Key

case class ResultsSubmitCommand(fixtures:List[ResultValues], reportText:Option[String], userID:String)
case class ResultValues(fixtureKey:Key, homeScore:Int, awayScore:Int)


text:
@interface XSYLoveBeenFirstPageWebViewController ()<UIWebViewDelegate>

@end

@implementation XSYLoveBeenFirstPageWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIWebView *webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webview.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
    [self.view addSubview:webview];

    NSURLRequest* request = [NSURLRequest requestWithURL:self.url];//创建NSURLRequest
    [webview loadRequest:request];//加载

    // 设置代理
    webview.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated{
    [SVProgressHUD dismiss];
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    [SVProgressHUD showWithStatus:@"加载中"];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [SVProgressHUD dismiss];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [SVProgressHUD dismiss];
    [SVProgressHUD showErrorWithStatus:@"网络不佳"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // seconds秒后异步执行这里的代码...
        [SVProgressHUD dismiss];
    });
}
@end


text:
/*
* Runtime benchmarking
* (C) 2008 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_RUNTIME_BENCHMARK_H__
#define BOTAN_RUNTIME_BENCHMARK_H__

#include <botan/algo_factory.h>
#include <botan/rng.h>
#include <map>
#include <string>

namespace Botan {

/**
* Algorithm benchmark
* @param name the name of the algorithm to test (cipher, hash, or MAC)
* @param af the algorithm factory used to create objects
* @param rng the rng to use to generate random inputs
* @param milliseconds total time for the benchmark to run
* @param buf_size size of buffer to benchmark against, in KiB
* @return results a map from provider to speed in mebibytes per second
*/
std::map<std::string, double>
BOTAN_DLL algorithm_benchmark(const std::string& name,
                              Algorithm_Factory& af,
                              RandomNumberGenerator& rng,
                              u32bit milliseconds,
                              size_t buf_size);

}

#endif


text:
import { ActionType, ContextModule, OwnerType, TappedShowMore } from "@artsy/cohesion"
import { MyCollectionArtworkArtistArticles_artwork$data } from "__generated__/MyCollectionArtworkArtistArticles_artwork.graphql"
import { CaretButton } from "app/Components/Buttons/CaretButton"
import { navigate } from "app/navigation/navigate"
import { ScreenMargin } from "app/Scenes/MyCollection/Components/ScreenMargin"
import { extractNodes } from "app/utils/extractNodes"
import { Box, Flex, Separator, Spacer, Text } from "palette"
import { Image, TouchableOpacity } from "react-native"
import { createFragmentContainer, graphql } from "react-relay"
import { useTracking } from "react-tracking"

interface MyCollectionArtworkArtistArticlesProps {
  artwork: MyCollectionArtworkArtistArticles_artwork$data
}

const MyCollectionArtworkArtistArticles: React.FC<MyCollectionArtworkArtistArticlesProps> = (
  props
) => {
  const artist = props?.artwork?.artist!
  const articleEdges = extractNodes(artist?.articlesConnection)
  const { trackEvent } = useTracking()

  if (!articleEdges.length) {
    return null
  }

  return (
    <ScreenMargin>
      <Separator mb={3} />

      <Text variant="sm" mb={2}>
        Latest Articles featuring {artist?.name}
      </Text>

      {articleEdges.map(({ thumbnailTitle, slug, publishedAt, internalID, thumbnailImage }) => {
        return (
          <TouchableOpacity onPress={() => navigate(`/article/${slug}`)} key={internalID}>
            <Box my={0.5}>
              <Flex flexDirection="row">
                <Box pr={1} style={{ flex: 1 }}>
                  <Flex flexDirection="row">
                    <Text style={{ flex: 1 }}>{thumbnailTitle}</Text>
                  </Flex>
                  <Text color="black60" my={0.5}>
                    {publishedAt}
                  </Text>
                </Box>
                <Image
                  style={{ flexShrink: 1, width: 80, height: 60 }}
                  source={{ uri: thumbnailImage?.url ?? undefined }}
                />
              </Flex>
            </Box>
          </TouchableOpacity>
        )
      })}

      <Spacer my={1} />

      <Box mb={2}>
        <CaretButton
          onPress={() => {
            trackEvent(
              tracks.tappedShowMore(
                props.artwork.internalID,
                props.artwork.slug,
                "See all articles"
              )
            )
            navigate(`/artist/${artist?.slug}/articles`)
          }}
          text="See all articles"
        />
      </Box>
    </ScreenMargin>
  )
}

export const MyCollectionArtworkArtistArticlesFragmentContainer = createFragmentContainer(
  MyCollectionArtworkArtistArticles,
  {
    artwork: graphql`
      fragment MyCollectionArtworkArtistArticles_artwork on Artwork {
        internalID
        slug
        artist {
          slug
          name
          internalID
          articlesConnection(first: 3, sort: PUBLISHED_AT_DESC, inEditorialFeed: true) {
            edges {
              node {
                slug
                internalID
                href
                thumbnailTitle
                author {
                  name
                }
                publishedAt(format: "MMM Do, YYYY")
                thumbnailImage {
                  url
                }
                href
              }
            }
          }
        }
      }
    `,
  }
)

const tracks = {
  tappedShowMore: (internalID: string, slug: string, subject: string) => {
    const tappedShowMore: TappedShowMore = {
      action: ActionType.tappedShowMore,
      context_module: ContextModule.relatedArticles,
      context_screen_owner_type: OwnerType.myCollectionArtwork,
      context_screen_owner_id: internalID,
      context_screen_owner_slug: slug,
      subject,
    }
    return tappedShowMore
  },
}


text: Appcelerator Titanium Mobile Alloy App Playground


text:
namespace riakboost{} namespace boost = riakboost; namespace riakboost{

    class thread_interrupted
    {};

    class thread_exception:
        public std::exception
    {
    protected:
        thread_exception():
            m_sys_err(0)
        {}

        thread_exception(int sys_err_code):
            m_sys_err(sys_err_code)
        {}

    public:
        ~thread_exception() throw()
        {}

        int native_error() const
        {
            return m_sys_err;
        }

    private:
        int m_sys_err;
    };

    class condition_error:
        public std::exception
    {
    public:
        const char* what() const throw()
        {
            return "Condition error";
        }
    };

    class lock_error:
        public thread_exception
    {
    public:
        lock_error()
        {}

        lock_error(int sys_err_code):
            thread_exception(sys_err_code)
        {}

        ~lock_error() throw()
        {}

        virtual const char* what() const throw()
        {
            return "riakboost::lock_error";
        }
    };

    class thread_resource_error:
        public thread_exception
    {
    public:
        thread_resource_error()
        {}

        thread_resource_error(int sys_err_code):
            thread_exception(sys_err_code)
        {}

        ~thread_resource_error() throw()
        {}

        virtual const char* what() const throw()
        {
            return "riakboost::thread_resource_error";
        }

    };

    class unsupported_thread_option:
        public thread_exception
    {
    public:
        unsupported_thread_option()
        {}

        unsupported_thread_option(int sys_err_code):
            thread_exception(sys_err_code)
        {}

        ~unsupported_thread_option() throw()
        {}

        virtual const char* what() const throw()
        {
            return "riakboost::unsupported_thread_option";
        }

    };

    class invalid_thread_argument:
        public thread_exception
    {
    public:
        invalid_thread_argument()
        {}

        invalid_thread_argument(int sys_err_code):
            thread_exception(sys_err_code)
        {}

        ~invalid_thread_argument() throw()
        {}

        virtual const char* what() const throw()
        {
            return "riakboost::invalid_thread_argument";
        }

    };

    class thread_permission_error:
        public thread_exception
    {
    public:
        thread_permission_error()
        {}

        thread_permission_error(int sys_err_code):
            thread_exception(sys_err_code)
        {}

        ~thread_permission_error() throw()
        {}

        virtual const char* what() const throw()
        {
            return "riakboost::thread_permission_error";
        }

    };

} // namespace riakboost

#include <boost/config/abi_suffix.hpp>

#endif


text:
package site.hanschen.runwithyou.ui.home.setting;

import dagger.Component;
import site.hanschen.runwithyou.application.ApplicationComponent;
import site.hanschen.runwithyou.dagger.FragmentScoped;

/**
 * @author HansChen
 */
@FragmentScoped
@Component(dependencies = ApplicationComponent.class, modules = PreferenceModule.class)
interface PreferenceComponent {

    void inject(SettingPreferenceFragment fragment);
}


text:
extern crate runfiles;

use std::io::BufRead;
use std::io::BufReader;
use std::process::{Child, Command, Stdio};
use std::str::FromStr;

use runfiles::Runfiles;

struct ServerInfo {
    process: Child,
    port: u16,
}

macro_rules! assert_contains {
    ($s: expr, $e: expr) => {
        assert!($s.find($e).is_some());
    };
}

impl ServerInfo {
    fn new() -> ServerInfo {
        let r = Runfiles::create().unwrap();
        let mut c =
            Command::new(r.rlocation("examples/proto/helloworld/greeter_server/greeter_server"))
                .arg("0")
                .stdout(Stdio::piped())
                .spawn()
                .expect("Unable to start server");
        let mut port: u16 = 0;
        {
            let mut stdout = BufReader::new(c.stdout.as_mut().expect("Failed to open stdout"));
            let port_prefix = "greeter server started on port ";
            while port == 0 {
                let mut line = String::new();
                stdout
                    .read_line(&mut line)
                    .expect("Waiting for server startup");
                line = line.trim().to_owned();
                if let Some(argp) = line.strip_prefix(port_prefix) {
                    port = u16::from_str(argp)
                        .unwrap_or_else(|_| panic!("Invalid port number {}", argp))
                }
            }
        }
        println!("Started server on port {}", port);
        ServerInfo { process: c, port }
    }

    fn run_client_impl(&self, arg: Option<String>) -> String {
        let r = Runfiles::create().unwrap();

        let mut cmd0 =
            Command::new(r.rlocation("examples/proto/helloworld/greeter_client/greeter_client"));
        let cmd = cmd0.arg(format!("-p={}", self.port));

        let output = if let Some(s) = arg { cmd.arg(s) } else { cmd }
            .output()
            .expect("Unable to start client");
        assert!(output.status.success());
        String::from_utf8(output.stdout).expect("Non UTF-8 output from the client")
    }

    fn run_client(&self) -> String {
        self.run_client_impl(None)
    }
    fn run_client_with_arg(&self, arg: &str) -> String {
        self.run_client_impl(Some(arg.to_owned()))
    }

    fn expect_log(&mut self, log: &str) {
        let mut reader =
            BufReader::new(self.process.stdout.as_mut().expect("Failed to open stdout"));
        let mut line = String::new();
        reader
            .read_line(&mut line)
            .expect("Failed to read line from the server");
        assert_contains!(line, log);
    }

    fn destroy(&mut self) {
        self.process.kill().unwrap();
    }
}

#[test]
fn test_client_server() {
    let mut s = ServerInfo::new();
    assert_contains!(s.run_client(), "message: \"Hello world\"");
    s.expect_log("greeting request from world");
    assert_contains!(s.run_client_with_arg("thou"), "message: \"Hello thou\"");
    s.expect_log("greeting request from thou");
    s.destroy();
}