text:
namespace po = boost::program_options;
extern fa_template fa_template_imp;
extern std::vector<atlas> atlas_list;
std::string get_fa_template_path(void);

bool atl_load_atlas(std::string atlas_name)
{
    std::cout << "loading atlas..." << std::endl;
    std::replace(atlas_name.begin(),atlas_name.end(),',',' ');
    std::istringstream in(atlas_name);
    std::vector<std::string> name_list;
    std::copy(std::istream_iterator<std::string>(in),
              std::istream_iterator<std::string>(),std::back_inserter(name_list));

    for(unsigned int index = 0;index < name_list.size();++index)
    {
        std::string atlas_path = QCoreApplication::applicationDirPath().toLocal8Bit().begin();
        atlas_path += "/atlas/";
        atlas_path += name_list[index];
        atlas_path += ".nii.gz";
        atlas_list.push_back(atlas());
        if(!atlas_list.back().load_from_file(atlas_path.c_str()))
        {
            std::cout << "Cannot load atlas " << atlas_path << std::endl;
            return false;
        }
        std::cout << name_list[index] << " loaded." << std::endl;
        atlas_list.back().name = name_list[index];

    }
    return true;
}
void atl_get_mapping(image::basic_image<float,3>& from,
                     image::basic_image<float,3>& to,
                     const image::vector<3>& vs,
                     unsigned int factor,
                     unsigned int thread_count,
                     image::basic_image<image::vector<3>,3>& mapping,
                     float* out_trans)
{
    std::cout << "perform image registration..." << std::endl;
    image::affine_transform<3,float> arg;
    arg.scaling[0] = vs[0] / std::fabs(fa_template_imp.tran[0]);
    arg.scaling[1] = vs[1] / std::fabs(fa_template_imp.tran[5]);
    arg.scaling[2] = vs[2] / std::fabs(fa_template_imp.tran[10]);
    image::reg::align_center(from,to,arg);

    image::filter::gaussian(from);
    from -= image::segmentation::otsu_threshold(from);
    image::lower_threshold(from,0.0);

    image::normalize(from,1.0);
    image::normalize(to,1.0);

    bool terminated = false;
    std::cout << "perform linear registration..." << std::endl;
    image::reg::linear(from,to,arg,image::reg::affine,image::reg::mutual_information(),terminated);
    image::transformation_matrix<3,float> T(arg,from.geometry(),to.geometry()),iT(arg,from.geometry(),to.geometry());
    iT.inverse();

    // output linear registration
    float T_buf[16];
    T.save_to_transform(T_buf);
    T_buf[15] = 1.0;
    std::copy(T_buf,T_buf+4,std::ostream_iterator<float>(std::cout," "));
    std::cout << std::endl;
    std::copy(T_buf+4,T_buf+8,std::ostream_iterator<float>(std::cout," "));
    std::cout << std::endl;
    std::copy(T_buf+8,T_buf+12,std::ostream_iterator<float>(std::cout," "));
    std::cout << std::endl;

    image::basic_image<float,3> new_from(to.geometry());
    image::resample(from,new_from,iT);

    std::cout << "perform nonlinear registration..." << std::endl;
    //image::reg::bfnorm(new_from,to,*bnorm_data,*terminated);

    std::cout << "order=" << factor << std::endl;
    std::cout << "thread count=" << thread_count << std::endl;

    image::reg::bfnorm_mapping<float,3> mni(new_from.geometry(),image::geometry<3>(factor*7,factor*9,factor*7));
    multi_thread_reg(mni,new_from,to,thread_count,terminated);
    mapping.resize(from.geometry());
    for(image::pixel_index<3> index;from.geometry().is_valid(index);index.next(from.geometry()))
        if(from[index.index()] > 0)
        {
            image::vector<3,float> pos;
            T(index,pos);// from -> new_from
            mni(pos,mapping[index.index()]); // new_from -> to
            fa_template_imp.to_mni(mapping[index.index()]);
        }
    image::matrix::product(fa_template_imp.tran.begin(),T_buf,out_trans,image::dyndim(4,4),image::dyndim(4,4));
}

void atl_save_mapping(const std::string& file_name,const image::geometry<3>& geo,
                      const image::basic_image<image::vector<3>,3>& mapping,const float* trans,const float* vs,
                      bool multiple)
{
    for(unsigned int i = 0;i < atlas_list.size();++i)
    {
        std::string base_name = file_name;
        base_name += ".";
        base_name += atlas_list[i].name;
        image::basic_image<short,3> all_roi(geo);
        for(unsigned int j = 0;j < atlas_list[i].get_list().size();++j)
        {
            std::string output = base_name;
            output += ".";
            output += atlas_list[i].get_list()[j];
            output += ".nii.gz";

            image::basic_image<unsigned char,3> roi(geo);
            for(unsigned int k = 0;k < mapping.size();++k)
                if (atlas_list[i].is_labeled_as(mapping[k], j))
                {
                    roi[k] = 1;
                    all_roi[k] = atlas_list[i].get_label_at(mapping[k]);
                }
            if(multiple)
            {
                image::io::nifti out;
                out.set_voxel_size(vs);
                if(trans)
                    out.set_image_transformation(trans);
                else
                    image::flip_xy(roi);
                out << roi;
                out.save_to_file(output.c_str());
                std::cout << "save " << output << std::endl;
            }
        }
        {
            std::string label_name = base_name;
            label_name += ".txt";
            std::ofstream txt_out(label_name.c_str());
            for(unsigned int j = 0;j < atlas_list[i].get_list().size();++j)
                txt_out << atlas_list[i].get_num()[j] << " " << atlas_list[i].get_list()[j] << std::endl;
        }
        base_name += ".nii.gz";
        image::io::nifti out;
        out.set_voxel_size(vs);
        if(trans)
            out.set_image_transformation(trans);
        else
            image::flip_xy(all_roi);
        out << all_roi;
        out.save_to_file(base_name.c_str());
        std::cout << "save " << base_name << std::endl;
    }
}

int atl(int ac, char *av[])
{
    po::options_description norm_desc("fiber tracking options");
    norm_desc.add_options()
    ("help", "help message")
    ("action", po::value<std::string>(), "atl: output atlas")
    ("source", po::value<std::string>(), "assign the .fib file name")
    ("order", po::value<int>()->default_value(0), "normalization order (0~3)")
    ("thread_count", po::value<int>()->default_value(4), "thread count")
    ("atlas", po::value<std::string>(), "atlas name")
    ("output", po::value<std::string>()->default_value("multiple"), "output files")
    ;

    if(!ac)
    {
        std::cout << norm_desc << std::endl;
        return 1;
    }

    po::variables_map vm;
    po::store(po::command_line_parser(ac, av).options(norm_desc).run(), vm);
    po::notify(vm);

    gz_mat_read mat_reader;
    std::string file_name = vm["source"].as<std::string>();
    std::cout << "loading " << file_name << "..." <<std::endl;
    if(!QFileInfo(file_name.c_str()).exists())
    {
        std::cout << file_name << " does not exist. terminating..." << std::endl;
        return 0;
    }
    if (!mat_reader.load_from_file(file_name.c_str()))
    {
        std::cout << "Invalid MAT file format" << std::endl;
        return 0;
    }

    unsigned int col,row;
    const unsigned short* dim = 0;
    const float* vs = 0;
    const float* fa0 = 0;
    if(!mat_reader.read("dimension",row,col,dim) ||
       !mat_reader.read("voxel_size",row,col,vs) ||
       !mat_reader.read("fa0",row,col,fa0))
    {
        std::cout << "Invalid file format" << std::endl;
        return 0;
    }
    image::geometry<3> geo(dim);

    if(!fa_template_imp.load_from_file(get_fa_template_path().c_str()) ||
       !atl_load_atlas(vm["atlas"].as<std::string>()))
        return -1;

    const float* trans = 0;
    //QSDR
    if(mat_reader.read("trans",row,col,trans))
    {
        std::cout << "Transformation matrix found." << std::endl;
        image::basic_image<image::vector<3>,3> mapping(geo);
        for(image::pixel_index<3> index;geo.is_valid(index);index.next(geo))
        {
            image::vector<3,float> pos(index),mni;
            image::vector_transformation(pos.begin(),mni.begin(),trans,image::vdim<3>());
            mapping[index.index()] = mni;
        }
        atl_save_mapping(file_name,geo,mapping,trans,vs,vm["output"].as<std::string>() == "multiple");
        return 0;
    }

    image::basic_image<float,3> from(fa0,geo);
    image::basic_image<image::vector<3>,3> mapping;
    unsigned int factor = vm["order"].as<int>() + 1;
    unsigned int thread_count = vm["thread_count"].as<int>();
    image::vector<3> vs_(vs);
    float out_trans[16];
    atl_get_mapping(from,fa_template_imp.I,vs_,factor,thread_count,mapping,out_trans);
    atl_save_mapping(file_name,geo,mapping,0,vs,vm["output"].as<std::string>() == "multiple");
}


text:
import unittest

from framework.lwm2m.tlv import TLV
from framework.lwm2m_test import *

TEST_OBJECT_OID = 1337
TEST_OBJECT_RES_BYTES = 5
TEST_OBJECT_RES_BYTES_SIZE = 6
TEST_OBJECT_RES_BYTES_BURST = 7

class BlockResponseTest(test_suite.Lwm2mSingleServerTest):
    def setUp(self, bytes_size=9001, extra_cmdline_args=None):
        super(BlockResponseTest, self).setUp(extra_cmdline_args=extra_cmdline_args)
        self.make_test_instance()
        self.set_bytes_size(1, bytes_size)
        self.set_bytes_burst(1, 1000)

    @unittest.skip
    def runTest(self):
        pass

    def assertIdentityMatches(self, response, request):
        self.assertEqual(request.msg_id, response.msg_id)

        if response.code != coap.Code.EMPTY:
            self.assertEqual(request.token, response.token)

    def assertBlockResponse(self, response, seq_num, has_more, block_size):
        self.assertEqual(response.get_options(coap.Option.BLOCK2)[0].has_more(), has_more)
        self.assertEqual(response.get_options(coap.Option.BLOCK2)[0].seq_num(), seq_num)
        self.assertEqual(response.get_options(coap.Option.BLOCK2)[0].block_size(), block_size)

    def make_test_instance(self):
        req = Lwm2mCreate("/%d" % TEST_OBJECT_OID)
        self.serv.send(req)
        response = self.serv.recv()
        self.assertMsgEqual(Lwm2mCreated.matching(req)(), response);

    def set_bytes_size(self, iid, size):
        req = Lwm2mWrite("/%d/%d/%d" % (TEST_OBJECT_OID, iid, TEST_OBJECT_RES_BYTES_SIZE), str(size))
        self.serv.send(req)
        response = self.serv.recv()
        self.assertMsgEqual(Lwm2mChanged.matching(req)(), response);

    def set_bytes_burst(self, iid, size):
        req = Lwm2mWrite("/%d/%d" % (TEST_OBJECT_OID, iid),
                         TLV.make_resource(TEST_OBJECT_RES_BYTES_BURST, int(size)).serialize(),
                         format=coap.ContentFormat.APPLICATION_LWM2M_TLV)
        self.serv.send(req)
        response = self.serv.recv()
        self.assertMsgEqual(Lwm2mChanged.matching(req)(), response);

    def read_bytes(self, iid, seq_num=None, block_size=None, options_modifier=None, accept=None):
        opts = [coap.Option.BLOCK2(seq_num=seq_num, has_more=0, block_size=block_size)] \
            if seq_num is not None and block_size else []
        if options_modifier is not None:
            opts = options_modifier(opts)

        req = Lwm2mRead("/%d/%d/%d" % (TEST_OBJECT_OID, iid, TEST_OBJECT_RES_BYTES),
                        options=opts, accept=accept)
        self.serv.send(req)
        res = self.serv.recv(timeout_s=5)
        self.assertIdentityMatches(res, req)
        return res

    def read_blocks(self, iid, block_size=1024, base_seq=0, accept=None):
        data = bytearray()
        while True:
            tmp = self.read_bytes(iid, base_seq, block_size, accept=accept)
            data += tmp.content
            base_seq += 1
            if not tmp.get_options(coap.Option.BLOCK2)[0].has_more():
                break
        return data

