Skip to content

Commit

Permalink
Update item_rep_method.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenyueh authored Feb 19, 2023
1 parent b9feb8a commit a05ceaa
Showing 1 changed file with 0 additions and 113 deletions.
113 changes: 0 additions & 113 deletions item_rep_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,116 +38,3 @@ def no_tokenization():
}
return lambda x: mapping[x]


def composition_resolution(item_index, resolution, overlap):
assert type(item_index) == str
assert resolution > 0
assert resolution > overlap
sub_indices = []
number_of_sub_indices = math.ceil(len(item_index) / (resolution - overlap))
for i in range(number_of_sub_indices):
sub_indices.append(
item_index[
i * (resolution - overlap) : (i * (resolution - overlap) + resolution)
]
)
split_zero_sub_indices = []
for i in range(len(sub_indices)):
if sub_indices[i].startswith("0"):
zero_index = sub_indices[i]
j = 0
while zero_index[j:].startswith("0"):
split_zero_sub_indices.append("0")
j += 1
if zero_index[j:] != "":
split_zero_sub_indices.append(zero_index[j:])
else:
split_zero_sub_indices.append(sub_indices[i])

return split_zero_sub_indices


def unit_test_composition_resolution():
######## no overlap ########
######## no overlap ########
# test 1
item_index = "1230"
resolution = 2
overlap = 0
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["12", "30"]

# test 2
item_index = "12301"
resolution = 2
overlap = 0
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["12", "30", "1"]

# test 3
item_index = "12301"
resolution = 3
overlap = 0
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["123", "0", "1"]

# test 4
item_index = "123010"
resolution = 3
overlap = 0
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["123", "0", "10"]

######## with overlap = 1 ########
######## with overlap = 1 ########
# test 5
item_index = "123010"
resolution = 2
overlap = 1
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["12", "23", "30", "0", "1", "10", "0"]

# test 6
item_index = "123010"
resolution = 3
overlap = 1
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["123", "301", "10"]

# test 7
item_index = "123010"
resolution = 3
overlap = 1
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["1230", "0", "10"]

# test 8
item_index = "123010"
resolution = 5
overlap = 1
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["12301", "10"]

######## with overlap = 2 ########
######## with overlap = 2 ########
# test 8
item_index = "1"
resolution = 4
overlap = 2
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["1"]

# test 9
item_index = "12"
resolution = 4
overlap = 2
sub_indices = composition_resolution(item_index, resolution, overlap)
assert sub_indices == ["12"]


if __name__ == "__main__":
item_index = "12"
resolution = 4
overlap = 2
sub_indices = composition_resolution(item_index, resolution, overlap)
print(sub_indices)

0 comments on commit a05ceaa

Please sign in to comment.