def get_citation_from_doi(query, email='*****@*****.**', tool='Referencer', database='pubmed'): params = { 'db': database, 'tool': tool, 'email': email, 'term': query + "[doi]", 'usehistory': 'y', 'retmax': 1 } # try to resolve the PubMed ID of the DOI url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + urllib.urlencode( params) data = referencer.download(_("Resolving DOI"), _("Finding PubMed ID from DOI %s") % query, url) # parse XML output from PubMed... xmldoc = minidom.parseString(data) ids = xmldoc.getElementsByTagName('Id') # nothing found, exit if len(ids) == 0: raise "pubmed.get_citation_from_doi: DOI not found" # get ID id = ids[0].childNodes[0].data print "pubmed.get_citation_from_doi: DOI ", query, " has PubMed ID ", id return get_citation_from_pmid(id)
def get_citation_from_doi(query, email='*****@*****.**', tool='Referencer', database='pubmed'): params = { 'db':database, 'tool':tool, 'email':email, 'term':query + "[doi]", 'usehistory':'y', 'retmax':1 } # try to resolve the PubMed ID of the DOI url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + urllib.urlencode(params) data = referencer.download (_("Resolving DOI"), _("Finding PubMed ID from DOI %s") % query , url); # parse XML output from PubMed... xmldoc = minidom.parseString(data) ids = xmldoc.getElementsByTagName('Id') # nothing found, exit if len(ids) == 0: raise "pubmed.get_citation_from_doi: DOI not found" # get ID id = ids[0].childNodes[0].data print "pubmed.get_citation_from_doi: DOI ", query, " has PubMed ID ", id return get_citation_from_pmid (id)
def __init__(self, parent = None): gtk.Dialog.__init__(self,"expj plugin configuration", parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_OK)) #vbox = gtk.VBox() label = gtk.Label(_("Journal name database download link:")) self.dllink = gtk.Entry() self.dllink.set_text(DEFAULTDOWNLOAD) self.vbox.pack_start(label,padding=3) self.vbox.pack_start(self.dllink,padding=3) hbox = gtk.HBox() text = _('The above link should direct to a text file following the syntax described on the JabRef web page where also other possible useful Journal name database files can be found.\n<a href="http://jabref.sourceforge.net/resources.php">http://jabref.sourceforge.net/resources.php</a>\nBe aware that the downloaded file will replace your current Journal name database. Your custom entries saved in a separate file will remain unchanged!') label = gtk.Label() label.set_markup(text) label.set_line_wrap(True) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_INFO,gtk.ICON_SIZE_DIALOG) hbox.pack_start(image) hbox.pack_start(label) self.vbox.pack_start(hbox,padding=3) self.vbox.show_all()
def resolve_metadata (doc, method): if method != "doi": return False doi = doc.get_field("doi") params = { 'data_type':"XML", 'doi':doi } url = "http://adsabs.harvard.edu/cgi-bin/nph-bib_query?" + urllib.urlencode (params) data = referencer.download (_("Resolving DOI"), _("Fetching metadata from NASA ADS for DOI %s") % doi, url); if data.find ("retrieved=\"1\"") == -1: print "Couldn't get info from ADS" return False fields = [] try: xmldoc = minidom.parseString (data) fields.append (["journal", get_field(xmldoc, "journal")]) fields.append (["title", get_field(xmldoc, "title")]) fields.append (["volume", get_field(xmldoc, "volume")]) authors = xmldoc.getElementsByTagName('author') authorString = "" first = True for author in authors: name = author.childNodes[0].data.encode("utf-8") if (first == False): authorString += " and " print "got author", name authorString += name first = False fields.append (["author", authorString]) print "appended authors" pages = get_field (xmldoc, "page") print "getting lastPage" lastPage = get_field (xmldoc, "lastpage") if (len(lastPage) > 0): pages += "-" pages += lastPage print "got pages " , pages fields.append (["page", pages]) print "appended pages" except: print "exception" return False for field in fields: if len(field[1]) > 0: doc.set_field(field[0], field[1]) # TODO: parse pubdata element for "Jul 1989" (month and year fields) return True
def get_citation_from_pmid (pmid, email='*****@*****.**', tool='Referencer', database='pubmed'): params = { 'db':database, 'tool':tool, 'email':email, 'id':pmid, 'retmode':'xml' } # get citation info: url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' + urllib.urlencode(params) data = referencer.download (_("Resolving PubMed ID"), _("Fetching metadata from NCBI for PubMed ID %s") % pmid, url); return data
def get_number_of_records (document): title = document.get_field("title") year = document.get_field ("year") author= document.get_field ("author") url0='http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&rspType=xml&method=search&firstRec=1&numRecs=1' url0+= '&query='+get_query(document) data0 = referencer.download( _("Obtaining data from ISI-WebOfScience"), _("Fetching number of ocurrences for %s/%s/%s") % (author,title,year), url0) print data0 xmldoc0 = minidom.parseString(data0) recordsFound=get_field(xmldoc0,"recordsFound") return int(recordsFound)
def get_data(self,document, firstrec=None, numrecs=None): title = document.get_field("title") year = document.get_field ("year") author= document.get_field ("author") if firstrec is None: firstrec = 1 if numrecs is None: numrecs = 1 url='http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&SID=Q1mNFhCECOk6c8aELLh&rspType=xml&method=searchRetrieve' url += \ '&firstRec=' + str(firstrec) + \ '&numRecs=' + str(numrecs) + \ '&query=' + get_query(document) data = referencer.download(_("Obtaining data from ISI-WebOfScience"), _("Fetching data for %s/%s/%s") % (author,title,year), url); return data
def do_search(document): title = document.get_field("title") year = document.get_field("year") author = document.get_field("author") url0 = 'http://estipub.isiknowledge.com/esti/cgi?action=search&viewType=xml&mode=GeneralSearch&product=WOS&ServiceName=GeneralSearch&filter=&Start=&End=%d&DestApp=WOS' % ( get_MAXRECORDS()) url0 += "&" + get_query(document) print "isi query url:", url0 if False: #debugging #data0 = open("plugins/isi-plugin-testdata.txt").read() data0 = open("plugins/isi-plugin-testdata2.txt").read() else: data0 = referencer.download( _("Obtaining data from ISI-WebOfScience"), _("Querying for %s/%s/%s") % (author, title, year), url0) print data0 xmldoc0 = minidom.parseString(data0) return xmldoc0
def resolve_metadata(doc, method=None): # try with title, otherwise try with author + year title = doc.get_field("title") if title: searchTerms = [title] else: searchTerms = [get_first_author(doc.get_field("author"))] searchTerms += [doc.get_field("year")] searchTerm = " ".join(searchTerms) for c in "(),.{}!\"':=#%$/&[]+": searchTerm = searchTerm.replace(c, "") searchTerm = searchTerm.replace("-", " ") while searchTerm.find(" ") > 0: #remove double spaces searchTerm = searchTerm.replace(" ", " ") #print "DBLP:searchTerm:", repr(searchTerm) url = "http://www.dblp.org/search/api/?%s&h=1000&c=0&f=0&format=xml" % ( urllib.urlencode({'q': searchTerm})) print "DBLP:url:", repr(url) data = referencer.download( _("Searching DBLP"), _("Fetching metadata from DBLP for search query '%s'") % searchTerm, url) if not data: return False hits = parse_hits_get_urls(data) print "DBLP:hits:", hits if len(hits) != 1: #XXX, display UI? print "DBLP: Not exactly one hit, giving up" return False bibtex_xml = get_bibtex_xml_from_url(hits[0]) #print bibtex_xml bibtex = bibtex_xml_to_bibtex(bibtex_xml) #print bibtex doc.parse_bibtex(bibtex) return True
def do_search (document): title = document.get_field("title") year = document.get_field ("year") author= document.get_field ("author") url0='http://estipub.isiknowledge.com/esti/cgi?action=search&viewType=xml&mode=GeneralSearch&product=WOS&ServiceName=GeneralSearch&filter=&Start=&End=%d&DestApp=WOS' % (get_MAXRECORDS()) url0+= "&" + get_query(document) print "isi query url:", url0 if False: #debugging #data0 = open("plugins/isi-plugin-testdata.txt").read() data0 = open("plugins/isi-plugin-testdata2.txt").read() else: data0 = referencer.download( _("Obtaining data from ISI-WebOfScience"), _("Querying for %s/%s/%s") % (author,title,year), url0) print data0 xmldoc0 = minidom.parseString(data0) return xmldoc0
def get_citation_from_pmid(pmid, email='*****@*****.**', tool='Referencer', database='pubmed'): params = { 'db': database, 'tool': tool, 'email': email, 'id': pmid, 'retmode': 'xml' } # get citation info: url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' + urllib.urlencode( params) data = referencer.download( _("Resolving PubMed ID"), _("Fetching metadata from NCBI for PubMed ID %s") % pmid, url) return data
def resolve_metadata (doc, method=None): # try with title, otherwise try with author + year title = doc.get_field("title") if title: searchTerms = [title] else: searchTerms = [get_first_author(doc.get_field("author"))] searchTerms += [doc.get_field("year")] searchTerm = " ".join(searchTerms) for c in "(),.{}!\"':=#%$/&[]+": searchTerm = searchTerm.replace(c, "") searchTerm = searchTerm.replace("-", " ") while searchTerm.find(" ") > 0: #remove double spaces searchTerm = searchTerm.replace(" ", " ") #print "DBLP:searchTerm:", repr(searchTerm) url = "http://www.dblp.org/search/api/?%s&h=1000&c=0&f=0&format=xml" % (urllib.urlencode({'q': searchTerm})) print "DBLP:url:", repr(url) data = referencer.download (_("Searching DBLP"), _("Fetching metadata from DBLP for search query '%s'") % searchTerm, url); if not data: return False hits = parse_hits_get_urls(data) print "DBLP:hits:", hits if len(hits) != 1: #XXX, display UI? print "DBLP: Not exactly one hit, giving up" return False bibtex_xml = get_bibtex_xml_from_url(hits[0]) #print bibtex_xml bibtex = bibtex_xml_to_bibtex(bibtex_xml) #print bibtex doc.parse_bibtex(bibtex) return True
def get_bibtex_xml_from_url(url): url = url + ".xml" data = referencer.download (_("Searching DBLP"), _("Fetching metadata from DBLP for url '%s'") % url, url); return data
def referencer_search_TEST(search_text): email = '*****@*****.**' tool = 'Referencer' database = 'pubmed' retmax = 100 params = { 'db': database, 'tool': tool, 'email': email, 'term': search_text, 'usehistory': 'y', 'retmax': retmax } # try to resolve the PubMed ID of the DOI url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + urllib.urlencode( params) data = referencer.download(_("Searching pubmed"), _("Searching pubmed for '%s'") % search_text, url) # parse XML output from PubMed... print data xmldoc = minidom.parseString(data) ids = xmldoc.getElementsByTagName('Id') # nothing found, exit # FIXME: not really an error if len(ids) == 0: raise "pubmed.referencer_search: no results" webenv = xmldoc.getElementsByTagName('WebEnv') if len(webenv) == 0: raise "pubmed.referencer_search: no webenv" webenv = webenv[0].childNodes[0].data query_key = xmldoc.getElementsByTagName('QueryKey') if len(query_key) == 0: raise "pubmed.referencer_search: no query_key" query_key = query_key[0].childNodes[0].data params = { 'db': database, 'tool': tool, 'email': email, 'webenv': webenv, 'query_key': query_key, 'retmax': retmax } url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?' + urllib.urlencode( params) data = referencer.download( _("Retrieving pubmed summaries"), _("Retrieving summaries for '%s'") % search_text, url) xmldoc = minidom.parseString(data) results = [] for docsum in xmldoc.getElementsByTagName('DocSum'): title = "" author = "" pmid = "" id = docsum.getElementsByTagName("Id") if len(id) != 0: pmid = id[0].childNodes[0].data else: raise "pubmed.referencer_search: docsum without id" for childnode in docsum.getElementsByTagName("Item"): if childnode.getAttribute("Name") == "Title": title = childnode.childNodes[0].data if childnode.getAttribute("Name") == "Author": author = childnode.childNodes[0].data results.append({"token": pmid, "title": title, "author": author}) print results return results
#!/usr/bin/env python # Simple script to query pubmed for a DOI # (c) Simon Greenhill, 2007 # http://simon.net.nz/ # Modified for integration with referencer by John Spray, 2007 import urllib import referencer from referencer import _ from xml.dom import minidom referencer_plugin_info = { "longname": _("PubMed DOI resolver"), "author": "Simon Greenhill, John Spray" } referencer_plugin_capabilities = ["doi", "pubmed"] # Encoding: every PyUnicode that minidom gives us gets # encoded as utf-8 into a PyString, this is what PyString_AsString on the C++ # side will expect def get_field (doc, field): value = doc.getElementsByTagName(field) if len(value) == 0: return ""
</menu> </menubar> <toolbar name='ToolBar'> <placeholder name='PluginToolBarActions'> <toolitem action='_plugin_isi'/> </placeholder> </toolbar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_isi'/> </placeholder> </popup> </ui> """, "longname": _("ISI Web of Science resolver (requires subscription)"), "action": _("Get metadata from ISI Web of Science"), "tooltip": _("ISI Web of Science resolver (requires subscription)")} referencer_plugin_actions = [{ "name":"_plugin_isi", "label":_("ISI Info"), "tooltip":_("Retrieve metadata for the selected documents from ISI Web of Science"), "icon":"_stock:gtk-edit", "callback":"do_action", "sensitivity":"sensitivity_genkey", "accelerator":"<control>i" }] class isiRec: def __init__(self, document = None, firstrec = None):
#!/usr/bin/env python # -*- coding: utf-8 -*- # Add quote in lyx using lyxclient import os import referencer from referencer import _ referencer_plugin_info = { "longname": _("PaperCrop"), "author": "Taesoobear", "ui": """ <ui> <menubar name='MenuBar'> <menu action='DocMenu'> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_papercrop'/> </placeholder> </menu> </menubar> <toolbar name='ToolBar'> <placeholder name='PluginToolBarActions'> <toolitem action='_plugin_papercrop'/> </placeholder> </toolbar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_papercrop'/> </placeholder>
#!/usr/bin/env python # -*- coding: utf-8 -*- # Add quote in lyx using lyxclient import os import referencer from referencer import _ referencer_plugin_info = { "longname": _("Cite in LyX"), "author": "Aurélien Naldi", "ui": """ <ui> <menubar name='MenuBar'> <menu action='DocMenu'> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_lyx_cite'/> </placeholder> </menu> </menubar> <toolbar name='ToolBar'> <placeholder name='PluginToolBarActions'> <toolitem action='_plugin_lyx_cite'/> </placeholder> </toolbar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_lyx_cite'/> </placeholder>
</menu> </menubar> <toolbar name='ToolBar'> <placeholder name='PluginToolBarActions'> <toolitem action='_plugin_isi'/> </placeholder> </toolbar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_isi'/> </placeholder> </popup> </ui> """, "longname": _("ISI Web of Science resolver (requires subscription)"), "action": _("Get metadata from ISI Web of Science"), "tooltip": _("ISI Web of Science resolver (requires subscription)") } referencer_plugin_actions = [{ "name": "_plugin_isi", "label": _("ISI Info"), "tooltip": _("Retrieve metadata for the selected documents from ISI Web of Science"), "icon": "_stock:gtk-edit", "callback": "do_action",
def resolve_metadata (doc, method): if method != "doi": return False doi = doc.get_field("doi") params = { 'data_type':"XML", 'doi':doi } url = "http://adsabs.harvard.edu/cgi-bin/nph-bib_query?" + urllib.urlencode (params) data = referencer.download (_("Resolving DOI"), _("Fetching metadata from NASA ADS for DOI %s") % doi, url); if data.find ("retrieved=\"1\"") == -1: print "Couldn't get info from ADS" return False fields = [] try: xmldoc = minidom.parseString (data) fields.append (["title", get_field(xmldoc, "title")]) fields.append (["volume", get_field(xmldoc, "volume")]) fields.append (["issue", get_field(xmldoc, "issue")]) fields.append (["year", get_field(xmldoc, "pubdate").partition(' ')[2]]) fields.append (["Month", str.lower(get_field(xmldoc, "pubdate").partition(' ')[0])]) fields.append (["Adsurl", xmldoc.getElementsByTagName('url')[-1].childNodes[0].data.encode("utf-8")]) fields.append (["Adsbibcode", get_field(xmldoc, "bibcode")]) # ADS include full bibliographic information in the journal XML tag, # see http://doc.adsabs.harvard.edu/abs_doc/help_pages/taggedformat.html#jnl journal = get_field(xmldoc, "journal") journalString = re.sub(', [vV]ol(ume|\.).*', '', journal) fields.append (["journal", journalString]) authors = xmldoc.getElementsByTagName('author') authorString = "" first = True for author in authors: name = author.childNodes[0].data.encode("utf-8") if (first == False): authorString += " and " print "got author", name authorString += name first = False fields.append (["author", authorString]) print "appended authors" pages = get_field (xmldoc, "page") print "getting lastPage" lastPage = get_field (xmldoc, "lastpage") if (len(lastPage) > 0): pages += "-" pages += lastPage print "got pages " , pages fields.append (["pages", pages]) print "appended pages" except: print "exception" return False for field in fields: if len(field[1]) > 0: doc.set_field(field[0], field[1]) return True
USERPLDIR = os.path.join( os.path.expanduser("~"), ".referencer", "plugins") # os.path.dirname(os.path.realpath(__file__)) DBs = [] DBs.append(os.path.join(USERPLDIR, "expj_journaldb_user.txt")) DBs.append(os.path.join(USERPLDIR, "expj_journaldb_base.txt")) DEFAULTMAXSUGGESTIONS = 5 # number of suggestions displayed in case no exact match is found DEFAULTDOWNLOAD = "http://jabref.sourceforge.net/journals/journal_abbreviations_general.txt" DEBUG = True referencer_plugin_info = { "longname": _("Expand and abbreviate Journal names"), "author": "Dominik Kriegner", "version": "0.2.0", "ui": """ <ui> <menubar name='MenuBar'> <menu action='DocMenu'> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_expj_expand'/> </placeholder> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_expj_shorten'/> </placeholder>
def do_shorten (library, documents): """ perform shortening of Journal names for listed documents """ global expanded,contracted if len(expanded) == 0: # on first use of the plugin the database has to be loaded load_db() for doc in documents: # check if it is a article pass # seems this is not necessary because asking for journal name on not articles # returns an empty string # get current journal field longv = doc.get_field('journal') repl = longv if longv != "": try: # look for exact match in database idx = map(string.lower,expanded).index(longv.strip().lower()) repl = contracted[idx] except ValueError: try: # check if journal name is already the shortened version idx = map(string.lower,contracted).index(longv.strip().lower()) if idx: continue except: pass # no exact match was found, we will ask the user what to do match = difflib.get_close_matches(longv,expanded,DEFAULTMAXSUGGESTIONS) # find 5 most likely replacements # Prompt the user for the correct entry dialog = gtk.Dialog(buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) dialog.set_has_separator(False) dialog.vbox.set_spacing(6) dialog.set_default_response(gtk.RESPONSE_ACCEPT) if DISPHINT: text = _('No Journal name database found: consider checking the plugin configuration dialog to download a prepared list') label = gtk.Label(text) label.set_line_wrap(True) image = gtk.Image() image.set_from_stock(gtk.STOCK_DIALOG_INFO,gtk.ICON_SIZE_DIALOG) hbox = gtk.HBox() hbox.pack_start(image) hbox.pack_start(label) dialog.vbox.pack_start(hbox,padding=3) if len(match)==0: label = gtk.Label(_("No match found in database!\nEnter replacement entry for journal") + " '%s'"%(longv)) else: label = gtk.Label(_("No exact match found!\nChoose correct entry for journal") + " '%s'"%(longv)) dialog.vbox.pack_start(label) for i in range(len(match)): if i==0: rb = gtk.RadioButton(None,contracted[expanded.index(match[i])]) rb.set_active(True) else: rb = gtk.RadioButton(rb,contracted[expanded.index(match[i])]) dialog.vbox.pack_start(rb) hbox = gtk.HBox (spacing=6) if len(match)!=0: rb = gtk.RadioButton(rb,_("Custom:")) else: rb = gtk.Label(_("Replacement:")) def activate_custom(widget,rb): """ the custom entry will be activated upon a text entry """ rb.set_active(True) entry = gtk.Entry() entry.set_text(_("journal abbreviation")) entry.set_activates_default(True) entry.select_region(0,len(entry.get_text())) if len(match)!=0: entry.connect("changed",activate_custom,rb) dialog.vbox.pack_start(hbox) hbox.pack_start(rb) hbox.pack_start(entry) dialog.vbox.pack_start(hbox) dialog.set_focus(entry) cb = gtk.CheckButton(label=_("Add replacement to database")) dialog.vbox.pack_start(cb) dialog.show_all() response = dialog.run() dialog.hide() if (response == gtk.RESPONSE_REJECT): continue # do not change anthing and continue with next document # obtain users choice if len(match)!=0: active_radio = [r for r in rb.get_group() if r.get_active()][0] if active_radio.get_label() != _("Custom:"): repl = active_radio.get_label() else: repl = entry.get_text() else: repl = entry.get_text() if cb.get_active(): # save the custom entry to the database expanded.append(longv) contracted.append(repl) save_db() # change the journal name doc.set_field('journal',repl) if DEBUG: print("expj: changed journal entry from '%s' to '%s'"%(longv,repl)) return True
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import urllib try: import referencer from referencer import _ except: #for doctesting referencer = None _ = lambda x: x from xml.dom import minidom referencer_plugin_info = { "longname": _("DBLP resolver"), "version": "0.1", "author": "Mads Chr. Olesen <*****@*****.**>" } referencer_plugin_capabilities = ["resolve_metadata"] def can_resolve_metadata(doc): author = doc.get_field("author") #let's pretend this is an easter egg ;-) if author and "Mads" in author and "Olesen" in author: return 80 elif "DBLP" in str(doc.get_field("bibsource")): return 80 elif doc.get_field("title"):
import gtk import re import referencer from referencer import _ # A referencer plugin to get bibtex info for a book from Google Books # # Copyright 2011 Phoenix87 # Copyright 2012 Mads Chr. Olesen <*****@*****.**> referencer_plugin_info = { "author": "Phoenix87", "version": "0.2", "longname": _("Fetch BiBTeX metadata from Google Books") } referencer_plugin_capabilities = ["url"] pattern = r'http://books[.]google[.](.+?)/books.+?id=([a-zA-Z0-9_]+)' def can_resolve_metadata(doc): url = doc.get_field("url") if not url: return -1 res = re.match(pattern, url) if res: return 90 return -1
def get_bibtex_xml_from_url(url): url = url + ".xml" data = referencer.download( _("Searching DBLP"), _("Fetching metadata from DBLP for url '%s'") % url, url) return data
# Generate Bob08 Alice99 Alice99b type keys import os import referencer from referencer import _ import gobject import gtk referencer_plugin_info = { "author": "John Spray", "version": "1.1.2", "longname": _("Generate keys from metadata"), "ui": """ <ui> <menubar name='MenuBar'> <menu action='ToolsMenu'> <placeholder name ='PluginToolsActions'> <menuitem action='_plugin_genkey_genkey'/> </placeholder> </menu> </menubar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_genkey_genkey'/> </placeholder>
#!/usr/bin/env python # -*- coding: utf-8 -*- # Add quote in lyx using lyxclient import os import referencer from referencer import _ referencer_plugin_info = { "longname": _("PaperCrop"), "author": "Taesoobear", "ui": """ <ui> <menubar name='MenuBar'> <menu action='DocMenu'> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_papercrop'/> </placeholder> </menu> </menubar> <toolbar name='ToolBar'> <placeholder name='PluginToolBarActions'> <toolitem action='_plugin_papercrop'/> </placeholder> </toolbar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'>
def referencer_search_TEST (search_text): email='*****@*****.**' tool='Referencer' database='pubmed' retmax = 100 params = { 'db':database, 'tool':tool, 'email':email, 'term':search_text, 'usehistory':'y', 'retmax':retmax } # try to resolve the PubMed ID of the DOI url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + urllib.urlencode(params) data = referencer.download (_("Searching pubmed"), _("Searching pubmed for '%s'") % search_text , url); # parse XML output from PubMed... print data xmldoc = minidom.parseString(data) ids = xmldoc.getElementsByTagName('Id') # nothing found, exit # FIXME: not really an error if len(ids) == 0: raise "pubmed.referencer_search: no results" webenv = xmldoc.getElementsByTagName('WebEnv') if len(webenv) == 0: raise "pubmed.referencer_search: no webenv" webenv = webenv[0].childNodes[0].data query_key = xmldoc.getElementsByTagName('QueryKey') if len(query_key) == 0: raise "pubmed.referencer_search: no query_key" query_key = query_key[0].childNodes[0].data params = { 'db':database, 'tool':tool, 'email':email, 'webenv':webenv, 'query_key':query_key, 'retmax':retmax } url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?' + urllib.urlencode(params) data = referencer.download (_("Retrieving pubmed summaries"), _("Retrieving summaries for '%s'") % search_text , url); xmldoc = minidom.parseString(data) results = [] for docsum in xmldoc.getElementsByTagName('DocSum'): title = "" author = "" pmid = "" id = docsum.getElementsByTagName("Id") if len(id) !=0: pmid = id[0].childNodes[0].data else: raise "pubmed.referencer_search: docsum without id" for childnode in docsum.getElementsByTagName("Item"): if childnode.getAttribute("Name") == "Title": title = childnode.childNodes[0].data if childnode.getAttribute("Name") == "Author": author = childnode.childNodes[0].data results.append ({"token":pmid,"title":title,"author":author}) print results return results
import string # for string handling import difflib # to find closest matching entry for replacement USERPLDIR = os.path.join(os.path.expanduser("~"), ".referencer","plugins") # os.path.dirname(os.path.realpath(__file__)) DBs = [] DBs.append(os.path.join(USERPLDIR,"expj_journaldb_user.txt")) DBs.append(os.path.join(USERPLDIR,"expj_journaldb_base.txt")) DEFAULTMAXSUGGESTIONS = 5 # number of suggestions displayed in case no exact match is found DEFAULTDOWNLOAD = "http://jabref.sourceforge.net/journals/journal_abbreviations_general.txt" DEBUG = True referencer_plugin_info = { "longname": _("Expand and abbreviate Journal names"), "author": "Dominik Kriegner", "version": "0.2.0", "ui": """ <ui> <menubar name='MenuBar'> <menu action='DocMenu'> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_expj_expand'/> </placeholder> <placeholder name='PluginDocMenuActions'> <menuitem action='_plugin_expj_shorten'/> </placeholder> </menu> </menubar>
#!/usr/bin/env python # Generate Bob08 Alice99 Alice99b type keys import os import referencer from referencer import _ import gobject import gtk referencer_plugin_info = { "author": "John Spray", "version": "1.1.2", "longname": _("Generate keys from metadata"), "ui": """ <ui> <menubar name='MenuBar'> <menu action='ToolsMenu'> <placeholder name ='PluginToolsActions'> <menuitem action='_plugin_genkey_genkey'/> </placeholder> </menu> </menubar> <popup name='DocPopup'> <placeholder name='PluginDocPopupActions'> <menuitem action='_plugin_genkey_genkey'/> </placeholder> </popup>
#!/usr/bin/env python # ADS metadata scraper, Copyright 2008 John Spray import urllib import referencer from referencer import _ from xml.dom import minidom referencer_plugin_info = { "author": "John Spray", "longname": _("NASA Astrophysics Data System DOI resolver") } referencer_plugin_capabilities = ["doi"] # Encoding: every PyUnicode that minidom gives us gets # encoded as utf-8 into a PyString, this is what PyString_AsString on the C++ # side will expect def get_field(doc, field): value = doc.getElementsByTagName(field) print "get_field: value = ", value if len(value) == 0: return "" else: return value[0].childNodes[0].data.encode("utf-8") def can_resolve_metadata(doc): if doc.get_field("doi"):
def resolve_metadata(doc, method): if method != "doi": return False doi = doc.get_field("doi") params = {'data_type': "XML", 'doi': doi} url = "http://adsabs.harvard.edu/cgi-bin/nph-bib_query?" + urllib.urlencode( params) data = referencer.download( _("Resolving DOI"), _("Fetching metadata from NASA ADS for DOI %s") % doi, url) if data.find("retrieved=\"1\"") == -1: print "Couldn't get info from ADS" return False fields = [] try: xmldoc = minidom.parseString(data) fields.append(["journal", get_field(xmldoc, "journal")]) fields.append(["title", get_field(xmldoc, "title")]) fields.append(["volume", get_field(xmldoc, "volume")]) fields.append(["issue", get_field(xmldoc, "issue")]) fields.append(["year", get_field(xmldoc, "pubdate").partition(' ')[2]]) fields.append([ "Month", str.lower(get_field(xmldoc, "pubdate").partition(' ')[0]) ]) fields.append([ "Adsurl", xmldoc.getElementsByTagName('url')[-1].childNodes[0].data.encode( "utf-8") ]) fields.append(["Adsbibcode", get_field(xmldoc, "bibcode")]) authors = xmldoc.getElementsByTagName('author') authorString = "" first = True for author in authors: name = author.childNodes[0].data.encode("utf-8") if (first == False): authorString += " and " print "got author", name authorString += name first = False fields.append(["author", authorString]) print "appended authors" pages = get_field(xmldoc, "page") print "getting lastPage" lastPage = get_field(xmldoc, "lastpage") if (len(lastPage) > 0): pages += "-" pages += lastPage print "got pages ", pages fields.append(["pages", pages]) print "appended pages" except: print "exception" return False for field in fields: if len(field[1]) > 0: doc.set_field(field[0], field[1]) return True
#!/usr/bin/env python # ADS metadata scraper, Copyright 2008 John Spray import urllib import referencer from referencer import _ from xml.dom import minidom referencer_plugin_info = { "author": "John Spray", "longname": _("NASA Astrophysics Data System DOI resolver") } referencer_plugin_capabilities = ["doi"] # Encoding: every PyUnicode that minidom gives us gets # encoded as utf-8 into a PyString, this is what PyString_AsString on the C++ # side will expect def get_field (doc, field): value = doc.getElementsByTagName(field) print "get_field: value = ", value if len(value) == 0: return "" else: return value[0].childNodes[0].data.encode("utf-8") def resolve_metadata (doc, method): if method != "doi": return False
#!/usr/bin/env python # Simple script to query pubmed for a DOI # (c) Simon Greenhill, 2007 # http://simon.net.nz/ # Modified for integration with referencer by John Spray, 2007 import urllib import referencer from referencer import _ from xml.dom import minidom referencer_plugin_info = { "longname": _("PubMed DOI resolver"), "author": "Simon Greenhill, John Spray" } referencer_plugin_capabilities = ["doi", "pubmed"] # Encoding: every PyUnicode that minidom gives us gets # encoded as utf-8 into a PyString, this is what PyString_AsString on the C++ # side will expect def get_field(doc, field): value = doc.getElementsByTagName(field) if len(value) == 0: return "" else: if (len(value[0].childNodes) == 0):
import gtk import re import referencer from referencer import _ # A referencer plugin to get bibtex info for a book from Google Books # # Copyright 2011 Phoenix87 # Copyright 2012 Mads Chr. Olesen <*****@*****.**> # Copyright 2015 Gabriele N. Tornetta <*****@*****.**> referencer_plugin_info = { "author": "Gabriele N. Tornetta (a.k.a. Phoenix87)", "version": "1.0", "longname": _("Fetch BiBTeX metadata from Google Books") } referencer_plugin_capabilities = ["url"] pattern = r'https?://books[.]google[.](.+?)/books.+?id=(.+)' def can_resolve_metadata (doc): url = doc.get_field("url") if not url: return -1 res = re.match(pattern, url) if res: return 90 return -1 def resolve_metadata(doc, method):
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import urllib try: import referencer from referencer import _ except: #for doctesting referencer = None _ = lambda x: x from xml.dom import minidom referencer_plugin_info = { "longname": _("DBLP resolver"), "version": "0.1", "author": "Mads Chr. Olesen <*****@*****.**>" } referencer_plugin_capabilities = ["resolve_metadata"] def can_resolve_metadata (doc): author = doc.get_field ("author") #let's pretend this is an easter egg ;-) if author and "Mads" in author and "Olesen" in author: return 80 elif "DBLP" in str(doc.get_field("bibsource")): return 80 elif doc.get_field ("title"): return 20