From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K Subject: zotero-cite (A Proposal) Date: Sat, 12 Nov 2011 02:04:52 +0530 Message-ID: <81k4762yab.fsf_-_@gmail.com> References: <81hb2drhmu.fsf@gmail.com> <81mxc4ovlh.fsf@gmail.com> <87k477hnqy.wl%egh@e6h.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:43101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROxoa-0003vr-TP for emacs-orgmode@gnu.org; Fri, 11 Nov 2011 15:35:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROxoZ-0005HB-77 for emacs-orgmode@gnu.org; Fri, 11 Nov 2011 15:35:08 -0500 Received: from mail-pz0-f47.google.com ([209.85.210.47]:49311) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROxoY-0005Fo-SI for emacs-orgmode@gnu.org; Fri, 11 Nov 2011 15:35:07 -0500 Received: by pzk1 with SMTP id 1so4009289pzk.6 for ; Fri, 11 Nov 2011 12:35:05 -0800 (PST) In-Reply-To: <87k477hnqy.wl%egh@e6h.org> (Erik Hetzner's message of "Thu, 10 Nov 2011 09:48:53 -0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Erik Hetzner Cc: Org Mode , mail@christianmoe.com --=-=-= Content-Type: text/plain Hello Erik Good news. Getting a frugal Zotero-based citations is *definitely* possible. It is just a matter of time. Your libraries already provide the necessary plumbing to accomplish the job. Long story ========== For my own understanding, I tried trimming down zot4rst to it's bare essentials and the attached zotcite.py is the result. What zotcite does is this: For two Zotero Items, it prints their Bibliogrpahic entries and their Citation Reference, in "Text" format using Chicago-Author-Date style. I believe a commandline interface could be built around this file along the following lines. (Will you be interested in building this interface for us?) $ zotcite --style chicago --format --items I1, I2 --print biblio $ zotcite --style chicago --format --items I1, I2 --print citeref Once this is done, Emacs/Org can do invoke zotcite and get the required Bibliographic definitions and references using "shell-command". The assumption is that Emacs/Org somehow has captured zotero keys through org-protocol or org-zotero.el or someother means. Here is a output from zotcite.py. --8<---------------cut here---------------start------------->8--- $ python zotcite.py C.UTF-8 C.UTF-8 ======== KEYS ======== I4AUIZ4S AKJZBHRW ======== ITEM_IDs ======== [6, 40] ======== BIBDATA ======== [u'Brin, S. 1999. \u201cExtracting patterns and relations from the world wide web.\u201d The World Wide Web and Databases: 172\u2013183.\n', u'Jambunathan, K. On Choice of Connection-Polynomials for LFSR-Based Stream Ciphers. In Progress in Cryptology \u2014INDOCRYPT 2000, ed. Bimal Roy and Eiji Okamoto, 1977:9-18. Berlin, Heidelberg: Springer Berlin Heidelberg. http://www.springerlink.com/content/n27yjr5eqhabux0g/.\n'] ===== CITATION REFERENCE ===== (This Brin 1999 That) --8<---------------cut here---------------end--------------->8--- IIRC, I made two changes to the export.js in your Javascript backend. 1. I had trouble understanding the organization of citation clusters. So I modified getCitationBlock as below. Note the use of "true" as a second param of the appendCitationCluster. This is OK as registerItemIds already does updateItems(). --8<---------------cut here---------------start------------->8--- function getCitationBlock (citation) { var results; var str = ""; try { results = zotero.reStructuredCSL.appendCitationCluster(citation, true); } catch (e) { zotero.debug("XXX oops: "+e); } // var index = citation['properties']['index']; // for (var i = 0 ; i <= results.length ; i++) { // // if (results[i][0] == index) { // return escape(str + results[i][1]); // // } // } return escape(results[0][1]); } --8<---------------cut here---------------end--------------->8--- 2. There should be way to set the output format form python side of things. I had to modify instantiateCiteProc by hand to set the output format to "text". You know what output format that LibreOffice plugin uses? I see "text", "html" and "rtf" as output formats. But not ODT. See https://bitbucket.org/fbennett/citeproc-js/src/tip/src/formats.js --8<---------------cut here---------------start------------->8--- function instantiateCiteProc (styleid) { // Suspenders and a belt. try { if (!styleid) { styleid = "chicago-author-date"; } if (styleid.slice(0,7) !== 'http://') { styleid = 'http://www.zotero.org/styles/' + styleid; } zotero.debug("XXX does this exist?: " + styleid); var style = zotero.Styles.get(styleid); zotero.reStructuredCSL = style.csl; zotero.reStructuredCSL.setOutputFormat("text"); } catch (e) { zotero.debug("XXX instantiateCiteProc oops: " + e); } }; --8<---------------cut here---------------end--------------->8--- Btw, I found that with my 2-day old zotero database and for printing the above 2 keys, the whole machinery takes a perceivably a lot of time. Is this your experience as well? I am not a netbook. --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=zotcite.py Content-Description: zotcite.py """ Module """ # -*- coding: utf-8 -*- import ConfigParser import json import os # Workaround for crashes seen with localename setting print os.environ["LANG"] os.environ["LANG"]="C.UTF-8" print os.environ["LANG"] import string import sys import jsbridge from zot4rst.util import unquote DEFAULT_CITATION_FORMAT = "http://www.zotero.org/styles/chicago-author-date" # placeholder for global bridge to Zotero zotero_conn = None; # verbose flag verbose_flag = False class ZoteroConn(object): def __init__(self, format, **kwargs): # connect & setup self.back_channel, self.bridge = jsbridge.wait_and_create_network("127.0.0.1", 24242) self.back_channel.timeout = self.bridge.timeout = 60 self.methods = jsbridge.JSObject(self.bridge, "Components.utils.import('resource://csl/export.js')") if zotero_conn is None: zotero_conn = ZoteroConn(DEFAULT_CITATION_FORMAT) zotero_conn.methods.instantiateCiteProc(DEFAULT_CITATION_FORMAT) print "======== KEYS ========" key1 = "I4AUIZ4S" key2 = "AKJZBHRW" print key1 print key2 print "======== ITEM_IDs ========" itemid1 = int(zotero_conn.methods.getItemId(key1)) itemid2 = int(zotero_conn.methods.getItemId(key2)) itemids = [] itemids.append(itemid1) itemids.append(itemid2) print itemids zotero_conn.methods.registerItemIds(itemids) print "======== BIBDATA ========" bibdata = unquote(json.loads(zotero_conn.methods.getBibliographyData())) print bibdata[1] print "===== CITATION REFERENCE ===== " from xciterst import CitationInfo citation = CitationInfo(); citation.id = "40"; citation.prefix="This"; citation.suffix="That"; citation = { 'citationItems' : [citation], 'properties' : { 'index' : 0, # zotero_conn.get_index(cluster) 'noteIndex': 0 # note_index }} res = zotero_conn.methods.getCitationBlock(citation) print unquote(res) --=-=-=--