Skip to content

Commit

Permalink
Merge pull request #101 from NatLibFi/Classify-Poetry-as-Fiction
Browse files Browse the repository at this point in the history
EKIR-389 Classify poetry as fiction
  • Loading branch information
natlibfi-kaisa authored Oct 3, 2024
2 parents 7d58a67 + 294cb09 commit 9de2d77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/classifier/bisac.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class BISACClassifier(Classifier):
m(True, "Literary Collections"),
m(stop, "Humor"),
m(stop, "Drama"),
m(stop, "Poetry"),
m(True, "Poetry"),
m(False, anything),
]

Expand Down
12 changes: 11 additions & 1 deletion core/model/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,22 @@ def __repr__(self):
length = len(classifier.genres[self.name].subgenres)
else:
length = 0
return "<Genre %s (%d subjects, %d works, %d subcategories)>" % (
genre_data = "<Genre %s (%d subjects, %d works, %d subcategories)>" % (
self.name,
len(self.subjects),
len(self.works),
length,
)
genre_data += "\n <Subjects: %s>" % (
", ".join(
[
f"{subject.name} ({subject.type}, {subject.identifier})"
for subject in self.subjects
]
)
)

return genre_data

def cache_key(self):
return self.name
Expand Down
17 changes: 11 additions & 6 deletions tests/core/classifiers/test_bisac.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ def test_every_rule_fires(self):
# We determined fiction/nonfiction status for every BISAC
# subject except for humor, drama, and poetry.
for subject in need_fiction:
assert any(
subject.name.lower().startswith(x) for x in ["humor", "drama", "poetry"]
)
assert any(subject.name.lower().startswith(x) for x in ["humor", "drama"])

# We determined the target audience for every BISAC subject.
assert [] == need_audience
Expand Down Expand Up @@ -228,6 +226,10 @@ def test_genre_spot_checks(self):

genre_is("Young Adult Fiction / Poetry", "Poetry")
genre_is("Poetry", "Poetry")
# Making sure we classify Poetry as Poetry
genre_is("Poetry / European / General", "Poetry")
# Making sure we classify Literary Criticism as such, not Poetry
genre_is("Literary Criticism / Poetry", "Literary Criticism")

# Grandfathered in from an older test to validate that the new
# BISAC algorithm gives the same results as the old one.
Expand Down Expand Up @@ -262,13 +264,16 @@ def fiction_is(name, expect):
fiction_is("Fiction / Science Fiction", True)
fiction_is("Antiques & Collectibles / Kitchenware", False)

# Humor, drama and poetry do not have fiction classifications
# Humor and drama do not have fiction classifications
# unless the fiction classification comes from elsewhere in the
# subject.
# subject. Poetry used y´to be in this category but as changed in
# e-kirjasto.
fiction_is("Humor", None)
fiction_is("Drama", None)
fiction_is("Poetry", None)
fiction_is("Poetry / Russian & Former Soviet Union", True)
fiction_is("Young Adult Fiction / Poetry", True)
# When Poetry is a subclass, fiction status is based on the upper class.
fiction_is("Literary Criticism / Poetry", False)

fiction_is("Young Adult Nonfiction / Humor", False)
fiction_is("Juvenile Fiction / Humorous Stories", True)
Expand Down

0 comments on commit 9de2d77

Please sign in to comment.