コード例 #1
0
    def __init__(self, **kwargs):
        self.kwargs = {k:v for k,v in kwargs.items()}
        self.method = self.kwargs.get('method', 'nb')
        self.db_name = self.kwargs.get('db_name', 'tweets')
        self.coll_name = self.kwargs.get('coll_name')
        self.tweet_files_path = self.kwargs.get('tweet_files_path')
        self.root_path = self.kwargs.get('root_path')
        self.tweets = None
        self.s = Stream(db_name=self.db_name, coll_name=self.coll_name)  # use some of Stream methods
        self.stopwords = nltk.corpus.stopwords.words('english')
        self.combined_array = None
        self.words = []

        if self.kwargs.get('train'):
            self.pprocess_induction()
            self.naive_bayes()

        if not self.kwargs.get('train') and not self.kwargs.get('vader', False):
            self.pprocess_induction()
            self.get_tweets()
            # array = t.pprocess_predict(string='cpt marvel was a really good movie')
            array = self.pprocess_predict()
            self.naive_bayes(array)
            self.write_json(f_name=os.path.join(self.kwargs.get('root_path'), 'output', 'nb_results.json'))

        if self.kwargs.get('vader'):
            self.get_tweets()
コード例 #2
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def diff(x):
    """Differentiate `x`.

    :returns: Differentiated `x`.
    :rtype: :class:`Stream`

    .. seealso:: :func:`streaming._iterator.diff`
    .. note:: Typically when differentiating one needs to multiple as well with the sample frequency
    """
    return Stream(streaming._iterator.diff(x.samples()._iterator))
コード例 #3
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def constant(value, nblock=None):
    """Stream with constant value.

    :rtype: :class:`Stream` or :class:`BlockStream` if `nblock` is not `None`.
    """

    if nblock is not None:
        return BlockStream([np.ones(nblock) * value], nblock).cycle()
    else:
        return Stream([value]).cycle()
コード例 #4
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def filter_sos(x, sos):
    """Apply IIR filter to `x`.

    :param x: Signal.
    :param sos: Second-order sections.
    :returns: Filtered signal.

    .. seealso:: :func:`scipy.signal.sosfilt`

    """
    return Stream(streaming._iterator.filter_sos(x.samples()._iterator, sos))
コード例 #5
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def filter_ba(x, b, a):
    """Apply IIR filter to `x`.

    :param x: Signal.
    :param b: Numerator coefficients.
    :param a: Denominator coefficients.
    :returns: Filtered signal.

    .. seealso:: :func:`scipy.signal.lfilter`
    """
    return Stream(streaming._iterator.filter_ba(x.samples()._iterator, b, a))
