www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 2b0bebe7a462ae95c45653cf9594a18191b6c1bf
parent e5404f4938eaec2032a727cb9d19a25fa3f43ec4
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon,  4 Sep 2006 18:16:50 +0000

closes #258, MARC translator should capitalize titles


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/utilities.js | 33+++++++++++++++++++++++++++++++++
Mscrapers.sql | 13++++++++++---
2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/utilities.js b/chrome/chromeFiles/content/scholar/xpcom/utilities.js @@ -133,6 +133,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 */ diff --git a/scrapers.sql b/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() {