class BlockResponseFirstRequestIsNotBlock(BlockResponseTest):
    def setUp(self):
        super(BlockResponseFirstRequestIsNotBlock, self).setUp(bytes_size=9025)

    def runTest(self):
        response = self.read_bytes(iid=1)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)
        # Currently we have to read this till the end
        self.read_blocks(iid=1)

class BlockResponseFirstRequestIsBlock(BlockResponseTest):
    def runTest(self):
        response = self.read_bytes(iid=1, seq_num=1, block_size=1024)
        # Started from seq_num=1, clearly incorrect request
        self.assertEqual(response.code, coap.Code.RES_REQUEST_ENTITY_INCOMPLETE)

        # Normal request
        response = self.read_bytes(iid=1, seq_num=0, block_size=1024)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)
        self.read_blocks(iid=1)

class BlockResponseSizeNegotiation(BlockResponseTest):
    def runTest(self):
        # Forcing block_size from the very first request
        data = self.read_blocks(iid=1, block_size=16, base_seq=0)
        for i in range(len(data)):
            self.assertEqual(data[i], i % 128)

        # Forcing block_size after first message
        response = self.read_bytes(iid=1)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        second_payload = self.read_blocks(iid=1)
        self.assertEqual(data, second_payload)

        # Negotiation after first message
        response = self.read_bytes(iid=1, seq_num=0, block_size=32)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=32)

        third_payload = self.read_blocks(iid=1, block_size=32)
        self.assertEqual(data, third_payload)

class BlockResponseSizeRenegotiation(BlockResponseTest):
    def runTest(self):
        # Case 0: when first request does not contain BLOCK2 option.
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        response = self.read_bytes(iid=1, seq_num=0, block_size=32)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=32)

        response = self.read_bytes(iid=1, seq_num=0, block_size=16)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=16)

        self.read_blocks(iid=1, block_size=16)

        # Case 1: when first request does contain BLOCK2 option.
        response = self.read_bytes(iid=1, seq_num=0, block_size=512)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=512)

        response = self.read_bytes(iid=1, seq_num=0, block_size=32)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=32)

        response = self.read_bytes(iid=1, seq_num=0, block_size=16)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=16)

        self.read_blocks(iid=1, block_size=16)

class BlockResponseSizeRenegotiationInTheMiddleOfTransfer(BlockResponseTest):
    def runTest(self):
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        # request new size on non-first block. the client should reject such
        # packet and wait for a valid one instead
        response = self.read_bytes(iid=1, seq_num=1, block_size=16)
        self.assertIsInstance(response, Lwm2mErrorResponse)
        self.assertEqual(coap.Code.RES_BAD_REQUEST, response.code)

        self.read_blocks(iid=1, block_size=1024)

class BlockResponseInvalidSizeDuringRenegotation(BlockResponseTest):
    def runTest(self):
        # Case 0: when first request does not contain BLOCK2 option.
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        response = self.read_bytes(iid=1, seq_num=0, block_size=2048)
        self.assertIsInstance(response, Lwm2mErrorResponse)
        self.assertEqual(response.code, coap.Code.RES_BAD_REQUEST)

        # the error does not abort block-wise transfer; finish it
        # before continuing
        self.read_blocks(iid=1, block_size=1024)

        # Case 1: when first request does contain BLOCK2 option.
        response = self.read_bytes(iid=1, seq_num=0, block_size=2048)
        self.assertIsInstance(response, Lwm2mErrorResponse)
        self.assertEqual(response.code, coap.Code.RES_BAD_REQUEST)

class BlockResponseBadBlock2SizeInTheMiddleOfTransfer(BlockResponseTest):
    def runTest(self):
        first_invalid_seq_num = 4
        for seq_num in range(first_invalid_seq_num):
            response = self.read_bytes(iid=1, seq_num=seq_num, block_size=1024)
            self.assertBlockResponse(response, seq_num=seq_num, has_more=1, block_size=1024)

        response = self.read_bytes(iid=1, seq_num=first_invalid_seq_num, block_size=2048)
        self.assertIsInstance(response, Lwm2mErrorResponse)
        self.assertEqual(response.code, coap.Code.RES_BAD_REQUEST)

        # should abort the transfer

class BlockResponseBadBlock1(BlockResponseTest):
    def runTest(self):
        def opts_modifier(opts):
            return opts + [coap.Option.BLOCK1(0, 0, 16)]

        response = self.read_bytes(iid=1, seq_num=0, block_size=512)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=512)
        response = self.read_bytes(iid=1, seq_num=1, block_size=512,
                                   options_modifier=opts_modifier)

        # should continue the transfer
        self.assertEqual(response.code, coap.Code.RES_SERVICE_UNAVAILABLE)

        self.read_blocks(iid=1, block_size=512)

class BlockResponseBiggerBlockSizeThanData(BlockResponseTest):
    def setUp(self):
        super().setUp(bytes_size=5)

    def runTest(self):
        response = self.read_bytes(iid=1, seq_num=0, block_size=1024)
        self.assertBlockResponse(response, seq_num=0, has_more=0, block_size=1024)

# Tests different rates at which anjay's stream buffers are filled
class BlockResponseDifferentBursts(BlockResponseTest):
    BYTES_AMOUNT = 9001

    def setUp(self):
        super().setUp(bytes_size=BlockResponseDifferentBursts.BYTES_AMOUNT)

    def runTest(self):
        for i in (1, 10, 50, 100, 1000, 1024, 1200, 2048, 4096, 5000, 9001):
            self.set_bytes_burst(1, i)

            response = self.read_bytes(iid=1)
            self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)
            self.read_blocks(iid=1)

class BlockResponseToNonBlockRequestRetransmission(BlockResponseTest):
    def runTest(self):
        # non-BLOCK request
        req = Lwm2mRead(ResPath.Test[1].ResBytes)
        self.serv.send(req)

        # BLOCK response received
        res = self.serv.recv(timeout_s=5)
        self.assertIdentityMatches(res, req)

        block_opts = res.get_options(coap.Option.BLOCK2)
        self.assertNotEqual([], block_opts)

        # retransmit non-BLOCK request
        self.serv.send(req)

        # should receive the same response as before
        res2 = self.serv.recv(timeout_s=5)
        self.assertMsgEqual(res, res2)

        # should be able to continue the transfer
        self.read_blocks(iid=1, block_size=block_opts[0].block_size(), base_seq=1)

class BlockResponseOutOfOrder(BlockResponseTest):
    def runTest(self):
        # RFC 7959 does not define the expected behaviour when a CoAP client attempt to retrieve a block that is past
        # the end of the resource. Various CoAP implementations (taken from http://coap.technology/impls.html) behave
        # differently:
        #
        # - Erbium (http://people.inf.ethz.ch/mkovatsc/erbium.php) - 4.02 Bad Option
        # - Lobaro CoAP (http://www.lobaro.com/portfolio/lobaro-coap/) - 4.02 Bad Option
        # - MR-CoAP (https://github.com/MR-CoAP/CoAP) - 4.00 Bad Request
        # - Californium (http://www.eclipse.org/californium/) - success with empty content and Block2.More=false
        #
        # Anjay generates the resource contents on the fly, so it cannot even know the size of the resource in advance
        # and does not accept request for any sequence number other than either the previously retrieved one or the one
        # after it (retransmission or continuation).
        #
        # And it actually sends Reset upon receiving unexpected block number. We are not sure whether it makes any
        # sense, but here's a test for that.

        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        response = self.read_bytes(iid=1, seq_num=42, block_size=1024)
        self.assertIsInstance(response, Lwm2mReset)

        # should be able to continue the transfer
        self.read_blocks(iid=1, block_size=1024, base_seq=1)

class BlockResponseUnrelatedRequestsDoNotAbortTransfer(BlockResponseTest):
    def runTest(self):
        # start BLOCK response transfer
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        # send unrelated request
        req = Lwm2mRead(ResPath.Device.SerialNumber)
        self.serv.send(req)
        self.assertMsgEqual(Lwm2mErrorResponse.matching(req)(coap.Code.RES_SERVICE_UNAVAILABLE),
                            self.serv.recv())

        # send another unrelated request
        req = Lwm2mWrite(ResPath.FirmwareUpdate.Package, b'A' * 16,
                         options=[coap.Option.BLOCK1(seq_num=0, block_size=16, has_more=False)],
                         format=coap.ContentFormat.APPLICATION_OCTET_STREAM)
        self.serv.send(req)
        self.assertMsgEqual(Lwm2mErrorResponse.matching(req)(coap.Code.RES_SERVICE_UNAVAILABLE),
                            self.serv.recv())

        # should be able to continue the transfer
        block_opts = response.get_options(coap.Option.BLOCK2)
        self.read_blocks(iid=1, block_size=block_opts[0].block_size(), base_seq=1)

class BlockResponseUnexpectedServerRequestInTheMiddleOfTransfer(BlockResponseTest):
    def runTest(self):
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        # send an unrelated request during a block-wise transfer
        req = Lwm2mRead('/3/0/0')
        self.serv.send(req)
        res = self.serv.recv()
        self.assertMsgEqual(Lwm2mErrorResponse.matching(req)(coap.Code.RES_SERVICE_UNAVAILABLE),
                            res)
        self.assertEqual(1, len(res.get_options(coap.Option.MAX_AGE)))

        # continue reading block-wise response
        self.read_blocks(iid=1, block_size=1024)

class BlockResponseUnexpectedBlockServerRequestInTheMiddleOfTransfer(BlockResponseTest):
    def runTest(self):
        response = self.read_bytes(iid=1, seq_num=None, block_size=None)
        self.assertBlockResponse(response, seq_num=0, has_more=1, block_size=1024)

        # send an unrelated request during a block-wise transfer
        # use BLOCK2 Option to not trigger heuristic based on it
        req = Lwm2mRead('/3/0/0', options=[coap.Option.BLOCK2(seq_num=0, has_more=0, block_size=1024)])
        self.serv.send(req)
        res = self.serv.recv()
        self.assertMsgEqual(Lwm2mErrorResponse.matching(req)(coap.Code.RES_SERVICE_UNAVAILABLE),
                            res)
        self.assertEqual(1, len(res.get_options(coap.Option.MAX_AGE)))

        # continue reading block-wise response
        self.read_blocks(iid=1, block_size=1024)

