Skip to content

Commit

Permalink
EKIRJASTO-127 Commented debugging code
Browse files Browse the repository at this point in the history
Could be useful later on to analyze how well any improvement attempts work
  • Loading branch information
natlibfi-kaisa committed Nov 18, 2024
1 parent 9c63b74 commit 1d0d376
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/classifier/bisac.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, result, *ruleset):

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

def match(self, *subject):
Expand Down
22 changes: 19 additions & 3 deletions tests/core/classifiers/test_bisac.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,29 @@ def test_every_rule_fires(self):
subjects = []
for identifier, name in sorted(BISACClassifier.NAMES.items()):
subjects.append(self._subject(identifier, name))

# caught_fiction_rules = []
for i in BISACClassifier.FICTION:
if i.caught == []:
# caught_fiction_rules.append(i)
raise Exception("Fiction rule %s didn't catch anything!" % i.ruleset)
# print("Caught fiction rules: ", len(caught_fiction_rules))
# for rule in caught_fiction_rules:
# print(rule)

# caught_genre_rules = []
for i in BISACClassifier.GENRE:
if i.caught == []:
# caught_genre_rules.append(i)
raise Exception("Genre rule %s didn't catch anything!" % i.ruleset)
# print("Caught genre rules: ", len(caught_genre_rules))
# for rule in caught_genre_rules:
# print(rule)

need_fiction = []
need_audience = []
for subject in subjects:
if subject.fiction is None: # == humor, drama
if subject.fiction is None: # == humor, drama
need_fiction.append(subject)
if subject.audience is None:
need_audience.append(subject)
Expand All @@ -182,8 +193,13 @@ def test_every_rule_fires(self):
# Not every subject has to be classified under a genre, but
# if it's possible for one to be, it should be. This is the place
# to check how well the current rules are operating.
#

# DEBUGGING:
# need_genre = sorted(x.name for x in subjects if x.genre is None)
# print("Bisac subjects without a genre: ", len(need_genre))
# print("Subjects without a genre: ")
# for genre in need_genre:
# print(genre)

def test_genre_spot_checks(self):
"""Test some unusual cases with respect to how BISAC
Expand All @@ -203,7 +219,7 @@ def test_genre_spot_checks(self):
genre_is(
"History / Modern / 17th Century", "Renaissance & Early Modern History"
)
genre_is("Biography & Autobiography / Music","Music"),
genre_is("Biography & Autobiography / Music", "Music"),
genre_is(
"Biography & Autobiography / Entertainment & Performing Arts",
"Entertainment",
Expand Down

0 comments on commit 1d0d376

Please sign in to comment.