Skip to content

Commit

Permalink
Merge pull request #34 from rskmoi/feature/fix_bug_with_long_name
Browse files Browse the repository at this point in the history
Fixed bug with long name
  • Loading branch information
rskmoi authored Jul 17, 2023
2 parents d2b260d + 0041fea commit ececbe9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions namedivider/feature/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ def _create_length_mask(full_name_length: int, char_idx: int) -> npt.NDArray[np.
:rtype: np.ndarray
"""
min_family = char_idx + 1
min_family_idx = 4 if min_family > 4 else min_family
max_family = full_name_length - 1
max_family = 4 if max_family > 4 else max_family
max_family_idx = 4 if max_family > 4 else max_family
min_given = full_name_length - char_idx
min_given_idx = 4 if min_given > 4 else min_given
max_given = full_name_length - 1
max_given = 4 if max_given > 4 else max_given
max_given_idx = 4 if max_given > 4 else max_given
lc_family = np.array([0, 0, 0, 0])
if min_family <= max_family:
lc_family[min_family - 1 : max_family] = 1
lc_family[min_family_idx - 1 : max_family_idx] = 1
lc_given = np.array([0, 0, 0, 0])
if min_given <= max_given:
lc_given[min_given - 1 : max_given] = 1
lc_given[min_given_idx - 1 : max_given_idx] = 1
return np.concatenate([lc_family, lc_given])


Expand Down
16 changes: 16 additions & 0 deletions tests/feature/test_functional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np
import pytest

from namedivider.feature.functional import _create_length_mask

test_data = [
(2, 0, np.array([1, 0, 0, 0, 0, 0, 0, 0])), # short name
(5, 3, np.array([0, 0, 0, 1, 0, 1, 1, 1])), # middle name
(8, 1, np.array([0, 1, 1, 1, 0, 0, 0, 1])), # long name
]


@pytest.mark.parametrize("full_name_length, char_idx, expect", test_data)
def test_create_length_mask(full_name_length: int, char_idx: int, expect: np.ndarray):
mask = _create_length_mask(full_name_length=full_name_length, char_idx=char_idx)
assert (mask == expect).all()

0 comments on commit ececbe9

Please sign in to comment.