Created
July 8, 2020 10:04
-
-
Save iddan/b267964355bb33aae7e2a96437d2c9d8 to your computer and use it in GitHub Desktop.
Script used for adding context to JSON-LD test cases documents in Cayley
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"github.com/piprate/json-gold/ld" | |
) | |
func main() { | |
dir := "query/linkedql/steps/test-cases/" | |
files, err := ioutil.ReadDir(dir) | |
if err != nil { | |
panic(err) | |
} | |
for _, f := range files { | |
fmt.Println(f.Name()) | |
if f.IsDir() { | |
continue | |
} | |
path := dir + "/" + f.Name() | |
data, err := ioutil.ReadFile(path) | |
if err != nil { | |
panic(err) | |
} | |
var a map[string]interface{} | |
err = json.Unmarshal(data, &a) | |
if err != nil { | |
panic(err) | |
} | |
processor := ld.NewJsonLdProcessor() | |
options := ld.NewJsonLdOptions("") | |
context := map[string]interface{}{ | |
"@base": "http://example.com/", | |
"@vocab": "http://example.com/", | |
} | |
compact, err := processor.Compact(a["results"], context, options) | |
if err != nil { | |
panic(err) | |
} | |
a["results"] = compact | |
data, err = json.Marshal(a) | |
if err != nil { | |
panic(err) | |
} | |
ioutil.WriteFile(path, data, f.Mode().Perm()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment