// 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) } } }
// NewReaderFromMap returns quad reader for JSON-LD map object. func NewReaderFromMap(o interface{}) *Reader { data, err := gojsonld.ToRDF(o, gojsonld.NewOptions("")) if err != nil { return &Reader{err: err} } return &Reader{ graphs: data.Graphs, } }