Skip to content

Commit 1d0d376

Browse files
EKIRJASTO-127 Commented debugging code
Could be useful later on to analyze how well any improvement attempts work
1 parent 9c63b74 commit 1d0d376

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

core/classifier/bisac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(self, result, *ruleset):
111111

112112
# Mostly for debugging purposes
113113
def __repr__(self):
114-
caught_str = ', '.join(str(item) for item in self.caught)
114+
caught_str = ", ".join(str(item) for item in self.caught)
115115
return f"MatchingRule(ruleset={self.ruleset}, caught=[{caught_str}])"
116116

117117
def match(self, *subject):

tests/core/classifiers/test_bisac.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,29 @@ def test_every_rule_fires(self):
150150
subjects = []
151151
for identifier, name in sorted(BISACClassifier.NAMES.items()):
152152
subjects.append(self._subject(identifier, name))
153+
154+
# caught_fiction_rules = []
153155
for i in BISACClassifier.FICTION:
154156
if i.caught == []:
157+
# caught_fiction_rules.append(i)
155158
raise Exception("Fiction rule %s didn't catch anything!" % i.ruleset)
159+
# print("Caught fiction rules: ", len(caught_fiction_rules))
160+
# for rule in caught_fiction_rules:
161+
# print(rule)
156162

163+
# caught_genre_rules = []
157164
for i in BISACClassifier.GENRE:
158165
if i.caught == []:
166+
# caught_genre_rules.append(i)
159167
raise Exception("Genre rule %s didn't catch anything!" % i.ruleset)
168+
# print("Caught genre rules: ", len(caught_genre_rules))
169+
# for rule in caught_genre_rules:
170+
# print(rule)
160171

161172
need_fiction = []
162173
need_audience = []
163174
for subject in subjects:
164-
if subject.fiction is None: # == humor, drama
175+
if subject.fiction is None: # == humor, drama
165176
need_fiction.append(subject)
166177
if subject.audience is None:
167178
need_audience.append(subject)
@@ -182,8 +193,13 @@ def test_every_rule_fires(self):
182193
# Not every subject has to be classified under a genre, but
183194
# if it's possible for one to be, it should be. This is the place
184195
# to check how well the current rules are operating.
185-
#
196+
197+
# DEBUGGING:
186198
# need_genre = sorted(x.name for x in subjects if x.genre is None)
199+
# print("Bisac subjects without a genre: ", len(need_genre))
200+
# print("Subjects without a genre: ")
201+
# for genre in need_genre:
202+
# print(genre)
187203

188204
def test_genre_spot_checks(self):
189205
"""Test some unusual cases with respect to how BISAC
@@ -203,7 +219,7 @@ def test_genre_spot_checks(self):
203219
genre_is(
204220
"History / Modern / 17th Century", "Renaissance & Early Modern History"
205221
)
206-
genre_is("Biography & Autobiography / Music","Music"),
222+
genre_is("Biography & Autobiography / Music", "Music"),
207223
genre_is(
208224
"Biography & Autobiography / Entertainment & Performing Arts",
209225
"Entertainment",

0 commit comments

Comments
 (0)