Skip to content

Commit

Permalink
Merge pull request Aspen-Discovery#1959 from Abhyastamita/24.09.00
Browse files Browse the repository at this point in the history
Add target audience diagnostics
  • Loading branch information
mdnoble73 authored Aug 7, 2024
2 parents 822bac8 + 7582b2e commit a19cd81
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ private String loadAxis360Subjects(AbstractGroupedWorkSolr groupedWork, JSONObje
groupedWork.addLiteraryFormsFull(literaryFormFull);
}
}

if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is " + targetAudience + " based on Boundless record", 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience list is " + targetAudienceFull + " based on Boundless record", 2);}
groupedWork.addTargetAudience(targetAudience);
groupedWork.addTargetAudienceFull(targetAudienceFull);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier
if (targetAudience.equals("ADULT")) {
targetAudience = "Adult";
}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is " + targetAudience + " based on cloudLibrary record", 2);}
groupedWork.addTargetAudience(targetAudience);

boolean isAdult = targetAudience.equalsIgnoreCase("Adult");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ SolrInputDocument getSolrDocument(BaseIndexingLogEntry logEntry) {
if (targetAudience.isEmpty()) {
targetAudience.add(groupedWorkIndexer.getTreatUnknownAudienceAs());
}
if (this.isDebugEnabled()) {this.addDebugMessage("Final target audience is " + targetAudience, 4);}
if (this.isDebugEnabled()) {this.addDebugMessage("Final full target audience is " + targetAudienceFull, 4);}
doc.addField("target_audience", targetAudience);
doc.addField("system_list", systemLists);
//Date added to catalog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isKids = true;
groupedWork.addTargetAudience("Juvenile");
groupedWork.addTargetAudienceFull("Juvenile");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Juvenile based on Hoopla record", 2);}
}else {
//Todo: Also check the genres (Children's, Teen
boolean foundAudience = false;
Expand All @@ -171,21 +172,27 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isTeen = true;
groupedWork.addTargetAudience("Young Adult");
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla genre", 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla genre", 2);}
foundAudience = true;
} else if (genres.getString(i).startsWith("Young Adult")) {
isTeen = true;
groupedWork.addTargetAudience("Young Adult");
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla genre", 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla genre", 2);}
foundAudience = true;
} else if (genres.getString(i).equals("Children's")) {
isKids = true;
groupedWork.addTargetAudience("Juvenile");
groupedWork.addTargetAudienceFull("Juvenile");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Juvenile based on Hoopla genre", 2);}
foundAudience = true;
} else if (genres.getString(i).equals("Adult")) {
isAdult = true;
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla genre", 2);}
foundAudience = true;
}
}
Expand All @@ -198,6 +205,7 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isAdult = true;
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating", 2);}
} else {
if (kind.equals("MOVIE") || kind.equals("TELEVISION")) {
switch (rating) {
Expand All @@ -209,6 +217,7 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isAdult = true;
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating " + rating, 2);}
break;
case "PG-13":
case "PG13":
Expand All @@ -221,15 +230,19 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isTeen = true;
groupedWork.addTargetAudience("Young Adult");
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla rating " + rating, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla rating " + rating, 2);}
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating " + rating, 2);}
break;
case "TVY":
case "TVY7":
case "NRC":
isKids = true;
groupedWork.addTargetAudience("Juvenile");
groupedWork.addTargetAudienceFull("Juvenile");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Juvenile based on Hoopla rating " + rating, 2);}
break;
case "TVG":
case "G":
Expand All @@ -238,6 +251,7 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isAdult = true;
groupedWork.addTargetAudience("General");
groupedWork.addTargetAudienceFull("General");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is General based on Hoopla rating " + rating, 2);}
break;
default:
//todo, do we want to add additional ratings here?
Expand All @@ -250,26 +264,33 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
isKids = true;
groupedWork.addTargetAudience("Juvenile");
groupedWork.addTargetAudienceFull("Juvenile");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Juvenile based on Hoopla rating " + rating, 2);}
break;
case "PA":
case "EX":
isAdult = true;
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating " + rating, 2);}
break;
case "T":
isTeen = true;
groupedWork.addTargetAudience("Young Adult");
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla rating " + rating, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla rating " + rating, 2);}
break;
case "T+":
default:
isAdult = true;
isTeen = true;
groupedWork.addTargetAudience("Young Adult");
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla rating " + rating, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla rating " + rating, 2);}
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating " + rating, 2);}
}

} else {
Expand All @@ -279,12 +300,16 @@ void processRecord(AbstractGroupedWorkSolr groupedWork, String identifier, BaseI
groupedWork.addTargetAudienceFull("Adolescent (14-17)");
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Hoopla rating " + rating, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Hoopla rating " + rating, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla rating " + rating, 2);}
}
}
} else if (!foundAudience) {
isAdult = true;
groupedWork.addTargetAudience("Adult");
groupedWork.addTargetAudienceFull("Adult");
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Adult based on Hoopla record", 2);}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1788,45 +1788,55 @@ HashSet<String> translateCollection(String mapName, Set<String> values, String i

protected void loadTargetAudiences(AbstractGroupedWorkSolr groupedWork, org.marc4j.marc.Record record, ArrayList<ItemInfo> printItems, String identifier) {
if (settings.getDetermineAudienceBy() == 0) {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Determining target audience by bib record data", 1);}
super.loadTargetAudiences(groupedWork, record, printItems, identifier, settings.getTreatUnknownAudienceAs());
}else{
HashSet<String> targetAudiences = new HashSet<>();
if (settings.getDetermineAudienceBy() == 1) {
//Load based on collection
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Determining audience by collection", 1);}
for (ItemInfo printItem : printItems){
String collection = printItem.getCollection();
if (collection != null) {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience code includes " + collection.toLowerCase() + " based on collection for item " + printItem.getItemIdentifier(), 1);}
targetAudiences.add(collection.toLowerCase());
}
}
}else if (settings.getDetermineAudienceBy() == 2) {
//Load based on shelf location
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Determining audience by location", 1);}
for (ItemInfo printItem : printItems){
String shelfLocationCode = printItem.getShelfLocationCode();
if (shelfLocationCode != null) {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience includes code " + shelfLocationCode.toLowerCase() + " based on shelf location for item " + printItem.getItemIdentifier(), 1);}
targetAudiences.add(shelfLocationCode.toLowerCase());
}
}
}else if (settings.getDetermineAudienceBy() == 3){
//Load based on a specified subfield
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Determining audience by subfield " + settings.getAudienceSubfield(), 1);}
for (ItemInfo printItem : printItems){
List<String> audienceCodes = printItem.getSubfields(settings.getAudienceSubfield());
for (String audienceCode : audienceCodes) {
String audienceCodeLower = audienceCode.toLowerCase();
if (hasTranslation("audience", audienceCodeLower)) {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience includes code " + audienceCodeLower + " based on subfield for item " + printItem.getItemIdentifier(), 1);}
targetAudiences.add(audienceCodeLower);
}
}
}
}
HashSet<String> translatedAudiences = translateCollection("audience", targetAudiences, identifier, true);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience code(s) " + targetAudiences + " translate(s) to " + translatedAudiences, 1);}

if (! settings.getTreatUnknownAudienceAs().equals("Unknown") && translatedAudiences.contains("Unknown")) {
translatedAudiences.remove("Unknown");
translatedAudiences.add( settings.getTreatUnknownAudienceAs());
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Replacing unknown target audience with " + settings.getTreatUnknownAudienceAs(), 1);}
}
if (translatedAudiences.isEmpty()){
//We didn't get anything from the items (including Unknown), check the bib record
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Could not find target audience based on item - checking the bib record", 1);}
super.loadTargetAudiences(groupedWork, record, printItems, identifier, settings.getTreatUnknownAudienceAs());
}else {
groupedWork.addTargetAudiences(translatedAudiences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,17 +631,21 @@ protected void loadTargetAudiences(AbstractGroupedWorkSolr groupedWork, org.marc
targetAudienceChar = Character.toUpperCase(ohOhSixField.getData().charAt(5));
if (targetAudienceChar != ' ') {
targetAudiences.add(Character.toString(targetAudienceChar));
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience determined by 006/5", 2);}
}
}
if (targetAudiences.isEmpty() && ohOhEightField != null && ohOhEightField.getData().length() > 22) {
targetAudienceChar = Character.toUpperCase(ohOhEightField.getData().charAt(22));
if (targetAudienceChar != ' ') {
targetAudiences.add(Character.toString(targetAudienceChar));
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience determined by 008/22", 2);}
}
} else if (targetAudiences.isEmpty()) {
targetAudiences.add(unknownAudienceLabel);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience " + unknownAudienceLabel + " because 006/5 and 008/22 did not exist", 2);}
}
} else {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience unknown based on Leader 6/7", 2);}
targetAudiences.add(unknownAudienceLabel);
}
} catch (Exception e) {
Expand All @@ -651,30 +655,36 @@ protected void loadTargetAudiences(AbstractGroupedWorkSolr groupedWork, org.marc
}

if (targetAudiences.isEmpty()) {
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is " + unknownAudienceLabel + " because 006/5 and 008/22 were both blank", 2);}
targetAudiences.add(unknownAudienceLabel);
}

LinkedHashSet<String> translatedAudiences;
if (settings == null) {
translatedAudiences = indexer.translateSystemCollection("target_audience", targetAudiences, identifier);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is " + translatedAudiences + " based on system target_audience translation map", 2);}
}else{
translatedAudiences = settings.translateCollection("target_audience", targetAudiences, identifier, indexer.getLogEntry(), logger, true);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is " + translatedAudiences + " based on target_audience translation map in settings", 2);}
}
if (!unknownAudienceLabel.equals("Unknown") && translatedAudiences.contains("Unknown")){
translatedAudiences.remove("Unknown");
translatedAudiences.add(unknownAudienceLabel);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Updating unknown target audience to " + unknownAudienceLabel, 2);}
}
groupedWork.addTargetAudiences(translatedAudiences);

LinkedHashSet<String> translatedAudiencesFull;
if (settings == null) {
translatedAudiencesFull = indexer.translateSystemCollection("target_audience_full", targetAudiences, identifier);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is " + translatedAudiencesFull + " based on system target_audience translation map", 2);}
}else {
translatedAudiencesFull = settings.translateCollection("target_audience_full", targetAudiences, identifier, indexer.getLogEntry(), logger, true);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is " + translatedAudiencesFull + " based on target_audience translation map in settings", 2);}
}
if (!unknownAudienceLabel.equals("Unknown") && translatedAudiencesFull.contains("Unknown")){
translatedAudiencesFull.remove("Unknown");
translatedAudiencesFull.add(unknownAudienceLabel);
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Updating unknown full target audience to " + unknownAudienceLabel, 2);}
}
groupedWork.addTargetAudiencesFull(translatedAudiencesFull);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,22 @@ private String loadOverDriveSubjects(AbstractGroupedWorkSolr groupedWork, JSONOb
if (curSubject.contains("Juvenile")) {
targetAudience = "Juvenile";
targetAudienceFull = "Juvenile";
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target/full target audience is Juvenile based on Overdrive subject " + curSubject, 2);}
} else if (curSubject.contains("Young Adult")) {
targetAudience = "Young Adult";
targetAudienceFull = "Adolescent (14-17)";
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Young Adult based on Overdrive subject " + curSubject, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Adolescent (14-17) based on Overdrive subject " + curSubject, 2);}
} else if (curSubject.contains("Picture Book")) {
targetAudience = "Juvenile";
targetAudienceFull = "Preschool (0-5)";
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Juvenile based on Overdrive subject " + curSubject, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Preschool (0-5) based on Overdrive subject " + curSubject, 2);}
} else if (curSubject.contains("Beginning Reader")) {
targetAudience = "Juvenile";
targetAudienceFull = "Primary (6-8)";
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Target audience is Juvenile based on Overdrive subject " + curSubject, 2);}
if (groupedWork != null && groupedWork.isDebugEnabled()) {groupedWork.addDebugMessage("Full target audience is Primary (6-8) based on Overdrive subject " + curSubject, 2);}
}

topics.add(curSubject);
Expand Down
Loading

0 comments on commit a19cd81

Please sign in to comment.