closes #258, MARC translator should capitalize titles
This commit is contained in:
parent
e5404f4938
commit
2b0bebe7a4
2 changed files with 43 additions and 3 deletions
|
@ -132,6 +132,39 @@ Scholar.Utilities.prototype.itemTypeExists = function(type) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleans a title, capitalizing the proper words and replacing " :" with ":"
|
||||
*/
|
||||
Scholar.Utilities.capitalizeSkipWords = ["but", "or", "yet", "so", "for", "and",
|
||||
"nor", "a", "an", "the", "at", "by", "from", "in", "into", "of", "on", "to",
|
||||
"with", "up", "down"];
|
||||
Scholar.Utilities.prototype.capitalizeTitle = function(title) {
|
||||
title = title.replace(/ : /g, ": ");
|
||||
var words = title.split(" ");
|
||||
|
||||
// always capitalize first
|
||||
words[0] = words[0][0].toUpperCase() + words[0].substr(1);
|
||||
if(words.length > 1) {
|
||||
var lastWordIndex = words.length-1;
|
||||
// always capitalize last
|
||||
words[lastWordIndex] = words[lastWordIndex][0].toUpperCase() + words[lastWordIndex].substr(1);
|
||||
|
||||
if(words.length > 2) {
|
||||
for(var i=1; i<lastWordIndex; i++) {
|
||||
// if not a skip word
|
||||
if(Scholar.Utilities.capitalizeSkipWords.indexOf(words[i].toLowerCase()) == -1 ||
|
||||
words[i-1][words[i-1].length-1] == ":") {
|
||||
words[i] = words[i][0].toUpperCase() + words[i].substr(1);
|
||||
} else {
|
||||
words[i] = words[i].toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
/*
|
||||
* END SCHOLAR FOR FIREFOX EXTENSIONS
|
||||
*/
|
||||
|
|
13
scrapers.sql
13
scrapers.sql
|
@ -1,4 +1,4 @@
|
|||
-- 74
|
||||
-- 75
|
||||
|
||||
-- Set the following timestamp to the most recent scraper update date
|
||||
REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-31 22:44:00'));
|
||||
|
@ -185,7 +185,7 @@ REPLACE INTO "translators" VALUES ('838d8849-4ffb-9f44-3d0d-aa8a0a079afe', '2006
|
|||
if(title.substring(title.length-2) == " /") {
|
||||
title = title.substring(0, title.length-2);
|
||||
}
|
||||
newItem.title = title;
|
||||
newItem.title = Scholar.Utilities.capitalizeTitle(title);
|
||||
} else if(match[1] == ''Author(s)'') {
|
||||
var yearRegexp = /[0-9]{4}-([0-9]{4})?/;
|
||||
|
||||
|
@ -1029,7 +1029,7 @@ REPLACE INTO "translators" VALUES ('add7c71c-21f3-ee14-d188-caf9da12728b', '2006
|
|||
newItem.ISBN = m[0];
|
||||
} else if(field == "title") {
|
||||
var titleParts = value.split(" / ");
|
||||
newItem.title = titleParts[0];
|
||||
newItem.title = Scholar.Utilities.capitalizeTitle(titleParts[0]);
|
||||
} else if(field == "publication info") {
|
||||
var pubParts = value.split(" : ");
|
||||
newItem.place = pubParts[0];
|
||||
|
@ -3679,6 +3679,9 @@ function processOWC(doc) {
|
|||
var spanTitle = spanTags[i].getAttribute("title");
|
||||
var item = new Scholar.Item();
|
||||
if(Scholar.Utilities.parseContextObject(spanTitle, item)) {
|
||||
if(item.title) {
|
||||
item.title = Scholar.Utilities.capitalizeTitle(item.title);
|
||||
}
|
||||
item.complete();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -5934,6 +5937,10 @@ record.prototype.translate = function(item) {
|
|||
this._associateDBField(item, "070", "ab", "callNumber");
|
||||
this._associateDBField(item, "060", "ab", "callNumber");
|
||||
this._associateDBField(item, "050", "ab", "callNumber");
|
||||
|
||||
if(item.title) {
|
||||
item.title = Scholar.Utilities.capitalizeTitle(item.title);
|
||||
}
|
||||
}
|
||||
|
||||
function doImport() {
|
||||
|
|
Loading…
Reference in a new issue