func DataSets(request *restful.Request, response *restful.Response) { data := `{ "@context": "/hydra/api-demo/contexts/Collection.jsonld", "@type": "Collection", "@id": "http://data.geolink.org/hydra/entry/datasets/", "members": [ { "@id": "http://data.geolink.org/docs/ds/1", "@type": "schema.org:Dataset" }, { "@id": "http://data.geolink.org/docs/ds/2", "@type": "schema.org:Dataset" }, { "@id": "http://data.geolink.org/docs/ds/3", "@type": "schema.org:Dataset" } ] }` dataparsed, _ := jsonld.ReadJSON([]byte(data)) response.WriteEntity(dataparsed) }
// Parse is used to parse RDF data from a reader, using the provided mime type func (g *Graph) Parse(reader io.Reader, mime string) { parserName := mimeParser[mime] if len(parserName) == 0 { parserName = "guess" } if parserName == "jsonld" { buf := new(bytes.Buffer) buf.ReadFrom(reader) jsonData, err := jsonld.ReadJSON(buf.Bytes()) options := &jsonld.Options{} options.Base = "" options.ProduceGeneralizedRdf = false dataSet, err := jsonld.ToRDF(jsonData, options) if err != nil { log.Println(err) return } for t := range dataSet.IterTriples() { g.AddTriple(jterm2term(t.Subject), jterm2term(t.Predicate), jterm2term(t.Object)) } } else { parser := crdf.NewParser(parserName) parser.SetLogHandler(func(level int, message string) { log.Println(message) }) defer parser.Free() out := parser.Parse(reader, g.uri) for s := range out { g.AddStatement(s) } } }
func Entry(request *restful.Request, response *restful.Response) { mapD := map[string]string{"@context": "/hydra/entry/contexts/EntryPoint.jsonld", "@id": "/hydra/entry/", "@type": "EntryPoint", "datasets": "/hydra/entry/datasets/", "datacatalogs": "/hydra/entry/datacatalogs/"} mapB, _ := json.Marshal(mapD) fmt.Println(string(mapB)) data, _ := jsonld.ReadJSON(mapB) log.Println(string(mapB)) response.WriteEntity(data) }