redpajama_set_name: RedPajamaGithub


text:
<?php
/**
 * Example restore script.
 *
 * @author Ioannis Botis
 * @date 27/9/2016
 * @version: restore.duplicity.php 9:55 am
 * @since 27/9/2016
 */

require_once(__DIR__ . '/../../settings.php');

use Backup\Tools\Factory as ToolFactory;
use Backup\IncrementalBackup;

$settings = array(
    'path_to_backup' => $path_to_backup,
    'destination' => array(
        'type' => 'ftp',
        'host' => 'localhost',
        'username' => 'user1',
        'password' => 'abc123',
        'path' => '/'
    ),
//    'passphrase' => 'abcdef',
//    'exclude' => array('folder')
);

$duplicity = ToolFactory::create('Duplicity', $settings);

echo "Version: " . $duplicity->getVersion() . "\n";

$backupClass = new IncrementalBackup ($duplicity);

$backups = $backupClass->getAllBackups();

echo 'Backup #, time ' . "\n";
$d = new \DateTime();

$i = 1;
foreach ($backups as $time) {
    $d->setTimestamp($time);
    echo $i++ . '. ' . $d->format(\DateTime::W3C) . "\n";
}

echo "Please select version to restore. Type int to continue: ";
$handle = fopen("php://stdin", "r");
$backup_to_restore = intval(fgets($handle));

if (!in_array($backup_to_restore, range(1, $i - 1))) {
    echo 'invalid backup selected.' . "\n";
    exit;
}

// Restore last backup to this directory.
if ($backupClass->restoreTo($backups[$backup_to_restore - 1], $path_to_restore)) {
    echo 'Directory restored.' . "\n";
} else {
    echo 'Could not restore to directory.' . "\n";
}


text:
int main() try // Function try block
{
   AfxThrowMemoryException();
   return EXIT_SUCCESS;
}
catch (...)
{
   using namespace mittens;
   return   all_catcher(-1,
            std_exception_handler(-2,
            generic_handler<CException*>(-3, [](CException* e) { e->Delete(); },            // Release CException object to prevent a leak
            bad_alloc_handler(-4,
            generic_handler<CMemoryException*>(-5, [](CMemoryException* e) { e->Delete(); } // Release CException object to prevent a leak
            ))))).handleException();
}


text:
/**
 * This contains fare calculation implementations that are used in accessibility analysis to apply cost limits while
 * a search is happening. This is a resource limiting problem and requires pareto-path routing. It's a distinct
 * problem from calculating fares for Modeify or normal point to point routing, where fares are not considered during
 * routing and are only calculated after the path is already found.
 */
package com.conveyal.r5.analyst.fare;