コード例 #6
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def noise(nblock=None, state=None, color='white', ntaps=None):
    """Generate white noise with standard Gaussian distribution.

    :param nblock: Amount of samples per block.
    :param state: State of PRNG.
    :type state: :class:`np.random.RandomState`
    :returns: When `nblock=None`, individual samples are generated and a :class:`streaming.Stream` is
    returned. When integer, a :class:`streaming.BlockStream` is returned.
    """
    if state is None:
        state = np.random.RandomState()

    # Generate white noise
    if nblock is None:
        # Generate individual samples.
        stream = Stream((state.randn(1)[0] for i in itertools.count()))
    else:
        # Generate blocks.
        stream = BlockStream((state.randn(nblock) for i in itertools.count()),
                             nblock=nblock,
                             noverlap=0)

    # Apply filter for specific color
    if color is not 'white':
        if ntaps is None:
            raise ValueError("Amount of taps has not been specified.")
        ir = noisy.COLORS[color](ntaps)
        if nblock is None:
            nhop = ntaps
        else:
            nhop = max(nblock, ntaps)
        stream = convolve_overlap_add(stream, constant(ir), nhop,
                                      ntaps).samples().drop(ntaps // 2)

    # Output as desired
    if nblock is None:
        return stream.samples()
    else:
        return stream.blocks(nblock)
コード例 #7
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def interpolate(x, y, xnew):
    """Interpolate `y` at `xnew`.

    :param x: Previous sample positions
    :param y: Previous sample values
    :param xnew: New sample positions
    :returns: Interpolated sample positions
    :rtype: :class:`Stream`

    .. seealso:: :func:`streaming._iterator.interpolate_linear`
    """
    return Stream(
        streaming._iterator.interpolate_linear(x.samples()._iterator,
                                               y.samples()._iterator,
                                               xnew.samples()._iterator))
コード例 #8
0
ファイル: signal.py プロジェクト: FRidh/streaming
def noise(nblock=None, state=None, color='white', ntaps=None):
    """Generate white noise with standard Gaussian distribution.

    :param nblock: Amount of samples per block.
    :param state: State of PRNG.
    :type state: :class:`np.random.RandomState`
    :returns: When `nblock=None`, individual samples are generated and a :class:`streaming.Stream` is
    returned. When integer, a :class:`streaming.BlockStream` is returned.
    """
    if state is None:
        state = np.random.RandomState()

    # Generate white noise
    if nblock is None:
        # Generate individual samples.
        stream = Stream((state.randn(1)[0] for i in itertools.count()))
    else:
        # Generate blocks.
        stream = BlockStream((state.randn(nblock) for i in itertools.count()), nblock=nblock, noverlap=0)

    # Apply filter for specific color
    if color is not 'white':
        if ntaps is None:
            raise ValueError("Amount of taps has not been specified.")
        ir = noisy.COLORS[color](ntaps)
        if nblock is None:
            nhop = ntaps
        else:
            nhop = max(nblock, ntaps)
        stream = convolve_overlap_add(stream, constant(ir), nhop, ntaps).samples().drop(ntaps//2)

    # Output as desired
    if nblock is None:
        return stream.samples()
    else:
        return stream.blocks(nblock)
コード例 #9
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def vdl(signal, times, delay, initial_value=0.0):
    """Variable delay line which delays `signal` at `times` with `delay`.

    :param signal: Signal to be delayed.
    :param times: Sample times corresponding to signal before delay.
    :param delay: Delays to apply to signal.
    :param initial_value: Value to return before first sample.
    :returns: Delayed version of `signal`.
    :rtype: :class:`Stream`

    .. seealso:: :func:`streaming._iterator.vdl`
    """
    return Stream(
        streaming._iterator.vdl(signal.samples()._iterator,
                                times.samples()._iterator,
                                delay.samples()._iterator,
                                initial_value=initial_value))
コード例 #10
0
ファイル: signal.py プロジェクト: pombredanne/streaming
def cumsum(x):
    """Cumulative sum.

    .. seealso:: :func:`itertools.accumulate`
    """
    return Stream(streaming._iterator.cumsum(x.samples()._iterator))
コード例 #11
0
ファイル: test_signal.py プロジェクト: pombredanne/streaming
def delay(nsamples):
    return Stream(np.ones(nsamples) * 0.1 + np.arange(nsamples) * 0.001)
コード例 #12
0
ファイル: test_signal.py プロジェクト: pombredanne/streaming
def times(nsamples):
    return Stream(range(nsamples))
コード例 #13
0
ファイル: test_signal.py プロジェクト: pombredanne/streaming
def impulse_responses(nsamples, ntaps, nblock, time_variant):
    if time_variant: # Unique IR for each block
        nblocks = nsamples // nblock
        return Stream(iter(np.random.randn(nblocks, ntaps)))
    else: # Same IR for each block
        return Stream(itertools.cycle([np.random.randn(ntaps)]))
コード例 #14
0
ファイル: test_signal.py プロジェクト: pombredanne/streaming
def stream(sequence, blocked, nblock):
    stream = Stream(sequence)
    if blocked:
        stream = stream.blocks(nblock)
    return stream