{ "translatorID": "d71e9b6d-2baa-44ed-acb4-13fe2fe592c0", "label": "Google Patents", "creator": "Adam Crymble, Avram Lyon", "target": "^https?://(www\\.)?google\\.[^/]+/(?:patents|[^/]*[&?#]tbm=pts)", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", "lastUpdated": "2014-08-15 02:22:24" } function detectWeb(doc, url) { if (!doc.getElementsByTagName("body")[0].hasChildNodes()) return; if (getSearchResults(doc).length) { return "multiple"; } else if(getScraper(doc)) { return "patent"; } } function getSearchResults(doc) { return ZU.xpath(doc, '//div[@id="ires"]//li[@class="g"]//h3/a'); } function fixAuthorCase(name) { if(name.toUpperCase() == name) { return ZU.capitalizeTitle(name, true).replace(/\sa(\.?)\s/,' A$1 '); } else { return name; } } var scrapers = [ //U.S. (?) patent page. E.g. http://www.google.com/patents/US20090289560 { getBoxes: function(doc) { return ZU.xpath(doc, '(//div[@class="patent_bibdata"]//*[./b]|//div[@class="patent_bibdata"][./b])'); }, detect: function(doc) { return this.getBoxes(doc).length; }, fieldMap: { 'PATENT NUMBER': 'patentNumber', 'FILING DATE': 'filingDate', 'ISSUE DATE': 'date', 'APPLICATION NUMBER': 'applicationNumber', 'ORIGINAL ASSIGNEE': 'assignee', 'INVENTORS': 'creators', 'INVENTOR': 'creators', 'CURRENT U.S. CLASSIFICATION': 'extra/U.S. Classification', 'INTERNATIONAL CLASSIFICATION': 'extra/International Classification' /* 'PRIMARY EXAMINER': 'SECONDARY EXAMINER': 'ATTORNEY': 'ATTORNEYS': */ }, addField: function(fields, label, value) { if(!value.length) return; var zField = this.fieldMap[label]; if(value.length && zField) { zField = zField.split('/'); switch(zField[0]) { case 'creators': if(!fields.creators) fields.creators = []; fields.creators = fields.creators.concat(value); break; case 'extra': if(fields.extra) fields.extra += '\n'; else fields.extra = ''; if(zField[1]) fields.extra += zField[1] + ': '; fields.extra += value.join('; '); break; default: if(fields[zField[0]]) return; //do not overwrite previous fields fields[zField[0]] = value.join('; '); } } }, addValue: function(label, value, node) { switch(label) { case 'PATENT NUMBER': case 'FILING DATE': case 'ISSUE DATE': case 'APPLICATION NUMBER': case 'PRIMARY EXAMINER': case 'SECONDARY EXAMINER': value[0] = node.textContent.trim().replace(/^:\s*/,''); break; case 'ATTORNEY': case 'ATTORNEYS': value = value.concat( fixAuthorCase( node.textContent.trim() .replace(/^:\s*/,'') ).split(/\s*,\s*(?=\S)(?!(?:LLC|LLP|Esq)\b)/i)); break; case 'ORIGINAL ASSIGNEE': if(node.nodeName.toUpperCase() != 'A') break; value[0] = fixAuthorCase(node.textContent.trim()); break; case 'INVENTORS': case 'INVENTOR': if(node.nodeName.toUpperCase() != 'A') break; var name = node.textContent.trim().split(/\s*,\s*/); //look for suffix var inv = ZU.cleanAuthor(fixAuthorCase(name[0]), 'inventor'); if(name[1]) { //re-add suffix if we had one inv.firstName += ', ' + name[1]; } value.push(inv); break; case 'CURRENT U.S. CLASSIFICATION': if(node.nodeName.toUpperCase() != 'A') break; value.push(node.textContent.trim()); break; case 'INTERNATIONAL CLASSIFICATION': value = value.concat(node.textContent.trim() .replace(/^:\s*/,'') .split(/\s*;\s*/)); break; } return value; }, getMetadata: function(doc) { var fieldBoxes = this.getBoxes(doc); var fields = {}; for(var i=0, n=fieldBoxes.length; i var box = fieldBoxes[i]; var node = box.firstChild; var label, value = []; while(node) { switch(node.nodeName.toUpperCase()) { case 'B': if(!label) { label = node.textContent.trim().toUpperCase(); } else { value = this.addValue(label, value, node); } break; case 'BR': if(label) { if(value.length) { this.addField(fields, label, value); } label = undefined; value = []; } break; default: if(!label) break; value = this.addValue(label, value, node); } node = node.nextSibling; } if(label && value.length) { this.addField(fields, label, value); } } //add some other fields fields.abstractNote = ZU.xpathText(doc, '//p[@class="patent_abstract_text"]'); fields.title = ZU.xpathText(doc, '//h1[@class="gb-volume-title"]'); if(fields.title.toUpperCase() == fields.title) { fields.title = ZU.capitalizeTitle(fields.title, true); } if(fields.extra && fields.extra.indexOf('U.S. Classification') != -1) { fields.country = "United States"; } var url = doc.location.href; fields.url = 'http://' + doc.location.host + doc.location.pathname; var m; if(m = url.match(/[?&](id=[^&]+)/)) fields.url += '?' + m[1]; Z.debug(fields.url) fields.attachments = [ { url: ZU.xpathText(doc, '//a[@id="appbar-download-pdf-link"]/@href'), title: "Google Patents PDF", mimeType: "application/pdf" } ]; return fields; } }, //European (?) patent page. E.g. http://www.google.com/patents/EP0011951A1 { detect: function(doc) { return this.getRows(doc).length; }, getRows: function(doc) { return ZU.xpath(doc, '//table[contains(@class,"patent-bibdata")]//tr[not(@class) or @class="" or @class="patent-bibdata-list-row "][./td[@class="patent-bibdata-heading"]]'); }, getMetadata: function(doc) { var rows = this.getRows(doc); var label, values, zField; var fields = {}; for(var i=0, n=rows.length; i