text:
from math import ceil
import pandas as pd
import numpy as np
from scipy.stats import ttest_ind, mannwhitneyu
from ldpred import ld

from collections import defaultdict

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

from genda import calculate_minor_allele_frequency, calculate_ld
from genda.plotting import (snp_arrow)
from genda.eQTL import plot_eQTL

#:TODO move this to plotting utils
def remove_tr_spines(ax):
    invisible_spines = ['top', 'right']
    for i in invisible_spines:
        ax.spines[i].set_visible(False)
        ax.xaxis.set_ticks_position('bottom')
        ax.yaxis.set_ticks_position('left')

    return(ax)

def single_snp_aei_test(geno, outliers, allelic_ratio, num_threshold=2,
        nonparametric=False):
    """
    """
    geno = geno[np.logical_not(outliers)]
    het_combined = allelic_ratio[np.array(geno == 1)]
    homo_combined = allelic_ratio[np.array(np.logical_or(geno==0, geno==2))]
    if len(het_combined) < num_threshold or len(homo_combined) < num_threshold:
        return(1)
    else:
        if nonparametric == True:
            pvalue = mannwhitneyu(het_combined, homo_combined)[1]
        else:
            pvalue = ttest_ind(het_combined, homo_combined, equal_var=False)[1]
    return(pvalue)

def single_snp_aei_test2(geno, allelic_ratio, num_threshold=2,
        nonparametric=False):
    het_combined = allelic_ratio[np.array(geno == 1)]
    homo_combined = allelic_ratio[np.array(np.logical_or(geno==0, geno==2))]
    # Het_combined must have a higher ratio than homo_combined
    if len(het_combined) < num_threshold or len(homo_combined) < num_threshold:
        return(np.nan)
    elif (het_combined.mean() > homo_combined.mean()):
        return(np.nan)
    else:
        if nonparametric == True:
            pvalue = mannwhitneyu(het_combined, homo_combined)[1]
        else:
            pvalue = ttest_ind(het_combined, homo_combined, equal_var=False)[1]
        return(pvalue)

def single_snp_aei_test_mixture_model(geno, allelic_ration, num_threshold=2):

    pass

def dosage_round(geno, threshold = 0.5):
    """ Rounds dosage to threshold
    """
    geno[ geno < 1 - threshold] = 0
    geno[np.logical_and(geno >= 1-threshold, geno <= 1 + threshold)] = 1
    geno[ geno > 1 + threshold] = 2
    return geno