text:
module Sequel
  module FilterHaving
    # Operate on HAVING clause if HAVING clause already present.
    def and(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def exclude(*cond, &block)
      if @opts[:having]
        exclude_having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def filter(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def or(*cond, &block)
      if having = @opts[:having]
        cond = cond.first if cond.size == 1
        clone(:having => SQL::BooleanExpression.new(:OR, having, filter_expr(cond, &block)))
      else
        super
      end
    end
  end

  Dataset.register_extension(:filter_having, FilterHaving)
end


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace LangLib
{
    public class LangLibrary
    {
        private List<string> appLangStrings = new List<string>();
        public LangLibrary(string rootDir, string Lang)
        {
            try
            {
            using (StreamReader sr = new StreamReader(rootDir + "/lang/" + Lang + "/strings.ini")) //To allow for easy disposal of object when we are done.
            {
                int index = 0;
                while(!sr.EndOfStream)
                {
                    string line = sr.ReadLine(); // Read a line from the language file
                    try
                    {
                        appLangStrings[index] = line.Replace("{" + index + "}=", ""); // Strip the identifier key out of the string and add it to the language string list
                    }
                    catch
                    {
                        //we have hit an error
                        sr.Close();
                        break;
                    }
                }
            }
            }
            catch
            {
                //The file does not exist
                throw new Exception("LangLib-0x001");
            }
        }
        public string getById(int id)
        {
            try
            {
                return appLangStrings[id];
            }
            catch
            {
                throw new Exception("LangLib-0x002");
            }
        }
        public static string getVersion()
        {
            getVersion("n vT, c");
        }
        public static string getVersion(string paramString)
        {
            paramString = paramString.Replace("n", "LangLib");
            paramString = paramString.Replace("v", "1.1");
            paramString = paramString.Replace("t", "Stable");
            paramString = paramString.Replace("T", "S");
            paramString = paramString.Replace("c", "Copyright 2015 Joshua Zenn);
            paramString = paramString.Replace("a", "Joshua Zenn");
            paramString = paramString.Replace("y", "2015");
            return paramString;
        }
    }
}


text: <button type="button" class="btn btn-success btn-lg cursor-pointer" (click)="open()" >Додати опитування</button>


text:
import json
import logging
import datetime
from potnanny_core.models import (Trigger, OutletController, ActionPluginBase,
    FutureOutletAction)
from potnanny_core.database import db_session
from potnanny_core.utils import eval_condition

logger = logging.getLogger('potnanny.plugins.timed_on_action')

"""
TriggeredTimedOnAction

An action that will power an outlet on when a fault threshold is crossed, and
turn the outlet back off N minutes later.

"""
class TriggeredTimedOnAction(ActionPluginBase):
    action_name = 'outlet timed-on'

    def __init__(self, *args, **kwargs):
        self.on_condition = None
        self.on_minutes = 0
        self.outlet = None

        required = ['on_condition', 'on_minutes', 'outlet']
        for k, v in kwargs.items():
            if k in required:
                setattr(self, k, v)

        for r in required:
            if getattr(self, r) is None:
                raise ValueError("{} must provide value for '{}'".format(
                    self.__name__, r))

    def __repr__(self):
        return json.dumps(self.as_dict())

    def as_dict(self):
        return {
            'class': self.__class__.__name__,
            'name': self.action_name,
            'on_condition': self.on_condition,
            'on_minutes': self.on_minutes,
            'outlet': self.outlet,
        }

    """
    eval a measurement value, see what actions, if any, it will trigger

    params:
        - the Action instance that is our parent
        - a Measurement instance
    returns:
        a dict of action details, or None
    """
    def handle_measurement(self, parent, meas):
        now = datetime.datetime.utcnow().replace(second=0, microsecond=0)
        trigger = None
        if parent.triggers:
            trigger = parent.triggers[0]

        def make_trigger():
            closed = now + datetime.timedelta(minutes=self.on_minutes)
            if parent.sleep_minutes:
                closed = closed + datetime.timedelta(minutes=parent.sleep_minutes)

            opts = {
                'action_id': parent.id,
                'created': now,
                'closed': closed,
            }

            t = Trigger(**opts)
            db_session.add(t)
            db_session.commit()

        if not trigger and eval_condition(meas.value, self.on_condition):
            oc = OutletController()
            result = oc.turn_on(self.outlet)
            if result:
                make_trigger()
                run_time = now + datetime.timedelta(minutes=self.on_minutes)
                fa = FutureOutletAction(
                    action='off',
                    outlet=json.dumps(self.outlet),
                    run_at=run_time,
                )
                db_session.add(fa)
                db_session.commit()

            return


text:
- Added support for the *target* argument in the following commands. The target argument is supported only in operational type commands. Meaning, you cannot use it with commit, logs, or PCAP commands.
  - ***pan-os-get-url-category***
  - ***pan-os-device-reboot***
  - ***pan-os-list-rules***
  - ***pan-os-show-device-version***
  - ***pan-os-download-latest-content-update***
  - ***pan-os-content-update-download-status***
  - ***pan-os-install-latest-content-update***
  - ***pan-os-content-update-install-status***
  - ***pan-os-check-latest-panos-software***
  - ***pan-os-download-panos-version***
  - ***pan-os-download-panos-status***
  - ***pan-os-install-panos-version***
  - ***pan-os-install-panos-status***
  - ***pan-os***
- Added the top 5 most recent software releases in the ***pan-os-check-latest-panos-software*** command.


text:
<?php
namespace Chamilo\Core\Repository\ContentObject\AssessmentMatrixQuestion\Integration\Chamilo\Core\Repository\ContentObject\Assessment\Display;

use Chamilo\Core\Repository\Common\ContentObjectResourceRenderer;
use Chamilo\Core\Repository\ContentObject\Assessment\Display\Component\Viewer\QuestionDisplay;
use Chamilo\Core\Repository\ContentObject\AssessmentMatrixQuestion\Storage\DataClass\AssessmentMatrixQuestion;

/**
 *
 * @package repository.lib.complex_display.assessment.component.viewer.wizard.inc.question_display
 */
class Display extends QuestionDisplay
{

    public function add_question_form()
    {
        $formvalidator = $this->get_formvalidator();
        $renderer = $this->get_renderer();
        $clo_question = $this->get_complex_content_object_question();
        $question = $this->get_question();

        if ($clo_question->get_random())
        {
            $options = $this->shuffle_with_keys($question->get_options());
            $matches = $this->shuffle_with_keys($question->get_matches());
        }
        else
        {
            $options = $question->get_options();
            $matches = $question->get_matches();
        }

        $type = $question->get_matrix_type();

        $table_header = array();
        $table_header[] = '
';
        $table_header[] = '
';
        $table_header[] = '
';
        $table_header[] = '	';

        foreach ($matches as $match)
        {
            $table_header[] = '' . $match . '	';
        }

        $table_header[] = '
';
        $table_header[] = '
';
        $table_header[] = '
';
        $formvalidator->addElement('html', implode(PHP_EOL, $table_header));

        $question_id = $clo_question->get_id();

        foreach ($options as $i => $option)
        {
            $group = array();

            $object_renderer = new ContentObjectResourceRenderer(
                $this->get_formvalidator()->get_assessment_viewer(),
                $option->get_value());

            $group[] = $formvalidator->createElement(
                'static',
                null,
                null,
                '
' . $object_renderer->run() . '
');

            foreach ($matches as $j => $match)
            {
                if ($type == AssessmentMatrixQuestion::MATRIX_TYPE_RADIO)
                {
                    $answer_name = $question_id . '_' . $i;
                    $group[] = $formvalidator->createElement('radio', $answer_name, null, null, $j);
                    $defaults[$answer_name] = -1;
                }
                elseif ($type == AssessmentMatrixQuestion::MATRIX_TYPE_CHECKBOX)
                {
                    $answer_name = $question_id . '_' . $i . '[' . $j . ']';
                    $group[] = $formvalidator->createElement('checkbox', $answer_name);
                }
            }

            $formvalidator->addGroup($group, 'matrix_option_' . $question_id . '_' . $i, null, '', false);

            $renderer->setElementTemplate('
{element}
', 'matrix_option_' . $question_id . '_' . $i);
            $renderer->setGroupElementTemplate(
                '{element}	',
                'matrix_option_' . $question_id . '_' . $i);
        }

        $table_footer[] = '
';
        $table_footer[] = '
';
        $formvalidator->addElement('html', implode(PHP_EOL, $table_footer));

        $formvalidator->setDefaults($defaults);
    }

    public function add_border()
    {
        return false;
    }
}


text:
title: "PuppetDB 1.6 » API » v1 » Querying Resources"
layout: default
canonical: "/puppetdb/latest/api/query/v1/resources.html"
---

[curl]: ../curl.html#using-curl-from-localhost-non-sslhttp

Resources are queried via an HTTP request to the
`/resources` REST endpoint.

## Query format

Queries for resources must conform to the following format:

* A `GET` is used.
* There is a single parameter, `query`.
* The `query` parameter is a JSON array of query predicates, in prefix
  form, conforming to the format described below.

The `query` parameter adheres to the following grammar:

    query: [ {type} {query}+ ] | [ {match} {field} {value} ]
    field:  string | [ string+ ]
    value:  string
    type:   "or" | "and" | "not"
    match:  "="

`field` strings may be any of the following:

`tag`
: a case-insensitive tag on the resource

`["node", "name"]`
: the name of the node associated with the resource

`["node", "active"]`
: `true` if the node has not been deactivated, `false` if it has

`["parameter", "<parameter name>"]`
: a parameter of the resource

`type`
: the resource type

`title`
: the resource title

`exported`
: whether or not the resource is exported

`sourcefile`
: the manifest file where the resource was declared

`sourceline`
: the line of the manifest in which the resource was declared

For example, the JSON query structure for file resources, tagged "magical", and present on any active host except
for "example.local" would be:

    ["and", ["not", ["=", ["node", "name"], "example.local"]],
            ["=", ["node", "active"], true],
            ["=", "type", "File"],
            ["=", "tag",  "magical"],
            ["=", ["parameter", "ensure"], "enabled"]]

The following conditionals for type behaviors are defined:

`or`
: If *any* condition is true, the result is true.

`and`
: If *all* conditions are true, the result is true.

`not`
: If *none* of the conditions are true, the result is true.

The following match operator behaviors are defined:

`=`
: Exact string equality of the field and the value.

## Response format

An array of zero or more resource objects, with each object in the
following form:

    {"certname":   "the certname of the associated host",
     "resource":   "the resource's unique hash",
     "type":       "File",
     "title":      "/etc/hosts",
     "exported":   "true",
     "tags":       ["foo", "bar"],
     "sourcefile": "/etc/puppet/manifests/site.pp",
     "sourceline": "1",
     "parameters": {<parameter>: <value>,
                    <parameter>: <value>,
                    ...}}

## Example

[Using `curl` from localhost][curl]:

Retrieving the resource `File['/etc/ipsec.conf']`:

    curl -G 'http://localhost:8080/resources' --data-urlencode 'query=["and", ["=", "type", "File"], ["=", "title", "/etc/ipsec.conf"]]'


text:
// BSD License (http://lemurproject.org/galago-license)

package org.lemurproject.galago.krovetz;

/**
 *
Title: Kstemmer

 *
Description: This is a java version of Bob Krovetz' kstem stemmer

 *
Copyright: Copyright (c) 2003

 *
Company: CIIR University of Massachusetts Amherst (http://ciir.cs.umass.edu)

 * @author Sergio Guzman-Lara
 * @version 1.1
 */

import java.io.FileReader;
import java.io.LineNumberReader;
import java.util.HashMap;

/**
 This class implements the Kstem algorithm
 */
public class KStem {

 /** Default size of the cache that stores (word,stem) pairs.

This speeds up processing since Kstem works by
  sucessive "transformations" to the input word until a
  suitable stem is found.
  */
 //static public int DEFAULT_CACHE_SIZE = 20000;
 static private final int MaxWordLen = 100;
 static private final String[] exceptionWords = {"aide",
     "bathe", "caste", "cute", "dame", "dime", "doge", "done", "dune",
     "envelope", "gage", "grille", "grippe", "lobe", "mane", "mare",
     "nape", "node", "pane", "pate", "plane", "pope", "programme",
     "quite", "ripe", "rote", "rune", "sage", "severe", "shoppe",
     "sine", "slime", "snipe", "steppe", "suite", "swinge", "tare",
     "tine", "tope", "tripe", "twine"};
 static private final String[][] directConflations = {
     {"aging", "age"}, {"going", "go"}, {"goes", "go"}, {"lying", "lie"},
     {"using", "use"}, {"owing", "owe"}, {"suing", "sue"}, {"dying", "die"},
     {"tying", "tie"}, {"vying", "vie"}, {"aged", "age"}, {"used", "use"},
     {"vied", "vie"}, {"cued", "cue"}, {"died", "die"}, {"eyed", "eye"},
     {"hued", "hue"}, {"iced", "ice"}, {"lied", "lie"}, {"owed", "owe"},
     {"sued", "sue"}, {"toed", "toe"}, {"tied", "tie"}, {"does", "do"},
     {"doing", "do"}, {"aeronautical", "aeronautics"},
     {"mathematical", "mathematics"}, {"political", "politics"},
     {"metaphysical", "metaphysics"}, {"cylindrical", "cylinder"},
     {"nazism", "nazi"}, {"ambiguity", "ambiguous"}, {"barbarity", "barbarous"},
     {"credulity", "credulous"}, {"generosity", "generous"}, {"spontaneity", "spontaneous"},
     {"unanimity", "unanimous"}, {"voracity", "voracious"}, {"fled", "flee"},
     {"miscarriage", "miscarry"},
     {"appendices", "appendix"},
     {"babysitting", "babysit"},
     {"bater", "bate"},
     {"belying", "belie"},
     {"bookshelves", "bookshelf"},
     {"bootstrapped", "bootstrap"},
     {"bootstrapping", "bootstrap"},
     {"checksummed", "checksum"},
     {"checksumming", "checksum"},
     {"crises", "crisis"},
     {"dwarves", "dwarf"},
     {"eerily", "eerie"},
     {"housewives", "housewife"},
     {"midwives", "midwife"},
     {"oases", "oasis"},
     {"parentheses", "parenthesis"},
     {"scarves", "scarf"},
     {"synopses", "synopsis"},
     {"syntheses", "synthesis"},
     {"taxied", "taxi"},
     {"testes", "testicle"},
     {"theses", "thesis"},
     {"thieves", "thief"},
     {"vortices", "vortex"},
     {"wharves", "wharf"},
     {"wolves", "wolf"},
     {"yourselves", "yourself"}};
 static private final String[][] countryNationality = {
     {"afghan", "afghanistan"}, {"african", "africa"}, {"albanian", "albania"},
     {"algerian", "algeria"}, {"american", "america"}, {"andorran", "andorra"},
     {"angolan", "angola"}, {"arabian", "arabia"}, {"argentine", "argentina"},
     {"armenian", "armenia"}, {"asian", "asia"}, {"australian", "australia"},
     {"austrian", "austria"}, {"azerbaijani", "azerbaijan"},
     {"azeri", "azerbaijan"}, {"bangladeshi", "bangladesh"},
     {"belgian", "belgium"}, {"bermudan", "bermuda"},
     {"bolivian", "bolivia"}, {"bosnian", "bosnia"}, {"botswanan", "botswana"},
     {"brazilian", "brazil"}, {"british", "britain"}, {"bulgarian", "bulgaria"},
     {"burmese", "burma"}, {"californian", "california"}, {"cambodian", "cambodia"},
     {"canadian", "canada"}, {"chadian", "chad"}, {"chilean", "chile"},
     {"chinese", "china"}, {"colombian", "colombia"}, {"croat", "croatia"},
     {"croatian", "croatia"}, {"cuban", "cuba"}, {"cypriot", "cyprus"},
     {"czechoslovakian", "czechoslovakia"}, {"danish", "denmark"}, {"egyptian", "egypt"},
     {"equadorian", "equador"}, {"eritrean", "eritrea"}, {"estonian", "estonia"},
     {"ethiopian", "ethiopia"}, {"european", "europe"}, {"fijian", "fiji"},
     {"filipino", "philippines"}, {"finnish", "finland"}, {"french", "france"},
     {"gambian", "gambia"}, {"georgian", "georgia"}, {"german", "germany"},
     {"ghanian", "ghana"}, {"greek", "greece"}, {"grenadan", "grenada"},
     {"guamian", "guam"}, {"guatemalan", "guatemala"}, {"guinean", "guinea"},
     {"guyanan", "guyana"}, {"haitian", "haiti"}, {"hawaiian", "hawaii"},
     {"holland", "dutch"}, {"honduran", "honduras"}, {"hungarian", "hungary"},
     {"icelandic", "iceland"}, {"indonesian", "indonesia"},
     {"iranian", "iran"}, {"iraqi", "iraq"}, {"iraqui", "iraq"}, {"irish", "ireland"},
     {"israeli", "israel"}, {"italian", "italy"}, {"jamaican", "jamaica"}, {"japanese", "japan"},
     {"jordanian", "jordan"}, {"kampuchean", "cambodia"}, {"kenyan", "kenya"},
     {"korean", "korea"}, {"kuwaiti", "kuwait"}, {"lankan", "lanka"},
     {"laotian", "laos"}, {"latvian", "latvia"}, {"lebanese", "lebanon"},
     {"liberian", "liberia"}, {"libyan", "libya"}, {"lithuanian", "lithuania"},
     {"macedonian", "macedonia"}, {"madagascan", "madagascar"}, {"malaysian", "malaysia"},
     {"maltese", "malta"}, {"mauritanian", "mauritania"}, {"mexican", "mexico"},
     {"micronesian", "micronesia"}, {"moldovan", "moldova"}, {"monacan", "monaco"},
     {"mongolian", "mongolia"}, {"montenegran", "montenegro"}, {"moroccan", "morocco"},
     {"myanmar", "burma"}, {"namibian", "namibia"}, {"nepalese", "nepal"},
     //{"netherlands", "dutch"},
     {"nicaraguan", "nicaragua"}, {"nigerian", "nigeria"},
     {"norwegian", "norway"}, {"omani", "oman"}, {"pakistani", "pakistan"},
     {"panamanian", "panama"}, {"papuan", "papua"}, {"paraguayan", "paraguay"},
     {"peruvian", "peru"}, {"portuguese", "portugal"}, {"romanian", "romania"},
     {"rumania", "romania"}, {"rumanian", "romania"}, {"russian", "russia"},
     {"rwandan", "rwanda"}, {"samoan", "samoa"}, {"scottish", "scotland"},
     {"serb", "serbia"}, {"serbian", "serbia"}, {"siam", "thailand"},
     {"siamese", "thailand"}, {"slovakia", "slovak"}, {"slovakian", "slovak"},
     {"slovenian", "slovenia"}, {"somali", "somalia"}, {"somalian", "somalia"},
     {"spanish", "spain"}, {"swedish", "sweden"}, {"swiss", "switzerland"},
     {"syrian", "syria"}, {"taiwanese", "taiwan"}, {"tanzanian", "tanzania"},
     {"texan", "texas"}, {"thai", "thailand"}, {"tunisian", "tunisia"},
     {"turkish", "turkey"}, {"ugandan", "uganda"}, {"ukrainian", "ukraine"},
     {"uruguayan", "uruguay"}, {"uzbek", "uzbekistan"}, {"venezuelan", "venezuela"},
     {"vietnamese", "viet"}, {"virginian", "virginia"}, {"yemeni", "yemen"},
     {"yugoslav", "yugoslavia"}, {"yugoslavian", "yugoslavia"}, {"zambian", "zambia"},
     {"zealander", "zealand"}, {"zimbabwean", "zimbabwe"}};
 static private final String[] supplementDict = {
     "aids",
     "applicator", "capacitor", "digitize", "electromagnet",
     "ellipsoid", "exosphere", "extensible", "ferromagnet",
     "graphics", "hydromagnet", "polygraph", "toroid", "superconduct",
     "backscatter", "connectionism"
 };
 static private final String[] properNouns = {
     "abrams", "achilles", "acropolis", "adams", "agnes",
     "aires", "alexander", "alexis", "alfred", "algiers",
     "alps", "amadeus", "ames", "amos", "andes",
     "angeles", "annapolis", "antilles", "aquarius", "archimedes",
     "arkansas", "asher", "ashly", "athens", "atkins",
     "atlantis", "avis", "bahamas", "bangor", "barbados",
     "barger", "bering", "brahms", "brandeis", "brussels",
     "bruxelles", "cairns", "camoros", "camus", "carlos",
     "celts", "chalker", "charles", "cheops", "ching",
     "christmas", "cocos", "collins", "columbus", "confucius",
     "conners", "connolly", "copernicus", "cramer", "cyclops",
     "cygnus", "cyprus", "dallas", "damascus", "daniels",
     "davies", "davis", "decker", "denning", "dennis",
     "descartes", "dickens", "doris", "douglas", "downs",
     "dreyfus", "dukakis", "dulles", "dumfries", "ecclesiastes",
     "edwards", "emily", "erasmus", "euphrates", "evans",
     "everglades", "fairbanks", "federales", "fisher", "fitzsimmons",
     "fleming", "forbes", "fowler",
     "france",
     "francis",
     "goering", "goodling", "goths", "grenadines", "guiness",
     "hades", "harding", "harris", "hastings", "hawkes",
     "hawking", "hayes", "heights", "hercules", "himalayas",
     "hippocrates", "hobbs", "holmes", "honduras", "hopkins",
     "hughes", "humphreys", "illinois", "indianapolis", "inverness",
     "iris", "iroquois", "irving", "isaacs", "italy",
     "james", "jarvis", "jeffreys", "jesus", "jones",
     "josephus", "judas", "julius", "kansas", "keynes",
     "kipling", "kiwanis", "lansing", "laos", "leeds",
     "levis", "leviticus", "lewis", "louis", "maccabees",
     "madras", "maimonides", "maldive", "massachusetts", "matthews",
     "mauritius", "memphis", "mercedes", "midas", "mingus",
     "minneapolis", "mohammed", "moines", "morris", "moses",
     "myers", "myknos", "nablus", "nanjing", "nantes",
     "naples", "neal", "netherlands", "nevis", "nostradamus",
     "oedipus", "olympus", "orleans", "orly", "papas",
     "paris", "parker", "pauling", "peking", "pershing",
     "peter", "peters", "philippines", "phineas", "pisces",
     "pryor", "pythagoras", "queens", "rabelais", "ramses",
     "reynolds", "rhesus", "rhodes", "richards", "robins",
     "rodgers", "rogers", "rubens", "sagittarius", "seychelles",
     "socrates", "texas", "thames", "thomas", "tiberias",
     "tunis", "venus", "vilnius", "wales", "warner",
     "wilkins", "williams", "wyoming", "xmas", "yonkers",
     "zeus", "frances", "aarhus", "adonis", "andrews", "angus",
     "antares", "aquinas", "arcturus", "ares", "artemis", "augustus",
     "ayers", "barnabas", "barnes", "becker", "bejing", "biggs",
     "billings", "boeing", "boris", "borroughs", "briggs", "buenos",
     "calais", "caracas", "cassius", "cerberus", "ceres", "cervantes",
     "chantilly", "chartres", "chester", "connally",
     "conner", "coors", "cummings", "curtis", "daedalus", "dionysus",
     "dobbs", "dolores", "edmonds"};

 private static class DictEntry {

  boolean exception;
  String root;

  public DictEntry(String root, boolean isException) {
   this.root = root;
   this.exception = isException;
  }
 }
 private static HashMap<String,DictEntry> dict_ht = null;
 //private int MaxCacheSize;
 //private HashMap stem_ht = null;
 private StringBuffer word;
 private int j; /* index of final letter in stem (within word) */

 private int k; /* INDEX of final letter in word.
  You must add 1 to k to get the current length of word.
  When you want the length of word, use the method
  wordLength, which returns (k+1). */

 //  private void initializeStemHash() {
//    stem_ht = new HashMap();
//  }
 private char finalChar() {
  return word.charAt(k);
 }

 private char penultChar() {
  return word.charAt(k - 1);
 }

 private boolean isVowel(int index) {
  return !isCons(index);
 }

 private boolean isCons(int index) {
  char ch;

  ch = word.charAt(index);

  if ((ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u')) {
   return false;
  }
  if ((ch != 'y') || (index == 0)) {
   return true;
  } else {
   return (!isCons(index - 1));
  }
 }

 private static synchronized void initializeDictHash() {
  DictEntry defaultEntry;
  DictEntry entry;

  if (dict_ht != null) {
   return;
  }

  dict_ht = new HashMap<>();
   for (String exceptionWord : exceptionWords) {
     if (!dict_ht.containsKey(exceptionWord)) {
       entry = new DictEntry(exceptionWord, true);
       dict_ht.put(exceptionWord, entry);
     } else {
       System.out.println("Warning: Entry [" + exceptionWord
           + "] already in dictionary 1");
     }
   }

   for (String[] directConflation : directConflations) {
     if (!dict_ht.containsKey(directConflation[0])) {
       entry = new DictEntry(directConflation[1], false);
       dict_ht.put(directConflation[0], entry);
     } else {
       System.out.println("Warning: Entry [" + directConflation[0]
           + "] already in dictionary 2");
     }
   }

   for (String[] aCountryNationality : countryNationality) {
     if (!dict_ht.containsKey(aCountryNationality[0])) {
       entry = new DictEntry(aCountryNationality[1], false);
       dict_ht.put(aCountryNationality[0], entry);
     } else {
       System.out.println("Warning: Entry ["
           + aCountryNationality[0]
           + "] already in dictionary 3");
     }
   }

  defaultEntry = new DictEntry(null, false);

  String[] array;
  array = KStemData1.data;

   for (String anArray1 : array) {
     if (!dict_ht.containsKey(anArray1)) {
       dict_ht.put(anArray1, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray1
           + "] already in dictionary 4");
     }
   }

  array = KStemData2.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  array = KStemData3.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  array = KStemData4.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  array = KStemData5.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  array = KStemData6.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  array = KStemData7.data;
   for (String anArray : array) {
     if (!dict_ht.containsKey(anArray)) {
       dict_ht.put(anArray, defaultEntry);
     } else {
       System.out.println("Warning: Entry [" + anArray
           + "] already in dictionary 4");
     }
   }

  for (int i = 0; i < KStemData8.data.length; i++) {
   if (!dict_ht.containsKey(KStemData8.data[i])) {
    dict_ht.put(KStemData8.data[i], defaultEntry);
   } else {
    System.out.println("Warning: Entry [" + KStemData8.data[i]
        + "] already in dictionary 4");
   }
  }

   for (String aSupplementDict : supplementDict) {
     if (!dict_ht.containsKey(aSupplementDict)) {
       dict_ht.put(aSupplementDict, defaultEntry);
     } else {
       System.out.println("Warning: Entry ["
           + aSupplementDict
           + "] already in dictionary 5");
     }
   }

   for (String properNoun : properNouns) {
     if (!dict_ht.containsKey(properNoun)) {
       dict_ht.put(properNoun, defaultEntry);
     } else {
       System.out.println("Warning: Entry ["
           + properNoun
           + "] already in dictionary 6");
     }
   }
 }

 private boolean isAlpha(char ch) {
  if ((ch >= 'a') && (ch <= 'z')) {
   return true;
  }
  if ((ch >= 'A') && (ch <= 'Z')) {
   return true;
  }
  return false;
 }

 /* length of stem within word */
 private int stemLength() {
  return j + 1;
 }

 private boolean endsIn(String s) {
  boolean match;
  int sufflength = s.length();

  int r = word.length() - sufflength; /* length of word before this suffix */
  if (sufflength > k) {
   return false;
  }

  match = true;
  for (int r1 = r, i = 0; (i < sufflength) && (match); i++, r1++) {
   if (s.charAt(i) != word.charAt(r1)) {
    match = false;
   }
  }

  if (match) {
   j = r - 1;  /* index of the character BEFORE the posfix */
  } else {
   j = k;
  }
  return match;
 }

 private DictEntry wordInDict() {
  String s = word.toString();
  return dict_ht.get(s);
 }

 /* Convert plurals to singular form, and '-ies' to 'y' */
 private void plural() {
  if (finalChar() == 's') {
   if (endsIn("ies")) {
    word.setLength(j + 3);
    k--;
    if (lookup(word.toString())) /* ensure calories -> calorie */ {
     return;
    }
    k++;
    word.append('s');
    setSuffix("y");
   } else if (endsIn("es")) {
        /* try just removing the "s" */
    word.setLength(j + 2);
    k--;

        /* note: don't check for exceptions here.  So, `aides' -> `aide',
        but `aided' -> `aid'.  The exception for double s is used to prevent
        crosses -> crosse.  This is actually correct if crosses is a plural
        noun (a type of racket used in lacrosse), but the verb is much more
        common */

    if ((j > 0) && (lookup(word.toString()))
        && !((word.charAt(j) == 's')
        && (word.charAt(j - 1) == 's'))) {
     return;
    }

        /* try removing the "es" */

    word.setLength(j + 1);
    k--;
    if (lookup(word.toString())) {
     return;
    }

        /* the default is to retain the "e" */
    word.append('e');
    k++;
    return;
   } else {
    if (word.length() > 3 && penultChar() != 's'
        && !endsIn("ous")) {
          /* unless the word ends in "ous" or a double "s", remove the final "s" */

     word.setLength(k);
     k--;
    }
   }
  }
 }

 private void setSuffix(String s) {
  setSuff(s, s.length());
 }

 /* replace old suffix with s */
 private void setSuff(String s, int len) {
  word.setLength(j + 1);
  for (int l = 0; l < len; l++) {
   word.append(s.charAt(l));
  }
  k = j + len;
 }

 /* Returns true if s is found in the dictionary */
 private boolean lookup(String s) {
   return dict_ht.containsKey(s);
 }

 /* convert past tense (-ed) to present, and `-ied' to `y' */
 private void pastTense() {
    /* Handle words less than 5 letters with a direct mapping
    This prevents (fled -> fl).  */

  if (word.length() <= 4) {
   return;
  }

  if (endsIn("ied")) {
   word.setLength(j + 3);
   k--;
   if (lookup(word.toString())) /* we almost always want to convert -ied to -y, but */ {
    return;                  /* this isn't true for short words (died->die)      */
   }
   k++;                         /* I don't know any long words that this applies to, */
   word.append('d');            /* but just in case...                              */
   setSuffix("y");
   return;
  }

    /* the vowelInStem() is necessary so we don't stem acronyms */
  if (endsIn("ed") && vowelInStem()) {
      /* see if the root ends in `e' */
   word.setLength(j + 2);
   k = j + 1;

   DictEntry entry = wordInDict();
   if (entry != null) {
    if (!entry.exception) /* if it's in the dictionary and not an exception */ {
     return;
    }
   }

      /* try removing the "ed" */
   word.setLength(j + 1);
   k = j;
   if (lookup(word.toString())) {
    return;
   }

      /* try removing a doubled consonant.  if the root isn't found in
      the dictionary, the default is to leave it doubled.  This will
      correctly capture `backfilled' -> `backfill' instead of
      `backfill' -> `backfille', and seems correct most of the time  */

   if (doubleC(k)) {
    word.setLength(k);
    k--;
    if (lookup(word.toString())) {
     return;
    }
    word.append(word.charAt(k));
    k++;
    return;
   }

      /* if we have a `un-' prefix, then leave the word alone  */
      /* (this will sometimes screw up with `under-', but we   */
      /*  will take care of that later)                        */

   if ((word.charAt(0) == 'u') && (word.charAt(1) == 'n')) {
    word.append('e');
    word.append('d');
    k = k + 2;
    return;
   }

      /* it wasn't found by just removing the `d' or the `ed', so prefer to
      end with an `e' (e.g., `microcoded' -> `microcode'). */

   word.setLength(j + 1);
   word.append('e');
   k = j + 1;
   return;
  }
 }

 /* return TRUE if word ends with a double consonant */
 private boolean doubleC(int i) {
  if (i < 1) {
   return false;
  }

  if (word.charAt(i) != word.charAt(i - 1)) {
   return false;
  }
  return (isCons(i));
 }

 private boolean vowelInStem() {
  for (int i = 0; i < stemLength(); i++) {
   if (isVowel(i)) {
    return true;
   }
  }
  return false;
 }

 /* handle `-ing' endings */
 private void aspect() {
    /* handle short words (aging -> age) via a direct mapping.  This
    prevents (thing -> the) in the version of this routine that
    ignores inflectional variants that are mentioned in the dictionary
    (when the root is also present) */

  if (word.length() <= 5) {
   return;
  }

    /* the vowelinstem() is necessary so we don't stem acronyms */
  if (endsIn("ing") && vowelInStem()) {

      /* try adding an `e' to the stem and check against the dictionary */
   word.setCharAt(j + 1, 'e');
   word.setLength(j + 2);
   k = j + 1;

   DictEntry entry = wordInDict();
   if (entry != null) {
    if (!entry.exception) /* if it's in the dictionary and not an exception */ {
     return;
    }
   }

      /* adding on the `e' didn't work, so remove it */
   word.setLength(k);
   k--;           /* note that `ing' has also been removed */

   if (lookup(word.toString())) {
    return;
   }

      /* if I can remove a doubled consonant and get a word, then do so */
   if (doubleC(k)) {
    k--;
    word.setLength(k + 1);
    if (lookup(word.toString())) {
     return;
    }
    word.append(word.charAt(k)); /* restore the doubled consonant */

        /* the default is to leave the consonant doubled            */
        /*  (e.g.,`fingerspelling' -> `fingerspell').  Unfortunately */
        /*  `bookselling' -> `booksell' and `mislabelling' -> `mislabell'). */
        /*  Without making the algorithm significantly more complicated, this */
        /*  is the best I can do */
    k++;
    return;
   }

      /* the word wasn't in the dictionary after removing the stem, and then
      checking with and without a final `e'.  The default is to add an `e'
      unless the word ends in two consonants, so `microcoding' -> `microcode'.
      The two consonants restriction wouldn't normally be necessary, but is
      needed because we don't try to deal with prefixes and compounds, and
      most of the time it is correct (e.g., footstamping -> footstamp, not
      footstampe; however, decoupled -> decoupl).  We can prevent almost all
      of the incorrect stems if we try to do some prefix analysis first */

   if ((j > 0) && isCons(j) && isCons(j - 1)) {
    k = j;
    word.setLength(k + 1);
    return;
   }

   word.setLength(j + 1);
   word.append('e');
   k = j + 1;
   return;
  }
 }

 /* this routine deals with -ity endings.  It accepts -ability, -ibility,
 and -ality, even without checking the dictionary because they are so
 productive.  The first two are mapped to -ble, and the -ity is remove
 for the latter */
 private void ityEndings() {
  int old_k = k;

  if (endsIn("ity")) {
   word.setLength(j + 1);          /* try just removing -ity */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.append('e');             /* try removing -ity and adding -e */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }
   word.setCharAt(j + 1, 'i');
   word.append("ty");
   k = old_k;
      /* the -ability and -ibility endings are highly productive, so just accept them */
   if ((j > 0) && (word.charAt(j - 1) == 'i') && (word.charAt(j) == 'l')) {
    word.setLength(j - 1);
    word.append("le");   /* convert to -ble */
    k = j;
    return;
   }

      /* ditto for -ivity */
   if ((j > 0) && (word.charAt(j - 1) == 'i') && (word.charAt(j) == 'v')) {
    word.setLength(j + 1);
    word.append('e');         /* convert to -ive */
    k = j + 1;
    return;
   }
      /* ditto for -ality */
   if ((j > 0) && (word.charAt(j - 1) == 'a') && (word.charAt(j) == 'l')) {
    word.setLength(j + 1);
    k = j;
    return;
   }

      /* if the root isn't in the dictionary, and the variant *is*
      there, then use the variant.  This allows `immunity'->`immune',
      but prevents `capacity'->`capac'.  If neither the variant nor
      the root form are in the dictionary, then remove the ending
      as a default */

   if (lookup(word.toString())) {
    return;
   }

      /* the default is to remove -ity altogether */
   word.setLength(j + 1);
   k = j;
   return;
  }
 }

 /* handle -ence and -ance */
 private void nceEndings() {
  int old_k = k;
  char word_char;

  if (endsIn("nce")) {
   if (!((word.charAt(j) == 'e') || (word.charAt(j) == 'a'))) {
    return;
   }
   word_char = word.charAt(j);
   word.setLength(j);
   word.append('e');     /* try converting -e/ance to -e (adherance/adhere) */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j); /* try removing -e/ance altogether (disappearance/disappear) */
   k = j - 1;
   if (lookup(word.toString())) {
    return;
   }
   word.append(word_char);  /* restore the original ending */
   word.append("nce");
   k = old_k;
  }
  return;
 }

 /* handle -ness */
 private void nessEndings() {
  if (endsIn("ness")) {     /* this is a very productive endings, so just accept it */
   word.setLength(j + 1);
   k = j;
   if (word.charAt(j) == 'i') {
    word.setCharAt(j, 'y');
   }
  }
  return;
 }

 /* handle -ism */
 private void ismEndings() {
  if (endsIn("ism")) {    /* this is a very productive ending, so just accept it */
   word.setLength(j + 1);
   k = j;
  }
  return;
 }

 /* this routine deals with -ment endings. */
 private void mentEndings() {
  int old_k = k;

  if (endsIn("ment")) {
   word.setLength(j + 1);
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.append("ment");
   k = old_k;
  }
  return;
 }

 /* this routine deals with -ize endings. */
 private void izeEndings() {
  int old_k = k;

  if (endsIn("ize")) {
   word.setLength(j + 1);       /* try removing -ize entirely */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.append('i');

   if (doubleC(j)) {      /* allow for a doubled consonant */
    word.setLength(j);
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }
    word.append(word.charAt(j - 1));
   }

   word.setLength(j + 1);
   word.append('e');        /* try removing -ize and adding -e */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j + 1);
   word.append("ize");
   k = old_k;
  }
  return;
 }

 /* handle -ency and -ancy */
 private void ncyEndings() {
  if (endsIn("ncy")) {
   if (!((word.charAt(j) == 'e') || (word.charAt(j) == 'a'))) {
    return;
   }
   word.setCharAt(j + 2, 't');  /* try converting -ncy to -nt */
   word.setLength(j + 3);
   k = j + 2;

   if (lookup(word.toString())) {
    return;
   }

   word.setCharAt(j + 2, 'c');  /* the default is to convert it to -nce */
   word.append('e');
   k = j + 3;
  }
  return;
 }

 /* handle -able and -ible */
 private void bleEndings() {
  int old_k = k;
  char word_char;

  if (endsIn("ble")) {
   if (!((word.charAt(j) == 'a') || (word.charAt(j) == 'i'))) {
    return;
   }
   word_char = word.charAt(j);
   word.setLength(j);         /* try just removing the ending */
   k = j - 1;
   if (lookup(word.toString())) {
    return;
   }
   if (doubleC(k)) {          /* allow for a doubled consonant */
    word.setLength(k);
    k--;
    if (lookup(word.toString())) {
     return;
    }
    k++;
    word.append(word.charAt(k - 1));
   }
   word.setLength(j);
   word.append('e');   /* try removing -a/ible and adding -e */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j);
   word.append("ate"); /* try removing -able and adding -ate */
      /* (e.g., compensable/compensate)     */
   k = j + 2;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j);
   word.append(word_char);        /* restore the original values */
   word.append("ble");
   k = old_k;
  }
  return;
 }

 /* handle -ic endings.   This is fairly straightforward, but this is
 also the only place we try *expanding* an ending, -ic -> -ical.
 This is to handle cases like `canonic' -> `canonical' */
 private void icEndings() {
  if (endsIn("ic")) {
   word.setLength(j + 3);
   word.append("al");        /* try converting -ic to -ical */
   k = j + 4;
   if (lookup(word.toString())) {
    return;
   }

   word.setCharAt(j + 1, 'y');        /* try converting -ic to -y */
   word.setLength(j + 2);
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }

   word.setCharAt(j + 1, 'e');        /* try converting -ic to -e */
   if (lookup(word.toString())) {
    return;
   }

   word.setLength(j + 1); /* try removing -ic altogether */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.append("ic"); /* restore the original ending */
   k = j + 2;
  }
  return;
 }

 /* handle some derivational endings */
  /* this routine deals with -ion, -ition, -ation, -ization, and -ication.  The
  -ization ending is always converted to -ize */
 private void ionEndings() {
  int old_k = k;

  if (endsIn("ization")) {   /* the -ize ending is very productive, so simply accept it as the root */
   word.setLength(j + 3);
   word.append('e');
   k = j + 3;
   return;
  }

  if (endsIn("ition")) {
   word.setLength(j + 1);
   word.append('e');
   k = j + 1;
   if (lookup(word.toString())) /* remove -ition and add `e', and check against the dictionary */ {
    return;                    /* (e.g., definition->define, opposition->oppose) */
   }

      /* restore original values */
   word.setLength(j + 1);
   word.append("ition");
   k = old_k;
  }

  if (endsIn("ation")) {
   word.setLength(j + 3);
   word.append('e');
   k = j + 3;
   if (lookup(word.toString())) /* remove -ion and add `e', and check against the dictionary */ {
    return;                  /* (elmination -> eliminate)  */
   }

   word.setLength(j + 1);
   word.append('e');   /* remove -ation and add `e', and check against the dictionary */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }

   word.setLength(j + 1);/* just remove -ation (resignation->resign) and check dictionary */
   k = j;
   if (lookup(word.toString())) {
    return;
   }

      /* restore original values */
   word.setLength(j + 1);
   word.append("ation");
   k = old_k;
  }

    /* test -ication after -ation is attempted (e.g., `complication->complicate'
    rather than `complication->comply') */

  if (endsIn("ication")) {
   word.setLength(j + 1);
   word.append('y');
   k = j + 1;
   if (lookup(word.toString())) /* remove -ication and add `y', and check against the dictionary */ {
    return;                 /* (e.g., amplification -> amplify) */
   }

      /* restore original values */
   word.setLength(j + 1);
   word.append("ication");
   k = old_k;
  }

  if (endsIn("ion")) {
   word.setLength(j + 1);
   word.append('e');
   k = j + 1;
   if (lookup(word.toString())) /* remove -ion and add `e', and check against the dictionary */ {
    return;
   }

   word.setLength(j + 1);
   k = j;
   if (lookup(word.toString())) /* remove -ion, and if it's found, treat that as the root */ {
    return;
   }

      /* restore original values */
   word.setLength(j + 1);
   word.append("ion");
   k = old_k;
  }

  return;
 }

 /* this routine deals with -er, -or, -ier, and -eer.  The -izer ending is always converted to
 -ize */
 private void erAndOrEndings() {
  int old_k = k;

  char word_char;                 /* so we can remember if it was -er or -or */

  if (endsIn("izer")) {          /* -ize is very productive, so accept it as the root */
   word.setLength(j + 4);
   k = j + 3;
   return;
  }

  if (endsIn("er") || endsIn("or")) {
   word_char = word.charAt(j + 1);
   if (doubleC(j)) {
    word.setLength(j);
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }
    word.append(word.charAt(j - 1));       /* restore the doubled consonant */
   }

   if (word.charAt(j) == 'i') {         /* do we have a -ier ending? */
    word.setCharAt(j, 'y');
    word.setLength(j + 1);
    k = j;
    if (lookup(word.toString())) /* yes, so check against the dictionary */ {
     return;
    }
    word.setCharAt(j, 'i');             /* restore the endings */
    word.append('e');
   }

   if (word.charAt(j) == 'e') {         /* handle -eer */
    word.setLength(j);
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }
    word.append('e');
   }

   word.setLength(j + 2); /* remove the -r ending */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j + 1); /* try removing -er/-or */
   k = j;
   if (lookup(word.toString())) {
    return;
   }
   word.append('e');    /* try removing -or and adding -e */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j + 1);
   word.append(word_char);
   word.append('r');    /* restore the word to the way it was */
   k = old_k;
  }

 }

 /* this routine deals with -ly endings.  The -ally ending is always converted to -al
 Sometimes this will temporarily leave us with a non-word (e.g., heuristically
 maps to heuristical), but then the -al is removed in the next step.  */
 private void lyEndings() {
  int old_k = k;

  if (endsIn("ly")) {

   word.setCharAt(j + 2, 'e');             /* try converting -ly to -le */

   if (lookup(word.toString())) {
    return;
   }
   word.setCharAt(j + 2, 'y');

   word.setLength(j + 1);         /* try just removing the -ly */
   k = j;

   if (lookup(word.toString())) {
    return;
   }

   if ((j > 0) && (word.charAt(j - 1) == 'a') && (word.charAt(j) == 'l')) /* always convert -ally to -al */ {
    return;
   }
   word.append("ly");
   k = old_k;

   if ((j > 0) && (word.charAt(j - 1) == 'a') && (word.charAt(j) == 'b')) {  /* always convert -ably to -able */
    word.setCharAt(j + 2, 'e');
    k = j + 2;
    return;
   }

   if (word.charAt(j) == 'i') {        /* e.g., militarily -> military */
    word.setLength(j);
    word.append('y');
    k = j;
    if (lookup(word.toString())) {
     return;
    }
    word.setLength(j);
    word.append("ily");
    k = old_k;
   }

   word.setLength(j + 1); /* the default is to remove -ly */

   k = j;
  }
  return;
 }

 /* this routine deals with -al endings.  Some of the endings from the previous routine
 are finished up here.  */
 private void alEndings() {
  int old_k = k;

  if (word.length() < 4) {
   return;
  }
  if (endsIn("al")) {
   word.setLength(j + 1);
   k = j;
   if (lookup(word.toString())) /* try just removing the -al */ {
    return;
   }

   if (doubleC(j)) {            /* allow for a doubled consonant */
    word.setLength(j);
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }
    word.append(word.charAt(j - 1));
   }

   word.setLength(j + 1);
   word.append('e');              /* try removing the -al and adding -e */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }

   word.setLength(j + 1);
   word.append("um");    /* try converting -al to -um */
      /* (e.g., optimal - > optimum ) */
   k = j + 2;
   if (lookup(word.toString())) {
    return;
   }

   word.setLength(j + 1);
   word.append("al");    /* restore the ending to the way it was */
   k = old_k;

   if ((j > 0) && (word.charAt(j - 1) == 'i') && (word.charAt(j) == 'c')) {
    word.setLength(j - 1); /* try removing -ical  */
    k = j - 2;
    if (lookup(word.toString())) {
     return;
    }

    word.setLength(j - 1);
    word.append('y');/* try turning -ical to -y (e.g., bibliographical) */
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }

    word.setLength(j - 1);
    word.append("ic"); /* the default is to convert -ical to -ic */
    k = j;
    return;
   }

   if (word.charAt(j) == 'i') {        /* sometimes -ial endings should be removed */
    word.setLength(j); /* (sometimes it gets turned into -y, but we */
    k = j - 1;                  /* aren't dealing with that case for now) */
    if (lookup(word.toString())) {
     return;
    }
    word.append("ial");
    k = old_k;
   }

  }
  return;
 }

 /* this routine deals with -ive endings.  It normalizes some of the
 -ative endings directly, and also maps some -ive endings to -ion. */
 private void iveEndings() {
  int old_k = k;

  if (endsIn("ive")) {
   word.setLength(j + 1);     /* try removing -ive entirely */
   k = j;
   if (lookup(word.toString())) {
    return;
   }

   word.append('e');          /* try removing -ive and adding -e */
   k = j + 1;
   if (lookup(word.toString())) {
    return;
   }
   word.setLength(j + 1);
   word.append("ive");
   if ((j > 0) && (word.charAt(j - 1) == 'a') && (word.charAt(j) == 't')) {
    word.setCharAt(j - 1, 'e');       /* try removing -ative and adding -e */
    word.setLength(j);        /* (e.g., determinative -> determine) */
    k = j - 1;
    if (lookup(word.toString())) {
     return;
    }
    word.setLength(j - 1); /* try just removing -ative */
    if (lookup(word.toString())) {
     return;
    }

    word.append("ative");
    k = old_k;
   }

      /* try mapping -ive to -ion (e.g., injunctive/injunction) */
   word.setCharAt(j + 2, 'o');
   word.setCharAt(j + 3, 'n');
   if (lookup(word.toString())) {
    return;
   }

   word.setCharAt(j + 2, 'v');       /* restore the original values */
   word.setCharAt(j + 3, 'e');
   k = old_k;
  }
  return;
 }

 /** Create a KrovetzStemmer
  *
  */
 public KStem() {
//    MaxCacheSize = DEFAULT_CACHE_SIZE;
  if (dict_ht == null) {
   initializeDictHash();
  }
 }

 /** Returns the stem of a word.
  *  @param term The word to be stemmed.
  *  @return The stem form of the term.
  */
 public String stemTerm(String term) {
  boolean stemIt;
  String result;
  String original;

//    if (stem_ht == null) {
//      initializeStemHash();
//    }

  k = term.length() - 1;

    /* If the word is too long or too short, or not
    entirely alphabetic, just lowercase copy it
    into stem and return */
  stemIt = true;
  if ((k <= 1) || (k >= MaxWordLen - 1)) {
   stemIt = false;
  } else {
   word = new StringBuffer(term.length());
   for (int i = 0; i < term.length(); i++) {
    char ch = Character.toLowerCase(term.charAt(i));
    word.append(ch);
    if (!isAlpha(ch)) {
     stemIt = false;
     break;
    }
   }
  }
  if (!stemIt) {
   return term.toLowerCase();
  }
    /* Check to see if it's in the cache */
  original = word.toString();
//    if (stem_ht.containsKey(original)) {
//      return (String) stem_ht.get(original);
//    }

  result = original; /* default response */

    /* This while loop will never be executed more than one time;
    it is here only to allow the break statement to be used to escape
    as soon as a word is recognized */

  DictEntry entry = null;

  while (true) {
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   plural();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   pastTense();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   aspect();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   ityEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   nessEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   ionEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   erAndOrEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   lyEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   alEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   iveEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   izeEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   mentEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   bleEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   ismEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   icEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   ncyEndings();
   entry = wordInDict();
   if (entry != null) {
    break;
   }
   nceEndings();
   entry = wordInDict();
   break;
  }

    /* try for a direct mapping (allows for cases like `Italian'->`Italy' and
    `Italians'->`Italy')
     */
  if (entry != null) {
   if (entry.root != null) {
    result = entry.root;
   } else {
    result = word.toString();
   }
  } else {
   result = word.toString();
  }

    /* Enter into cache, at the place not used by the last cache hit */
  //   if (stem_ht.size() < MaxCacheSize) {
      /* Add term to cache */
  //    stem_ht.put(original, result);
  //  }

  return result;
 }

 // DEPRECATED....
 static private void usage() {
  System.out.println("Usage:");
  System.out.println("  KStemmer <inputFile>");
  System.out.println("    or");
  System.out.println("  KStemmer -w <word>");
  System.exit(1);
 }

 /** For testing only.

Usage:

KrovetzStemmer <inputFile>

 Will stem all words
  in <inputFile> (one word per line).

KrovetzStemmer -w <word>

 Will stem a single
  <word>

  In either case, the output is sent to System.out
  */
 static public void main(String[] args) {
  KStem stemmer = new KStem();
  String line = null;

  if ((args.length == 0) || (args.length > 2)) {
   usage();
  }

  if (args.length == 2) {
   if (!args[0].equals("-w")) {
    usage();
   }
   System.out.println(args[1] + " " + stemmer.stemTerm(args[1]));
   return;
  }

  // If we get here, we are about to process a file

  try {
   LineNumberReader reader = new LineNumberReader(new FileReader(args[0]));

   line = reader.readLine();
   while (line != null) {
    line = line.trim();
    System.out.println(line + " " + stemmer.stemTerm(line));
    line = reader.readLine();
   }
   reader.close();

  } catch (Exception e) {
   System.out.println("Exception while processing term [" + line + "]");
   e.printStackTrace();
  }
 }
}


