Created
November 29, 2011 20:12
-
-
Save lawlesst/1406254 to your computer and use it in GitHub Desktop.
OpenURL context objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Really messy attempt at creating OpenURL context | |
objects for use in link resolver middleware. | |
Primary use will be to map resolved citiation metadata | |
from the 360 Link knowledge base and create open url | |
context objects that can be passed on to other services | |
- like Illiad - or used in other software. | |
""" | |
from eulxml import xmlmap | |
from eulxml.xmlmap import load_xmlobject_from_file | |
from eulxml.xmlmap import StringField as SF | |
import urllib | |
import sys | |
import os | |
import codecs | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
from datetime import datetime | |
""" | |
Need to map the SerSol citation dicts to standard open url | |
kevs. | |
""" | |
SCHEMA = 'http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx' | |
_schema = xmlmap.loadSchema(SCHEMA) | |
""" | |
coContainer = doc.add_element "ctx:context-objects" | |
coContainer.add_namespace("ctx","info:ofi/fmt:xml:xsd:ctx") | |
coContainer.add_namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance") | |
coContainer.add_attribute("xsi:schemaLocation", "info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx" | |
""" | |
now = datetime.now().isoformat() | |
class Common(xmlmap.XmlObject): | |
ROOT_NAMESPACES = { | |
'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | |
'ctx': 'info:ofi/fmt:xml:xsd:ctx', | |
"rft": "info:ofi/fmt:xml:xsd:journal", | |
} | |
class Journal(Common): | |
#ROOT_NS = 'info:ofi/fmt:xml:xsd:ctx' | |
""" | |
http://ocoins.info/cobg.html | |
{ | |
issn: { | |
print: "0021-843X", | |
electronic: "1939-1846" | |
}, | |
format: "journal", | |
issue: "4", | |
creatorLast: "Nolen-Hoeksema", | |
volume: "100", | |
source: "Journal of abnormal psychology (1965)", | |
creatorFirst: "S", | |
date: "1991-11", | |
title: "Responses to depression and their effects on the duration of depressive episodes", | |
pmid: "1757671", | |
spage: "569", | |
creator: "Nolen-Hoeksema, S" | |
} | |
""" | |
ROOT_NAME = 'journal' | |
title = SF('rft:atitle') | |
source = SF('rft:jtitle') | |
creator = SF('rft:au') | |
creatorFirst = SF('rft:aufirst') | |
creatorLast = SF('rft:aulast') | |
volume = SF('rft:volume') | |
issue = SF('rft:issue') | |
spage = SF('rft:spage') | |
epage = SF('rft:epage') | |
issn = SF('rft:issn') | |
eissn = SF('rft:eissn') | |
#doi = SF('rft_id:doi/') | |
schema_location = SF('@xsi:schemaLocation') | |
class Metadata(Common): | |
ROOT_NAME = 'metadata' | |
journal = xmlmap.NodeListField('journal', Journal) | |
class Referent(Common): | |
ROOT_NAME = 'referent' | |
format = SF('./ctx:metadata-by-val/ctx:format') | |
metadata = xmlmap.NodeField('./ctx:metadata-by-val/ctx:metadata', Metadata) | |
class ContextObject(Common): | |
ROOT_NAME = 'context-object' | |
timestamp = SF('@timestamp') | |
version = SF('@version') | |
identifier = SF('@identifier') | |
encoding = SF('@encoding') | |
referent = xmlmap.NodeField('ctx:referent', Referent) | |
class ContextObjects(xmlmap.XmlObject): | |
ROOT_NAME = 'context-objects' | |
ROOT_NAMESPACES = { | |
'xsi': 'http://www.w3.org/2001/XMLSchema-instance', | |
'ctx': 'info:ofi/fmt:xml:xsd:ctx', | |
#"rft": "info:ofi/fmt:xml:xsd:journal", | |
} | |
schema_location = SF('@xsi:schemaLocation') | |
context_object = xmlmap.NodeListField('ctx:context-object', ContextObject) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment