# Path: jubakit/weight.py
# class Weight(BaseService):
#   """
#   Weight service.
#   """
# 
#   @classmethod
#   def name(cls):
#     return 'weight'
# 
#   @classmethod
#   def _client_class(cls):
#     return jubatus.weight.client.Weight
# 
#   @classmethod
#   def _embedded_class(cls):
#     return jubatus.embedded.Weight
# 
#   def update(self, dataset):
#     """
#     Updates the weight using the given dataset and returns extracted feature vectors.
#     """
# 
#     cli = self._client()
#     for (idx, d) in dataset:
#       result = cli.update(d)
#       yield (idx, result)
# 
#   def calc_weight(self, dataset):
#     """
#     Returns extracted feature vectors, without modifying the weight model.
#     """
# 
#     cli = self._client()
#     for (idx, d) in dataset:
#       result = cli.calc_weight(d)
#       yield (idx, result)
# 
# class Schema(GenericSchema):
#   """
#   Schema for Weight service.
#   """
#   pass
# 
# class Dataset(BaseDataset):
#   """
#   Dataset for Weight service.
#   """
# 
#   @classmethod
#   def _predict(cls, row):
#     return Schema.predict(row, False)
# 
# class Config(GenericConfig):
#   """
#   Configuration to run Weight service.
#   """
# 
#   @classmethod
#   def methods(cls):
#     return [None]
# 
#   @classmethod
#   def _default_method(cls):
#     return None
# 
#   @classmethod
#   def _default_parameter(cls, method):
#     return None
# 
# Path: jubakit/loader/csv.py
# class CSVLoader(BaseLoader):
#   """
#   Loader to process CSV files.
#   """
# 
#   def __init__(self, filename, fieldnames=None, encoding='utf-8', *args, **kwargs):
#     """
#     Creates a new loader that processes CSV files.
# 
#     You can optionally give `fieldnames` option.
#     If `fieldnames` is not specified (which is a default) or specifeid as True,
#     the first line of the CSV is used for column names.  If `fieldnames` is
#     specified as False, sequential column names are automatically generated
#     like ['c0', 'c1', ...].  If `fieldnames` is a list, it is used as column
#     names.
# 
#     Any other optional or keyword arguments are passed to the underlying
#     `csv.DictReader`.
# 
#     >>> loader = CSVLoader('dataset.tsv', fieldnames=False, encoding='cp932', delimiter='\t')
#     """
# 
#     if fieldnames == True:
#       # Automatically estimate field names later.
#       fieldnames = None
#     elif fieldnames == False:
#       # Generate field names by peeking number of columns in the first row of the CSV.
#       with io.open(filename, encoding=encoding, newline='') as f:
#         # Use fieldnames from DictReader to count number of columns in the first row.
#         r = _UnicodeDictReader(f, encoding, fieldnames=None, *args, **kwargs)
#         fieldnames = ['c{0}'.format(i) for i in range(len(r.fieldnames))]
# 
#     self._filename = filename
#     self._fieldnames = fieldnames
#     self._encoding = encoding
#     self._args = args
#     self._kwargs = kwargs
# 
#   def rows(self):
#     with io.open(self._filename, encoding=self._encoding, newline='') as f:
#       reader = _UnicodeDictReader(f, self._encoding, fieldnames=self._fieldnames, *self._args, **self._kwargs)
#       for row in reader:
#         yield row


from jubakit.weight import Weight, Schema, Dataset, Config
from jubakit.loader.csv import CSVLoader
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

"""
Using Weight Service
====================

This example illustrates how to use Weight engine to debug fv_converter
behavior (i.e. `converter` section of the config file).
"""


# Load a CSV file.
loader = CSVLoader('shogun.train.csv')

# Create a Dataset; schema will be auto-predicted.
dataset = Dataset(loader)

# Create a Weight Service.

# Path: jubakit/weight.py
# class Weight(BaseService):
#   """
#   Weight service.
#   """
# 
#   @classmethod
#   def name(cls):
#     return 'weight'
# 
#   @classmethod
#   def _client_class(cls):
#     return jubatus.weight.client.Weight
# 
#   @classmethod
#   def _embedded_class(cls):
#     return jubatus.embedded.Weight
# 
#   def update(self, dataset):
#     """
#     Updates the weight using the given dataset and returns extracted feature vectors.
#     """
# 
#     cli = self._client()
#     for (idx, d) in dataset:
#       result = cli.update(d)
#       yield (idx, result)
# 
#   def calc_weight(self, dataset):
#     """
#     Returns extracted feature vectors, without modifying the weight model.
#     """
# 
#     cli = self._client()
#     for (idx, d) in dataset:
#       result = cli.calc_weight(d)
#       yield (idx, result)
# 
# class Schema(GenericSchema):
#   """
#   Schema for Weight service.
#   """
#   pass
# 
# class Dataset(BaseDataset):
#   """
#   Dataset for Weight service.
#   """
# 
#   @classmethod
#   def _predict(cls, row):
#     return Schema.predict(row, False)
# 
# class Config(GenericConfig):
#   """
#   Configuration to run Weight service.
#   """
# 
#   @classmethod
#   def methods(cls):
#     return [None]
# 
#   @classmethod
#   def _default_method(cls):
#     return None
# 
#   @classmethod
#   def _default_parameter(cls, method):
#     return None
# 
# Path: jubakit/loader/csv.py
# class CSVLoader(BaseLoader):
#   """
#   Loader to process CSV files.
#   """
# 
#   def __init__(self, filename, fieldnames=None, encoding='utf-8', *args, **kwargs):
#     """
#     Creates a new loader that processes CSV files.
# 
#     You can optionally give `fieldnames` option.
#     If `fieldnames` is not specified (which is a default) or specifeid as True,
#     the first line of the CSV is used for column names.  If `fieldnames` is
#     specified as False, sequential column names are automatically generated
#     like ['c0', 'c1', ...].  If `fieldnames` is a list, it is used as column
#     names.
# 
#     Any other optional or keyword arguments are passed to the underlying
#     `csv.DictReader`.
# 
#     >>> loader = CSVLoader('dataset.tsv', fieldnames=False, encoding='cp932', delimiter='\t')
#     """
# 
#     if fieldnames == True:
#       # Automatically estimate field names later.
#       fieldnames = None
#     elif fieldnames == False:
#       # Generate field names by peeking number of columns in the first row of the CSV.
#       with io.open(filename, encoding=encoding, newline='') as f:
#         # Use fieldnames from DictReader to count number of columns in the first row.
#         r = _UnicodeDictReader(f, encoding, fieldnames=None, *args, **kwargs)
#         fieldnames = ['c{0}'.format(i) for i in range(len(r.fieldnames))]
# 
#     self._filename = filename
#     self._fieldnames = fieldnames
#     self._encoding = encoding
#     self._args = args
#     self._kwargs = kwargs
# 
#   def rows(self):
#     with io.open(self._filename, encoding=self._encoding, newline='') as f:
#       reader = _UnicodeDictReader(f, self._encoding, fieldnames=self._fieldnames, *self._args, **self._kwargs)
#       for row in reader:
#         yield row


# Path: example/weight_shogun.py
from jubakit.weight import Weight, Schema, Dataset, Config
from jubakit.loader.csv import CSVLoader

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals

"""
Using Weight Service
====================

This example illustrates how to use Weight engine to debug fv_converter
behavior (i.e. `converter` section of the config file).
"""


# Load a CSV file.
loader = CSVLoader('shogun.train.csv')

# Create a Dataset; schema will be auto-predicted.
dataset = Dataset(loader)

# Create a Weight Service.

cfg = Config()