diff --git a/sonar/modules/documents/dojson/contrib/marc21tojson/model.py b/sonar/modules/documents/dojson/contrib/marc21tojson/model.py
index 976f8da7..32d7bba9 100644
--- a/sonar/modules/documents/dojson/contrib/marc21tojson/model.py
+++ b/sonar/modules/documents/dojson/contrib/marc21tojson/model.py
@@ -474,299 +474,140 @@ def marc21_to_abstract(self, key, value):
return None
+@marc21tojson.over('identifiedBy', '001')
+@utils.ignore_value
+def marc21_to_identified_by_from_001(self, key, value):
+ """Get identifier from field 001."""
+ identified_by = self.get('identifiedBy', [])
+
+ identified_by.append({
+ 'type': 'bf:Local',
+ 'source': 'RERO DOC',
+ 'value': value
+ })
+
+ return identified_by
+
+
@marc21tojson.over('identifiedBy', '^020..')
@utils.ignore_value
-def marc21_to_identifiedBy_from_field_020(self, key, value):
+def marc21_to_identified_by_from_020(self, key, value):
"""Get identifier from field 020."""
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a'):
+ return None
+
+ identified_by.append({
+ 'type': 'bf:Isbn',
+ 'value': value.get('a')
+ })
+
+ return identified_by
- def build_identifier_from(subfield_data, status=None):
- subfield_data = subfield_data.strip()
- identifier = {'value': subfield_data}
- subfield_c = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'c',
- default='').strip()
- if subfield_c:
- identifier['acquisitionTerms'] = subfield_c
- if value.get('q'): # $q is repetitive
- identifier['qualifier'] = \
- ', '.join(utils.force_list(value.get('q')))
-
- match = re.search(r'^(.+?)\s*\((.+)\)$', subfield_data)
- if match:
- # match.group(2) : parentheses content
- identifier['qualifier'] = ', '.join(
- filter(None, [match.group(2),
- identifier.get('qualifier', '')]))
- # value without parenthesis and parentheses content
- identifier['value'] = match.group(1)
- if status:
- identifier['status'] = status
- identifier['type'] = 'bf:Isbn'
- identifiedBy.append(identifier)
-
- identifiedBy = self.get('identifiedBy', [])
- subfield_a = not_repetitive(marc21tojson.bib_id, key, value, 'a')
- if subfield_a:
- build_identifier_from(subfield_a)
- subfields_z = value.get('z')
- if subfields_z:
- for subfield_z in utils.force_list(subfields_z):
- build_identifier_from(subfield_z, status='invalid or cancelled')
- return identifiedBy or None
-
-
-@marc21tojson.over('identifiedBy', '^022..')
-@utils.ignore_value
-def marc21_to_identifiedBy_from_field_022(self, key, value):
- """Get identifier from field 022."""
- status_for = {'m': 'cancelled', 'y': 'invalid'}
- type_for = {
- 'a': 'bf:Issn',
- 'l': 'bf:IssnL',
- 'm': 'bf:IssnL',
- 'y': 'bf:Issn'
- }
- identifiedBy = self.get('identifiedBy', [])
- for subfield_code in ['a', 'l', 'm', 'y']:
- subfields_data = value.get(subfield_code)
- if subfields_data:
- if isinstance(subfields_data, str):
- subfields_data = [subfields_data]
- for subfield_data in subfields_data:
- subfield_data = subfield_data.strip()
- identifier = {}
- identifier['type'] = type_for[subfield_code]
- identifier['value'] = subfield_data
- if subfield_code in status_for:
- identifier['status'] = status_for[subfield_code]
- identifiedBy.append(identifier)
- return identifiedBy or None
-
-
-@marc21tojson.over('identifiedBy', '^024..')
+@marc21tojson.over('identifiedBy', '^0247.')
@utils.ignore_value
-def marc21_to_identifiedBy_from_field_024(self, key, value):
+def marc21_to_identified_by_from_024(self, key, value):
"""Get identifier from field 024."""
+ identified_by = self.get('identifiedBy', [])
- def populate_acquisitionTerms_note_qualifier(identifier):
- subfield_c = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'c',
- default='').strip()
- if subfield_c:
- identifier['acquisitionTerms'] = subfield_c
- subfield_d = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'd',
- default='').strip()
- if subfield_d:
- identifier['note'] = subfield_d
- if value.get('q'): # $q is repetitive
- identifier['qualifier'] = \
- ', '.join(utils.force_list(value.get('q')))
-
- subfield_2_regexp = {
- 'doi': {
- 'type': 'bf:Doi'
- },
- 'urn': {
- 'type': 'bf:Urn'
- },
- 'nipo': {
- 'type': 'bf:Local',
- 'source': 'NIPO'
- },
- 'danacode': {
- 'type': 'bf:Local',
- 'source': 'danacode'
- },
- 'vd18': {
- 'type': 'bf:Local',
- 'source': 'vd18'
- },
- 'gtin-14': {
- 'type': 'bf:Gtin14Number'
- }
- }
+ if not value.get('a') or value.get('2') != 'urn':
+ return None
- type_for_ind1 = {
- '0': {
- 'type': 'bf:Isrc'
- },
- '1': {
- 'type': 'bf:Upc'
- },
- '2': {
- 'pattern': r'^(M|9790|979-0)',
- 'matching_type': 'bf:Ismn'
- },
- '3': {
- 'pattern': r'^97',
- 'matching_type': 'bf:Ean'
- },
- '8': {
- # 33 chars example: 0000-0002-A3B1-0000-0-0000-0000-2
- 'pattern': r'^(.{24}|.{26}|(.{4}-){4}.-(.{4}\-){2}.)$',
- 'matching_type': 'bf:Isan'
- }
- }
+ identified_by.append({
+ 'type': 'bf:Urn',
+ 'value': value.get('a')
+ })
- identifiedBy = self.get('identifiedBy', [])
- identifier = {}
- subfield_a = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'a',
- default='').strip()
- subfield_2 = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- '2',
- default='').strip()
- if subfield_a:
- if re.search(r'permalink\.snl\.ch', subfield_a, re.IGNORECASE):
- identifier.update({
- 'value': subfield_a,
- 'type': 'uri',
- 'source': 'SNL'
- })
- elif re.search(r'bnf\.fr/ark', subfield_a, re.IGNORECASE):
- identifier.update({
- 'value': subfield_a,
- 'type': 'uri',
- 'source': 'BNF'
- })
- elif subfield_2:
- identifier['value'] = subfield_a
- populate_acquisitionTerms_note_qualifier(identifier)
- for pattern in subfield_2_regexp:
- if re.search(pattern, subfield_2, re.IGNORECASE):
- identifier.update(subfield_2_regexp[pattern])
- else: # without subfield $2
- ind1 = key[3] # indicateur_1
- if ind1 in ('0', '1', '2', '3', '8'):
- populate_acquisitionTerms_note_qualifier(identifier)
- match = re.search(r'^(.+?)\s*\((.*)\)$', subfield_a)
- if match:
- # match.group(2) : parentheses content
- identifier['qualifier'] = ', '.join(
- filter(
- None,
- [match.group(2),
- identifier.get('qualifier', '')]))
- # value without parenthesis and parentheses content
- identifier['value'] = match.group(1)
- else:
- identifier['value'] = subfield_a
- if 'type' in type_for_ind1[ind1]: # ind1 0,1
- identifier['type'] = type_for_ind1[ind1]['type']
- else: # ind1 in (2, 3, 8)
- data = subfield_a
- if ind1 == '8':
- data = identifier['value']
- if re.search(type_for_ind1[ind1]['pattern'], data):
- identifier['type'] = \
- type_for_ind1[ind1]['matching_type']
- else:
- identifier['type'] = 'bf:Identifier'
- else: # ind1 not in (0, 1, 2, 3, 8)
- identifier.update({
- 'value': subfield_a,
- 'type': 'bf:Identifier'
- })
- if not identifier.get('type'):
- identifier['type'] = 'bf:Identifier'
- identifiedBy.append(identifier)
- return identifiedBy or None
+ return identified_by
-@marc21tojson.over('identifiedBy', '^028..')
+@marc21tojson.over('identifiedBy', '^027..')
@utils.ignore_value
-def marc21_to_identifiedBy_from_field_028(self, key, value):
- """Get identifier from field 028."""
- type_for_ind1 = {
- '0': 'bf:AudioIssueNumber',
- '1': 'bf:MatrixNumber',
- '2': 'bf:MusicPlate',
- '3': 'bf:MusicPublisherNumber',
- '4': 'bf:VideoRecordingNumber',
- '5': 'bf:PublisherNumber',
- '6': 'bf:MusicDistributorNumber'
- }
+def marc21_to_identified_by_from_027(self, key, value):
+ """Get identifier from field 027."""
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a'):
+ return None
+
+ identified_by.append({
+ 'type': 'bf:Strn',
+ 'value': value.get('a')
+ })
- identifier = {}
- subfield_a = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'a',
- default='').strip()
- if subfield_a:
- identifier['value'] = subfield_a
- if value.get('q'): # $q is repetitive
- identifier['qualifier'] = \
- ', '.join(utils.force_list(value.get('q')))
- subfield_b = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'b',
- default='').strip()
- if subfield_b:
- identifier['source'] = subfield_b
- # key[3] is the indicateur_1
- identifier['type'] = type_for_ind1.get(key[3], 'bf:Identifier')
- identifiedBy = self.get('identifiedBy', [])
- identifiedBy.append(identifier)
- return identifiedBy or None
+ return identified_by
@marc21tojson.over('identifiedBy', '^035..')
@utils.ignore_value
-def marc21_to_identifiedBy_from_field_035(self, key, value):
+def marc21_to_identified_by_from_035(self, key, value):
"""Get identifier from field 035."""
- subfield_a = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'a',
- default='').strip()
- if subfield_a:
- identifier = {
- 'value': subfield_a,
- 'type': 'bf:Local',
- 'source': 'RERO'
- }
- identifiedBy = self.get('identifiedBy', [])
- identifiedBy.append(identifier)
- return identifiedBy or None
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a'):
+ return None
+
+ identified_by.append({
+ 'type': 'bf:Local',
+ 'source': 'RERO',
+ 'value': value.get('a')
+ })
+ return identified_by
-@marc21tojson.over('identifiedBy', '^930..')
+
+@marc21tojson.over('identifiedBy', '^037..')
@utils.ignore_value
-def marc21_to_identifiedBy_from_field_930(self, key, value):
- """Get identifier from field 930."""
- subfield_a = not_repetitive(marc21tojson.bib_id,
- key,
- value,
- 'a',
- default='').strip()
- if subfield_a:
- identifier = {}
- match = re.search(r'^\((.+?)\)\s*(.*)$', subfield_a)
- if match:
- # match.group(1) : parentheses content
- identifier['source'] = match.group(1)
- # value without parenthesis and parentheses content
- identifier['value'] = match.group(2)
- else:
- identifier['value'] = subfield_a
- identifier['type'] = 'bf:Local'
- identifiedBy = self.get('identifiedBy', [])
- identifiedBy.append(identifier)
- return identifiedBy or None
+def marc21_to_identified_by_from_037(self, key, value):
+ """Get identifier from field 037."""
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a'):
+ return None
+
+ identified_by.append({
+ 'type': 'bf:Local',
+ 'source': 'Swissbib',
+ 'value': value.get('a').replace('swissbib.ch:', '').strip()
+ })
+
+ return identified_by
+
+
+@marc21tojson.over('identifiedBy', '^088..')
+@utils.ignore_value
+def marc21_to_identified_by_from_088(self, key, value):
+ """Get identifier from field 088."""
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a'):
+ return None
+
+ identified_by.append({
+ 'type': 'bf:ReportNumber',
+ 'value': value.get('a')
+ })
+
+ return identified_by
+
+
+@marc21tojson.over('identifiedBy', '^091..')
+@utils.ignore_value
+def marc21_to_identified_by_from_091(self, key, value):
+ """Get identifier from field 091."""
+ identified_by = self.get('identifiedBy', [])
+
+ if not value.get('a') or value.get('b') != 'pmid':
+ return None
+
+ identified_by.append({
+ 'type': 'pmid',
+ 'value': value.get('a')
+ })
+
+ return identified_by
@marc21tojson.over('notes', '^500..')
diff --git a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
index df9bd310..b409755a 100644
--- a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
+++ b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json
@@ -1567,7 +1567,10 @@
"bf:Upc",
"bf:Urn",
"bf:VideoRecordingNumber",
- "uri"
+ "bf:Strn",
+ "bf:ReportNumber",
+ "uri",
+ "pmid"
],
"minLength": 1
},
diff --git a/tests/ui/documents/test_marc21tojson.py b/tests/ui/documents/test_marc21tojson.py
index 76fbe3c7..c9e3527f 100644
--- a/tests/ui/documents/test_marc21tojson.py
+++ b/tests/ui/documents/test_marc21tojson.py
@@ -1949,380 +1949,370 @@ def test_marc21_to_subjects():
assert not data.get('subjects')
-def test_marc21_to_identifiedby_from_020():
- """Test dojson identifiedBy from 020."""
+def test_marc21_to_identified_by_from_001():
+ """Test identifiedBy from 001."""
marc21xml = """
-
- 8124605254
-
-
- 9788124605257 (broché)
-
-
- 9788189997212
- hbk.
- £125.00
-
+ 327171
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Isbn',
- 'status': 'invalid or cancelled',
- 'value': '8124605254'
- }, {
- 'type': 'bf:Isbn',
- 'qualifier': 'broché',
- 'value': '9788124605257'
- }, {
- 'type': 'bf:Isbn',
- 'qualifier': 'hbk.',
- 'acquisitionTerms': '£125.00',
- 'value': '9788189997212'
+ 'type': 'bf:Local',
+ 'source': 'RERO DOC',
+ 'value': '327171'
}]
+ marc21xml = ""
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
-def test_marc21_to_identifiedby_from_022():
- """Test dojson identifiedBy from 022."""
+def test_marc21_to_identified_by_from_020():
+ """Test identifiedBy from 020."""
marc21xml = """
-
- 0264-2875
- 0264-2875
-
-
- 0264-2875
- 0080-4649
-
-
- 0080-4650
-
+
+ 9783796539138
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Issn',
- 'value': '0264-2875'
- }, {
- 'type': 'bf:IssnL',
- 'value': '0264-2875'
- }, {
- 'type': 'bf:Issn',
- 'value': '0264-2875'
- }, {
- 'type': 'bf:Issn',
- 'status': 'invalid',
- 'value': '0080-4649'
- }, {
- 'type': 'bf:IssnL',
- 'status': 'cancelled',
- 'value': '0080-4650'
+ 'type': 'bf:Isbn',
+ 'value': '9783796539138'
}]
+ # Without code $a
+ marc21xml = """
+
+
+ 9783796539138
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
+
+def test_marc21_to_identified_by_from_024():
+ """Test identifiedBy from 024."""
-def test_marc21_to_identifiedby_from_024_snl_bnf():
- """Test dojson identifiedBy from 024 field snl and bnf."""
marc21xml = """
-
- http://permalink.snl.ch/bib/chccsa86779
- permalink
-
-
- http://catalogue.bnf.fr/ark:/12148/cb312v
- uri
-
+
+ urn:nbn:ch:rero-002-118667
+ urn
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type':
- 'uri',
- 'source':
- 'SNL',
- 'value':
- 'http://permalink.snl.ch/bib/chccsa86779'
- }, {
- 'type':
- 'uri',
- 'source':
- 'BNF',
- 'value':
- 'http://catalogue.bnf.fr/ark:/12148/cb312v'
+ 'type': 'bf:Urn',
+ 'value': 'urn:nbn:ch:rero-002-118667'
}]
+ # Without code $a
+ marc21xml = """
+
+
+ urn
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
-def test_marc21_to_identifiedby_from_024_with_subfield_2():
- """Test dojson identifiedBy from 024 field with subfield 2."""
+ # Without code $2
+ marc21xml = """
+
+
+ urn:nbn:ch:rero-002-118667
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+ # $2 is a falsy value
marc21xml = """
-
- 10.1007/978-3-540-37973-7
- £125.00
- note
- doi
-
-
- urn:nbn:de:101:1-201609052530
- urn
-
-
- NIPO 035-16-060-7
- nipo
-
-
- 7290105422026
- danacode
-
-
- VD18 10153438
- vd18
-
-
- 00028947969525
- gtin-14
-
+
+ urn:nbn:ch:rero-002-118667
+ falsy_value
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
- assert data.get('identifiedBy') == [{
- 'type': 'bf:Doi',
- 'value': '10.1007/978-3-540-37973-7',
- 'acquisitionTerms': '£125.00',
- 'note': 'note'
- }, {
- 'type':
- 'bf:Urn',
- 'value':
- 'urn:nbn:de:101:1-201609052530'
- }, {
- 'type': 'bf:Local',
- 'source': 'NIPO',
- 'value': 'NIPO 035-16-060-7'
- }, {
- 'type': 'bf:Local',
- 'source': 'danacode',
- 'value': '7290105422026'
- }, {
- 'type': 'bf:Local',
- 'source': 'vd18',
- 'value': 'VD18 10153438'
- }, {
- 'type': 'bf:Gtin14Number',
- 'value': '00028947969525'
- }]
+ assert not data.get('identifiedBy')
+ # Without ind1 == 7
+ marc21xml = """
+
+
+ urn:nbn:ch:rero-002-118667
+ falsy_value
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
-def test_marc21_to_identifiedby_from_024_without_subfield_2():
- """Test dojson identifiedBy from 024 field without subfield 2."""
+
+def test_marc21_to_identified_by_from_027():
+ """Test identifiedBy from 027."""
marc21xml = """
-
- 9782100745463
-
-
- 702391010582 (vol. 2)
-
-
- Erato ECD 88030
-
-
- 604907014223 (vol. 5)
-
-
- EMI Classics 5 55585 2
-
-
- M006546565 (kritischer B., kartoniert)
- vol. 1
-
-
- 9790201858135
- Kritischer Bericht
-
-
- 4018262101065 (Bd. 1)
-
-
- 309-5-56-196162-1
- CD audio classe
-
-
- 9783737407427
- Bd 1
- pbk.
-
-
- EP 2305
-
-
- 97 EP 1234
-
-
- ELC1283925
-
-
- 0000-0002-A3B1-0000-0-0000-0000-2
-
+
+ 9789027223951
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Identifier',
- 'value': '9782100745463'
- }, {
- 'type': 'bf:Isrc',
- 'qualifier': 'vol. 2',
- 'value': '702391010582'
- }, {
- 'type': 'bf:Isrc',
- 'value': 'Erato ECD 88030'
- }, {
- 'type': 'bf:Upc',
- 'qualifier': 'vol. 5',
- 'value': '604907014223'
- }, {
- 'type': 'bf:Upc',
- 'value': 'EMI Classics 5 55585 2'
- }, {
- 'type': 'bf:Ismn',
- 'qualifier': 'kritischer B., kartoniert, vol. 1',
- 'value': 'M006546565'
- }, {
- 'type': 'bf:Ismn',
- 'qualifier': 'Kritischer Bericht',
- 'value': '9790201858135'
- }, {
- 'type': 'bf:Identifier',
- 'qualifier': 'Bd. 1',
- 'value': '4018262101065'
- }, {
- 'type': 'bf:Identifier',
- 'qualifier': 'CD audio classe',
- 'value': '309-5-56-196162-1'
- }, {
- 'type': 'bf:Ean',
- 'qualifier': 'Bd 1, pbk.',
- 'value': '9783737407427'
- }, {
- 'type': 'bf:Identifier',
- 'value': 'EP 2305'
- }, {
- 'type': 'bf:Ean',
- 'value': '97 EP 1234'
- }, {
- 'type': 'bf:Identifier',
- 'value': 'ELC1283925'
- }, {
- 'type':
- 'bf:Isan',
- 'value':
- '0000-0002-A3B1-0000-0-0000-0000-2'
+ 'type': 'bf:Strn',
+ 'value': '9789027223951'
}]
+ # Without code $a
+ marc21xml = """
+
+
+ 9789027223951
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
-def test_marc21_to_identifiedby_from_028():
- """Test dojson identifiedBy from 035."""
+
+def test_marc21_to_identified_by_from_035():
+ """Test identifiedBy from 035."""
marc21xml = """
-
- 1234
- SRC
- Qualif1
- Qualif2
-
+
+ R008966083
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:MusicPublisherNumber',
- 'source': 'SRC',
- 'qualifier': 'Qualif1, Qualif2',
- 'value': '1234'
+ 'type': 'bf:Local',
+ 'source': 'RERO',
+ 'value': 'R008966083'
}]
+ # Without code $a
marc21xml = """
-
- 1234
- SRC
- Qualif1
- Qualif2
-
+
+ R008966083
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
+
+def test_marc21_to_identified_by_from_037():
+ """Test identifiedBy from 037."""
+
+ marc21xml = """
+
+
+
+ swissbib.ch:(NATIONALLICENCE)springer-10.1007/s00209-014-1344-0
+
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Identifier',
- 'source': 'SRC',
- 'qualifier': 'Qualif1, Qualif2',
- 'value': '1234'
+ 'type': 'bf:Local',
+ 'source': 'Swissbib',
+ 'value': '(NATIONALLICENCE)springer-10.1007/s00209-014-1344-0'
}]
+ # Without code $a
+ marc21xml = """
+
+
+
+ swissbib.ch:(NATIONALLICENCE)springer-10.1007/s00209-014-1344-0
+
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
-def test_marc21_to_identifiedby_from_035():
- """Test dojson identifiedBy from 035."""
+
+def test_marc21_to_identified_by_from_088():
+ """Test identifiedBy from 088."""
marc21xml = """
-
- R008945501
-
+
+ 25
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Local',
- 'source': 'RERO',
- 'value': 'R008945501'
+ 'type': 'bf:ReportNumber',
+ 'value': '25'
}]
+ # Without code $a
+ marc21xml = """
+
+
+ 25
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
-def test_marc21_to_identifiedby_from_930():
- """Test dojson identifiedBy from 930."""
- # identifier with source in parenthesis
+def test_marc21_to_identified_by_from_091():
+ """Test identifiedBy from 091."""
+
marc21xml = """
-
- (OCoLC) ocm11113722
-
+
+ 24638240
+ pmid
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
- 'type': 'bf:Local',
- 'source': 'OCoLC',
- 'value': 'ocm11113722'
+ 'type': 'pmid',
+ 'value': '24638240'
}]
- # identifier without source in parenthesis
+
+ # Without code $a
marc21xml = """
-
- ocm11113722
-
+
+ pmid
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
+ # Without code $b
+ marc21xml = """
+
+
+ 24638240
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
+ # Invalid code $b
+ marc21xml = """
+
+
+ 24638240
+ fake
+
+
+ """
+ marc21json = create_record(marc21xml)
+ data = marc21tojson.do(marc21json)
+ assert not data.get('identifiedBy')
+
+
+def test_marc21_to_identified_by_full():
+ """Test full identified by."""
+ marc21xml = """
+
+ 327171
+
+ 9783796539138
+
+
+ urn:nbn:ch:rero-002-118667
+ urn
+
+
+ 9789027223951
+
+
+ R008966083
+
+
+
+ swissbib.ch:(NATIONALLICENCE)springer-10.1007/s00209-014-1344-0
+
+
+
+ 25
+
+
+ 24638240
+ pmid
+
"""
marc21json = create_record(marc21xml)
data = marc21tojson.do(marc21json)
assert data.get('identifiedBy') == [{
'type': 'bf:Local',
- 'value': 'ocm11113722'
+ 'source': 'RERO DOC',
+ 'value': '327171'
+ }, {
+ 'type': 'bf:Isbn',
+ 'value': '9783796539138'
+ }, {
+ 'type': 'bf:Urn',
+ 'value': 'urn:nbn:ch:rero-002-118667'
+ }, {
+ 'type': 'bf:Strn',
+ 'value': '9789027223951'
+ }, {
+ 'type': 'bf:Local',
+ 'source': 'RERO',
+ 'value': 'R008966083'
+ }, {
+ 'type': 'bf:Local',
+ 'source': 'Swissbib',
+ 'value': '(NATIONALLICENCE)springer-10.1007/s00209-014-1344-0'
+ }, {
+ 'type': 'bf:ReportNumber',
+ 'value': '25'
+ }, {
+ 'type': 'pmid',
+ 'value': '24638240'
}]