{
"translatorID": "5e3ad958-ac79-463d-812b-a86a9235c28f",
"label": "RDF",
"creator": "Simon Kornblith",
"target": "rdf",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 100,
"configOptions": {
"dataMode": "rdf/xml"
},
"inRepository": true,
"translatorType": 1,
"browserSupport": "gcs",
"lastUpdated": "2014-03-11 13:44:24"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2011 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see .
***** END LICENSE BLOCK *****
*/
function detectImport() {
// Make sure there are actually nodes
var nodes = Zotero.RDF.getAllResources();
if(nodes) {
return true;
}
}
var rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
var n = {
bib:"http://purl.org/net/biblio#",
bibo:"http://purl.org/ontology/bibo/",
dc1_0:"http://purl.org/dc/elements/1.0/",
dc:"http://purl.org/dc/elements/1.1/",
dcterms:"http://purl.org/dc/terms/",
prism:"http://prismstandard.org/namespaces/1.2/basic/",
prism2_0:"http://prismstandard.org/namespaces/basic/2.0/",
prism2_1:"http://prismstandard.org/namespaces/basic/2.1/",
foaf:"http://xmlns.com/foaf/0.1/",
vcard:"http://nwalsh.com/rdf/vCard#",
vcard2:"http://www.w3.org/2006/vcard/ns#", // currently used only for NSF, but is probably
// very similar to the nwalsh vcard ontology in a
// different namespace
link:"http://purl.org/rss/1.0/modules/link/",
z:"http://www.zotero.org/namespaces/export#",
eprints:"http://purl.org/eprint/terms/",
og:"http://ogp.me/ns#", // Used for Facebook's OpenGraph Protocol
article:"http://ogp.me/ns/article#",
book:"http://ogp.me/ns/book#"
};
var callNumberTypes = [n.dcterms+"LCC", n.dcterms+"DDC", n.dcterms+"UDC"];
// gets the first result set for a property that can be encoded in multiple
// ontologies
function getFirstResults(node, properties, onlyOneString) {
for(var i=0; i to collection", 2);
continue;
}
// all other items are added by ID
collection.children.push({id:Zotero.RDF.getResourceURI(child), type:"item"});
}
}
return collection;
}
function processSeeAlso(node, newItem) {
var relations;
newItem.itemID = Zotero.RDF.getResourceURI(node);
newItem.seeAlso = new Array();
if(relations = getFirstResults(node, [n.dc+"relation", n.dc1_0+"relation", n.dcterms+"relation"])) {
for each(var relation in relations) {
newItem.seeAlso.push(Zotero.RDF.getResourceURI(relation));
}
}
}
function processTags(node, newItem) {
var subjects;
newItem.tags = new Array();
if(subjects = getFirstResults(node, [n.dc+"subject", n.dc1_0+"subject", n.dcterms+"subject"])) {
for each(var subject in subjects) {
if(typeof(subject) == "string") { // a regular tag
newItem.tags.push(subject);
} else {
// a call number
var type = Zotero.RDF.getTargets(subject, rdf+"type");
if(type) {
type = Zotero.RDF.getResourceURI(type[0]);
if(type == n.z+"AutomaticTag") {
newItem.tags.push({tag:getFirstResults(subject, [rdf+"value"], true), type:1});
}
}
}
}
}
}
// gets the node with a given type from an array
function getNodeByType(nodes, type) {
if(!nodes) {
return false;
}
if(typeof(type) == "string") {
type = [type];
}
for each(var node in nodes) {
var nodeType = Zotero.RDF.getTargets(node, rdf+"type");
if(nodeType) {
nodeType = Zotero.RDF.getResourceURI(nodeType[0]);
if(type.indexOf(nodeType) != -1) { // we have a node of the correct type
return node;
}
}
}
return false;
}
// returns true if this resource is part of another (related by any arc besides
// dc:relation or dcterms:hasPart)
//
// used to differentiate independent notes and files
function isPart(node) {
var arcs = Zotero.RDF.getArcsIn(node);
var skip = false;
for each(var arc in arcs) {
arc = Zotero.RDF.getResourceURI(arc);
if(arc != n.dc+"relation" && arc != n.dc1_0+"relation"
&& arc != n.dcterms+"relation" && arc != n.dcterms+"hasPart") {
// related to another item by some arc besides see also
skip = true;
}
}
return skip;
}
function detectType(newItem, node, ret) {
if(!node) return false;
// also deal with type detection based on parts, so we can differentiate
// magazine and journal articles, and find container elements
var isPartOf = getFirstResults(node, [n.dcterms+"isPartOf"]);
// get parts of parts, because parts are sections of wholes.
if(isPartOf) {
//keep track of processed parts, so we don't end up in an infinite loop
var processedParts = isPartOf.slice(0);
for(var i=0; i