class AEI(object):
    def __init__(self, aei_dataframe, geno, snp_annot, gene_name,
            maf_threshold = 0.05, ld_prune=False):
        """
        Arguments
        ---------
        aei_dataframe - AEI count dataframe gotton from func :TODO list script
        to obtain aei from bam file in genda/scripts.  Must be subsetted for
        SNPs within gene.
        geno - genotype dataframe to do testing on
        surrounding SNP.
        snp_annot - dataframe of SNP annotations
        """
        self.aei = aei_dataframe
        # :TODO assert self.geno and self.snp_annot are same shape
        try:
            self.sample_ids = [i[0] for i in self.aei.columns][::4]
        except AttributeError:
            self.sample_ids = [i[0] for i in self.aei.index][::4]

        ids = (pd.Index(self.sample_ids)
                .intersection(geno.columns))
        idx = pd.IndexSlice
        try:
            self.aei.sort_index(axis=1, inplace=True)
            self.aei = self.aei.loc[:, idx[ids, :]]
            self.aei.sort_index(axis=1, inplace=True)
            self.geno = geno.ix[:,
                    self.aei.columns.get_level_values(0)[::4]]
        except TypeError:
            # Case where aei_dataframe is just a series
            self.aei = self.aei.sort_index()
            self.aei = self.aei.loc[idx[ids, :]]
            self.aei = self.aei.sort_index()
            self.geno = geno.ix[:,
                    self.aei.index.get_level_values(0)[::4]]
        self.ids = self.geno.columns
        self.maf = calculate_minor_allele_frequency(self.geno.ix[:, ids])
        # Restrict to  > 5%
        self.geno = self.geno.ix[(self.maf >= maf_threshold) &\
                (self.maf <= 1 - maf_threshold), :]
        self.snp_annot = snp_annot.ix[self.geno.index, :]
        self.maf = self.maf[self.geno.index]

        self.gene_name = gene_name
        self.aei = self.aei.ix[self.geno.index.intersection(self.aei.index),:]
        # SNPs of interest

    def calc_aei(self, num_threshold=5, count_threshold = 20,
            single_snp=None, outlier_thresh=-4.32):
        """
        :TODO split this up into two functions 1 for series and one for
        dataframe

        Arguments
        ---------
        eQTL : eQTL pvalues
        num_threshold : threshold of heterozygous samples at the tag SNP
        required
        single_snp : calculate the pvalue at just a single SNP
        count_threshold : number counts at the tag SNP within an
        individual before that individual will be used in the fit
        """
        base_pair_to_index = {'A':0, 'C': 1, 'G': 2, 'T': 3}
        ids = self.ids
        # Focusing only on single-nucleotide polymorphisms as indicator
        if type(self.aei) == pd.DataFrame:
            not_indel = [i for i in self.aei.index if\
                    (len(self.snp_annot.ix[i, 'a1']) == 1)\
                     & len(self.snp_annot.ix[i, 'a0']) == 1]
        else:
            not_indel = [self.aei.name]
        geno_t = dosage_round(self.geno)
        hets = geno_t.ix[not_indel, :]
        m_size = (len(ids), len(not_indel))
        aei_ratios = pd.DataFrame(
                np.zeros(m_size, dtype=np.uint32),
                index=self.geno.columns,
                columns=pd.Index(not_indel))
        overall_counts = pd.DataFrame(
                np.zeros((len(not_indel), 2), dtype=np.uint32),
                index=pd.Index(not_indel))
        # 1 = False.  True for outliers_m means not outliers
        outliers_m = pd.DataFrame(np.ones(m_size,
                dtype=bool),
                index=self.geno.columns,
                columns=pd.Index(not_indel))
        ref_counts = pd.DataFrame(np.zeros(m_size,
            dtype=np.uint16),
            index=self.geno.columns,
            columns=pd.Index(not_indel))
        alt_counts = pd.DataFrame(np.zeros(m_size,
            dtype=np.uint16),
            index=self.geno.columns,
            columns=pd.Index(not_indel))
        # sufficient hets is really het counts
        sufficient_hets = pd.Series(
                data=np.repeat(0, len(not_indel)),
                index=pd.Index(not_indel),
                dtype=np.int32)
        hets_dict = {}

        #REF = [base_pair_to_index[i] for i in self.snp_annot.ix[not_indel, 'a0']]
        #ALT = [base_pair_to_index[i] for i in self.snp_annot.ix[not_indel, 'a1']]
        def _run_df(hetr):
            #hi = hetr[(hetr == 1.0) &  np.logical_not(pd.isnull(hetr))]
            return((hetr == 1.0) &  np.logical_not(pd.isnull(hetr)))

        #:TODO deal with aei being class series
        hets = hets.apply(_run_df, axis=1)
        #print(hets)
        sufficient_hets = hets.sum(axis=1)
        hets = hets.ix[sufficient_hets >= num_threshold, :]
        aei_t = self.aei.ix[hets.index,:]
        #self.aei.apply(calc_pvalues, axis=1, args=(hets))
        # :TODO filter on LD option
        pvalues_out = np.ones((self.geno.shape[0], aei_t.shape[0]),
            dtype=np.double)
        pvalues_out = pd.DataFrame(pvalues_out, index=self.geno.index,
                columns=aei_t.index)
        aei_ratios = pd.DataFrame(
                np.zeros((len(ids), len(aei_t.index)), dtype=np.uint32),
                index=self.geno.columns,
                columns=aei_t.index)

        c = 0

        for i, row in hets.iterrows():
            try:
                REF = base_pair_to_index[self.snp_annot.ix[i, 'a0']]
                ALT = base_pair_to_index[self.snp_annot.ix[i, 'a1']]
            except KeyError:
                continue
            # hi = hets index
            hi = list(row[row].index)
            idx = pd.IndexSlice
            ref = np.asarray(aei_t.loc[i, idx[hi, REF]].values,
                    dtype=np.float64)
            alt = np.asarray(aei_t.loc[i, idx[hi, ALT]].values,
                    dtype=np.float64)
            #s_c = ref + alt
            #sum_thresh = s_c >= count_threshold
            allelic_ratio = alt/ref
            allelic_ratio = pd.Series(allelic_ratio,
                    index=hi)
            aei_ratios.ix[hi, c] = allelic_ratio
            ref_counts.ix[hi, c] = ref
            alt_counts.ix[hi, c] = alt
            allelic_ratio[allelic_ratio > 1] =\
                    1/allelic_ratio[allelic_ratio > 1]
            outliers = (np.log2(allelic_ratio) < outlier_thresh) |\
                    np.isinf(np.log2(allelic_ratio))
            #outliers = np.logical_or(outliers, np.logical_not(sum_thresh))
            outliers_m.ix[hi, i] = outliers
            allelic_ratio = allelic_ratio[np.logical_not(outliers)]
            geno_i = geno_t.ix[:, allelic_ratio.index]
            pvalues_out.iloc[:, c] = (geno_i.
                               apply(single_snp_aei_test2, axis=1,
                               args=(allelic_ratio,), nonparametric=False))
            hets_dict[i] = hi
            c += 1
        self.pvalues = pvalues_out
        self.hets_dict = hets_dict
        self.ratios = aei_ratios
        self.outliers = outliers_m
        self.ref = ref_counts
        self.alt = alt_counts

    def aei_barplot(self, csnp, tsnp, ax=None, gene_name=None, title=True):
        """ AEI barplot

        Arguments
        ---------
        csnp - cis snp to test association
        tsnp - tag snp to run the AEI test on
        ax - axis to plot on if None creates a new figure
        gene_name - replace the default ID ie replace with more
        readable gene symbol
        """
        color = dosage_round(self.geno.ix[csnp, self.hets_dict[tsnp]])
        nplots = 1
        if ax:
            pass
        else:
            fig, ax = plt.subplots(nrows=nplots, ncols=1,
                    figsize=(12, 4*nplots), sharey=False,
                    sharex=True, subplot_kw=dict(axisbg='#FFFFFF'))
        title_str = ('AEI at tag SNP {tag} for {gene}\n shaded by'
                'genotype at {csnp}')
        if gene_name:
            title_str = title_str.format(tag=tsnp,
                    gene=gene_name, csnp=csnp)
        else:
            title_str = title_str.format(tag=tsnp,
                    gene=self.gene_name, csnp=csnp)
        if title:
            ax.set_title(title_str)
        else:
            ax.set_title('')
        ax.set_xlabel('Samples')
        ax.set_ylabel('$log_{2}$ Allelic Fraction')
        width = 1
        allelic_ratio = self.ratios.ix[self.hets_dict[tsnp], tsnp]
        allelic_ratio_i = np.argsort(allelic_ratio.values)
        allelic_ratio = np.log2(allelic_ratio.iloc[allelic_ratio_i])
        outliers = np.logical_not(self.outliers.ix[self.hets_dict[tsnp], tsnp])
        color_geno = []
        color = color[allelic_ratio_i][outliers]
        for i in color:
            if i == 0 or i ==2:
                color_geno.append('green')
            else:
                color_geno.append('#FFAE00')
        allelic_ratio = allelic_ratio[outliers]
        ind = np.arange(len(allelic_ratio))
        rects1 = ax.bar(ind, allelic_ratio, width, color = color_geno,
                linewidth=1)
        ax.set_xlim((-1, len(allelic_ratio+1)))
        ax = remove_tr_spines(ax)
        if ax:
            return(ax)
        else:
            fig.tight_layout()
            return(fig)

    def aei_within_individual(self, ax=None):
        ''' A hidden Markov attempt at determining AEI within
        a transcript
        '''
        self.aei

    def barplot_across_genes(self, samples, other_samples,
            ax=None, bar_width = 0.35):
        if ax:
            pass
        else:
            fig, ax = plt.subplots(nrows=2 , ncols=1,
                    sharey=False, sharex=True,
                    subplot_kw=dict(axisbg='#FFFFFF'))
        np.zeros((2, self.ratios.shape[1]), dtype=np.float64)
        ar_samp = defaultdict(list)
        ar_osamp = defaultdict(list)
        for i in self.ratios.columns:
            ar_samp[i] = []
            ar_osamp[i] = []
        for i in samples:
            ar = []
            for j in self.ratios.columns:
                if i in self.hets_dict[j]:
                    c_ar = self.ratios.ix[i, j]
                    if c_ar <= 1:
                        c_ar = 1/c_ar
                    else: pass
                    if self.outliers.ix[i, j]:
                        pass
                    else:
                        ar_samp[j].append(c_ar)
                else: pass
        for i in other_samples:
            for j in self.ratios.columns:
                if i in self.hets_dict[j]:
                    c_ar = self.ratios.ix[i, j]
                    if c_ar <= 1:
                        c_ar = 1/c_ar
                    else: pass
                    if self.outliers.ix[i, j]:
                        pass
                    else:
                        ar_osamp[j].append(c_ar)
                else: pass
        smean = []
        sstd = []
        for snps, ratios in ar_samp.iteritems():
            mdat = np.ma.masked_array(ratios, np.isnan(ratios))
            smean.append(np.mean(mdat))
            sstd.append(np.std(mdat))
        osm = []
        sosm = []
        for snps, ratios in ar_osamp.iteritems():
            mdat = np.ma.masked_array(ratios,np.isnan(ratios))
            osm.append(np.mean(mdat))
            sosm.append(np.std(mdat))
        ind = np.arange(len(ar_samp.keys()))
        rects1 = ax.bar(ind, smean, bar_width, color='r', yerr=sstd)
        rects2 = ax.bar(ind + bar_width, osm, bar_width,  color='y', yerr=sosm)
        if ax:
            return(ax)
        else: return(fig)

    def plot_aei_within_individual(self, samples,
            other_samples=None, ax=None, exon_scale=1,
            intron_scale=20):
        if ax:
            pass
        else:
            fig, ax = plt.subplots(nrows=1 , ncols=1,
                    sharey=False, sharex=True,
                    subplot_kw=dict(axisbg='#FFFFFF'))
        counter = 0
        for i in samples:
            pos = []
            ar = []
            for j in self.ratios.columns:
                if i in self.hets_dict[j]:
                    c_ar = self.ratios.ix[i, j]
                    if c_ar <= 1:
                        c_ar = 1/c_ar
                    else: pass
                    if self.outliers.ix[i, j]:
                        pass
                    else:
                        pos.append(self.snp_annot.ix[j, 'pos'])
                        ar.append(c_ar)
                else: pass
            scatter = ax.plot(pos, ar, '-o')
            counter += 1
        if ax:
            return(ax)
        else: return(fig)

    def aei_plot_single(self, cissnp, ax=None, focus_snp=None):
        """
        Arguments
        ---------
        tsnp - a particular tag snp to plot association with """
        x_scale = 1e6
        cm = plt.cm.get_cmap('Blues')
        size_maf = ((200 * self.maf) + 20)
        pos = self.snp_annot.loc[:, 'pos']
        pos = np.asarray(pos, dtype=np.uint64)/x_scale
        if ax:
            pass
        else:
            fig, ax = plt.subplots(nrows=1 , ncols=1,
                    sharey=False, sharex=True,
                    subplot_kw=dict(axisbg='#FFFFFF'))
        adj_pvalue = -1*np.log10(self.pvalues.loc[:, cissnp])
        if focus_snp:
            print('focus snp')
            snp = focus_snp
        else:
            # :TODO fix for both use cases
            #snp = subset.iloc[np.nanargmax(adj_pv), 0]
            snp = self.pvalues.index[np.nanargmax(adj_pvalue)]
        print(snp)
        snp_iloc = [i for i, j in enumerate(adj_pvalue.index)\
                if j == snp][0]
        color1 = calculate_ld(self.geno,
            snp)[adj_pvalue.index].values
        scatter = ax.scatter(pos,
                        adj_pvalue, s=size_maf, c=color1)
        ax.set_ylabel(r'-$log_{10}$ AEI p-value')
        ylim = (max(adj_pvalue) + max(adj_pvalue/6.0))
        ax.set_ylim((-0.01, ylim))
        #ax = add_snp_arrow(adj_pvalue[snp_iloc], pos[snp_iloc], snp, ax)
        ax = snp_arrow(pos[snp_iloc], adj_pvalue[snp_iloc], snp, ax)
        if ax:
            return(ax)
        else:
            return(fig)

    def aei_plot(self, meQTL, snp_plot=None, n_sufficient_hets=50,
            common_only=False, mpld3plot=False,
            focus_snp=None, ax=None, **kwargs):
        """
        Arguments
        ---------
        snp_plot - :TODO what is this again?
        n_sufficient -
        common_only - Only common SNPs (>0.05)
        ax - matplotlib axis in which to add plot (for multiploting) NOT
        IMPLMENTED
        """
        x_scale = 1e6
        maf = self.maf.copy()
        maf[maf > 0.5] = 1 - maf[maf > 0.5]
        size_maf = ((200 * maf) + 20)
        cm = plt.cm.get_cmap('Blues')
        '''
        color1 = calculate_ld(self.geno,
            focus_snp)[self.geno.index].values
        '''
        if type(snp_plot) == pd.Series or type(snp_plot) == list:
            suff_hets = pd.Series(snp_plot, index = pd.Index(snp_plot))
        else:
            suff_hets = self.sufficient_hets[
                        np.logical_and(self.sufficient_hets >= n_sufficient_hets,
                        self.overall_counts.sum(axis=1)>=500)]
        nplots = len(suff_hets) + 2
        pos = self.snp_annot.loc[:, 'pos']
        pos = np.asarray(pos, dtype=np.uint64)/x_scale
        if ax:
            pass
        else:
            if len(suff_hets) > 1:
                ncols = 2
            else:
                ncols = 1
            fig, ax = plt.subplots(nrows=int(ceil(nplots/ncols)) , ncols=2,
                    figsize=(20, 4*nplots/2),
                    sharey=False, sharex=True,
                    subplot_kw=dict(axisbg='#FFFFFF'))
        ko = 0
        for j in range(ncols):
            io = 0
            for i in range(int(ceil(len(suff_hets)/2.0))):
                if ko < len(suff_hets):
                    curr = suff_hets.index[ko]
                    adj_pvalue = -1*np.log10(self.pvalues.loc[:, curr])
                    scatter = ax[io, j].scatter(pos,
                                    adj_pvalue, s=30)
                    ax[io, j].set_ylabel(r'-$log_{10}$ AEI p-value')
                    ylim = (max(adj_pvalue) + max(adj_pvalue/6.0))
                    ax[io, j].set_ylim((-0.01, ylim))
                    # Need to make the text relative positioning
                    #labels = list(self.annot_table.index)
                    #tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
                    ko += 1
                    io += 1
                else:
                    pass
            scatter = ax[-1, j].scatter(pos,
                    -1*np.log10(meQTL.ix[self.snp_annot.index , 'p-value']),
                                     s=size_maf, cmap=cm)
            ax[-1, j].set_ylabel('-$log_{10}$ p-value')
            ax[-1, j].set_xlabel('Genomic Position (mb)')
            ax[-1, j] = plot_eQTL(meQTL, gene_name = self.gene_name,
                  annotation=self.snp_annot, dosage=self.geno, ax = ax[-1,j],
                  **kwargs)
            ax[-1, j] = remove_tr_spines(ax[-1, j])
            #ax[-1, j].set_title('%s eQTL plot' % (self.gene_name,), fontsize=25)
            '''
            labels = list(self.snp_table.index)
            tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=labels)
            mpld3.plugins.connect(fig, tooltip,  plugins.LinkedBrush(scatter))
            '''
        fig.tight_layout()
        return(fig)


