# Path: lxmls/data.py
# def find(filename):


import codecs
import gzip
import numpy as np  # This is also needed for theano=True
from itertools import chain
from random import shuffle
from lxmls.sequences.label_dictionary import *
from lxmls.sequences.sequence import *
from lxmls.sequences.sequence_list import *
from lxmls import data
from os.path import dirname

    def sample(self, set_name, batch_size=None):
        dset = self.datasets[set_name]
        nr_examples = self.nr_samples[set_name]
        if batch_size is None:
            nr_batch = 1
            batch_size = nr_examples
        else:
            nr_batch = int(np.ceil(nr_examples*1./batch_size))
        data = []
        for batch_n in range(nr_batch):
            #Colect data for this batch
            data_batch = {}
            sample = np.random.randint(0, nr_examples, batch_size)
            for side in ['input', 'output']:
                data_batch[side] = np.asarray(dset[side])[sample]
            data.append(data_batch)
        return DataIterator(data, nr_samples=self.nr_samples[set_name])


class DataIterator(object):
    """
    Basic data iterator
    """

    def __init__(self, data, nr_samples):
        self.data = data
        self.nr_samples = nr_samples

    def __len__(self):

# Path: lxmls/data.py
# def find(filename):


# Path: lxmls/readers/pos_corpus.py
import codecs
import gzip
import numpy as np  # This is also needed for theano=True
from itertools import chain
from random import shuffle
from lxmls.sequences.label_dictionary import *
from lxmls.sequences.sequence import *
from lxmls.sequences.sequence_list import *
from lxmls import data
from os.path import dirname


    def sample(self, set_name, batch_size=None):
        dset = self.datasets[set_name]
        nr_examples = self.nr_samples[set_name]
        if batch_size is None:
            nr_batch = 1
            batch_size = nr_examples
        else:
            nr_batch = int(np.ceil(nr_examples*1./batch_size))
        data = []
        for batch_n in range(nr_batch):
            #Colect data for this batch
            data_batch = {}
            sample = np.random.randint(0, nr_examples, batch_size)
            for side in ['input', 'output']:
                data_batch[side] = np.asarray(dset[side])[sample]
            data.append(data_batch)
        return DataIterator(data, nr_samples=self.nr_samples[set_name])


class DataIterator(object):
    """
    Basic data iterator
    """

    def __init__(self, data, nr_samples):
        self.data = data
        self.nr_samples = nr_samples

    def __len__(self):

        return len(self.data)