Skip to content

Commit

Permalink
0.9.4
Browse files Browse the repository at this point in the history
Fix for dawg node id
  • Loading branch information
Abhishek Singh committed Jun 19, 2020
1 parent f5150e1 commit 8f577b4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -9,4 +9,5 @@ sampledawg.py
dist
lexpy.egg-info
build
.venv
.venv
dawg_sample.py
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -43,6 +43,7 @@ Lexpy version `0.9.3` is recommended and it supports both Python 2 and Python 3.
| Search using wildcard expression | `search('a?b*')` | `search('a?b*)` |
| Search for prefix matches | `search_with_prefix('bar')` | `search_with_prefix('bar')` |
| Search for similar words within given edit distance. Here, the notion of edit distance is same as Levenshtein distance (LD) | `search_within_distance('apble', dist=1)` | `search_within_distance('apble', dist=1)` |
| Get the number of nodes in the automaton | `len(trie)` | `len(dawg)` |


# Examples
Expand Down Expand Up @@ -100,7 +101,7 @@ with open('/path/to/file.txt', 'r') as infile:
1. Check if exists using the `in` operator

```python
print 'ampyx' in trie
print('ampyx' in trie)
True
```

Expand Down
2 changes: 1 addition & 1 deletion lexpy/__init__.py
@@ -1,4 +1,4 @@

__version__ = "0.9.4"



Expand Down
7 changes: 4 additions & 3 deletions lexpy/dawg.py
Expand Up @@ -47,8 +47,9 @@ def add(self, word):
for letter in word[common_prefix_index:]:
_id = self._id + 1
node.add_child(letter, _id)
self.__unchecked_nodes.append((node, letter, node[letter]))
node = node[letter]
self.__unchecked_nodes.append((node, letter, node.children[letter]))
node = node.children[letter]
self._id = _id

node.eow = True
self._num_of_words += 1
Expand All @@ -61,7 +62,7 @@ def _reduce(self, to):
for i in range(len(self.__unchecked_nodes)-1, to-1, -1):
(parent, letter, child) = self.__unchecked_nodes[i]
if child in self.__minimized_nodes:
parent.children[letter] = child
parent.children[letter] = self.__minimized_nodes[child]
else:
self.__minimized_nodes[child] = child
self.__unchecked_nodes.pop()
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Expand Up @@ -4,6 +4,8 @@

from setuptools import setup, find_packages

from lexpy import __version__

LONG_DESCRIPTION = 'A lexicon is a data-structure which stores a set of words. ' \
'The difference between a dictionary and a lexicon is that in a lexicon there are no values associated with the words. ' \
'A lexicon is similar to a list of words or a set, but the internal representation is different and optimized for faster searches(of words, prefixes and wildcard patterns). ' \
Expand All @@ -18,7 +20,7 @@
DESCRIPTION = ('Python package for lexicon.')
LICENSE = 'GNU GPLv3'
URL = 'https://github.com/aosingh/lexpy'
VERSION = '0.9.3'
VERSION = __version__

PACKAGES = ['lexpy']

Expand All @@ -33,10 +35,10 @@
'Topic :: Text Processing :: Indexing',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'Operating System :: Microsoft :: Windows',
Expand Down

0 comments on commit 8f577b4

Please sign in to comment.