# Path: jubakit/model.py
# class JubaDump(object):
#   """
#   ``JubaDump`` provides a high-level dump of Jubatus models.
#   ``jubadump`` command must be installed.
#   """
# 
#   @classmethod
#   def dump_file(cls, target):
#     """
#     Returns the dumped model data structure of the model file path ``target``.
#     """
#     proc = JubaProcess.get_process(['jubadump', '-i', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#     (stdout, stderr) = proc.communicate()
#     status = proc.returncode
#     if status != 0:
#       raise InvalidModelFormatError('{0} (exit with status {1})'.format(stderr, status))
#     return json.loads(stdout.decode())
# 
#   @classmethod
#   def dump(cls, data):
#     """
#     Returns the dumped model data structure of the raw model data.
#     """
#     with tempfile.NamedTemporaryFile(mode='wb', prefix='jubakit-jubadump-') as f:
#       f.write(data)
#       f.flush()
#       return cls.dump_file(f.name)


import sys
from jubakit.model import JubaDump
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals



"""
Extracting Classifier Models
=============================================

This is an example to show the usage of ``jubakit.model`` package,
which allows low-level model manipulation.

To try this example, first save a model file of jubaclassifier
(hint: ``classifier_csv.py`` example automatically saves the model under /tmp)
Then run this example like:

    $ python classifier_model_extract.py /tmp/127.0.0.1_9199_example_snapshot.jubatus

to see the linear classifier weights, features and labels.
"""

# Load the model from file.
modelpath = 'classifier_iris_model.jubatus'
if 1 < len(sys.argv):
    modelpath = sys.argv[1]

# load the classifier model file.

# Path: jubakit/model.py
# class JubaDump(object):
#   """
#   ``JubaDump`` provides a high-level dump of Jubatus models.
#   ``jubadump`` command must be installed.
#   """
# 
#   @classmethod
#   def dump_file(cls, target):
#     """
#     Returns the dumped model data structure of the model file path ``target``.
#     """
#     proc = JubaProcess.get_process(['jubadump', '-i', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#     (stdout, stderr) = proc.communicate()
#     status = proc.returncode
#     if status != 0:
#       raise InvalidModelFormatError('{0} (exit with status {1})'.format(stderr, status))
#     return json.loads(stdout.decode())
# 
#   @classmethod
#   def dump(cls, data):
#     """
#     Returns the dumped model data structure of the raw model data.
#     """
#     with tempfile.NamedTemporaryFile(mode='wb', prefix='jubakit-jubadump-') as f:
#       f.write(data)
#       f.flush()
#       return cls.dump_file(f.name)


# Path: example/classifier_model_extract.py
import sys
from jubakit.model import JubaDump

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

from __future__ import absolute_import, division, print_function, unicode_literals



"""
Extracting Classifier Models
=============================================

This is an example to show the usage of ``jubakit.model`` package,
which allows low-level model manipulation.

To try this example, first save a model file of jubaclassifier
(hint: ``classifier_csv.py`` example automatically saves the model under /tmp)
Then run this example like:

    $ python classifier_model_extract.py /tmp/127.0.0.1_9199_example_snapshot.jubatus

to see the linear classifier weights, features and labels.
"""

# Load the model from file.
modelpath = 'classifier_iris_model.jubatus'
if 1 < len(sys.argv):
    modelpath = sys.argv[1]

# load the classifier model file.

model = JubaDump.dump_file(modelpath)