Exemplo n.º 1
0
 def testMapPmids2Dois(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate', date.today()))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({1: 'id1', 2: 'id2'}, Identifier.mapPmids2Dois([1, 2, 3]))
     self.assertDictEqual({}, Identifier.mapPmids2Dois([3, 4]))
Exemplo n.º 2
0
 def testMapPmids2Dois(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(DefaultCitation(2))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({1: 'id1', 2: 'id2'}, Identifier.mapPmids2Dois([1, 2, 3]))
     self.assertDictEqual({}, Identifier.mapPmids2Dois([3, 4]))
Exemplo n.º 3
0
 def testDoi2Pmid(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate',
                           date.today()))
     self.sess.commit()
     self.assertEqual(1, Identifier.doi2pmid('id'))
     self.assertEqual(None, Identifier.doi2pmid('other'))
Exemplo n.º 4
0
 def testPmid2Doi(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate',
                           date.today()))
     self.sess.commit()
     self.assertEqual('id', Identifier.pmid2doi(1))
     self.assertEqual(None, Identifier.pmid2doi(2))
Exemplo n.º 5
0
 def testMapDois2Pmids(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(DefaultCitation(2))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({'id1': 1, 'id2': 2},
                          Identifier.mapDois2Pmids(['id1', 'id2', 'id3']))
     self.assertDictEqual({}, Identifier.mapDois2Pmids(['id3', 'id4']))
Exemplo n.º 6
0
 def testMapDois2Pmids(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate', date.today()))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({'id1': 1, 'id2': 2},
                          Identifier.mapDois2Pmids(['id1', 'id2', 'id3']))
     self.assertDictEqual({}, Identifier.mapDois2Pmids(['id3', 'id4']))
Exemplo n.º 7
0
 def testMapPmids2Dois(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(DefaultCitation(2))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({
         1: 'id1',
         2: 'id2'
     }, Identifier.mapPmids2Dois([1, 2, 3]))
     self.assertDictEqual({}, Identifier.mapPmids2Dois([3, 4]))
Exemplo n.º 8
0
 def testMapDois2Pmids(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(DefaultCitation(2))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({
         'id1': 1,
         'id2': 2
     }, Identifier.mapDois2Pmids(['id1', 'id2', 'id3']))
     self.assertDictEqual({}, Identifier.mapDois2Pmids(['id3', 'id4']))
Exemplo n.º 9
0
 def testMapDois2Pmids(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate',
                           date.today()))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({
         'id1': 1,
         'id2': 2
     }, Identifier.mapDois2Pmids(['id1', 'id2', 'id3']))
     self.assertDictEqual({}, Identifier.mapDois2Pmids(['id3', 'id4']))
Exemplo n.º 10
0
 def testMapPmids2Dois(self):
     self.sess.add(Identifier(1, 'doi', 'id1'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate',
                           date.today()))
     self.sess.add(Identifier(2, 'doi', 'id2'))
     self.sess.commit()
     self.assertDictEqual({
         1: 'id1',
         2: 'id2'
     }, Identifier.mapPmids2Dois([1, 2, 3]))
     self.assertDictEqual({}, Identifier.mapPmids2Dois([3, 4]))
Exemplo n.º 11
0
    def ArticleId(self, element):
        instance = None
        ns = element.get('IdType').strip().lower()
        text = element.text.strip()

        if ns in self.namespaces:
            if re.match('\d[\d\.]+/.+', element.text.strip()) and \
                    'doi' not in self.namespaces:
                self.namespaces.add('doi')
                instance = Identifier(self.pmid, 'doi', text)
            else:
                logger.info('skipping duplicate %s identifier "%s"', ns, text)
        else:
            self.namespaces.add(ns)
            instance = Identifier(self.pmid, ns, text)

        return instance
Exemplo n.º 12
0
    def OtherID(self, element):
        if element.get('Source', None) == 'NLM':
            text = element.text.strip()

            if text.startswith('PMC'):
                if 'pmc' not in self.namespaces:
                    self.namespaces.add('pmc')
                    return Identifier(self.pmid, 'pmc', text.split(' ', 1)[0])
Exemplo n.º 13
0
 def testPmid2Doi(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(DefaultCitation(2))
     self.sess.commit()
     self.assertEqual('id', Identifier.pmid2doi(1))
     self.assertEqual(None, Identifier.pmid2doi(2))
Exemplo n.º 14
0
    def ELocationID(self, element):
        ns = element.get('EIdType').strip().lower()

        if ns not in self.namespaces:
            self.namespaces.add(ns)
            return Identifier(self.pmid, ns, element.text.strip())
Exemplo n.º 15
0
 def testDoi2Pmid(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(DefaultCitation(2))
     self.sess.commit()
     self.assertEqual(1, Identifier.doi2pmid('id'))
     self.assertEqual(None, Identifier.doi2pmid('other'))
Exemplo n.º 16
0
 def testPmid2Doi(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(DefaultCitation(2))
     self.sess.commit()
     self.assertEqual('id', Identifier.pmid2doi(1))
     self.assertEqual(None, Identifier.pmid2doi(2))
Exemplo n.º 17
0
 def testPmid2Doi(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate', date.today()))
     self.sess.commit()
     self.assertEqual('id', Identifier.pmid2doi(1))
     self.assertEqual(None, Identifier.pmid2doi(2))
Exemplo n.º 18
0
 def testDoi2Pmid(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(Medline(2, 'MEDLINE', 'Journal', 'PubDate', date.today()))
     self.sess.commit()
     self.assertEqual(1, Identifier.doi2pmid('id'))
     self.assertEqual(None, Identifier.doi2pmid('other'))
Exemplo n.º 19
0
from io import StringIO
from tempfile import TemporaryFile

from medic.orm import Medline, Section, Author, Descriptor, Qualifier, Database, Identifier, \
        Chemical, Keyword, PublicationType
from medic.crud import _dump

DATA = [
    Section(1, 1, 'Title', 'The Title'),
    Section(1, 2, 'Abstract', 'The Abstract'),
    Descriptor(1, 1, 'd_name', True),
    Descriptor(1, 2, 'd_name'),
    Qualifier(1, 1, 1, 'q_name', True),
    Author(1, 1, 'first'),
    Author(1, 2, 'last'),
    Identifier(1, 'ns', 'id'),
    Database(1, 'name', 'accession'),
    PublicationType(1, 'some'),
    PublicationType(1, 'another'),
    Chemical(1, 1, 'name', 'uid'),
    Keyword(1, 'NOTNLM', 1, 'name', True),
    Medline(1, 'MEDLINE', 'journal', 'pub_date', date.today()),
]


class ParserMock:
    def __init__(self, instances):
        self.instances = instances

    def parse(self, _):
        for i in self.instances:
Exemplo n.º 20
0
 def testToString(self):
     self.assertEqual('1\tns\tid\n', str(Identifier(1, 'ns', 'id')))
Exemplo n.º 21
0
 def testToRepr(self):
     self.assertEqual('Identifier<1:ns>', repr(Identifier(1, 'ns', 'id')))
Exemplo n.º 22
0
 def testDoi2Pmid(self):
     self.sess.add(Identifier(1, 'doi', 'id'))
     self.sess.add(DefaultCitation(2))
     self.sess.commit()
     self.assertEqual(1, Identifier.doi2pmid('id'))
     self.assertEqual(None, Identifier.doi2pmid('other'))
Exemplo n.º 23
0
 def testRelations(self):
     i = Identifier(1, 'ns', 'id')
     self.sess.add(i)
     self.sess.commit()
     self.assertEqual({'ns': i}, self.M.identifiers)
     self.assertEqual(self.M, i.citation)