{"id":25049109,"url":"https://github.com/deiu/rdf2go","last_synced_at":"2025-07-07T20:06:58.407Z","repository":{"id":57500003,"uuid":"88666435","full_name":"deiu/rdf2go","owner":"deiu","description":"Native golang library for RDF (includes parser/serializer for Turtle and JSON-LD)","archived":false,"fork":false,"pushed_at":"2024-12-12T21:12:04.000Z","size":48,"stargazers_count":72,"open_issues_count":1,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T05:58:26.732Z","etag":null,"topics":["graph","json-ld","rdf","serializer","triples","turtle"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-18T20:13:41.000Z","updated_at":"2025-04-10T13:32:20.000Z","dependencies_parsed_at":"2024-12-12T22:23:13.688Z","dependency_job_id":"9715e56a-9494-4dca-951b-2891ec781a0b","html_url":"https://github.com/deiu/rdf2go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deiu%2Frdf2go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deiu%2Frdf2go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deiu%2Frdf2go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deiu%2Frdf2go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deiu","download_url":"https://codeload.github.com/deiu/rdf2go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351389,"owners_count":21089271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph","json-ld","rdf","serializer","triples","turtle"],"created_at":"2025-02-06T08:02:22.933Z","updated_at":"2025-04-11T05:58:31.137Z","avatar_url":"https://github.com/deiu.png","language":"Go","funding_links":[],"categories":["Go","Programming"],"sub_categories":["Go"],"readme":"# rdf2go\n\n[![Build Status](https://api.travis-ci.org/deiu/rdf2go.svg?branch=master)](https://travis-ci.org/deiu/rdf2go)\n[![Coverage Status](https://coveralls.io/repos/github/deiu/rdf2go/badge.svg?branch=master)](https://coveralls.io/github/deiu/rdf2go?branch=master)\n\nNative golang parser/serializer from/to Turtle and JSON-LD.\n\n# Installation\n\nJust go get it!\n\n`go get -u github.com/deiu/rdf2go`\n\n# Example usage\n\n## Working with graphs\n\n```golang\n// Set a base URI\nbaseUri := \"https://example.org/foo\"\n\n// Create a new graph\ng := (baseUri)\n\n// Add a few triples to the graph\ntriple1 := NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"c\"))\ng.Add(triple1)\ntriple2 := NewTriple(NewResource(\"a\"), NewResource(\"d\"), NewResource(\"e\"))\ng.Add(triple2)\n\n// Get length of Graph (nr of triples)\ng.Len() // -\u003e 2\n\n// Dump graph contents to NTriples\nout := g.String()\n// \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n// \u003ca\u003e \u003cd\u003e \u003ce\u003e .\n\n// Delete a triple\ng.Remove(triple2)\n```\n\n## Looking up triples from the graph\n\n### Returning a single match\n\nThe `g.One()` method returns the first triple that matches against any (or all) of Subject, Predicate, Object patterns.\n\n```golang\n// Create a new graph\ng := NewGraph(\"https://example.org\")\n\n// Add a few triples\ng.Add(NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"c\")))\n\n// Look up one triple matching the given subject\ntriple := g.One(NewResource(\"a\"), nil, nil) // -\u003e \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n\n// Look up one triple matching the given predicate\ntriple = g.One(nil, NewResource(\"b\"), nil) // -\u003e \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n\n// Look up one triple matching the given object\ntriple = g.One(nil, nil, NewResource(\"c\")) // -\u003e \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n\n// Look up one triple matching the given subject and predicate\ntriple = g.One(NewResource(\"a\"), NewResource(\"b\"), nil) // -\u003e \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n\n// Look up one triple matching the a bad predicate\ntriple = g.One(nil, NewResource(\"z\"), nil) // -\u003e nil\n```\n\n### Returning a list of matches\n\nSimilar to `g.One()`, `g.All()` returns all triples that match the given pattern.\n\n```golang\n// Create a new graph\ng := NewGraph(\"https://example.org\")\n\n// Add a few triples\ng.Add(NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"c\")))\ng.Add(NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"d\")))\n\n// Look up one triple matching the given subject\ntriples := g.All(nil, nil, NewResource(\"c\")) //\nfor _, triple := range triples {\n\ttriple.String()\n}\n// Returns a single triple that matches object \u003cc\u003e:\n// \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n\ntriples = g.All(nil, NewResource(\"b\"), nil)\nfor _, triple := range triples {\n\ttriple.String()\n}\n// Returns all triples that match subject \u003cb\u003e: \n// \u003ca\u003e \u003cb\u003e \u003cc\u003e .\n// \u003ca\u003e \u003cb\u003e \u003cd\u003e .\n```\n\n## Different types of terms (resources)\n\n### IRIs\n\n```golang\n// Create a new IRI\niri := NewResource(\"https://example.org\")\niri.String() // -\u003e \u003chttps://example.org\u003e\n```\n\n### Literals\n\n```golang\n// Create a new simple Literal\nlit := NewLiteral(\"hello world\")\nlit.String() // -\u003e \"hello word\"\n\n// Create a new Literal with language tag\nlit := NewLiteralWithLanguage(\"hello world\", \"en\")\nlit.String() // -\u003e \"hello word\"@en\n\n// Create a new Literal with a data type\nlit := NewLiteralWithDatatype(\"newTypeVal\", NewResource(\"https://datatype.com\"))\nlit.String() // -\u003e \"newTypeVal\"^^\u003chttps://datatype.com\u003e\n```\n\n### Blank Nodes\n\n```golang\n// Create a new Blank Node with a given ID\nbn := NewBlankNode(9)\nbn.String() // -\u003e \"_:n9\"\n\n// Create an anonymous Blank Node with a random ID\nabn := NewAnonNode()\nabn.String() // -\u003e \"_:n192853\"\n```\n\n\n## Parsing data\n\nThe parser takes an `io.Reader` as first parameter, and the string containing the mime type as the second parameter.\n\nCurrently, the supported parsing formats are Turtle (with mime type `text/turtle`) and JSON-LD (with mime type `application/ld+json`).\n\n### Parsing Turtle from an io.Reader\n\n```golang\n// Set a base URI\nbaseUri := \"https://example.org/foo\"\n\n// Create a new graph\ng := NewGraph(baseUri)\n\n// r is of type io.Reader\ng.Parse(r, \"text/turtle\")\n```\n\n### Parsing JSON-LD from an io.Reader\n\n```golang\n// Set a base URI\nbaseUri := \"https://example.org/foo\"\n\n// Create a new graph\ng := NewGraph(baseUri)\n\n// r is an io.Reader\ng.Parse(r, \"application/ld+json\")\n```\n\n### Parsing either Turtle or JSON-LD from a URI on the Web\n\nIn this case you don't have to specify the mime type, as the internal http client will try to content negotiate to either Turtle or JSON-LD. An error will be returned if it fails.\n\n**Note:** The `NewGraph()` function accepts an optional parameter called `skipVerify` that is used to tell the internal http client whether or not to ignore bad/self-signed server side certificates. By default, it will not check if you omit this parameter, or if you set it to `true`.\n\n```golang\n// Set a base URI\nuri := \"https://example.org/foo\"\n\n// Check remote server certificate to see if it's valid \n// (don't skip verification)\nskipVerify := false\n\n// Create a new graph. You can also omit the skipVerify parameter\n// and accept invalid certificates (e.g. self-signed)\ng := NewGraph(uri, skipVerify)\n\nerr := g.LoadURI(uri)\nif err != nil {\n\t// deal with the error\n}\n```\n\n\n## Serializing data\n\n\nThe serializer takes an `io.Writer` as first parameter, and the string containing the mime type as the second parameter.\n\nCurrently, the supported serialization formats are Turtle (with mime type `text/turtle`) and JSON-LD (with mime type `application/ld+json`).\n\n\n### Serializing to Turtle\n\n```golang\n// Set a base URI\nbaseUri := \"https://example.org/foo\"\n\n// Create a new graph\ng := NewGraph(baseUri)\n\ntriple := NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"c\"))\ng.Add(triple)\n\n// w is of type io.Writer\ng.Serialize(w, \"text/turtle\")\n```\n\n### Serializing to JSON-LD\n\n```golang\n// Set a base URI\nbaseUri := \"https://example.org/foo\"\n\n// Create a new graph\ng := NewGraph(baseUri)\n\ntriple := NewTriple(NewResource(\"a\"), NewResource(\"b\"), NewResource(\"c\"))\ng.Add(triple)\n\n// w is of type io.Writer\ng.Serialize(w, \"application/ld+json\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeiu%2Frdf2go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeiu%2Frdf2go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeiu%2Frdf2go/lists"}