text:
The goal of image captioning is to convert a given input image into a natural language description. The encoder-decoder framework is widely used for this task. The image encoder is a convolutional neural network (CNN). In this tutorial, we used [resnet-152](https://arxiv.org/abs/1512.03385) model pretrained on the [ILSVRC-2012-CLS](http://www.image-net.org/challenges/LSVRC/2012/) image classification dataset. The decoder is a long short-term memory (LSTM) network.

![alt text](png/model.png)

#### Training phase
For the encoder part, the pretrained CNN extracts the feature vector from a given input image. The feature vector is linearly transformed to have the same dimension as the input dimension of the LSTM network. For the decoder part, source and target texts are predefined. For example, if the image description is **"Giraffes standing next to each other"**, the source sequence is a list containing **['\<start\>', 'Giraffes', 'standing', 'next', 'to', 'each', 'other']** and the target sequence is a list containing **['Giraffes', 'standing', 'next', 'to', 'each', 'other', '\<end\>']**. Using these source and target sequences and the feature vector, the LSTM decoder is trained as a language model conditioned on the feature vector.

#### Test phase
In the test phase, the encoder part is almost same as the training phase. The only difference is that batchnorm layer uses moving average and variance instead of mini-batch statistics. This can be easily implemented using [encoder.eval()](https://github.com/yunjey/pytorch-tutorial/blob/master/tutorials/03-advanced/image_captioning/sample.py#L37). For the decoder part, there is a significant difference between the training phase and the test phase. In the test phase, the LSTM decoder can't see the image description. To deal with this problem, the LSTM decoder feeds back the previosly generated word to the next input. This can be implemented using a [for-loop](https://github.com/yunjey/pytorch-tutorial/blob/master/tutorials/03-advanced/image_captioning/model.py#L48).

## Usage

#### 1. Clone the repositories
```bash
$ git clone https://github.com/pdollar/coco.git
$ cd coco/PythonAPI/
$ make
$ python setup.py build
$ python setup.py install
$ cd ../../
$ git clone https://github.com/yunjey/pytorch-tutorial.git
$ cd pytorch-tutorial/tutorials/03-advanced/image_captioning/
```

#### 2. Download the dataset

```bash
$ pip install -r requirements.txt
$ chmod +x download.sh
$ ./download.sh
```

#### 3. Preprocessing

```bash
$ python build_vocab.py
$ python resize.py
```

#### 4. Train the model

```bash
$ python train.py
```

#### 5. Test the model

```bash
$ python sample.py --image='png/example.png'
```

<br>

## Pretrained model
If you do not want to train the model from scratch, you can use a pretrained model. You can download the pretrained model [here](https://www.dropbox.com/s/ne0ixz5d58ccbbz/pretrained_model.zip?dl=0) and the vocabulary file [here](https://www.dropbox.com/s/26adb7y9m98uisa/vocap.zip?dl=0). You should extract pretrained_model.zip to `./models/` and vocab.pkl to `./data/` using `unzip` command.

redpajama_set_name: RedPajamaGithub


text:
#include <string.h>

#include "extmod/vfs.h"
#include "lib/oofatfs/ff.h"
#include "lib/oofatfs/diskio.h"
#include "py/mpstate.h"
#include "py/obj.h"
#include "py/objstr.h"
#include "py/runtime.h"
#include "shared-bindings/os/__init__.h"
#include "supervisor/shared/translate/translate.h"

//| """functions that an OS normally provides
//|
//| |see_cpython_module| :mod:`cpython:os`.
//| """
//|
//| import typing
//|

//| def uname() -> _Uname:
//|     """Returns a named tuple of operating specific and CircuitPython port
//|     specific information."""
//|     ...
//|
//| class _Uname(typing.NamedTuple):
//|     """The type of values that :py:func:`.uname()` returns"""
//|
//|     sysname: str
//|     nodename: str
//|     release: str
//|     version: str
//|     machine: str
//|
STATIC mp_obj_t os_uname(void) {
    return common_hal_os_uname();
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);

//| def chdir(path: str) -> None:
//|     """Change current directory."""
//|     ...
//|
STATIC mp_obj_t os_chdir(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    common_hal_os_chdir(path);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir);

//| def getcwd() -> str:
//|     """Get the current directory."""
//|     ...
//|
STATIC mp_obj_t os_getcwd(void) {
    return common_hal_os_getcwd();
}
MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);

//| def getenv(key: str, default: Optional[str] = None) -> Optional[str]:
//|     """Get the environment variable value for the given key or return ``default``.
//|
//|     This may load values from disk so cache the result instead of calling this often."""
//|     ...
//|
STATIC mp_obj_t os_getenv(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
    enum { ARG_key, ARG_default };
    static const mp_arg_t allowed_args[] = {
        { MP_QSTR_key, MP_ARG_REQUIRED | MP_ARG_OBJ },
        { MP_QSTR_default,  MP_ARG_OBJ, {.u_obj = mp_const_none} },
    };
    mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
    mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

    return common_hal_os_getenv(mp_obj_str_get_str(args[ARG_key].u_obj), args[ARG_default].u_obj);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(os_getenv_obj, 1, os_getenv);

//| def listdir(dir: str) -> str:
//|     """With no argument, list the current directory.  Otherwise list the given directory."""
//|     ...
//|
STATIC mp_obj_t os_listdir(size_t n_args, const mp_obj_t *args) {
    const char *path;
    if (n_args == 1) {
        path = mp_obj_str_get_str(args[0]);
    } else {
        path = mp_obj_str_get_str(common_hal_os_getcwd());
    }
    return common_hal_os_listdir(path);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir);

//| def mkdir(path: str) -> None:
//|     """Create a new directory."""
//|     ...
//|
STATIC mp_obj_t os_mkdir(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    common_hal_os_mkdir(path);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir);

//| def remove(path: str) -> None:
//|     """Remove a file."""
//|     ...
//|
STATIC mp_obj_t os_remove(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    common_hal_os_remove(path);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove);

//| def rmdir(path: str) -> None:
//|     """Remove a directory."""
//|     ...
//|
STATIC mp_obj_t os_rename(mp_obj_t old_path_in, mp_obj_t new_path_in) {
    const char *old_path = mp_obj_str_get_str(old_path_in);
    const char *new_path = mp_obj_str_get_str(new_path_in);
    common_hal_os_rename(old_path, new_path);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename);

//| def rename(old_path: str, new_path: str) -> str:
//|     """Rename a file."""
//|     ...
//|
STATIC mp_obj_t os_rmdir(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    common_hal_os_rmdir(path);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(os_rmdir_obj, os_rmdir);

//| def stat(path: str) -> Tuple[int, int, int, int, int, int, int, int, int, int]:
//|     """Get the status of a file or directory.
//|
//|        Returns a tuple with the status of a file or directory in the following order:
//|
//|
//|        * ``st_mode`` -- File type, regular or directory
//|        * ``st_ino``  -- Set to 0
//|        * ``st_dev`` -- Set to 0
//|        * ``st_nlink`` -- Set to 0
//|        * ``st_uid`` -- Set to 0
//|        * ``st_gid`` -- Set to 0
//|        * ``st_size`` -- Size of the file in bytes
//|        * ``st_atime`` -- Time of most recent access expressed in seconds
//|        * ``st_mtime`` -- Time of most recent content modification expressed in seconds.
//|        * ``st_ctime`` -- Time of most recent content modification expressed in seconds.
//|
//|     .. note:: On builds without long integers, the number of seconds
//|        for contemporary dates will not fit in a small integer.
//|        So the time fields return 946684800,
//|        which is the number of seconds corresponding to 1999-12-31."""
//|     ...
//|
STATIC mp_obj_t os_stat(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    return common_hal_os_stat(path);
}
MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat);

//| def statvfs(path: str) -> Tuple[int, int, int, int, int, int, int, int, int, int]:
//|     """Get the status of a filesystem.
//|
//|     Returns a tuple with the filesystem information in the following order:
//|
//|          * ``f_bsize`` -- file system block size
//|          * ``f_frsize`` -- fragment size
//|          * ``f_blocks`` -- size of fs in f_frsize units
//|          * ``f_bfree`` -- number of free blocks
//|          * ``f_bavail`` -- number of free blocks for unprivileged users
//|          * ``f_files`` -- number of inodes
//|          * ``f_ffree`` -- number of free inodes
//|          * ``f_favail`` -- number of free inodes for unprivileged users
//|          * ``f_flag`` -- mount flags
//|          * ``f_namemax`` -- maximum filename length
//|
//|     Parameters related to inodes: ``f_files``, ``f_ffree``, ``f_avail``
//|     and the ``f_flags`` parameter may return ``0`` as they can be unavailable
//|     in a port-specific implementation."""
//|     ...
//|
STATIC mp_obj_t os_statvfs(mp_obj_t path_in) {
    const char *path = mp_obj_str_get_str(path_in);
    return common_hal_os_statvfs(path);
}
MP_DEFINE_CONST_FUN_OBJ_1(os_statvfs_obj, os_statvfs);

//| def sync() -> None:
//|     """Sync all filesystems."""
//|     ...
//|
STATIC mp_obj_t os_sync(void) {
    for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) {
        // this assumes that vfs->obj is fs_user_mount_t with block device functions
        disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL);
    }
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(os_sync_obj, os_sync);

//| def urandom(size: int) -> str:
//|     """Returns a string of *size* random bytes based on a hardware True Random
//|     Number Generator. When not available, it will raise a NotImplementedError.
//|
//|     **Limitations:** Not yet available on nRF. Not available on SAMD21 due to lack of hardware.
//|     """
//|     ...
//|
STATIC mp_obj_t os_urandom(mp_obj_t size_in) {
    mp_int_t size = mp_obj_get_int(size_in);
    mp_obj_str_t *result = MP_OBJ_TO_PTR(mp_obj_new_bytes_of_zeros(size));
    if (!common_hal_os_urandom((uint8_t *)result->data, size)) {
        mp_raise_NotImplementedError(translate("No hardware random available"));
    }
    return result;
}
MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);

//| def utime(path: str, times: Tuple[int, int]) -> None:
//|     """Change the timestamp of a file."""
//|     ...
//|
STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t times_in) {
    const char *path = mp_obj_str_get_str(path_in);
    common_hal_os_utime(path, times_in);
    return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(os_utime_obj, os_utime);

STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
    { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },

    { MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },

    { MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&os_chdir_obj) },
    { MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&os_getcwd_obj) },
    { MP_ROM_QSTR(MP_QSTR_getenv), MP_ROM_PTR(&os_getenv_obj) },
    { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) },
    { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) },
    { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) },
    { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) },
    { MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&os_rmdir_obj) },
    { MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_stat_obj) },
    { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&os_statvfs_obj) },
    { MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&os_remove_obj) }, // unlink aliases to remove
    { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&os_utime_obj) },

    { MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&os_sync_obj) },

    { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },

