Exemple #1
0
    def test_0000_json_import_export_cycle(self):
        testid = 'test1'
        citation = Citation(testid)
        citation.ids = [u'urn:test1',]
        citation.title = u'Test Title One'
        citation.creator = [u'Tester One', u'Tester Two']
        citation.issued = u'2001-01-01'
        citation.bibliographicCitation = u'Test Journal'
        citation.abstract = None

        self.container[citation.id] = citation
        jsonstr = self.exporter.export(self.container)
        jsonstream = StringIO(jsonstr)

        new_container = self.folder
        self.importer.parseInto(new_container, jsonstream)
        
        self.assertEqual(new_container[testid].id, 
                         self.container[testid].id)
        self.assertEqual(new_container[testid].ids[0], 
                         self.container[testid].ids[0])
        self.assertEqual(new_container[testid].title, 
                         self.container[testid].title)
        self.assertEqual(new_container[testid].creator, 
                         self.container[testid].creator)
Exemple #2
0
    def test_0000_json_import_export_cycle(self):
        testid = 'test1'
        citation = Citation(testid)
        citation.ids = [
            u'urn:test1',
        ]
        citation.title = u'Test Title One'
        citation.creator = [u'Tester One', u'Tester Two']
        citation.issued = u'2001-01-01'
        citation.bibliographicCitation = u'Test Journal'
        citation.abstract = None

        self.container[citation.id] = citation
        jsonstr = self.exporter.export(self.container)
        jsonstream = StringIO(jsonstr)

        new_container = self.folder
        self.importer.parseInto(new_container, jsonstream)

        self.assertEqual(new_container[testid].id, self.container[testid].id)
        self.assertEqual(new_container[testid].ids[0],
                         self.container[testid].ids[0])
        self.assertEqual(new_container[testid].title,
                         self.container[testid].title)
        self.assertEqual(new_container[testid].creator,
                         self.container[testid].creator)
Exemple #3
0
    def parse(self, pmid, *a, **kw):
        """\
        Convert pmid into a citation object.
        """

        def to_medline(article):
            abbr = article.Journal.ISOAbbreviation
            pubdate = u' '.join(list(article.Journal.JournalIssue.PubDate))
            volume = article.Journal.JournalIssue.Volume
            issue = article.Journal.JournalIssue.Issue
            pages = article.Pagination.MedlinePgn
            result = u'%s %s;%s(%s):%s.' % (abbr, pubdate, volume, issue, pages)
            return result

        def to_author_list(article):
            author = article.AuthorList.Author
            if not isinstance(author, list):
                author = [author]
            return [u'%s %s' % (a.LastName, a.Initials) for a in author]

        def to_ids(id_):
            # assume info and miriam are all valid
            miriam_base = u'urn:miriam:pubmed:%s'
            info_base = u'info:pmid/%s'
            return [miriam_base % id_, info_base % id_]

        # XXX need to verify that we already have this item.

        try:
            raw = self.service.run_eFetch(db=self.db, id=pmid)
        except SOAPTimeoutError:
            # XXX handle timeout
            raise
        except Error:
            # XXX any SOAP error
            raise
        except:
            # Other errors will just be raised.
            raise

        # using info for now
        obj_id = str('pmid-%s' % pmid)
        article = raw.PubmedArticle.MedlineCitation.Article

        citation = Citation(obj_id)
        citation.ids = to_ids(pmid)
        citation.title = unicode(article.ArticleTitle)
        citation.creator = to_author_list(article)
        citation.issued = unicode(article.Journal.JournalIssue.PubDate.Year)
        try:
            # XXX sometimes this is not available.
            citation.abstract = unicode(article.Abstract.AbstractText)
        except:
            citation.abstract = u''
        citation.bibliographicCitation = to_medline(article)

        return [citation]
Exemple #4
0
    def parse(self, stream=None, *a, **kw):

        if not hasattr(stream, 'read'):
            raise TypeError('input must be a stream')

        raw_items = json.load(stream)
        results = []

        for raw_citation in raw_items:
            rawid = raw_citation['id']
            item = Citation(str(rawid))
            item.ids = raw_citation['ids']
            item.title = raw_citation['title']
            item.creator = raw_citation['creator']
            item.issued = raw_citation['issued']
            item.bibliographicCitation = raw_citation['bibliographicCitation']
            results.append(item)

        return results
Exemple #5
0
    def parse(self, stream=None, *a, **kw):

        if not hasattr(stream, 'read'):
            raise TypeError('input must be a stream')

        raw_items = json.load(stream)
        results = []

        for raw_citation in raw_items:
            rawid = raw_citation['id']
            item = Citation(str(rawid))
            item.ids = raw_citation['ids']
            item.title = raw_citation['title']
            item.creator = raw_citation['creator']
            item.issued = raw_citation['issued']
            item.bibliographicCitation = raw_citation['bibliographicCitation']
            results.append(item)

        return results