Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 9 merge in context jsonld to registration schema #12

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fastjsonschema = "*"
jsonref = "*"
pyyaml = "*"
click = "*"
pyld = "*"

[requires]
python_version = "3.8"
Expand Down
124 changes: 90 additions & 34 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ We provide the examples in YAML so that they're easier to read (and because JSON
$ python convert.py minimal_registration.yaml
{
"@context": "https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld",
"@id": "https://csiro.au/bogus_igsn/XXXCSIRO0001",
"igsn": "XXXCSIRO0001",
"registrant": {
"name": "CSIRO",
Expand Down Expand Up @@ -55,10 +56,11 @@ Let's walk through the examples we've got...

## Minimal registration

This is the minimal set of metadata required to define an IGSN - the `registrant` field pointing to the allocating agent, and the identifier itself. Not very useful but easy to do:
This is the minimal set of metadata required to define an IGSN - the `registrant` field pointing to the allocating agent, an `@id` tag that identifies the JSON document, and the identifier itself. Not very useful but easy to do:

```yaml
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": https://csiro.au/bogus_igsns/XXXCSIRO0001
igsn: XXXCSIRO0001
registrant:
name: CSIRO
Expand Down Expand Up @@ -168,6 +170,7 @@ We'll say that an archeology team from ANU, in collaboration with the Museum of

```yaml
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
@id: https://mfo.org/specimens/XXXMFO0001
igsn: XXXMFO0001
registrant:
name: Museum of Fictional Objects
Expand Down Expand Up @@ -205,6 +208,7 @@ The team have also sampled the stratigraphic horizon that this tooth was found i

```yaml
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
@id: https://mfo.org/specimens/XXXMFO0002
igsn: XXXMFO0002
registrant:
$ref: http://igsn.org/XXXMFO001#registrant
Expand Down
Binary file modified examples/full_registration.json
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/full_registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# IGSN data to be valid.
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld

# The ID tag identifies this document
"@id": https://csiro.au/bogus/igsn/XXXCSIRO0001

# This is the identifier that we are talking about. All identifier objects
# have a 'kind' key indicating what sort of identifier they are, and an id
# key pointing to a URI or resource definition
Expand Down
Binary file modified examples/lifecycle_1.json
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/lifecycle_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
--- # tooth

"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0001"

igsn: XXXMFO0001

Expand Down Expand Up @@ -51,6 +52,7 @@ log:

# Registration of the sediment horizon
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0002"

igsn: XXXMFO0002

Expand Down
Binary file modified examples/lifecycle_2.json
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/lifecycle_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--- # tooth

"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0001"

igsn: XXXMFO0001

Expand Down Expand Up @@ -61,6 +62,7 @@ log:

# Registration of the sediment horizon
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0002"

igsn: XXXMFO0002

Expand Down
Binary file modified examples/lifecycle_3.json
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/lifecycle_3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--- # tooth

"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0001"

igsn: XXXMFO0001

Expand Down Expand Up @@ -82,6 +83,7 @@ log:

# Registration of the sediment horizon
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://mfo.org/specimens/XXXMFO0002"

igsn: XXXMFO0002

Expand Down Expand Up @@ -134,6 +136,7 @@ log:
--- # tooth sample for CSIRO

"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld
"@id": "https://csiro.au/lab-samples/XXXCSIRO001"

igsn: XXXCSIRO001

Expand Down
Binary file modified examples/minimal_registration.json
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/minimal_registration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# IGSN data to be valid.
"@context": https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld

# The ID tag identifies this document
"@id": https://csiro.au/bogus/igsn/XXXCSIRO0001

# This is the identifier that we are talking about. All identifier objects
# have a 'kind' key indicating what sort of identifier they are, and an id
# key pointing to a URI or resource definition
Expand Down
6 changes: 5 additions & 1 deletion schema.igsn.org/json/registration/v0.1/main.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"@context": {
"const": "https://raw.githubusercontent.com/IGSN/igsn-json/master/schema.igsn.org/json/registration/v0.1/context.jsonld"
},
"@id": {
"type": "string",
"description": "An identifier for this JSON document (e.g. 'http://example-agent.org/igsn/id/XXXAGENT00234')"
},
"igsn": {
"$ref": "identifiers.schema.json#/definitions/igsnPid"
},
Expand Down Expand Up @@ -56,5 +60,5 @@
},
"log": { "$ref": "eventLog.schema.json" }
},
"required": ["@context", "igsn", "registrant"]
"required": ["@context", "@id", "igsn", "registrant"]
}
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extend-ignore =
console_output_stype = progress
log_level = INFO
junit_family = legacy
norecursedirs=tests/helpers
addopts =
--junitxml='tests/reports/test-output.junit.xml'
# --cov=app --cov-report term --cov-report xml --cov-report html
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from pathlib import Path
import sys

import pytest
import jsonref as json
from fastjsonschema import compile as compile_schema


# Get the root directory of the project
ROOT = Path(__file__).parent.parent.absolute()
TEST_DIR = ROOT / "tests"
HELPERS = ROOT / "tests" / "helpers"
sys.path.append(str(HELPERS))


@pytest.fixture()
Expand All @@ -29,7 +32,7 @@ def schema_home():
"host": "https://raw.githubusercontent.com",
"org": "IGSN",
"repo": "igsn-json",
"branch": "master",
"branch": "issue-9-Merge_in_context_jsonld_to_registration_schema",
}
return f"{github['host']}/{github['org']}/{github['repo']}/{github['branch']}"

Expand Down
Empty file added tests/helpers/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions tests/helpers/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pathlib import Path
import json
from collections import defaultdict

# Example files from examples folder
EXAMPLES = Path(__file__).parent.parent.parent / "examples"


def filenames(extension=None):
"""
Returns all the example files from the examples directory

Example files have both a JSON and YAML extension
"""
files = defaultdict(list)
for fname in EXAMPLES.iterdir():
files[fname.stem].append(fname.suffix)
names = [name for name, ext in files.items() if set(ext) == {".yaml", ".json"}]

# Wrap in extension if required
if extension is not None:
return [EXAMPLES / f"{name}.{extension}" for name in names]
else:
return names


def json_examples():
"Get all the JSON-formatted example data"
docs = {}
for name, jfile in zip(filenames(), filenames("json")):
with open(jfile, "rb") as source:
data = json.load(source)

if isinstance(data, list):
for idx, document in enumerate(data):
docs[f"{name}_doc_{id}"] = document
else:
docs[name] = data
return docs
Loading