//| sep: str
//| """Separator used to delineate path components such as folder and file names."""
    { MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) },
};

STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);

const mp_obj_module_t os_module = {
    .base = { &mp_type_module },
    .globals = (mp_obj_dict_t *)&os_module_globals,
};

MP_REGISTER_MODULE(MP_QSTR_os, os_module, CIRCUITPY_OS);


text:
<?php

namespace Ems\Core;

use Ems\Contracts\Core\TextFormatter as FormatterContract;
use Ems\Contracts\Core\NamedCallableChain as ChainContract;
use Ems\Testing\LoggingCallable;

class TextFormatterTest extends \Ems\TestCase
{
    public function test_implements_interface()
    {
        $this->assertInstanceOf(FormatterContract::class, $this->newFormatter());
        $this->assertInstanceOf(ChainContract::class, $this->newFormatter());
    }

    public function test_call_extension()
    {
        $formatter = $this->newFormatter();

        $input = 'foo';
        $result = 'bar';

        $extension = new LoggingCallable(function ($text) use ($result) { return $result; });

        $formatter->extend('foo', $extension);

        $this->assertEquals($result, $formatter->foo($input));
        $this->assertEquals($input, $extension->arg(0));
    }

    public function test_call_method()
    {
        $formatter = $this->newFormatter();

        $input = '
Immer Ärger mit Umlauten
Übel
';
        $result = "Immer Ärger mit Umlauten\nÜbel";

        $this->assertEquals($result, $formatter->__call('plain', [$input]));
    }

