piprate/json-gold

Empty normalization?

rokj opened this issue · 2 comments

rokj commented

I try to normalize following structure:

_data := map[string]interface{} {
	"@context": map[string]interface{}{
		"as": "https://www.w3.org/ns/activitystreams",
	},
	"id": "http://friendica2.local/activity/e6f33173-9381-86bb-c047-4f5c7be22380",
	"type": "Follow",
	"actor": "http://friendica2.local/profile/rjaklic5",
	"object": "http://friendica.local/profile/rjaklic15",
	"instrument": map[string]interface{}{
		"type": "Service",
		"name": "Friendica 'Red Hot Poker' 2020.03-1338",
		"url": "http://friendica2.local",
	},
	"to": []string{"http://friendica.local/profile/rjaklic15"},
}

but without success. All I get is an empty string. Any ideas why?

I am using following function to Normalize.

func Normalize(doc map[string]interface{}) (interface{}, error) {
	proc := ld.NewJsonLdProcessor()
	options := ld.NewJsonLdOptions("")
	options.Format = "application/n-quads"
	options.Algorithm = "URDNA2015"

	normalizedTriples, err := proc.Normalize(doc, options)

	return normalizedTriples, err
}

@rokj I suspect the issue is in your context definition. The only term you define is "as". All the other terms in your document will be ignored at the expansion stage of normalisation. As a result, the output is empty. A good way to debug complex operations like normalisation is to apply expansion to your JSON-LD document first. Most problems are at that stage. And the quickest way to do it is to use JSON-LD playground.

rokj commented

I got it working with:

_data := map[string]interface{} {
	"@context": "https://www.w3.org/ns/activitystreams.jsonld",
	"id": "http://friendica2.local/activity/e6f33173-9381-86bb-c047-4f5c7be22380",
	"type": "Follow",
	"actor": "http://friendica2.local/profile/rjaklic5",
	"object": "http://friendica.local/profile/rjaklic15",
	"instrument": map[string]interface{}{
		"type": "Service",
		"name": "Friendica 'Red Hot Poker' 2020.03-1338",
		"url": "http://friendica2.local",
	},
	"to": "http://friendica.local/profile/rjaklic15",
}