Skip to content

Commit

Permalink
Better use of call numbers for similar items (vufind-org#4119)
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-git authored Dec 10, 2024
1 parent 8976d13 commit bda7ee0
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 28 deletions.
73 changes: 69 additions & 4 deletions import/index_java/src/org/vufind/index/CallNumberTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand All @@ -40,23 +41,25 @@
public class CallNumberTools
{
/**
* Extract the call number label from a record
* Extract the first call number label from a record
* @deprecated Please use getCallNumberLabels instead
* @param record MARC record
* @return Call number label
*/
@Deprecated
public String getCallNumberLabel(final Record record) {

return getCallNumberLabel(record, "090a:050a");
}

/**
* Extract the call number label from a record
* Extract the first call number label from a record.
* @deprecated Please use getCallNumberLabels instead
* @param record MARC record
* @param fieldSpec taglist for call number fields
* @return Call number label
*/
@Deprecated
public String getCallNumberLabel(final Record record, String fieldSpec) {

String val = SolrIndexer.instance().getFirstFieldVal(record, fieldSpec);

if (val != null) {
Expand All @@ -70,6 +73,68 @@ public String getCallNumberLabel(final Record record, String fieldSpec) {
}
}

/**
* Extract the call number labels from a record
* @param record MARC record
* @return Call number labels
*/
public List<String> getCallNumberLabels(final Record record) {
return getCallNumberLabels(record, "050a:082a:083a:090a");
}

/**
* Extract the call number labels from a record.
* fieldSpec might include 952e for FOLIO, in which case we do not know the type of call number
* (also sometimes call numbers are in the wrong MARC field for their type).
* If LCC: classLetters, classLetters + classDigits, classLetters + classDigits + classDecimal
* If Dewey: classDigits, classDigits + classDecimal
* Otherwise: everything up until the dot (or everything if there is no dot)
* @param record MARC record
* @param fieldSpec taglist for call number fields
* @return Call number labels
*/
public List<String> getCallNumberLabels(final Record record, String fieldSpec) {
Set<String> values = SolrIndexer.instance().getFieldList(record, fieldSpec);
HashSet<String> result = new LinkedHashSet<String>();
for (String cn: values) {
String cnUp = cn.toUpperCase().trim();
LCCallNumber lcc = new LCCallNumber(cnUp);
DeweyCallNumber dewey = new DeweyCallNumber(cnUp);
boolean other = cnUp.contains(":") || (cnUp.length() > 10 && !cnUp.contains("."));
boolean isLcc = lcc.isValid() && !other;
boolean isDewey = dewey.isValid() && !other;
if (isLcc) {
result.add(lcc.getClassLetters());
result.add(lcc.getClassLetters() + lcc.getClassDigits());
if (lcc.getClassDecimal() != null) {
result.add(lcc.getClassLetters() + lcc.getClassDigits() + lcc.getClassDecimal());
}
} else if (isDewey) {
result.add(dewey.getClassDigits());
String classDecimal = dewey.getClassDecimal();
if (classDecimal != null) {
for (int i=1; i<5; i++) {
if (classDecimal.length() > i) {
result.add(dewey.getClassDigits() + classDecimal.substring(0, i+1));
}
}
}
} else {
// NOTE: we could add other classifications like SuDoc here (and add related MARC fields to fieldSpec)
int dotPos = cnUp.indexOf(".");
if (dotPos < 0) {
result.add(cnUp);
continue;
}
if (dotPos == 0) {
continue;
}
result.add(cnUp.substring(0, dotPos).trim());
}
}
return new ArrayList<String>(result);
}

/**
* Extract the subject component of the call number
*
Expand Down
2 changes: 1 addition & 1 deletion import/marc.properties
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ issn = 022a:440x:490x:730x:773x:776x:780x:785x

callnumber-first = 099a[0]:090a[0]:050a[0], callnumber_map.properties, first
callnumber-subject = custom, getCallNumberSubject(090a:050a), callnumber_subject_map.properties
callnumber-label = custom, getCallNumberLabel(090a:050a)
callnumber-label = custom, getCallNumberLabels(050a:082a:083a:090a)
callnumber-sort = custom, getLCSortable(099ab:090ab:050ab)
callnumber-raw = 099ab:090ab:050ab

Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/tests/fixtures/misc/testbug2.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"callnumber-subject-code":"DG",
"spelling":"Vico, Giambattista, 1668-1744. Principum Neapolitanorum coniurationis anni MDCCI historia. Italian & Latin La congiura dei Principi Napoletani 1701 : (prima e seconda stesura) / Giambattista Vico ; a cura di Claudia Pandolfi. Fictional edition. Morano : Centro di Studi Vichiani, 1992. 296 p. : ill. ; 24 cm. Opere di Giambattista Vico ; 2/1 Italian and Latin. Includes bibliographical references (p. [277]-281) and index. Sample abstract. April11phi Naples (Kingdom) History Spanish rule, 1442-1707 Sources. Pandolfi, Claudia. Vico, Giambattista, 1668-1744. Works. 1982 ; 2, pt. 1. http://fictional.com/sample/url",
"title_sub":"(prima e seconda stesura) /",
"callnumber-label":"DG848",
"callnumber-label":["DG848"],
"record_format":"marc",
"callnumber-first":"D - World History",
"title_auth":"La congiura dei Principi Napoletani 1701 : (prima e seconda stesura) /",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42001",
"callnumber-raw":["PS3552.R878 T47 2001"],
"callnumber-search":["PS3552.R878 T47 2001"],
Expand Down Expand Up @@ -157,7 +157,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42021",
"callnumber-raw":["PS3552.R878 T47 2021"],
"callnumber-search":["PS3552.R878 T47 2021"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42001",
"callnumber-raw":["PS3552.R878 T47 2001"],
"callnumber-search":["PS3552.R878 T47 2001"],
Expand Down Expand Up @@ -157,7 +157,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42021",
"callnumber-raw":["PS3552.R878 T47 2021"],
"callnumber-search":["PS3552.R878 T47 2021"],
Expand Down Expand Up @@ -233,7 +233,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -309,7 +309,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -385,7 +385,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42001",
"callnumber-raw":["PS3552.R878 T47 2001"],
"callnumber-search":["PS3552.R878 T47 2001"],
Expand Down Expand Up @@ -157,7 +157,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42021",
"callnumber-raw":["PS3552.R878 T47 2021"],
"callnumber-search":["PS3552.R878 T47 2021"],
Expand Down Expand Up @@ -233,7 +233,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -309,7 +309,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -385,7 +385,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -461,7 +461,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -537,7 +537,7 @@
"isbn":["1558612742 (pbk. : alk. paper)"],
"callnumber-first":"P - Language and Literature",
"callnumber-subject":"PS - American Literature",
"callnumber-label":"PS3552",
"callnumber-label":["PS3552"],
"callnumber-sort":"PS 43552 R878 T47 42011",
"callnumber-raw":["PS3552.R878 T47 2011"],
"callnumber-search":["PS3552.R878 T47 2011"],
Expand Down Expand Up @@ -608,7 +608,7 @@
"isbn":["8820737493"],
"callnumber-first":"D - World History",
"callnumber-subject":"DG - Italy, Malta",
"callnumber-label":"DG848",
"callnumber-label":["DG848"],
"callnumber-sort":"DG 3848.15 V53 41992",
"callnumber-raw":["DG848.15 .V53 1992"],
"callnumber-search":["DG848.15 .V53 1992"],
Expand Down Expand Up @@ -661,7 +661,7 @@
"isbn":["8820737493"],
"callnumber-first":"D - World History",
"callnumber-subject":"DG - Italy, Malta",
"callnumber-label":"DG848",
"callnumber-label":["DG848"],
"callnumber-sort":"DG 3848.15 V53 41992",
"callnumber-raw":["DG848.15 .V53 1992"],
"callnumber-search":["DG848.15 .V53 1992"],
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit bda7ee0

Please sign in to comment.