Skip to content

Commit 16111c0

Browse files
authored
Some changes after meeting with lauri (#3)
* Changed identifying keys to include $ sign * Changed mapper key to be in results.eln.lab_ids * Changing example to ELNMeasurements * Changed example upload to use basesections, removed own example classes * Fixing test * Fix regex pattern in mainfile_contents_dict * added pagination to query * Changed example from Measurement to Process * Fix escape character in mainfile_contents_dict
1 parent e7fa74d commit 16111c0

21 files changed

Lines changed: 220 additions & 674 deletions

docs/reference/references.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The JSON mapper the contains information of the schemas to map. Each of these st
1616
- ```main_key```: Mandatory for all schemas except the one with ```"is_main": "True"```. Gives the key in the main NOMAD schema, where this section is attached. Can be nested with ".". Format: string.
1717
- ```repeats```: Optional, indicates that the ```main_key``` point is a repeatable subsection, where this schema is just appended to. Default value: False. Format: boolean.
1818
- ```is_archive```: Optional, indicates that this schema is a separate archive and only the reference is linked in the main entry. Default value: False. Format: boolean.
19-
- ```rules```: Mandatory, contains mapping rules for the data. Simple mappings (also nested with ".") from source to target can be given just by ```"source": "target"```, more complex mapping rules are possible as described in the [Transformer]().
19+
- ```rules```: Mandatory, contains mapping rules for the data. Simple mappings (also nested with ".") from source to target can be given just by ```"source": "target"```, more complex mapping rules are possible as described in the [Transformer](https://nomad-lab.eu/prod/v1/docs/howto/manage/program/json_transformer.html).
2020

2121
## The data file
2222

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ where = ["src"]
119119
json_mapper_schema_package = "nomad_json_parser.schema_packages:json_mapper_schema_package"
120120
json_mapper_parser = "nomad_json_parser.parsers:json_mapper_parser"
121121
mapped_json_parser = "nomad_json_parser.parsers:mapped_json_parser"
122-
example_schema_package = "nomad_json_parser.schema_packages:example_schema_package"
123122
example_upload_entry_point = "nomad_json_parser.example_uploads:example_upload_entry_point"
124123

125124
[tool.cruft]

src/nomad_json_parser/example_uploads/json_mapper/README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ This is an example of a mapping from a JSON file to a NOMAD schema. Firstly, a m
77
Below, you find an overview of your uploaded data.
88
Click on the `> /` button to get a list of your data or select **FILES** from the top menu of this upload.
99

10-
The `example_mapper.json` contains the `json_mapper_class_key` against which the data files are tested later on. Additionally, it defines the classes used in the NOMAD schema and contains the rules how to map between the data JSON and the schema. The mapping rules follow the ones of the [NOMAD Transformer](https://nomad-lab.eu/prod/v1/docs/howto/programmatic/json_transformer.html).
10+
The `example_mapper.json` contains the `$json_mapper_class_key` against which the data files are tested later on. Additionally, it defines the classes used in the NOMAD schema and contains the rules how to map between the data JSON and the schema. The mapping rules follow the ones of the [NOMAD Transformer](https://nomad-lab.eu/prod/v1/docs/howto/programmatic/json_transformer.html).
1111

12-
The `example_data.json` contains the `mapped_json_class_key` to identify the suitable mapper and all data that should be mapped into the NOMAD schema.
12+
The `example_data.json` contains the `$mapped_json_class_key` to identify the suitable mapper and all data that should be mapped into the NOMAD schema.
1313

1414
You can create your own mapper and data files and try them out here or in separate uploads.
1515

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
2-
"mapped_json_class_key": "examplemapper",
3-
"Mainname": "This is the main name",
4-
"Sublevels": {"SublevelOne": "This is sublevel 1 name", "Sublevel2name": "This is sublevel 2 name", "Further": {"Sublevel3name": "This is sublevel 3 name"}},
5-
"Repeating": {"R1": "First section", "R2": "Second section"},
6-
"value": 1,
7-
"unit": "cm",
8-
"value_list": [1,3.4,1.5,2.6],
9-
"value_unit": "g",
10-
"reference_name": "This is the reference name"
2+
"$mapped_json_class_key": "basesectionexamplemapper",
3+
"title": "Create NaCl solution",
4+
"What_did_I_do": "Solution by stirring",
5+
"Details": {
6+
"Step_1": {
7+
"step_name": "NaCl into H2O",
8+
"step_description": "Put NaCl into H2O"
9+
},
10+
"Step_2": {
11+
"step_name": "Stirring",
12+
"step_description": "Stir clockwise",
13+
"How_long_did_it_take": 300.0,
14+
"time_unit": "seconds"
15+
}
16+
},
17+
"Chemicals": {
18+
"name": "Rocksalt",
19+
"labid": "JN123_NaCl",
20+
"substance_formula": "NaCl"
21+
}
1122
}
Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,54 @@
11
{
2-
"json_mapper_class_key": "examplemapper",
2+
"$json_mapper_class_key": "basesectionexamplemapper",
33
"main_schema": {
44
"is_main": "True",
5-
"schema": "nomad_json_parser.schema_packages.example.MainLevel",
6-
"rules": {
7-
"ID":{
8-
"source": "Mainname",
9-
"target": "string"
10-
},
11-
"name": {
12-
"source": "Main_name_real",
13-
"target": "name",
14-
"default_value": "default_name"
15-
}
16-
}
17-
},
18-
"Sublevel1": {
19-
"schema": "nomad_json_parser.schema_packages.example.SubLevel1",
20-
"main_key": "nesting",
21-
"rules": {
22-
"ID":{
23-
"source": "Sublevels.SublevelOne",
24-
"target": "string"
25-
}
26-
}
27-
},
28-
"Sublevel2": {
29-
"schema": "nomad_json_parser.schema_packages.example.SubLevel2",
30-
"main_key": "nesting.nesting",
31-
"rules": {
32-
"ID":{
33-
"source": "Sublevels.Sublevel2name",
34-
"target": "string"
35-
},
36-
"IDfd":{
37-
"source": "Sublevels.Sublevel2name",
38-
"target": "name"
5+
"schema": "nomad.datamodel.metainfo.basesections.v1.Process",
6+
"rules": {
7+
"title": "name",
8+
"What_did_I_do": "method",
9+
"location": {
10+
"source": "location",
11+
"target": "location",
12+
"default_value": "MPI CPfS Dresden"
3913
}
4014
}
4115
},
42-
"Sublevel3": {
43-
"schema": "nomad_json_parser.schema_packages.example.SubLevel3",
44-
"main_key": "nesting.nesting.nesting",
45-
"rules": {
46-
"ID":{
47-
"source": "Sublevels.Further.Sublevel3name",
48-
"target": "string"
49-
}
50-
}
51-
},
52-
"Repeating1": {
53-
"schema": "nomad_json_parser.schema_packages.example.SubLevelRepeating",
54-
"main_key": "repeating",
16+
"Activity_Step1": {
17+
"schema": "nomad.datamodel.metainfo.basesections.v1.ProcessStep",
18+
"main_key": "steps",
5519
"repeats": "True",
5620
"rules": {
57-
"Repeating.R1": "string"
21+
"Details.Step_1.step_name": "name",
22+
"Details.Step_1.step_description": "description"
5823
}
5924
},
60-
"Repeating2": {
61-
"schema": "nomad_json_parser.schema_packages.example.SubLevelRepeating",
62-
"main_key": "repeating",
25+
"ProcessStep2": {
26+
"schema": "nomad.datamodel.metainfo.basesections.v1.ProcessStep",
27+
"main_key": "steps",
6328
"repeats": "True",
6429
"rules": {
65-
"Repeating.R2": "string"
30+
"Details.Step_2.step_name": "name",
31+
"Details.Step_2.step_description": "description",
32+
"Details.Step_2.How_long_did_it_take": "duration",
33+
"Details.Step_2.time_unit": "tempunits.duration"
6634
}
6735
},
68-
"Unit": {
69-
"schema": "nomad_json_parser.schema_packages.example.SubLevelUnit",
70-
"main_key": "unit",
71-
"rules": {
72-
"value": "unit",
73-
"unit": "tempunits.unit"
74-
}
75-
},
76-
"List": {
77-
"schema": "nomad_json_parser.schema_packages.example.SubLevelList",
78-
"main_key": "list",
36+
"Sample": {
37+
"schema": "nomad.datamodel.metainfo.basesections.v1.CompositeSystemReference",
38+
"main_key": "samples",
39+
"repeats": "True",
7940
"rules": {
80-
"value_list": "unit",
81-
"value_unit": "tempunits.unit"
41+
"Chemicals.name": "name"
8242
}
8343
},
84-
"Reference": {
85-
"schema": "nomad_json_parser.schema_packages.example.SubLevelReference",
86-
"main_key": "reference",
44+
"System": {
45+
"schema": "nomad.datamodel.metainfo.basesections.v1.CompositeSystem",
46+
"main_key": "samples.reference",
8747
"is_archive": "True",
8848
"rules": {
89-
"reference_name": "name"
49+
"Chemicals.labid": "lab_id",
50+
"Chemicals.substance_formula": "name"
9051
}
52+
9153
}
9254
}

src/nomad_json_parser/parsers/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def load(self):
1414
name='MapperParser for Json Mapper files',
1515
description="""Parser for Json Mapping files.""",
1616
mainfile_name_re=r'.+\.json',
17-
mainfile_mime_re='application/json',
18-
mainfile_contents_re=r'.+json_mapper_class_key',
17+
# mainfile_mime_re='application/json',
18+
mainfile_contents_dict={'__has_key': r'\$json_mapper_class_key'},
1919
)
2020

2121

@@ -30,6 +30,6 @@ def load(self):
3030
name='JsonParser for Json Mapped files',
3131
description="""Parser for Json Mapped files.""",
3232
mainfile_name_re=r'.+\.json',
33-
mainfile_mime_re='application/json',
34-
mainfile_contents_re=r'.+mapped_json_class_key',
33+
# mainfile_mime_re='application/json',
34+
mainfile_contents_dict={'__has_key': r'\$mapped_json_class_key'},
3535
)

0 commit comments

Comments
 (0)