Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
jubatus/plugin/src/fv_converter/python_bridge/python/number_multiplier.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (27 sloc)
1.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
from unittest import TestCase | |
class NumberMultiplier(object): | |
# Example of Python-based num_types. | |
@classmethod | |
def create(cls, param): | |
# This example uses parameter ``n`` from config file. | |
# ``2`` is used when not specified. | |
n = int(param.get('n', 2)) | |
return cls(n) | |
def __init__(self, n): | |
self._n = n | |
def extract(self, key, value): | |
""" | |
Returns the number multipled by the number specified in the | |
config (``n``). | |
The key is typed as ``str`` (unicode). | |
The value is typed as ``float``. | |
This method should return list of key-values (pair of feature key | |
as ``str`` and its value as number). | |
""" | |
return [(key, value * self._n)] | |
class NumberMultiplierTest(TestCase): | |
def test_extract(self): | |
ex = NumberMultiplier.create({'n': 3}) | |
self.assertEqual([('v', 30)], ex.extract('v', 10)) |