emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] zotero-cite (A Proposal)


From: Jambunathan K
Subject: [O] zotero-cite (A Proposal)
Date: Sat, 12 Nov 2011 02:04:52 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (windows-nt)

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 <text> --items I1, I2 --print biblio
$ zotcite --style chicago --format <text> --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.

"""
  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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]