text:
""" A TVTK scene editor. """

# Author: Prabhu Ramachandran <prabhu_r@users.sf.net>
# Copyright (c) 2005, Enthought, Inc.
# License: BSD Style.

# Enthought library imports.
from apptools.preferences.api import get_default_preferences
from tvtk.pyface.tvtk_scene import TVTKScene
from tvtk.pyface.api import DecoratedScene
from pyface.workbench.api import Editor
from traits.api import Instance

#### Handy functions ##########################################################

def _id_generator():
    """ Return an ever-increasing number useful for creating unique Ids. """

    n = 1
    while True:
        yield(n)
        n += 1

_id_generator = _id_generator()

class SceneEditor(Editor):
    """ A TVTK scene editor. """

    #### 'SceneEditor' interface ##############################################

    # The TVTK scene object.
    scene = Instance(TVTKScene)

    ###########################################################################
    # 'IWorkbenchPart' interface.
    ###########################################################################

    #### Trait initializers ###################################################

    def _id_default(self):
        """ Trait initializer. """

        return self.name

    def _name_default(self):
        """ Trait initializer. """

        return 'TVTK Scene %d' % (_id_generator.next())

    #### Methods ##############################################################

    def create_control(self, parent):
        """ Create the toolkit-specific control that represents the editor. """

        # We hold a reference to the scene itself to make sure it does not get
        # garbage collected (because we only return the scene's 'control' not
        # the scene itself). The scene is also referenced by the scene manager.
        self.scene = self._create_decorated_scene(parent)
        self.scene.render()

        return self.scene.control

    def destroy_control(self):
        """ Destroy the toolkit-specific control that represents the
        editor.
        """
        if self.scene is not None:
            # Close the scene to cleanly shut it down.
            self.scene.close()

        # Call the parent method.
        return super(SceneEditor, self).destroy_control()

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _create_decorated_scene(self, parent):
        """ Create a new decorated scene. """

        pref = get_default_preferences()
        stereo = eval(pref.get('tvtk.scene.stereo'))

        scene = DecoratedScene(parent, stereo=stereo)

        # Set the scene's traits to preference values.
        scene.magnification = \
                eval(pref.get('tvtk.scene.magnification'))

        fg = eval(pref.get('tvtk.scene.foreground_color'))
        bg = eval(pref.get('tvtk.scene.background_color'))
        scene.foreground = fg
        scene.background = bg
        # FIXME: This seems necessary for some strange reason, if not
        # the actual background of the renderer never gets set even
        # though the renderer and the scene's background are synced.
        scene.renderer.background = scene.background

        return scene

