|
3 | 3 | from warnings import warn
|
4 | 4 |
|
5 | 5 | import pandas as pd
|
| 6 | +from nameparser import HumanName |
6 | 7 |
|
7 | 8 | import openminds.latest.core as omcore
|
8 | 9 | import openminds.latest.controlled_terms as controlled_terms
|
|
12 | 13 | from .mapping import bids2openminds_instance
|
13 | 14 |
|
14 | 15 |
|
| 16 | +def create_openminds_person(full_name): |
| 17 | + |
| 18 | + alternate_names = [] |
| 19 | + person = HumanName(full_name) |
| 20 | + given_name = person.first |
| 21 | + family_name = person.last |
| 22 | + |
| 23 | + if person.middle: |
| 24 | + alternate_names.append(person.full_name) |
| 25 | + |
| 26 | + if person.nickname: |
| 27 | + alternate_names.append(person.nickname) |
| 28 | + |
| 29 | + if not alternate_names: |
| 30 | + alternate_names = None |
| 31 | + |
| 32 | + openminds_person = omcore.Person( |
| 33 | + alternate_names=alternate_names, given_name=given_name, family_name=family_name) |
| 34 | + |
| 35 | + return openminds_person |
| 36 | + |
| 37 | + |
| 38 | +def create_persons(dataset_description, collection): |
| 39 | + |
| 40 | + if "Authors" in dataset_description: |
| 41 | + person_list = dataset_description["Authors"] |
| 42 | + else: |
| 43 | + return None |
| 44 | + |
| 45 | + if not (isinstance(person_list, list)): |
| 46 | + # handel's only one name |
| 47 | + if isinstance(person_list, str): |
| 48 | + openminds_person = create_openminds_person(person_list) |
| 49 | + collection.add(openminds_person) |
| 50 | + return openminds_person |
| 51 | + else: |
| 52 | + return None |
| 53 | + |
| 54 | + openminds_list = [] |
| 55 | + for person in person_list: |
| 56 | + openminds_person = create_openminds_person(person) |
| 57 | + openminds_list.append(openminds_person) |
| 58 | + collection.add(openminds_person) |
| 59 | + |
| 60 | + return openminds_list |
| 61 | + |
| 62 | + |
15 | 63 | def create_techniques(layout_df):
|
16 | 64 | suffixs = layout_df["suffix"].unique().tolist()
|
17 | 65 | techniques = []
|
@@ -56,8 +104,7 @@ def create_dataset_version(bids_layout, dataset_description, layout_df, studied_
|
56 | 104 | else:
|
57 | 105 | digital_identifier = None
|
58 | 106 |
|
59 |
| - # TODO extract person |
60 |
| - # author=person_create(dataset_description["Authors"]) |
| 107 | + authors = create_persons(dataset_description, collection) |
61 | 108 |
|
62 | 109 | if "Acknowledgements" in dataset_description:
|
63 | 110 | other_contribution = dataset_description["Acknowledgements"]
|
@@ -92,6 +139,7 @@ def create_dataset_version(bids_layout, dataset_description, layout_df, studied_
|
92 | 139 | experimental_approaches=experimental_approaches,
|
93 | 140 | short_name=dataset_description["Name"],
|
94 | 141 | studied_specimens=studied_specimens,
|
| 142 | + authors=authors, |
95 | 143 | techniques=techniques,
|
96 | 144 | how_to_cite=how_to_cite,
|
97 | 145 | repository=file_repository,
|
|
0 commit comments