-
Notifications
You must be signed in to change notification settings - Fork 0
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
Support several FAIRtracks versions at the same time (by dynamically loading all subschemas) #16
Comments
The augmentation service should support augmenting different versions of the FAIRtracks schema, depending on the
from copy import copy
def getPathsToElement(elName, url=None, data=None, path=[]):
assert(url is not None or data is not None)
if data is None:
data = json.load(urllib.request.urlopen(url))
if isinstance(data, dict):
for key, val in data.items():
newPath = copy(path)
newUrl = url
if key == '$ref':
newUrl = '/'.join([url.rsplit('/', 1)[0], val])
data = None
else:
newPath.append(key)
data = val
if key == elName:
yield url, newPath, val
else:
for _ in getPathsToElement(elName, newUrl, data, newPath):
yield _
elif isinstance(data, list):
for i, item in enumerate(data):
for _ in getPathsToElement(elName, url, item, path + [i]):
yield _ This allows for code like the following, which should fix #15: targetPropDict = {}
for url, path, val in getPathsToElement('required', topSchemaUrl):
if all(_ in path for _ in ['allOf', 'target']):
targetPropDict[(url, tuple(path[:2]))] = val
for url, path, val in getPathsToElement('const', topSchemaUrl):
targetProp = targetPropDict.get((url, tuple(path[:2])))
if targetProp:
print(val, targetProp) The function can also be used to traverse the input JSON data by setting Implementing the above changes allows for simplifying much of the rest of the code, e.g. for fetching ontology URLs (with no need to hardcode hacks for reused schemas like currently with
|
No description provided.
The text was updated successfully, but these errors were encountered: