-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
901,268 additions
and
700 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import json | ||
from pathlib import Path | ||
|
||
from importlib import resources | ||
from cell_annotation_schema import resource | ||
|
||
|
||
class CurieToIriConverter: | ||
|
||
DEFAULT_JSONLD_FILE_NAME = 'prefixes.jsonld' | ||
|
||
def __init__(self, jsonld_file=DEFAULT_JSONLD_FILE_NAME): | ||
self.jsonld_file = jsonld_file | ||
self.prefix_mappings = self.load_prefix_mappings(self.jsonld_file) | ||
|
||
@staticmethod | ||
def load_prefix_mappings(jsonld_file_name): | ||
prefix_resource_file = resources.files(resource) / jsonld_file_name | ||
if os.path.exists(jsonld_file_name): | ||
# read from the path provided by the user | ||
with open(jsonld_file_name, 'r') as file: | ||
prefixes = json.load(file) | ||
elif os.path.exists(prefix_resource_file): | ||
# read from importlib.resources (resource) package | ||
prefixes = json.loads(Path(prefix_resource_file).read_text()) | ||
else: | ||
# read from resource folder | ||
resource_dir = os.path.join(os.path.dirname(__file__), "./resource") | ||
prefixes_path = os.path.join(resource_dir, jsonld_file_name) | ||
prefixes = json.loads(Path(prefixes_path).read_text()) | ||
return prefixes.get('@context', {}) | ||
|
||
def curie_to_iri(self, curie): | ||
prefix, reference = curie.split(':', 1) | ||
if prefix in self.prefix_mappings: | ||
return self.prefix_mappings[prefix] + reference | ||
else: | ||
raise ValueError(f"Prefix '{prefix}' not found in prefix mappings.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from linkml_runtime.dumpers.json_dumper import JSONDumper | ||
from linkml_runtime.dumpers.rdf_dumper import RDFDumper | ||
from cell_annotation_schema.ontology.dumpers.rdflib_dumper import RDFLibDumper | ||
from linkml_runtime.dumpers.tsv_dumper import TSVDumper | ||
from linkml_runtime.dumpers.yaml_dumper import YAMLDumper | ||
from linkml_runtime.dumpers.csv_dumper import CSVDumper | ||
|
||
json_dumper = JSONDumper() | ||
rdf_dumper = RDFDumper() | ||
rdflib_dumper = RDFLibDumper() | ||
yaml_dumper = YAMLDumper() | ||
csv_dumper = CSVDumper() | ||
tsv_dumper = TSVDumper() |
Oops, something went wrong.