#### EOF ######################################################################


text:
'use strict';

import React from 'react';
import {Link} from 'react-router';
import classnames from "classnames";
import AuthPage from './AuthPage';
import RefluxFormController from '../../forms/components/RefluxFormController';
import {ConfirmResetRequest, AuthApiActions} from '../../api/AuthAPI';
import ConfirmResetFormModel from '../../forms/models/ConfirmResetFormModel';

class ConfirmPasswordResetPage extends React.Component {

    constructor(props) {
        super(props);
    }

    static propTypes = {
        location: React.PropTypes.object
    };

    render() {

        const authClass = classnames('confirm-password-reset-page');
        const {query} = this.props.location

        return (
            <AuthPage className={authClass} title="Password Reset">

                <RefluxFormController
                    requestManager={ConfirmResetRequest}
                    formAction={AuthApiActions.confirmReset}
                    formModel={ConfirmResetFormModel}
                    initialData={query}/>

                <div className="auth-links">
                    <Link to="/login"><- Back to login
                    </Link>
                </div>
            </AuthPage>
        );
    }

}

export default ConfirmPasswordResetPage;


text:
package eu.scape_project.archiventory;

import eu.scape_project.archiventory.cli.CliConfig;
import eu.scape_project.archiventory.cli.Options;
import eu.scape_project.archiventory.container.ArcContainer;
import eu.scape_project.archiventory.container.Container;
import eu.scape_project.archiventory.container.ZipContainer;
import eu.scape_project.archiventory.identifiers.Identification;
import eu.scape_project.archiventory.identifiers.IdentifierCollection;
import eu.scape_project.archiventory.output.OutWritable;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;