    public function test_standard_function()
    {
        $formatter = $this->newFormatter();

        $input = ' whitespace ';
        $result = 'whitespace';

        $this->assertEquals($result, $formatter->__call('trim', [$input]));
    }

    /**
     * @expectedException \Ems\Core\Exceptions\HandlerNotFoundException
     **/
    public function test_call_throws_HandlerNotFoundException_if_filter_unknown()
    {
        $formatter = $this->newFormatter();

        $input = ' whitespace ';
        $result = 'whitespace';

        $this->assertEquals($result, $formatter->__call('trimi', [$input]));
    }

    public function test_chain_of_filters_with_parameters()
    {
        $formatter = $this->newFormatter();

        $input = ' whitespace ';
        $filterInput = 'whitespace';
        $filterOutput = 'result';
        $filterParams = 'a,0,22,x';
        $result = "$filterOutput";

        $extension = new LoggingCallable(function ($text) use ($filterOutput) { return $filterOutput; });
        $formatter->extend('foo', $extension);

        $this->assertEquals($result, $formatter->format($input, "trim|foo:$filterParams|tag:em"));

        $this->assertEquals('whitespace', $extension->arg(0));
        $this->assertEquals('a', $extension->arg(1));
        $this->assertEquals('0', $extension->arg(2));
        $this->assertEquals('22', $extension->arg(3));
        $this->assertEquals('x', $extension->arg(4));
    }

