new translator, Unidade de Biologia da Conservação

2 views
Skip to first unread message

Giovanni Manghi

unread,
Sep 6, 2008, 11:31:54 PM9/6/08
to zoter...@googlegroups.com
Hi all,
I wrote a simple translator for the site of the research group I belong.

http://www.ubc.uevora.pt/index.php?option=com_jombib&Itemid=61

We publish a good number of references (actually 20000+, just
references, no pdf download but with many link to the reference page on
the publisher site) for the conservation biology field and I have been
asked to make them "zotero compatibles" and to make the translator
public.

As I have control on the output of the page that shows each reference,
and also on the reference db, I adapted the the html code to the
Scaffold tutorial that I found on the zotero site. This helped me also
because I have very limited Javascript skills.

The translator has been tested pretty deeply and it seems to work
without flaw.

Here is the code:


// Detect Code

function detectWeb(doc, url) {
if(doc.title == "UBC: referencia bibliografica") {
return "Reference found";
}
}

// End Detect Code

// Code

function doWeb(doc, url) {
scrape(doc,url);
}


function scrape(doc,url) {
var xpath = "/html/body/div/div/div[3]/div[3]/table/tbody/tr/td"
var xpathurl =
"/html/body/div/div/div[3]/div[3]/table/tbody/tr/td/a[1]"
var allRefText = Zotero.Utilities.cleanString(doc.evaluate(xpath, doc,
null, XPathResult.ANY_TYPE, null).iterateNext().textContent);
var allRefTexturl = Zotero.Utilities.cleanString(doc.evaluate(xpathurl,
doc, null, XPathResult.ANY_TYPE, null).iterateNext().textContent);


// bib data scraper code here

function getItem(reftext,re) {
var item = reftext.match(re);
// Zotero.debug(item[1]);
return item[1];
}

var TipoRe = "Type:(.*?)Title";
var tipoo = getItem(allRefText,TipoRe);

var titleRe = "Title:(.*?)Author";
var title = getItem(allRefText,titleRe);

var authorsRe = "Author.*?: (.*?)Journal";
var authors = getItem(allRefText,authorsRe);

var journalRe = "Journal:(.*?)Year";
var journal = getItem(allRefText,journalRe);

var yearRe = "Year:(.*?)Volume";
var year = getItem(allRefText,yearRe);

var volRe = "Volume:(.*?)Number";
var vol = getItem(allRefText,volRe);

var numRe = "Number:(.*?)Pages";
var num = getItem(allRefText,numRe);

var pageRe = "Pages:(.*?)Abstract";
var page = getItem(allRefText,pageRe);

var abstractRe = "Abstract:(.*?)Keywords";
var abstract = getItem(allRefText,abstractRe);

var keyRe = "Keywords:(.*?)Link";
var key = getItem(allRefText,keyRe);


// zotero entry creation code here

if (tipoo == "article")
{
tipooo = 'journalArticle';
}
else if (tipoo == "book")
{
tipooo = 'book';
}
else if (tipoo == "booklet")
{
tipooo = 'document';
}
else if (tipoo == "conference")
{
tipooo = 'conferencePaper';
}
else if (tipoo == "inbook")
{
tipooo = 'bookSection';
}
else if (tipoo == "incollection")
{
tipooo = 'bookSection';
}
else if (tipoo == "inproceedings")
{
tipooo = 'conferencePaper';
}
else if (tipoo == "manual")
{
tipooo = 'document';
}
else if (tipoo == "mastersthesis")
{
tipooo = 'thesis';
}
else if (tipoo == "misc")
{
tipooo = 'document';
}
else if (tipoo == "other")
{
tipooo = 'journalArticle';
}
else if (tipoo == "phdthesis")
{
tipooo = 'thesis';
}
else if (tipoo == "proceedings")
{
tipooo = 'conferencePaper';
}
else if (tipoo == "techreport")
{
tipooo = 'document';
}
else if (tipoo == "unpublished")
{
tipooo = 'document';
}
else
{
tipooo = 'document';
}

var newArticle = new Zotero.Item(tipooo);

var aus = authors.split(",");
for (var i=0; i< aus.length ; i++) {
newArticle.creators.push(Zotero.Utilities.cleanAuthor(aus[i],
"author"));
}

newArticle.title = title;
newArticle.publicationTitle = journal;
newArticle.date = year;
newArticle.volume = vol;
newArticle.issue = num;
newArticle.pages = page;
newArticle.abstractNote = abstract;
newArticle.keywords = key;

if (allRefTexturl == "no link")
{
newArticle.url = " ";
}
else
{
newArticle.url = allRefTexturl;
}

Zotero.debug(newArticle);

newArticle.complete();
}

// End Code

As I said I have very limited JS skills, so probably the code needs to
be cleaned.


Take care


--
 Giovanni Manghi
Conservation Biology Unit
University of Évora
Portugal

http://www.ubc.uevora.pt
giovann...@gmail.com

PGP Key available
Skype: toirao

Tel. + 351 96 7058216
--

lutra

unread,
Sep 15, 2008, 12:13:24 PM9/15/08
to zotero-dev
Hi all,
I would like to know if someone is actually reviewing the code I
posted and if there is any chance to see this translator integrated in
Zotero somewhere in the near future.

Thanks

-- GM --
> giovanni.man...@gmail.com

lutra

unread,
Sep 26, 2008, 6:00:46 PM9/26/08
to zotero-dev
Ok,
this is not urgent, but it starts to be a little frustrating.

On the Zotero site is asked to contribute in various forms, including
helping developing translators.
I made one, basically following the Scaffold tutorial.

I would like to have some feedback from the Zotero guys, even a "just
wait" would be nice, even a "we don't plan to include it in Zotero"
would be great, at least I know I will have to distribute it in
another way.


Regards

-- GM --

Dan Stillman

unread,
Sep 26, 2008, 6:24:02 PM9/26/08
to zoter...@googlegroups.com
Your translator was fixed up and checked in on September 8th, and it was
pushed to clients on the 22nd. (Usually there's not as much of a delay
between committing and pushing, but the translator development process
is a bit in flux at the moment due to changes on the trunk.)

Thanks for your contribution.

- Dan

lutra

unread,
Sep 29, 2008, 12:29:03 AM9/29/08
to zotero-dev
Sorry, my fault.

I'll give it a try in the next days and then let you know if I find
something wrong.


regards
Reply all
Reply to author
Forward
0 new messages