How to serialize/export an item as RDF

8 views
Skip to first unread message

Peter Sefton

unread,
Oct 29, 2009, 2:31:56 AM10/29/09
to zotero-dev
Hi all,

I'm wondering how I can get the default RDF export for a single item
in code. Looks like it involves translators, but I'm not having much
luck figuring out how I might use one to make an RDF string.

Peter

Peter Sefton

unread,
Nov 2, 2009, 12:15:49 AM11/2/09
to zotero-dev, Duncan Dickinson
Hi again,

Well I figured out how to save RDF for item or a group of items in javascript. I ran into a few problems though.

The key to exporting is translate.js

It seems that the translate() method is supposed to take an argument (line 702) but this argument doesn't appear to work, at least not for me.

To get the export to save files I had to do this:

translatorObj = new Zotero.Translate("export");
var possibleTranslators = translatorObj.getTranslators();
t = possibleTranslators[0]; //Zotero RDF
t.displayOptions["exportFileData"] = true; //This works
translatorObj.setTranslator(t);

It also seems that if you try to run the RDF translator without a file target it doesn't generate the output as a string, whereas this works fine for MODS output.

You can see more at our Trac site where we are working towards an add-on that will supplement Zotero and use the notifier to log all changes to your library out to disk.

2009/10/29 Peter Sefton <ptse...@gmail.com>



--
Peter Sefton
Manager, Software Research and Development Laboratory,
Australian Digital Futures Institute,
University of Southern Queensland
Toowoomba Queensland 4350 AUSTRALIA


Work: sef...@usq.edu.au
Private: p...@ptsefton.com

IM accounts:
Gmail: ptse...@gmail.com
Yahoo: peter_...@yahoo.com
MSN:  p...@ptsefton.com
AIM: ptsefton

p: +61 (0)7 4631 1640
m: +61 (0)410 326 955


USQ Website: http://www.usq.edu.au
Personal Website: http://ptsefton.com


Dan Stillman

unread,
Nov 2, 2009, 12:31:17 AM11/2/09
to zoter...@googlegroups.com
On 11/2/09 12:15 AM, Peter Sefton wrote:
It seems that the translate() method is supposed to take an argument (line 702) but this argument doesn't appear to work, at least not for me.

Don't know what you mean by this.


It also seems that if you try to run the RDF translator without a file target it doesn't generate the output as a string, whereas this works fine for MODS output.

This may be a current limitation of RDF support—Simon would be able to comment.


You can see more at our Trac site where we are working towards an add-on that will supplement Zotero and use the notifier to log all changes to your library out to disk.

The Notifier is primarily used for UI updates, which are a bit more forgiving, so let us know if you run into any glitches/inconsistencies.

Peter Sefton

unread,
Nov 2, 2009, 12:45:35 AM11/2/09
to zoter...@googlegroups.com
Thanks Dan

2009/11/2 Dan Stillman <dsti...@zotero.org>

On 11/2/09 12:15 AM, Peter Sefton wrote:
It seems that the translate() method is supposed to take an argument (line 702) but this argument doesn't appear to work, at least not for me.

Don't know what you mean by this.

If I pass true as the second argument to this: Zotero.Translate.prototype.translate = function(libraryID, saveAttachments)

No files are exported ie the function does not appear to work as designed. I have to set the displayOptions on the translator itself, implying to me that there is something missing in passing that parameter through to somewhere later, and the translator defaults are set to GUI defaults.
t.displayOptions["exportFileData"] = true;

This line looks odd (732):

this.saveFiles = this.saveAttachments;

Maybe it should read

 this.translator
.saveFiles  = this.saveAttachments;

But that's just a guess.





It also seems that if you try to run the RDF translator without a file target it doesn't generate the output as a string, whereas this works fine for MODS output.

This may be a current limitation of RDF support—Simon would be able to comment.


You can see more at our Trac site where we are working towards an add-on that will supplement Zotero and use the notifier to log all changes to your library out to disk.

The Notifier is primarily used for UI updates, which are a bit more forgiving, so let us know if you run into any glitches/inconsistencies.



Dan Stillman

unread,
Nov 2, 2009, 1:02:02 AM11/2/09
to zoter...@googlegroups.com
On 11/2/09 12:45 AM, Peter Sefton wrote:
> If I pass true as the second argument to this:
> Zotero.Translate.prototype.translate = function(libraryID,
> saveAttachments)
>
> No files are exported ie the function does not appear to work as designed.

No, it just doesn't do what you think it does. That parameter exists
only to allow callers to exclude attachment items on import—for example,
in the PDF recognizer, which only needs to save a regular item even if
the translator supports snapshots. It defaults to true, as indicated, so
there's never any need to pass true.

I'll add a comment to clarify this.

> I have to set the displayOptions on the translator itself

That is correct.

Reply all
Reply to author
Forward
0 new messages