/**
 * Archiventory - Container Item Property EXtraction.
 *
 * @author Sven Schlarb https://github.com/shsdev
 * @version 0.1
 */
public class Archiventory {

    public static final String SPRING_CONFIG_RESOURCE_PATH = "eu/scape_project/archiventory/spring-config.xml";
    private static ApplicationContext ctx;
    private static CliConfig config;
    // Logger instance
    private static Logger logger = LoggerFactory.getLogger(Archiventory.class.getName());

    /**
     * Reducer class.
     */
    public static class ContainerItemIdentificationReducer
            extends Reducer<Text, Text, Text, ObjectWritable> {

        private MultipleOutputs mos;

        @Override
        public void setup(Context context) {
            mos = new MultipleOutputs(context);
        }

        @Override
        public void cleanup(Context context) throws IOException, InterruptedException {
            mos.close();
        }

        @Override
        public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
            for (Text val : values) {
                mos.write("idtab", key, val);
            }
        }
    }

    /**
     * Mapper class.
     */
    public static class ContainerItemIdentificationMapper
            extends Mapper<LongWritable, Text, Text, ObjectWritable> {

        private MultipleOutputs mos;

        @Override
        public void setup(Context context) {
            mos = new MultipleOutputs(context);
        }

        @Override
        public void cleanup(Context context) throws IOException, InterruptedException {
            mos.close();
        }

        @Override
        public void map(LongWritable key, Text value, Mapper.Context context) throws IOException, InterruptedException, FileNotFoundException {
            Archiventory wai = new Archiventory();
            Path pt = new Path("hdfs://" + value);
            FileSystem fs = FileSystem.get(new Configuration());
            Container container = wai.createContainer(fs.open(pt), pt.getName());
            wai.performIdentification(container, mos);
        }
    }

    public Archiventory() {
    }

    public static CliConfig getConfig() {
        return config;
    }

    /**
     * Main entry point.
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        // Command line interface
        config = new CliConfig();
        CommandLineParser cmdParser = new PosixParser();
        GenericOptionsParser gop = new GenericOptionsParser(conf, args);
        CommandLine cmd = cmdParser.parse(Options.OPTIONS, gop.getRemainingArgs());
        if ((args.length == 0) || (cmd.hasOption(Options.HELP_OPT))) {
            Options.exit("Usage", 0);
        } else {
            Options.initOptions(cmd, config);
        }
        // Trying to load spring configuration from local file system (same
        // directory where the application is executed). If the spring
        // configuration is not given as a parameter, it is loaded as a
        // resource from the class path.
        if (config.getSpringConfig() != null && (new File(config.getSpringConfig()).exists())) {
            ctx = new FileSystemXmlApplicationContext("file://" + config.getSpringConfig());
        } else {
            ctx = new ClassPathXmlApplicationContext(SPRING_CONFIG_RESOURCE_PATH);
        }
        if (config.isMapReduceJob()) {
            startHadoopJob(conf);
        } else {
            startApplication();
        }
    }

    public static void startApplication() throws FileNotFoundException, IOException, InterruptedException {
        long startTime = System.currentTimeMillis();
        Archiventory wai = new Archiventory();
        wai.traverseDir(new File(config.getDirStr()));
        long elapsedTime = System.currentTimeMillis() - startTime;
        logger.debug("Processing time (sec): " + elapsedTime / 1000F);
        System.exit(0);
    }

    public static void startHadoopJob(Configuration conf) {
        try {
            Job job = new Job(conf, "archiventory");

            // local debugging (pseudo-distributed)
//             job.getConfiguration().set("mapred.job.tracker", "local");
//             job.getConfiguration().set("fs.default.name", "file:///");

            job.setJarByClass(Archiventory.class);

            job.setMapperClass(Archiventory.ContainerItemIdentificationMapper.class);
            job.setReducerClass(Archiventory.ContainerItemIdentificationReducer.class);

            job.setInputFormatClass(TextInputFormat.class);

            // tabular output of identification results
            MultipleOutputs.addNamedOutput(job, "idtab", TextOutputFormat.class, Text.class, Text.class);

            job.setMapOutputKeyClass(Text.class);
            job.setMapOutputValueClass(ObjectWritable.class);

            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(ObjectWritable.class);

            TextInputFormat.addInputPath(job, new Path(config.getDirStr()));
            String outpath = "output/" + System.currentTimeMillis();
            FileOutputFormat.setOutputPath(job, new Path(outpath));
            job.waitForCompletion(true);
            System.out.print(outpath);
            System.exit(0);
        } catch (Exception e) {
            logger.error("I/O error", e);
        }
    }

    private Container createContainer(InputStream containerFileStream, String containerFileName) throws IOException {
        Container container;
        if (containerFileName.endsWith(".arc.gz")) {
            container = new ArcContainer();
        } else if (containerFileName.endsWith(".zip")) {
            container = new ZipContainer();
        } else {
            logger.warn("Unsupported file skipped: " + containerFileName);
            return null;
        }
        container.init(containerFileName, containerFileStream);
        return container;
    }

    /**
     * Apply identification stack
     *
     * @param containerFileStream Content of the container file
     * @param containerFileName File name
     * @param context Hadoop context (only for Hadoop job execution)
     * @throws FileNotFoundException Exception if the container file cannot be
     * found
     * @throws IOException I/O Exception
     */
    private void performIdentification(Container container, MultipleOutputs mos) throws FileNotFoundException, IOException, InterruptedException {
        if (ctx == null) {
            ctx = new ClassPathXmlApplicationContext(SPRING_CONFIG_RESOURCE_PATH);
        }
        IdentifierCollection identificationStack = (IdentifierCollection) ctx.getBean("identificationStack");
        for (Identification identifierItem : identificationStack.getIdentifiers()) {
            Identification fli = (Identification) identifierItem;
            OutWritable outWriter = (OutWritable) ctx.getBean("outWriterBean");
            HashMap<String, List<String>> identifyFileList = fli.identifyFileList(container.getBidiIdentifierFilenameMap());
            if (mos != null) {
                outWriter.write(identifyFileList, mos);
            } else {
                outWriter.write(identifyFileList);
            }
        }
    }

    /**
     * Traverse the root directory recursively
     *
     * @param dir Root directory
     * @throws FileNotFoundException
     * @throws IOException
     */
    private void traverseDir(File dirStructItem) throws FileNotFoundException, IOException, InterruptedException {
        if (dirStructItem.isDirectory()) {
            String[] children = dirStructItem.list();
            for (String child : children) {
                traverseDir(new File(dirStructItem, child));
            }
        } else if (!dirStructItem.isDirectory()) {
            File arcFile = new File(dirStructItem.getAbsolutePath());
            FileInputStream fileInputStream = new FileInputStream(arcFile);
            Container container = createContainer(fileInputStream, arcFile.getName());
            performIdentification(container, null);
            // TODO: Add characterisation
        }
    }
}