    protected function newFormatter()
    {
        return new TextFormatter();
    }
}


text:
package txml.interpreter.command;

import txml.interpreter.model.SymbolTableItem;
import txml.interpreter.model.SymbolTableType;
import txml.TXmlException;
import txml.interpreter.InstructionsInterpreter;
import txml.xpath.model.NodeGlobalSettings;
import txml.xpath.model.TNodeList;

public class CommandNewList implements Command {

    @Override
    public void execute(InstructionsInterpreter interpreter, String operand1, String operand2, String operand3, String result) {
        if (interpreter.getConnection() == null) {
            throw new TXmlException("No database connection");
        }
        NodeGlobalSettings settings = new NodeGlobalSettings(interpreter.getConnection(), operand2, operand3, interpreter.getSqlStatements(), interpreter.isSort());
        TNodeList tNodeList = new TNodeList(settings);
        interpreter.getSymbolTable().getTable().put(result, new SymbolTableItem(SymbolTableType.TNODE_LIST, tNodeList));
        interpreter.setLastSettings(settings);
    }

}


text:
<!DOCTYPE html>
<html>
 <!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
 <!--
-->
 <head>
  <title>
   Closure Integration Tests - Old goog.db API
  </title>
  <script src="../base.js">
  </script>
  <script>
    goog.require('goog.oldDbTest');
  </script>
 </head>
 <body>
 </body>
</html>


text:
<?php

namespace ZF\Rpc;

use Zend\Mvc\Controller\AbstractActionController as BaseAbstractActionController;
use Zend\Mvc\MvcEvent;
use Zend\View\Model;

class RpcController extends BaseAbstractActionController
{

    protected $wrappedCallable;

    public function setWrappedCallable($wrappedCallable)
    {
        $this->wrappedCallable = $wrappedCallable;
    }

    public function onDispatch(MvcEvent $e)
    {
        $routeMatch = $e->getRouteMatch();

        $contentNegotiationParams = $e->getParam('ZFContentNegotiationParameterData');
        if ($contentNegotiationParams) {
            $routeParameters = $contentNegotiationParams->getRouteParams();
        } else {
            $routeParameters = $routeMatch->getParams();
        }

        $parameterMatcher = new ParameterMatcher($e);

        // match route params to dispatchable parameters
        if ($this->wrappedCallable instanceof \Closure) {
            $callable = $this->wrappedCallable;
        } elseif (is_array($this->wrappedCallable) && is_callable($this->wrappedCallable)) {
            $callable = $this->wrappedCallable;
        } elseif (is_object($this->wrappedCallable) || is_null($this->wrappedCallable)) {
            $action = $routeMatch->getParam('action', 'not-found');
            $method = static::getMethodFromAction($action);
            $callable = (is_null($this->wrappedCallable) && get_class($this) != __CLASS__) ? $this : $this->wrappedCallable;
            if (!method_exists($callable, $method)) {
                $method = 'notFoundAction';
            }
            $callable = array($callable, $method);
        } else {
            throw new \Exception('RPC Controller Not Understood');
        }

        $dispatchParameters = $parameterMatcher->getMatchedParameters($callable, $routeParameters);
        $result = call_user_func_array($callable, $dispatchParameters);

        $e->setParam('ZFContentNegotiationFallback', array('Zend\View\Model\JsonModel' => array('application/json')));
        $e->setResult($result);
    }

    /**
     * Transform an "action" token into a method name
     *
     * @param  string $action
     * @return string
     */
    public static function getMethodFromAction($action)
    {
        $method  = str_replace(array('.', '-', '_'), ' ', $action);
        $method  = ucwords($method);
        $method  = str_replace(' ', '', $method);
        $method  = lcfirst($method);

        return $method;
    }
}


