dam-lev


Namedam-lev JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/nickeldan/dam_lev
SummaryImplements the Damerau–Levenshtein diff algorithm
upload_time2023-01-06 03:45:01
maintainer
docs_urlNone
authorDaniel Walker
requires_python>=3.8
license
keywords diff
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =======
dam_lev
=======

:Author: Daniel Walker
:Version: 0.1.2
:Date: 2023-01-05

Overview
========

The :code:`dam_lev` package implements the
`Damerau–Levenshtein diff algorithm <https://en.wikipedia.org/wiki/Damerau–Levenshtein_distance>`_.  That is,
it will take two sequences and determine the minimum number of transpositions, substitutions, insertions, and
deletions needed to transform the first sequence into the second.

Usage
=====

The package exposes a single function, :code:`dam_lev.get_changes`.  It takes two sequences (i.e., they must
implement the :code:`__len__` and :code:`__getitem__` methods) and returns a list of :code:`dam_lev.Mutation`
objects.  There are four subclasses of :code:`dam_lev.Mutation` corresponding to the four types of
transformations.  For example,

.. code-block:: python

    diffs = dam_lev.get_changes('abcdef', 'bcedxy')
    print(diffs) # [Deletion(at=0), Transposition(at=3), Substitution(at=5, at2=4), Insertion(at=6, at2=5)]

We see that the sequence of transformations is:

* Delete the item at index 0 (:code:`'a'`)
* Transpose the item at index 3 (:code:`'d'`) with its successor
* Substitute the item at index 5 (:code:`'f'`) with the item from the second sequence at index 4 (:code:`'x'`)
* Insert at index 6 the item from the second sequence at index 5 (:code:`'y'`)

Note the index for the transposition.  Even though, after the deletion, the :code:`'d'` is at index 2, it's at
index 3 in the original version of the sequence.  Likewise for the successive mutations.

Key function
------------

You can also pass a callable as the :code:`key` keyword argument to :code:`dam_lev.get_changes`.  Similar to
:code:`list.sort`, this callable will be used to compare the elements of the sequences.  For example,

.. code-block:: python

    diffs = dam_lev.get_changes('aBc', 'AbC', key=str.upper)
    print(diffs) # []

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nickeldan/dam_lev",
    "name": "dam-lev",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "diff",
    "author": "Daniel Walker",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/e2/45/ad5e9475b5ff7c38cc3c44b3b0c5fda2618e5ee8b01a4dccf30c52e25ec0/dam_lev-0.1.2.tar.gz",
    "platform": null,
    "description": "=======\ndam_lev\n=======\n\n:Author: Daniel Walker\n:Version: 0.1.2\n:Date: 2023-01-05\n\nOverview\n========\n\nThe :code:`dam_lev` package implements the\n`Damerau\u2013Levenshtein diff algorithm <https://en.wikipedia.org/wiki/Damerau\u2013Levenshtein_distance>`_.  That is,\nit will take two sequences and determine the minimum number of transpositions, substitutions, insertions, and\ndeletions needed to transform the first sequence into the second.\n\nUsage\n=====\n\nThe package exposes a single function, :code:`dam_lev.get_changes`.  It takes two sequences (i.e., they must\nimplement the :code:`__len__` and :code:`__getitem__` methods) and returns a list of :code:`dam_lev.Mutation`\nobjects.  There are four subclasses of :code:`dam_lev.Mutation` corresponding to the four types of\ntransformations.  For example,\n\n.. code-block:: python\n\n    diffs = dam_lev.get_changes('abcdef', 'bcedxy')\n    print(diffs) # [Deletion(at=0), Transposition(at=3), Substitution(at=5, at2=4), Insertion(at=6, at2=5)]\n\nWe see that the sequence of transformations is:\n\n* Delete the item at index 0 (:code:`'a'`)\n* Transpose the item at index 3 (:code:`'d'`) with its successor\n* Substitute the item at index 5 (:code:`'f'`) with the item from the second sequence at index 4 (:code:`'x'`)\n* Insert at index 6 the item from the second sequence at index 5 (:code:`'y'`)\n\nNote the index for the transposition.  Even though, after the deletion, the :code:`'d'` is at index 2, it's at\nindex 3 in the original version of the sequence.  Likewise for the successive mutations.\n\nKey function\n------------\n\nYou can also pass a callable as the :code:`key` keyword argument to :code:`dam_lev.get_changes`.  Similar to\n:code:`list.sort`, this callable will be used to compare the elements of the sequences.  For example,\n\n.. code-block:: python\n\n    diffs = dam_lev.get_changes('aBc', 'AbC', key=str.upper)\n    print(diffs) # []\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Implements the Damerau\u2013Levenshtein diff algorithm",
    "version": "0.1.2",
    "split_keywords": [
        "diff"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4d7599555989638860f3b309d3798d03a94dbf3c1d75a80ab45a78a5b4cf66e",
                "md5": "3d029f7412d2b16b141e6ca6682ec9d3",
                "sha256": "1e0b5e3d5d6f948b0718b848183d44b70af073bddb260c1810826eaec29486eb"
            },
            "downloads": -1,
            "filename": "dam_lev-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d029f7412d2b16b141e6ca6682ec9d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3902,
            "upload_time": "2023-01-06T03:44:58",
            "upload_time_iso_8601": "2023-01-06T03:44:58.158619Z",
            "url": "https://files.pythonhosted.org/packages/a4/d7/599555989638860f3b309d3798d03a94dbf3c1d75a80ab45a78a5b4cf66e/dam_lev-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e245ad5e9475b5ff7c38cc3c44b3b0c5fda2618e5ee8b01a4dccf30c52e25ec0",
                "md5": "853544fb572180bbbe697c4c18f913c4",
                "sha256": "a2ab0e04751c51ca118a6a0ae31b923db3a78f355e3dc3cf6e33a93711ae17fd"
            },
            "downloads": -1,
            "filename": "dam_lev-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "853544fb572180bbbe697c4c18f913c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3558,
            "upload_time": "2023-01-06T03:45:01",
            "upload_time_iso_8601": "2023-01-06T03:45:01.935124Z",
            "url": "https://files.pythonhosted.org/packages/e2/45/ad5e9475b5ff7c38cc3c44b3b0c5fda2618e5ee8b01a4dccf30c52e25ec0/dam_lev-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-06 03:45:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nickeldan",
    "github_project": "dam_lev",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "dam-lev"
}
        
Elapsed time: 0.02515s