{ "info": { "author": "ZhouYang Luo", "author_email": "stupidme.me.lzy@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# stupidtree\nA generic tree implementation in Python.\n\n\n## Installation\n\nFrom pypi:\n```bash\npip install stupidtree\n```\n\nor clone this repo:\n```bash\ngit clone https://github.com/luozhouyang/stupidtree\n```\n\n## Architecture\n\nThe design of this lib is flexible and expandable.\n\nThe module `stupidtree.core` has already defines the `Node` class, which works for most situations. \nHere is the `__init__` function's signature:\n```python\ndef __init__(data, tag, parent):\n pass\n```\n\nFor your special needs, you can inherit the `Node` class and override some functions as your need.\n\nThis module also defines the `BaseTree` class, which is the base class of all trees. It has already implemented the\ninterface `BaseTreeInterface`. This interface(or abstract class) contains these useful methods:\n```python\nclass BaseTreeInterface(abc.ABC):\n\n def put(self, words):\n raise NotImplementedError()\n\n def remove(self, key, rm_filter):\n raise NotImplementedError()\n\n def get(self, key):\n raise NotImplementedError()\n``` \n\n**You can put nodes into the tree with any depth and any counts**.\n\nFor improving searching performance, a `Indexer` has been implemented. It is based on `dict`, using `hash` of keys to search nodes in O(1). \n\nModule `stupidtree.core` has implemented a tree `IndexedTree` that supports index. In most situations, the index will be helpful. And if you \nwant to add another index, just inherit `NodeIndexInterface` and implements the abstract methods.\n\n## Usage\nThe usage of `stupidtree` is quitely simple. You just need to put a string or a list into a constructed tree that derived from `BaseTree` or `IndexedTree`. \nHere is a example of Chinese address in `stupidtree.examples` package. \n\nFor intuitive, I am showing you a few test examples: \n\n```python\nimport unittest\n\nfrom stupidtree.examples.address.level import Level\nfrom stupidtree.examples.address.pcd_tree import PCDTree\n\n\nclass TestPCDTree(unittest.TestCase):\n\n def test_put(self):\n tree = PCDTree()\n a0 = '\u6d59\u6c5f\u7701 \u676d\u5dde\u5e02 \u897f\u6e56\u533a'\n tree.put(a0)\n self.assertEqual(4, tree.size())\n tree.print()\n a1 = '\u6d59\u6c5f\u7701 \u676d\u5dde\u5e02 \u6c5f\u5e72\u533a'\n tree.put(a1)\n self.assertEqual(5, tree.size())\n\n nodes = tree.get('\u6d59\u6c5f\u7701')\n self.assertEqual(1, len(nodes))\n for n in nodes:\n self.assertEqual(Level.PROVINCE, n.tag)\n\n def test_remove(self):\n tree = PCDTree()\n a0 = '\u6d59\u6c5f\u7701 \u676d\u5dde\u5e02 \u897f\u6e56\u533a'\n tree.put(a0)\n a1 = '\u6d59\u6c5f\u7701 \u676d\u5dde\u5e02 \u6c5f\u5e72\u533a'\n tree.put(a1)\n tree.print()\n\n tree.remove('\u6c5f\u5e72\u533a')\n self.assertEqual(4, tree.size())\n tree.print()\n\n tree.remove('\u6d59\u6c5f\u7701')\n self.assertEqual(1, tree.size())\n tree.print()\n\n tree.remove('')\n print()\n tree.print()\n self.assertEqual(0, tree.size())\n\n\nif __name__ == \"__main__\":\n unittest.main()\n``` \n\nAnd here are the outputs:\n```bash\n+--\n| +--\u6d59\u6c5f\u7701\n| | +--\u676d\u5dde\u5e02\n| | | +--\u897f\u6e56\u533a\n.+--\n| +--\u6d59\u6c5f\u7701\n| | +--\u676d\u5dde\u5e02\n| | | +--\u897f\u6e56\u533a\n| | | +--\u6c5f\u5e72\u533a\n+--\n| +--\u6d59\u6c5f\u7701\n| | +--\u676d\u5dde\u5e02\n| | | +--\u897f\u6e56\u533a\n| | | +--\u6c5f\u5e72\u533a\n+--\n| +--\u6d59\u6c5f\u7701\n| | +--\u676d\u5dde\u5e02\n| | | +--\u897f\u6e56\u533a\n| | | +--\u6c5f\u5e72\u533a\n\n+--\n| +--\u6d59\u6c5f\u7701\n| | +--\u676d\u5dde\u5e02\n| | | +--\u897f\u6e56\u533a\n| | | +--\u6c5f\u5e72\u533a\n``` \n\n## License \n```bash\nMIT License\n\nCopyright (c) 2018 luozhouyang\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n``` \n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/luozhouyang/stupidtree", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "stupidtree", "package_url": "https://pypi.org/project/stupidtree/", "platform": "", "project_url": "https://pypi.org/project/stupidtree/", "project_urls": { "Homepage": "https://github.com/luozhouyang/stupidtree" }, "release_url": "https://pypi.org/project/stupidtree/0.1.0/", "requires_dist": null, "requires_python": "", "summary": "A generic tree implementation in Python.", "version": "0.1.0" }, "last_serial": 4035434, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "201d1677affb3bb927d22657e300ead7", "sha256": "722dc08945e1aff262c75eb89f909261bdb3c06e4c1a87d4d5e7e23c534a4b61" }, "downloads": -1, "filename": "stupidtree-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "201d1677affb3bb927d22657e300ead7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20830, "upload_time": "2018-07-06T05:01:44", "url": "https://files.pythonhosted.org/packages/8b/bf/474d0326ba75fa8186a45cbd27e30320740a13a66f26d3b85f4cd8e83bc7/stupidtree-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61f8c7539b86ed08a6111beb52f14ccc", "sha256": "044291aae3e006b5a0cdfc8d42e9cfb4ac06087ed2ad9443b432176e4d509c31" }, "downloads": -1, "filename": "stupidtree-0.1.0.tar.gz", "has_sig": false, "md5_digest": "61f8c7539b86ed08a6111beb52f14ccc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7311, "upload_time": "2018-07-06T05:01:45", "url": "https://files.pythonhosted.org/packages/cc/a7/544bfa026cd49c8bbd0768cab09eedd22b6ff4bb748de3f543aff065ebd1/stupidtree-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "201d1677affb3bb927d22657e300ead7", "sha256": "722dc08945e1aff262c75eb89f909261bdb3c06e4c1a87d4d5e7e23c534a4b61" }, "downloads": -1, "filename": "stupidtree-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "201d1677affb3bb927d22657e300ead7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20830, "upload_time": "2018-07-06T05:01:44", "url": "https://files.pythonhosted.org/packages/8b/bf/474d0326ba75fa8186a45cbd27e30320740a13a66f26d3b85f4cd8e83bc7/stupidtree-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61f8c7539b86ed08a6111beb52f14ccc", "sha256": "044291aae3e006b5a0cdfc8d42e9cfb4ac06087ed2ad9443b432176e4d509c31" }, "downloads": -1, "filename": "stupidtree-0.1.0.tar.gz", "has_sig": false, "md5_digest": "61f8c7539b86ed08a6111beb52f14ccc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7311, "upload_time": "2018-07-06T05:01:45", "url": "https://files.pythonhosted.org/packages/cc/a7/544bfa026cd49c8bbd0768cab09eedd22b6ff4bb748de3f543aff065ebd1/stupidtree-0.1.0.tar.gz" } ] }