Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dict-trie
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Laros
dict-trie
Commits
c1c3d4ed
Commit
c1c3d4ed
authored
Aug 04, 2017
by
Laros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepared support for different types of leaf nodes.
parent
53880f20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
26 deletions
+29
-26
dict_trie/dict_trie.py
dict_trie/dict_trie.py
+29
-26
No files found.
dict_trie/dict_trie.py
View file @
c1c3d4ed
...
...
@@ -73,8 +73,9 @@ def _iterate(path, node):
yield
path
for
char
in
node
:
for
result
in
_iterate
(
path
+
char
,
node
[
char
]):
yield
result
if
char
:
for
result
in
_iterate
(
path
+
char
,
node
[
char
]):
yield
result
def
_fill
(
node
,
alphabet
,
length
):
...
...
@@ -117,16 +118,17 @@ def _hamming(path, node, word, distance, cigar):
car
,
cdr
=
word
[
0
],
word
[
1
:]
for
char
in
node
:
if
char
==
car
:
penalty
=
0
operation
=
'='
else
:
penalty
=
1
operation
=
'X'
for
result
in
_hamming
(
path
+
char
,
node
[
char
],
cdr
,
distance
-
penalty
,
cigar
+
operation
):
yield
result
if
char
:
if
char
==
car
:
penalty
=
0
operation
=
'='
else
:
penalty
=
1
operation
=
'X'
for
result
in
_hamming
(
path
+
char
,
node
[
char
],
cdr
,
distance
-
penalty
,
cigar
+
operation
):
yield
result
def
_levenshtein
(
path
,
node
,
word
,
distance
,
cigar
):
...
...
@@ -155,22 +157,23 @@ def _levenshtein(path, node, word, distance, cigar):
yield
result
for
char
in
node
:
# Substitution.
if
car
:
if
char
==
car
:
penalty
=
0
operation
=
'='
else
:
penalty
=
1
operation
=
'X'
if
char
:
# Substitution.
if
car
:
if
char
==
car
:
penalty
=
0
operation
=
'='
else
:
penalty
=
1
operation
=
'X'
for
result
in
_levenshtein
(
path
+
char
,
node
[
char
],
cdr
,
distance
-
penalty
,
cigar
+
operation
):
yield
result
# Insertion.
for
result
in
_levenshtein
(
path
+
char
,
node
[
char
],
cdr
,
distance
-
penalty
,
cigar
+
operation
):
path
+
char
,
node
[
char
],
word
,
distance
-
1
,
cigar
+
'I'
):
yield
result
# Insertion.
for
result
in
_levenshtein
(
path
+
char
,
node
[
char
],
word
,
distance
-
1
,
cigar
+
'I'
):
yield
result
class
Trie
(
object
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment