Skip to content

Commit

Permalink
deposit: improve document type detection.
Browse files Browse the repository at this point in the history
If field 502 is available in the record, it is
analyzed to determine the type of document.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Nov 9, 2021
1 parent dc2d35c commit cb9edd2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
27 changes: 15 additions & 12 deletions sonar/modules/documents/dojson/sru/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,23 +507,22 @@ def determine_type(field):
"""Determine type of document."""
# Bachelor thesis
if 'bachelor' in field.get(
'a', '') or 'bachelor' in field.get('b', ''):
'a', '').lower() or 'bachelor' in field.get('b', '').lower():
return 'coar:c_7a1f'

# Master thesis
if 'master' in field.get('a', '') or 'master' in field.get(
'b', ''):
if 'master' in field.get('a', '').lower() or 'master' in field.get(
'b', '').lower():
return 'coar:c_bdcc'

# Doctoral thesis
if 'dissertation' in field.get(
'a', '') or 'dissertation' in field.get(
'b', '') or 'thèse' in field.get(
'a', '') or 'thèse' in field.get('b', ''):
'a', '').lower() or 'dissertation' in field.get(
'b', '').lower() or 'thèse' in field.get(
'a', '').lower() or 'thèse' in field.get('b', '')\
.lower():
return 'coar:c_db06'

# Thesis
return 'coar:c_46ec'

leader_06 = value[6]

Expand Down Expand Up @@ -570,11 +569,15 @@ def determine_type(field):
if field_502:
if type(field_502) == tuple:
for fld502 in field_502:
# Bachelor thesis
return determine_type(fld502)
doctype = determine_type(fld502)
if doctype:
return doctype
else:
# Bachelor thesis
return determine_type(field_502)
doctype = determine_type(field_502)
if doctype:
return doctype
# Thesis
return 'coar:c_46ec'
# Book
if leader_07 == 'm':
return 'coar:c_2f33'
Expand Down
14 changes: 14 additions & 0 deletions tests/api/swisscovery/test_swisscovery_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


def test_get_record(client, user, submitter):
"""Test get record on swisscovery."""
url = url_for('swisscovery.get_record')

# Not logged
Expand Down Expand Up @@ -184,3 +185,16 @@ def test_get_record(client, user, submitter):
}
}
}


def test_document_type(client, submitter):
"""Test of the document type with the content of field 502."""
login_user_via_session(client, email=submitter['email'])
res = client.get(
url_for('swisscovery.get_record',
query='991050676859705501',
type='mms_id',
format='deposit'))
assert res.status_code == 200
data = res.json
assert data['metadata']['documentType'] == 'coar:c_db06'

0 comments on commit cb9edd2

Please # to comment.