{ "info": { "author": "Microdog", "author_email": "dlangu0393@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries" ], "description": "Hello GFW\n=========\n\nA simple text filter for GFW friendly UGC applications.\n\nUsage\n-----\n\nLoad Dict\n~~~~~~~~~\n\nLoad dict from iterable:\n\n.. code-block:: python\n\n >> words_filter = Filter([u'Word1', u'Word2'])\n\nOr load from file using `load_dict` utility, one word per line:\n\n.. code-block:: python\n\n >> words_iter = load_dict('/path/to/your/dict')\n >> words_filter = Filter(words_iter)\n\nThis library also provided a default dict in it, but it is not recommended:\n\n.. code-block:: python\n\n >> words_filter = Filter.default()\n\n.. note::\n\n All the words in the default dictionary are collected from internet, and just for testing purpose.\n\nContains\n~~~~~~~~\n\n.. code-block:: python\n\n >> words_filter.contains(u'There is a keyword.')\n True\n\nSearch\n~~~~~~\n\n.. code-block:: python\n\n >> words_filter.search(u'There is a keyword.')\n [(11, u'keyword')]\n\nReplace\n~~~~~~~\n\n.. code-block:: python\n\n >> words_filter.replace(u'There is a keyword.', u'*')\n u'There is a *******.'\n\nImplementations\n~~~~~~~~~~~~~~~\n\nStarting from version 0.1, two implementations of Filter are provided: DAWGFilter, DFAFilter(default).\nDFAFilter is written in pure Python and has a better performance than DAWGFilter, especially in PyPy.\n\n.. code-block:: python\n\n >> default_filter = Filter.default()\n >> dawg_filter = DAWGFilter.default()\n >> dfa_filter = DFAFilter.default()\n\n.. note::\n\n If you want to use DAWGFilter, you need to install `DAWG `_ dependency.\n\nPerformance\n-----------\n\nMacBook Pro (Retina, 13-inch, Early 2015), 3.1 GHz Intel Core i7\n\nDFAFilter with CPython 2.7.10\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: shell\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.contains(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 100000 loops, best of 3: 36.7 usec per loop\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.search(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 100000 loops, best of 3: 37.4 usec per loop\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.replace(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 100000 loops, best of 3: 38.9 usec per loop\n\n\nDFAFilter with PyPy 4.0.1(2.7.10)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: shell\n\n $ pypy -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.contains(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 1000000 loops, best of 3: 5.95 usec per loop\n\n $ pypy -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.search(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 1000000 loops, best of 3: 5.97 usec per loop\n\n $ pypy -m timeit -s \"import hgfw; f = hgfw.DFAFilter.default()\" \"f.replace(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 1000000 loops, best of 3: 6.06 usec per loop\n\nDAWGFilter with CPython 2.7.10\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: shell\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DAWGFilter.default()\" \"f.contains(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 10000 loops, best of 3: 64 usec per loop\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DAWGFilter.default()\" \"f.search(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 10000 loops, best of 3: 64.8 usec per loop\n\n $ python -m timeit -s \"import hgfw; f = hgfw.DAWGFilter.default()\" \"f.replace(u'\u6d4b\u8bd5\u5b57\u7b26\u4e32\u8981\u957f\u957f\u957f\u957f\u4e00\u4e9b\uff1a\u6210\u4eba\u5728\u7ebf\u7535X\uff0c642233\uff0c\u4ee3\u5f00\u53d1\u7968\uff0c\u4f5c\u5f0a\u4eea\u5668\uff0c\u5728~\u5bb6~\u521b~\u4e1a~\u3002\u5728\u5f53\u524d\u7684\u5f62 \u52bf\u4e0b\uff0c\u6211\u4eec\u8981\u66f4\u52a0\u79ef\u6781\u7684\u4e3e\u62a5\u9ec4\u8272\u7f51\u7ad9\u3002')\"\n 10000 loops, best of 3: 90.5 usec per loop\n\nTODO\n----\n\n* Optimize matching algorithm\n* Provide higher-quality dictionaries\n\nLicense\n-------\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Microdog\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\nDependency `DAWG `_ is licensed under MIT License.", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/microdog/hello-gfw", "keywords": "gfw filter", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "hello-gfw", "package_url": "https://pypi.org/project/hello-gfw/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/hello-gfw/", "project_urls": { "Homepage": "https://github.com/microdog/hello-gfw" }, "release_url": "https://pypi.org/project/hello-gfw/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "A simple text filter for GFW friendly UGC applications.", "version": "0.1.2" }, "last_serial": 1992271, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "faeb1ed5c182063f74b2d9dd4b9c505f", "sha256": "f778b573ae58667cfc94c63e37e9e04e10c841d45dc1326a3711290345986b0e" }, "downloads": -1, "filename": "hello_gfw-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "faeb1ed5c182063f74b2d9dd4b9c505f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9149, "upload_time": "2015-05-20T08:54:41", "url": "https://files.pythonhosted.org/packages/fd/a5/782c81594c55a8f3f27aed8926ded748e2d4d1a19fd33512358ad0dceff8/hello_gfw-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2db9cebf8c92040c987c43e4eb56decc", "sha256": "960dbf4bacc5b6b563a1bf1cd93fca364819fda7a530251aaaf241e147a484b5" }, "downloads": -1, "filename": "hello-gfw-0.0.1.tar.gz", "has_sig": false, "md5_digest": "2db9cebf8c92040c987c43e4eb56decc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8203, "upload_time": "2015-05-20T08:54:36", "url": "https://files.pythonhosted.org/packages/c7/d4/797d7060c61a76539587a8907d04dc612a25db7012e3433a32a3fa81d8cd/hello-gfw-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "5bde09c38f37e98e1eb892d27428ed5e", "sha256": "95edf220bccae86eeecef29d33270ce999c902beea8f947d19b5457aefbaf0ac" }, "downloads": -1, "filename": "hello-gfw-0.1.0.tar.gz", "has_sig": false, "md5_digest": "5bde09c38f37e98e1eb892d27428ed5e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51592, "upload_time": "2016-03-06T06:14:22", "url": "https://files.pythonhosted.org/packages/10/90/a76e35b3c0064e911d2f905574fe508170b68e1e23de5aaa334b212449f2/hello-gfw-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "1fc663cb61abf912659dfff2a0bfcc9e", "sha256": "2c8ade130cb5a131713224388f10b11265d4bb0d89632aa9241b3df31b1e78c8" }, "downloads": -1, "filename": "hello-gfw-0.1.1.tar.gz", "has_sig": false, "md5_digest": "1fc663cb61abf912659dfff2a0bfcc9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51592, "upload_time": "2016-03-06T06:20:30", "url": "https://files.pythonhosted.org/packages/26/f8/11d6998438002fab07a4c34b1a0281ecfd0d61557e5a745cf1e930af6435/hello-gfw-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "945ca5ff78228493e265ed7963274c7b", "sha256": "04c94703d65993db008317691a5de5eba2276f5ad41c47882e2b1638b252822c" }, "downloads": -1, "filename": "hello-gfw-0.1.2.tar.gz", "has_sig": false, "md5_digest": "945ca5ff78228493e265ed7963274c7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51827, "upload_time": "2016-03-06T16:06:19", "url": "https://files.pythonhosted.org/packages/6f/ff/f501cdc17db7073339f1c1c5e7b5bda7ec4611ef96883ef7d99bc0e76fd9/hello-gfw-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "945ca5ff78228493e265ed7963274c7b", "sha256": "04c94703d65993db008317691a5de5eba2276f5ad41c47882e2b1638b252822c" }, "downloads": -1, "filename": "hello-gfw-0.1.2.tar.gz", "has_sig": false, "md5_digest": "945ca5ff78228493e265ed7963274c7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51827, "upload_time": "2016-03-06T16:06:19", "url": "https://files.pythonhosted.org/packages/6f/ff/f501cdc17db7073339f1c1c5e7b5bda7ec4611ef96883ef7d99bc0e76fd9/hello-gfw-0.1.2.tar.gz" } ] }