diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.js b/chrome/chromeFiles/content/scholar/ingester/browser.js index 6ae2839ed4..3d8f3464a0 100644 --- a/chrome/chromeFiles/content/scholar/ingester/browser.js +++ b/chrome/chromeFiles/content/scholar/ingester/browser.js @@ -292,7 +292,7 @@ Scholar_Ingester_Interface._itemDone = function(obj, item, collection) { // add item to collection, if one was specified if(collection) { - collection.addItem(item); + collection.addItem(item.getID()); } } diff --git a/chrome/chromeFiles/content/scholar/xpcom/cite.js b/chrome/chromeFiles/content/scholar/xpcom/cite.js index 58bce2b24c..98ec3e1893 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/cite.js +++ b/chrome/chromeFiles/content/scholar/xpcom/cite.js @@ -47,7 +47,6 @@ Scholar.Cite = new function() { * want to use the Scholar data model, but does want to use CSL in JavaScript */ CSL = function(csl) { - Scholar.debug(csl); this._csl = new XML(this._cleanXML(csl)); // initialize CSL @@ -72,12 +71,13 @@ CSL = function(csl) { // load options this._opt = this._parseOptions(this._csl.bibliography); - Scholar.debug(this._opt); // create an associative array of available types this._types = new Object(); + this._serializations = new Object(); for each(var type in this._csl.bibliography.layout.item.choose.type) { this._types[type.@name] = true; + this._serializations[type.@name] = new Object(); } } @@ -90,12 +90,10 @@ CSL.prototype.createBibliography = function(items, format) { this._preprocessItems(items); // sort by sort order - Scholar.debug("sorting items"); var me = this; items.sort(function(a, b) { return me._compareItem(a, b); }); - Scholar.debug(items); // disambiguate items this._disambiguateItems(items); @@ -374,7 +372,7 @@ CSL.prototype._parseFieldDefaults = function(ref) { /* * parses a list of fields into an array of objects */ -CSL.prototype._parseFields = function(ref, useDefaults) { +CSL.prototype._parseFields = function(ref, type) { var typeDesc = new Array(); for each(var element in ref) { if(element.namespace() == CSL.ns) { // ignore elements in other namespaces @@ -384,17 +382,31 @@ CSL.prototype._parseFields = function(ref, useDefaults) { // parse attributes on this field this._parseFieldAttrChildren(element, itemDesc); - // add defaults - if(useDefaults) { + // add defaults, but only if we're parsing as a reference type + if(type) { var fieldDefaults = this._getFieldDefaults(itemDesc.name); itemDesc = this._merge(fieldDefaults, itemDesc); itemDesc = this._merge(this._opt.format, itemDesc); + + // create serialized representation + itemDesc._serialized = this._serializeElement(itemDesc.name, itemDesc); + // add to serialization for type + this._serializations[itemDesc._serialized] = itemDesc; } // parse group children if(itemDesc.name == "group" && itemDesc.children) { for(var i in itemDesc.children) { - itemDesc.children[i] = this._merge(this._getFieldDefaults(itemDesc.children[i].name), itemDesc.children[i]); + // don't bother merging fieldDefaults + itemDesc.children[i] = this._merge(this._getFieldDefaults(itemDesc.children[i].name), + itemDesc.children[i]); + if(type) { + // serialize children + itemDesc.children[i]._serialized = this._serializeElement(itemDesc.children[i].name, + itemDesc.children[i]); + // add to serialization for type + this._serializations[itemDesc._serialized] = itemDesc; + } } } @@ -422,18 +434,6 @@ CSL.prototype._parseOptions = function(bibliography) { opt.hangingIndent = true; } - // author as sort order - // for our purposes, this controls whether an author is last, first or - // first last (although for internationalized names it means something - // different) - if(bibliography['@author-as-sort-order']) { - if(bibliography['@author-as-sort-order'] == "first-author") { - opt.authorAsSortOrder = "first-author"; - } else if(bibliography['@author-as-sort-order'] == "all") { - opt.authorAsSortOrder = "all"; - } - } - // sort order var algorithm = bibliography.sort.@algorithm.toString(); if(algorithm) { @@ -483,7 +483,7 @@ CSL.prototype._parseOptions = function(bibliography) { */ CSL.prototype._parseReferenceType = function(reftype) { var ref = this._csl.bibliography.layout.item.choose.type.(@name==reftype).children(); - this._types[reftype] = this._parseFields(ref, true); + this._types[reftype] = this._parseFields(ref, reftype); } /* @@ -549,13 +549,19 @@ CSL.prototype._getTerm = function(term, plural) { */ CSL.prototype._processDate = function(string) { var date = new Object(); - + var dateRe = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/; var m = dateRe.exec(string); if(m) { // sql date var jsDate = new Date(m[1], m[2]-1, m[3], false, false, false); } else { // not an sql date - var jsDate = new Date(string); + var yearRe = /^[0-9]+$/; + if(yearRe) { // is a year + date.year = string; + return date; + } else { // who knows what this is + var jsDate = new Date(string) + } } if(isNaN(jsDate.valueOf())) { // couldn't parse @@ -580,15 +586,24 @@ CSL.prototype._processDate = function(string) { * formats a string according to the cs-format attributes on element */ CSL.prototype._formatString = function(element, string, format) { - if(format != "compare" && element.prefix) { - string = element.prefix+string; + if(element["text-transform"]) { + if(element["text-transform"] == "lowercase") { + // all lowercase + string = string.toLowerCase(); + } else if(element["text-transform"] == "uppercase") { + // all uppercase + string = string.toUpperCase(); + } else if(element["text-transform"] == "capitalize") { + // capitalize first + string = string[0].toUpperCase()+string.substr(1); + } } if(format == "HTML") { var style = ""; var cssAttributes = ["font-family", "font-style", "font-variant", - "font-weight", "text-transform"]; + "font-weight"]; for(var j in cssAttributes) { if(element[cssAttributes[j]] && element[cssAttributes[j]].indexOf('"') == -1) { style += cssAttributes[j]+":"+element[cssAttributes[j]]; @@ -600,6 +615,9 @@ CSL.prototype._formatString = function(element, string, format) { } } + if(format != "compare" && element.prefix) { + string = element.prefix+string; + } if(format != "compare" && element.suffix && (element.suffix.length != 1 || string[string.length-1] != element.suffix)) { // skip if suffix is the same as the last char @@ -610,9 +628,10 @@ CSL.prototype._formatString = function(element, string, format) { } /* - * formats a locator (pages, volume, issue) + * formats a locator (pages, volume, issue) or an identifier (isbn, doi) + * note that label should be null for an identifier */ -CSL.prototype._formatLocator = function(element, number, format) { +CSL.prototype._formatLocator = function(identifier, element, number, format) { var data = ""; if(number) { @@ -623,8 +642,12 @@ CSL.prototype._formatLocator = function(element, number, format) { if(child.name == "number") { string = number; } else if(child.name == "text") { - var plural = (item.pages.indexOf(",") != -1 || item.pages.indexOf("-") != -1); + var plural = (identifier && (number.indexOf(",") != -1 + || number.indexOf("-") != -1)); string = this._getTerm(child["term-name"], plural); + } else if(identifier && child.name == "label") { + var plural = (number.indexOf(",") != -1 || number.indexOf("-") != -1); + string = this._getTerm(identifier, plural); } if(string) { @@ -687,6 +710,21 @@ CSL.prototype._formatDate = function(element, date, format) { return data; } +/* + * serializes an element into a string suitable to prevent substitutes from + * recurring in the same style + */ +CSL.prototype._serializeElement = function(name, element) { + var string = name; + if(element.relation) { + string += " relation:"+element.relation; + } + if(element.role) { + string += " role"+element.role; + } + return string; +} + /* * pads a number or other string with a given string on the left */ @@ -730,12 +768,6 @@ CSL.prototype._preprocessItems = function(items) { // parse if(item.date) { // specific date item._csl.date = CSL.prototype._processDate(item.date); - } else { // no real date, but might salvage a year - item._csl.date = new Object(); - - if(item.year) { - item._csl.date.year = item.year; - } } } } @@ -759,10 +791,8 @@ CSL.prototype._disambiguateItems = function(items) { var citation = author+" "+this._getFieldValue("date", this._getFieldDefaults("date"), item, "disambiguate"); - Scholar.debug(citation); if(usedCitations[citation]) { - Scholar.debug("disambiguation necessary"); if(!usedCitations[citation]._csl.date.disambiguation) { usedCitations[citation]._csl.date.disambiguation = "a"; item._csl.date.disambiguation = "b"; @@ -848,8 +878,11 @@ CSL.prototype._processCreators = function(type, element, creators, format) { var authorStrings = []; var firstName, lastName; for(var i=0; i{item.distributor}; } - if(item.year) { - // Assume year is copyright date - originInfo += {item.year}; - } if(item.date) { + if(inArray(item.itemType, ["book", "bookSection"]) { + // Assume year is copyright date + originInfo += {item.year}; + } if(inArray(item.itemType, ["magazineArticle", "newspaperArticle"])) { // Assume date is date issued var dateType = "dateIssued"; @@ -3477,15 +3479,10 @@ function doExport() { // date/year if(item.date) { Scholar.RDF.addStatement(resource, n.dc+"date", item.date, true); - } else if(item.year) { - Scholar.RDF.addStatement(resource, n.dc+"date", item.year, true); } if(item.accessDate) { // use date submitted for access date? Scholar.RDF.addStatement(resource, n.dcterms+"dateSubmitted", item.accessDate, true); } - if(item.lastModified) { - Scholar.RDF.addStatement(resource, n.dcterms+"modified", item.lastModified, true); - } // callNumber if(item.callNumber) { @@ -3637,10 +3634,6 @@ REPLACE INTO "translators" VALUES ('6e372642-ed9d-4934-b5d1-c11ac758ebb7', '2006 // date/year if(item.date) { Scholar.RDF.addStatement(resource, dc+"date", item.date, true); - } else if(item.year) { - Scholar.RDF.addStatement(resource, dc+"date", item.year, true); - } else if(item.lastModified) { - Scholar.RDF.addStatement(resource, dc+"date", item.lastModified, true); } // ISBN/ISSN/DOI @@ -4306,7 +4299,7 @@ function doExport() { // date if(item.date) { - var isoDate = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/; + var isoDate = /^[0-9]{4}(-[0-9]{2}-[0-9]{2})?$/; if(isoDate.test(item.date)) { // can directly accept ISO format with minor mods addTag("Y1", item.date.replace("-", "/")+"/"); } else { // otherwise, extract year and attach other data @@ -4316,8 +4309,6 @@ function doExport() { addTag("Y1", m[2]+"///"+m[1]); } } - } else if(item.year) { - addTag("Y1", item.year+"///"); } // notes @@ -4805,7 +4796,7 @@ MARC_Record.prototype.translate = function(item) { // Extract publisher info this._associateDBField(item, ''260'', ''b'', ''publisher''); // Extract year - this._associateDBField(item, ''260'', ''c'', ''year'', _pullNumber); + this._associateDBField(item, ''260'', ''c'', ''date'', _pullNumber); // Extract series this._associateDBField(item, ''440'', ''a'', ''seriesTitle''); // Extract call number @@ -4871,30 +4862,27 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P Bruce D’Arcus bdarcus@sourceforge.net - 2006-08-03T11:01:30-05:00 + + Simon Kornblith + simon@simonster.com + + 2006-08-13T23:28:00-05:00 - + + + + - - - + @@ -4915,6 +4903,13 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P + + + + + + + @@ -4928,11 +4923,11 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P - + - + @@ -4950,7 +4945,10 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P - + + + + @@ -4960,16 +4958,26 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P - - - - + + + + + + + + + - - + + + @@ -4977,20 +4985,22 @@ REPLACE INTO "csl" VALUES('id-not-yet-given', '2006-08-12 19:22:00', 'American P - - + + + + + - - - - + + + + - -'); \ No newline at end of file +'); \ No newline at end of file