-
Notifications
You must be signed in to change notification settings - Fork 128
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
Automatically fetch URIs objects when framing #126
Comments
The |
Thanks for the reply.
|
#!/usr/bin/env python
# coding=utf-8
import os
import sys
# setup to run this code from pyld/tmp/example/
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../..', 'lib'))
from pyld import jsonld
import json
ctx = {
"knows": {"@type": "@id", "@id": "https://example.com/knows"},
"name": "https://example.com/name"
}
doc = {
"@context": ctx,
"knows": "https://example.org/alice"
}
alice = {
"@id": "https://example.org/alice",
"name": "Alice"
}
frame = {
"@context": ctx,
"@embed": "@always"
}
data = {
"@context": ctx,
"@graph": [
doc,
alice
]
}
print('---DATA---')
print(json.dumps(data, indent=2))
framed = jsonld.frame(data, frame)
print('---FRAMED---')
print(json.dumps(framed, indent=2))
output = framed["@graph"][0].copy()
output["@context"] = framed["@context"]
print('---OUTPUT---')
print(json.dumps(output, indent=2)) ---DATA---
{
"@context": {
"knows": {
"@type": "@id",
"@id": "https://example.com/knows"
},
"name": "https://example.com/name"
},
"@graph": [
{
"@context": {
"knows": {
"@type": "@id",
"@id": "https://example.com/knows"
},
"name": "https://example.com/name"
},
"knows": "https://example.org/alice"
},
{
"@id": "https://example.org/alice",
"name": "Alice"
}
]
}
---FRAMED---
{
"@context": {
"knows": {
"@type": "@id",
"@id": "https://example.com/knows"
},
"name": "https://example.com/name"
},
"@graph": [
{
"knows": {
"@id": "https://example.org/alice",
"name": "Alice"
}
},
{
"@id": "https://example.org/alice",
"name": "Alice"
}
]
}
---OUTPUT---
{
"knows": {
"@id": "https://example.org/alice",
"name": "Alice"
},
"@context": {
"knows": {
"@type": "@id",
"@id": "https://example.com/knows"
},
"name": "https://example.com/name"
}
} |
Thank you, that makes sense. However I think that a flag to automatically fetch remote documents might not be too difficult. What I mean is that |
Doing that type of processing is beyond the scope of the API here. Perhaps it's worth exploring a multi-step transformation in your app to get the same effect. Frame the data to find all the "knows" data, dereference that data in your app as appropriate, and merge the original data and all the "knows" results with a new frame. I think the output would be the same, it's just pushing the details and complexity up to the app. |
Let's say that I have a jsonld document that contains a property like
I would like to apply a frame to this context, such that
https://example.org/alice
is automatically fetched and inserted into the final document, that is:I've seen in the jsonld spec that it's possible to use
@embed
, but my question is: do I have to manually download thehttps://example.org/alice
document, add it to the jsonld document, and only then apply the frame? Or can pyld automatically fetch the document if I use@embed
?The text was updated successfully, but these errors were encountered: