Safe Mode
jekjektuanakal opened this issue · 3 comments
JSON LD Playground (https://json-ld.org/playground/) has something called safe mode option. This mode will reject unknown properties upon expansion. See https://github.com/setl/rdf-urdna/tree/master/jsonld-warnings
Do you have any plan to support it? I was able to do some hackish safe mode on Expand() by replacing continue with error
func (api *JsonLdApi) expandObject(activeCtx *Context, activeProperty string, expandedActiveProperty string, elem map[string]interface{}, resultMap map[string]interface{}, typeKey string, opts *JsonLdOptions, typeScopedContext *Context, frameExpansion bool) error {
// some code...
nests := make([]string, 0)
// 7)
for _, key := range GetOrderedKeys(elem) {
value := elem[key]
// 7.1)
if key == "@context" {
continue
}
// 7.2)
expandedProperty, err := activeCtx.ExpandIri(key, false, true, nil, nil)
if err != nil {
return err
}
var expandedValue interface{}
// 7.3)
if expandedProperty == "" || (!strings.Contains(expandedProperty, ":") && !IsKeyword(expandedProperty)) {
return NewJsonLdError(InvalidInput, "property didn't expand into absolute IRI or keyword")
}
// more code ...
I am looking forward for more thorough and proper solution. I am willing to create PR if you guide me.
@jekjektuanakal, this is a very useful feature indeed. I spent many hours debugging JSON-LD contexts and new shapes of documents only to find out some property name was misspelled. Adding this feature would be very beneficial for the library.
I think the best way to implement it is as follows:
- 'Safe mode' should be optional
- Adding a new non-normative option into https://github.com/piprate/json-gold/blob/master/ld/options.go#L61 would be a good way to pass it into the processor.
- The default behaviour should be as it is now (NOT safe mode).
I'd appreciate if you create a PR.
Hi @kazarena,
I have made the PR for this issue. Let me know how you think about it.
Thank you, @wijatplay3, will take a look.