text:
const gulp       = require('gulp');
const plumber    = require('gulp-plumber');
const concat     = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const path       = require('path');
const rename     = require('gulp-rename');

// Vendors
const uglify = require('gulp-uglify');
const ngAnnotate = require('gulp-ng-annotate');
const ngTpCache = require('gulp-angular-templatecache');
const PATH_VENDORS = [
    'public/js/vendors/angular.min.js',
    'public/js/vendors/*.js',
    '!public/js/vendors/*.map',
];
gulp.task('vendors', () => {
    return (
        gulp.src(PATH_VENDORS)
        .pipe(plumber())
        .pipe(sourcemaps.init())
            .pipe(uglify())
            .pipe(concat('vendors.js'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('public/dist'))
    );
});

// App:ng
const PATH_APP_NG = [
    'public/js/entry.js',
    'public/js/components/**/*.js',
    'public/js/utils/**/*.js',
];
gulp.task('app:ng', () => {
    return (
        gulp
        .src(PATH_APP_NG)
        .pipe(plumber())
        .pipe(ngAnnotate())
        .pipe(sourcemaps.init())
            .pipe(uglify())
            .pipe(concat('app.js'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('public/dist'))
    );
});

// App:templates
const PATH_APP_TEMPLATES = 'public/js/components/**/*.html';
gulp.task('app:templates', () => {
    return (
        gulp
        .src(PATH_APP_TEMPLATES)
        .pipe(ngTpCache({
            root      : 'components',
            module    : 'OldNews.templates',
            standalone: true,
        }))
        .pipe(gulp.dest('public/js/components'))
    );
});

// App:styles
const postcss = require('gulp-postcss');
const PATH_APP_STYLES_WATCH = 'public/css/**/*.css';
const PATH_APP_STYLES_ENTRY = 'public/css/app.css';
gulp.task('app:styles', () => {
    const processors = [
        require('postcss-import')({
            path: ['public/css'],
        }),
        require('postcss-nested'),
        require('postcss-short'),
        require('postcss-assets')({
            loadPaths: ['public/img/assets'],
        }),
        require('postcss-cssnext')({
            autoprefixer: true,
        }),
        require('css-mqpacker'),
        require('cssnano'),
    ];

    return (
        gulp.src(PATH_APP_STYLES_ENTRY)
        .pipe(plumber())
        .pipe(postcss(processors))
        .pipe(concat('app.css'))
        .pipe(gulp.dest('public/dist'))
    );
});

// App:svg
const svgmin   = require('gulp-svgmin');
const svgstore = require('gulp-svgstore');
const PATH_APP_SVG = 'public/img/src/*.svg';
gulp.task('app:svg', () => {
    return (
        gulp.src(PATH_APP_SVG)
        .pipe(svgmin(file => {
            const prefix = path.basename(file.relative, path.extname(file.relative));
            return {
                plugins: [{
                    cleanupIDs: {
                        prefix: `${prefix}-`,
                        minify: true,
                    },
                }],
            };
        }))
        .pipe(svgstore())
        .pipe(rename('icon-sprites.svg'))
        .pipe(gulp.dest('public/img'))
    );
});

/**
 * Task
 *
 */
// Watch
gulp.task('watch', () => {
    gulp.watch(PATH_VENDORS, ['vendors']);
    gulp.watch(PATH_APP_NG, ['app:ng']);
    gulp.watch(PATH_APP_TEMPLATES, ['app:templates']);
    gulp.watch(PATH_APP_STYLES_WATCH, ['app:styles']);
    gulp.watch(PATH_APP_SVG, ['app:svg']);
});
// Run
gulp.task('default', [
    'watch',
    'vendors',
    'app:ng',
    'app:templates',
    'app:styles',
    'app:svg',
]);


text:
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>W29935_text</title>
        <link rel="stylesheet" type="text/css" href="style.css" />

                «

    <p class="styleSans6.0000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">10/20/2014

    <p class="styleSans8.0000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">GEOLGGIC PRQGNOSIS Wells on Pad: 5 Well Name: Holstein Federal 4—25H Rig: Cyclone 14 Prospect: Antelope Target: Middle Bakken Spacing: 2560

SH_: 2100' FNL Sec. 25 McKenzie EEHL: 50' FNL Sec. 13
McKenzie

    <p class="styleSans4.0000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">

    <p class="styleSans7.0000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">2360' FEL
153N — 94W ND
1980' FWL 153N — 94W
ND

    <p class="styleSans12000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">

    <p class="styleSans6.0000<enum PANGO_WEIGHT_NORMAL of type PangoWeight><enum PANGO_STYLE_NORMAL of type PangoStyle>">Holstein Federal 4-25H AFE v1


text:
package com.company;

import com.company.driver.Tickable;

import java.util.ArrayList;

public interface TrainInterface extends Tickable {

    /**
     *
     * @return arraylist of passengers on the train
     */
    public ArrayList<Passenger> getPassengers();

    /**
     *
     * @return capacity of the train
     */
    public int getCapacity();

    /**
     * sets the capacity of the train
     * @param capacity
     */
    public void setCapacity(int capacity);

    /**
     * removes passengers from the train on the train
     */
    public void removePassengers();

    /**
     * picks up passengers at the station from the queue
     */
    public void pickupPassengers();

    /**
     *
     * @return true if capacity of train is reached
     */
    public boolean isFull();
}


text:
package ca.pfv.spmf.algorithms.sequentialpatterns.fournier2008_seqdim.multidimensionalsequentialpatterns;

import java.util.ArrayList;
import java.util.List;

import ca.pfv.spmf.algorithms.sequentialpatterns.fournier2008_seqdim.AlgoFournierViger08;

/**
 * A set of MDSequences organized by levels representing their size.
 * Returned by the AlgoSeqDim algorithm.

 * Level 0 = MDSequences of size 0

 * Level 1 = MDSequences of size 1

 *  ...

 * Level n = MDSequences of size n

 * @see AlgoFournierViger08
* @author Philippe Fournier-Viger
 */
public class MDSequences {

	// A list of list containing the MDSequences by size
	// For example, the position i is the list of MDSequences of
	// size i.
	private final List<List<MDSequence>> levels = new ArrayList<List<MDSequence>>();  // itemset sorted by size
	// the number of patterns stored in this structure
	private int sequencesCount=0;

	// a name given to the patterns
	private final String name;

	/**
	 * Constructor.
	 * @param name a name for the patterns that will be contained in this
	 *    structure (String).
	 */
	public MDSequences(String name){
		this.name = name;
		levels.add(new ArrayList<MDSequence>()); // the level 0  is empty by default.
	}

	/**
	 * Print the patterns contained in this structure to System.out.
	 * @param sequenceCount the number of MDSequences in the MDSequences database.
	 */

	public void printPatterns(int sequenceCount){
		// create a string buffer
		System.out.println(" ------- " + name + " -------");
		int levelCount=0;
		// for each level
		for(List<MDSequence> level : levels){
			System.out.println("  L" + levelCount + " ");
			// for each MDSequence
			for(MDSequence sequence : level){
				// print the MDSequence
				System.out.print("  pattern " + sequence.getId() + ":  ");
				sequence.print();
				// print its support
				System.out.print("support :  " + sequence.getFormattedRelativeSupport(sequenceCount));
				System.out.print(" (" + sequence.getAbsoluteSupport() + "/" + sequenceCount + ") ");
				System.out.println("");
			}
			levelCount++;  // go to next level
		}
		System.out.println(" --------------------------------");
	}

	/**
	 * Get a String representation of this set of MDSequences.
	 * @param sequenceCount the number of MDSequences in the MDSequences database.
	 * @return a string
	 */
	public String toString(int sequenceCount){
		// create a string buffer
		StringBuffer out = new StringBuffer(" ------- " + name + " -------");
		int levelCount=0;
		// for each level
		for(List<MDSequence> level : levels){
			out.append("  L" + levelCount + "\n");
			// for each MDSequence
			for(MDSequence sequence : level){
				// print the MDSequence
				out.append("  pattern " + sequence.getId() + ":  \n");
				out.append(sequence.toString());
				// print its support
				out.append("support :  " + sequence.getFormattedRelativeSupport(sequenceCount));
				out.append(" (" + sequence.getAbsoluteSupport() + "/" + sequenceCount + ") \n");
			}
			levelCount++;  // go to next level
		}
		out.append(" --------------------------------");
		return out.toString();
	}

	/**
	 * Add a MD-sequence to this structure
	 * @param sequence the MDSequence
	 * @param k  the size of the MDSequence
	 */
	public void addSequence(MDSequence sequence, int k){
		// for each level in this structure
		while(levels.size() <= k){
			// if there is no list for this level, then create one
			levels.add(new ArrayList<MDSequence>());
		}
		// add the pattern to this level
		levels.get(k).add(sequence);
		// increase the number of patterns found.
		sequencesCount++;
	}

	/**
	 * Get MDSequences of size k.
	 * @param k the size
	 * @return a list of MDSequence objects
	 */
	public List<MDSequence> getLevel(int k){
		return levels.get(k);
	}

	/**
	 * Get the number of MDSequences stored in this structure.
	 * @return an integer
	 */
	public int size() {
		return sequencesCount;
	}

	/**
	 * Get the size of the largest MD-Sequence stored in this structure.
	 * @return an int value.
	 */
	public List<List<MDSequence>> getLevels() {
		return levels;
	}

	/**
	 * Recalculate the number of MDSequences stored in this structure.
	 */
	public void recalculateSize() {
		// reset the count
		sequencesCount =0;
		// do a for loop over each level
		for(List<MDSequence> level : levels){
			// add the number of pattern for this level to the sum
			sequencesCount += level.size();
		}
	}
}


text:
<?php

namespace ConsoleApplication\DependencyInjection\Loader;

use ConsoleApplication\Bag\BagInterface;
use ConsoleApplication\Exception\ConfigurationException;
use ConsoleApplication\Exception\FileNotFoundException;

interface FileLoaderInterface
{
    /*------------------------------------------------------------------------*\
    | Public methods                                                           |
    \*------------------------------------------------------------------------*/

    /**
     * Loads a file configuration to a bag
     *
     * @param string       $filename
     * @param string       $root
     * @param BagInterface $bag
     * @param boolean      $recursive
     * @param boolean      $suppressException
     *
     * @return BagInterface
     *
     * @throws ConfigurationException
     * @throws FileNotFoundException
     */
    public function loadFileToBag($filename, $root, BagInterface $bag, $recursive = false, $suppressException = false);

    /**
     * Resolves parameters in a bag using another bag of parameters
     *
     * @param BagInterface $bag
     * @param BagInterface $parameters
     *
     * @return BagInterface
     *
     * @throws ConfigurationException
     */
    public function resolveParameters(BagInterface $bag, BagInterface $parameters);
}


text:
namespace server {
namespace state {
    class game : public base {
        scoped_connection_pool pool_;

        std::thread thread_;
        std::atomic<bool> saving_;

        ctl::ptr_vector<server::serializable> save_chunks_;

        std::unique_ptr<server::player_list> plist_;

        server::universe universe_;

    public :
        explicit game(server::instance& serv);

        void register_callbacks() override;

        void set_player_list(std::unique_ptr<server::player_list> plist);

        void save_to_directory(const std::string& dir);
        void load_from_directory(const std::string& dir);
        bool is_saved_game_directory(const std::string& dir) const;
    };
}
}

namespace request {
namespace server {
    NETCOM_PACKET(game_save) {
        NETCOM_REQUIRES("game_configurer");

        std::string save;

        struct answer {};
        struct failure {
            enum class reason {
                already_saving
            } rsn;

            std::string details;
        };
    };

    NETCOM_PACKET(game_load) {
        NETCOM_REQUIRES("game_configurer");

        std::string save;

        struct answer {};
        struct failure {
            enum class reason {
                cannot_load_while_saving,
                no_such_saved_game,
                invalid_saved_game
            } rsn;

            std::string details;
        };
    };
}
}

namespace message {
namespace server {
    NETCOM_PACKET(game_save_progress) {
        enum class step {
            gathering_game_data,
            saving_to_disk,
            game_saved
        } stp;
    };

    NETCOM_PACKET(game_load_progress) {
        std::uint16_t num_steps;
        std::uint16_t current_step;
        std::string   current_step_name;
    };
}
}

#ifndef NO_AUTOGEN
#include "autogen/packets/server_state_game.hpp"
#endif

#endif