# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['jange',
 'jange.apps',
 'jange.ops',
 'jange.ops.text',
 'jange.stream',
 'jange.vis']

package_data = \
{'': ['*']}

install_requires = \
['cytoolz>=0.10.0,<0.11.0',
 'jsonschema>=3.2.0,<4.0.0',
 'more_itertools>=8.4.0,<9.0.0',
 'networkx>=2.4,<3.0',
 'pandas>=1.0.5,<2.0.0',
 'plotly>=4.8.2,<5.0.0',
 'scikit-learn>=0.23.1,<0.24.0',
 'spacy>=2.2.0,<3.0.0']

setup_kwargs = {
    'name': 'jange',
    'version': '0.1.7',
    'description': 'Easy NLP library for Python',
    'long_description': '# jange\n[![Build Status](https://travis-ci.org/jangedoo/jange.svg?branch=master)](https://travis-ci.org/jangedoo/jange)\n------\njange is an easy to use NLP library for Python. It provides a high level API for commonly applications in NLP. It is based on popular libraries like `pandas`, `scikit-learn`, `spacy`, and `plotly`.\n\nTo get started, install using pip.\n```\npip install jange\n```\n\n# Overview\nFor common NLP applications, we clean the data, extract the features and apply some ML algorithm on the features.We apply some transformation on the raw input data to get the results we want. **jange** organizes these transformations as a series of operation we do on the input. The high level API for these transformation are easy to read and reason with. Take a look at the example below for clustering. Even without any explanation you should be able to read and understand what is happening without refering to a hour length tutorial or trying to wrap your head around multi-dimensional array slicing and dicing. Let\'s not forget the pain to migrate the code from prototyping to production. **jange** tries to simplify the transition from experimental phase to production use.\n\n\n```python\n# %% Load data\nfrom jange import ops, stream, vis\n\nds = stream.from_csv(\n    "https://raw.githubusercontent.com/jangedoo/jange/master/dataset/bbc.csv",\n    columns="news",\n    context_column="type",\n)\n\n# %% Extract clusters\n# Extract clusters\nresult_collector = {}\nclusters_ds = ds.apply(\n    ops.text.clean.pos_filter("NOUN", keep_matching_tokens=True),\n    ops.text.encode.tfidf(max_features=5000, name="tfidf"),\n    ops.cluster.minibatch_kmeans(n_clusters=5),\n    result_collector=result_collector,\n)\n\n# %% Get features extracted by tfidf\nfeatures_ds = result_collector[clusters_ds.applied_ops.find_by_name("tfidf")]\n\n# %% Visualization\nreduced_features = features_ds.apply(ops.dim.tsne(n_dim=2))\nvis.cluster.visualize(reduced_features, clusters_ds)\n\n# visualization looks good, lets export the operations\nwith ops.utils.disable_training(cluster_ds.applied_ops) as cluster_ops:\n    with open("cluster_ops.pkl", "wb") as f:\n        pickle.dump(cluster_ops, f)\n\n# in_another_file.py\n# load the saved operations and apply on a new stream to retrieve the clusters\nwith open("cluster_ops.pkl", "rb") as f:\n    cluster_ops = pickle.load(f)\n\nclusters_ds = input_ds.apply(cluster_ops)\n```\n![Cluster](https://sanjayasubedi.com.np/assets/images/nlp/clustering/cluster_jange.png)\n\n\n\nLooks convincing?\n\n# What can jange do for me?\nThe idea behind jange is for rapid prototyping and **deployment**. Jange supports\n\n- Data cleaning: remove stop words, emails, links, numbers, filter tokens based on POS or any filter operation using spacy\'s token matcher patterns. It provides a high-level api to spacy\'s TokenMatcher.\n- Text Encoding : Provides high level API for encoding texts as one-hot, count or tf-idf features using scikit-learn model\n- Embedding : Document embedding based on spacy\'s language model that captures semantics of the text\n- Clustering: High level API for several clustering algorithsm in scikit-learn library\n- Topic modeling: High level API for commonly used topic modeling algorithms (NMF, LDA)\n- Nearest Neighbors : High level API for finding similar pair or groups of similar items\n- Classification : High level API to train spacy\'s model or many of scikit-learn\'s classifiers\n- Dimension reduction: High level API for algorithms used to reduce dimension of feature space. Useful for visualization (tsne, pca) or compression\n- Extraction : High level API to extract sentences, or summary from texts\nAnd many more including visualization, operation persistence and quick apps.\n\n# Basic Concept\n## DataStream\nDataStream is a holder of your data. The data can be lazily loaded or can be in memory. A DataStream is nothing more than a list of items together with some context(optional). For example,\n```python\nfrom jange import stream\n# create stream from any python object including lists, numpy array, generators etc.\nds = stream.DataStream(items=["Product 1", "Product 2"], context=["pid1", "pid2"])\n# few helper functions\nstream.from_csv("path/to/csv")\nstream.from_df(df)\n```\n`ds` is a data stream that holds your data along with some context. In this case the database id of the products. The idea behind context is that it holds some metadata about the items you pass. If you don\'t pass anything to the context, then jange will internally create context values for each item. DataStream also maintains information about what operations have been applied to it in a variable `applied_ops`. For example, if you applied few cleaning, one tf-df and a topic modeling operation to an input stream, the final `DataStream` containing the output of topic modeling will know about all operations that were applied from the beginning. You can apply the same operations to a new raw input stream and exactly the same operations will be applied to the new input.\n\n\n## Operations\nTransformations to the input data are done by `Operation` in jange. Each operation takes in a DataStream and produces a DataStream. One or more operations are applied to a DataStream. Each operation will execute and pass the results to the next operation. Example below shows how you can apply \ndifferent operations. Of course, the output of an operation should be compatible with the input the next operation is expecting.\n\nOperations in **jange** are available under `ops` sub package. They are nicely organized into modules depending on their scope. For example, operations that work on input of texts are under `ops.text`. For cleaning the operations are under `ops.text.clean` and for encoding texts into vectors or embeddings, `ops.text.encode` or `ops.text.embedding` can be used.\n\nFor clustering, topic modeling, classification etc. they can be found under `ops.cluster`, `ops.topic`, `ops.classfy` etc.\n```python\ninput_ds = stream.from_csv(\n    "https://raw.githubusercontent.com/jangedoo/jange/master/dataset/bbc.csv",\n    columns="news",\n    context_column="type",\n)\nclusters_ds = input_ds.apply(\n    ops.text.clean.filter_pos("NOUN", keep_matching_tokens=True),\n    ops.text.encode.tfidf(max_features=5000, name="tfidf"),\n    ops.cluster.minibatch_kmeans(n_clusters=5)\n)\n\n# once we are happy with results save the operations to disk\nwith ops.utils.disable_training(cluster_ds.applied_ops) as cluster_ops:\n    with open("cluster_ops.pkl", "wb") as f:\n        pickle.dump(cluster_ops, f)\n\n# in_another_file.py\n# load the saved operations and apply on a new stream to retrieve the clusters\nwith open("cluster_ops.pkl", "rb") as f:\n    cluster_ops = pickle.load(f)\n\nclusters_ds = input_ds.apply(cluster_ops) # WOW! this easy for production? 👍\n```\n\n### How does it work?\n`Operation` has a very simple interface with one method `run(ds: DataStream) -> DataStream`. When it processes input DataStream, and produces an output, it will add itself and the `applied_ops` of input DataStream to the `applied_ops` of output DataStream. From the code above, if we print out `cluster_ds.applied_ops`, we\'ll see a list of 3 operations so we know exactly what operations were applied to produce this output. Each operation will also make sure the context is passed to the output appropriately. This is important when some operations discard one or more items from the input. If you solely rely on array indexing, the mapping of output to the original input index will no longer be valid as some items have been removed and you don\'t know which output maps to which original input anymore. Context helps to maintain the mapping with original data.\n\n What about operations where we need to train? These operations use `TrainableMixin` which has an attribute `should_train`. By default it is True, so when you run it, any trainable operation will train the underlying model (sklearn\'s or spacy\'s models) and then do the predictions. But during production, you don\'t want to train so a helper function `ops.utils.disable_training` will set `should_train` to False for all trainable operations. As shown in the example above, you can save these operations to disk and next time you load it, you can run these operations with out training any "trainable" operations again.\n\nCare has been taken in making sure that the operations can be pickled without saving unnecessary data. For example, instead of pickling spacy\'s language model, the operation only saves the path to the model and when operation is unpicked, spacy\'s model is loaded from that path. Also, the model loading is cached, so attempts to load the same spacy model will use the cached version instead of loading from the disk.\n\nSince the API is so simple, you can easily extend to fit your requirements.\n\nCheck out the [API Reference](https://jange.readthedocs.io/en/latest/api/index.html) for more details.\n\n# Installation\n```\npip install jange\n```\n\n## From source\nThis project uses poetry to manage dependencies. If you don\'t already have poetry installed then go to https://python-poetry.org/docs/#installation for instructions on how to install it for your OS.\n\nOnce poetry is installed, from the root directory of this project, run `poetry install`. It will create a virtual environment for this project and install the necessary dependencies (including dev dependencies).\n\n\n# Contributions 👩\u200d💻\nThis library is in a very early stage. Your perspective on how things could be done or improved would be greatly appreciated. Since this is in early stage, you\'ll most probably encounter some bugs and issues. Please let us know by opening an issue or if you know Python then you can contribute too!',
    'author': 'Sanjaya Subedi',
    'author_email': 'jangedoo@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/jangedoo/jange',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6.1,<4.0.0',
}


setup(**setup_kwargs)
