Skip to content

Commit 23bea73

Browse files
committed
1 parent ed9daa6 commit 23bea73

File tree

1,411 files changed

+30214
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,411 files changed

+30214
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof
25+
26+
# For Mac heads
27+
.DS_Store
28+
29+
# ignore the EARL report
30+
earl.jsonld

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# JSON-goLD ChangeLog
2+
3+
## v0.1.0 - 2017-12-24
4+
5+
- Copy the [original library](https://github.com/kazarena/json-gold) under the following terms:
6+
7+
- @piprate team will be the maintainer of the new library (github.com/piprate/json-gold)
8+
- The original repo (github.com/kazarena/json-gold) will remain available
9+
- Interfaces of the new library will be preserved, but may deviate in future versions
10+
- Licensing will not change
11+
- Past contributors will be recognised
12+
- Commit history will not be preserved in the new library
13+
- Versions of the new library will be reset
14+
15+
See the full announcement [here](https://github.com/kazarena/json-gold/issues/20).

CONTRIBUTORS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This library was originally written by Stan Nazarenko (@kazarena) with Pull Requests accepted from:
2+
3+
* Denys Smirnov (@dennwc), see all commits [here](https://github.com/kazarena/json-gold/commits?author=dennwc)
4+
* Cícero Verneck Corrêa (@cicerocomp), see all commits [here](https://github.com/kazarena/json-gold/commits?author=cicerocomp)
5+
6+
All future contributors will be recorded in this file.

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: all lint test fmt help
2+
3+
all: lint test
4+
5+
lint:
6+
go vet github.com/piprate/json-gold/...
7+
8+
test: lint
9+
go test github.com/piprate/json-gold/...
10+
11+
fmt:
12+
gofmt -s -w .
13+
14+
help:
15+
@echo ''
16+
@echo ' Targets:'
17+
@echo '--------------------------------------------------'
18+
@echo ' all - Run everything '
19+
@echo ' fmt - Format code '
20+
@echo ' lint - Run lint '
21+
@echo ' test - Run all tests '
22+
@echo '--------------------------------------------------'
23+
@echo ''

README.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# JSON-goLD
2+
3+
This library is an implementation of the [JSON-LD 1.0](http://json-ld.org/) specification in Go.
4+
It supports both URDNA2015 and URGNA2012 RDF dataset normalisation algorithms.
5+
6+
## MAINTAINER CHANGE NOTIFICATION ##
7+
8+
We are planning to add new features to this library, including support for Linked Data Signatures, content-addressable JSON-LD, etc. In order to facilitate this development, the maintainer of JSON-goLD (@kazarena) is going to copy this repository to the GitHub organisation of his company (@piprate). See the details and further discussion [here](https://github.com/kazarena/json-gold/issues/20). Feedback welcome.
9+
10+
## Testing & Compliance ##
11+
12+
As of December 1, 2017:
13+
14+
* all JSON-LD 1.0 tests from the [official JSON-LD test suite](https://github.com/json-ld/json-ld.org/tree/master/test-suite) pass
15+
* all RDF Dataset Normalisation tests from the [current test suite](https://json-ld.github.io/normalization/tests/index.html) pass
16+
* JSON-LD 1.1 spec is not currenty supported
17+
18+
## Inspiration ##
19+
20+
This implementation was heavily influenced by [JSONLD-Java](https://github.com/jsonld-java/jsonld-java) with some techniques borrowed from [PyLD](https://github.com/digitalbazaar/pyld) and [gojsonld](https://github.com/linkeddata/gojsonld). Big thank you to the contributors of the forementioned libraries for figuring out implementation details of the core algorithms.
21+
22+
## Examples ##
23+
24+
### Expand ###
25+
26+
See complete code in [examples/expand.go](examples/expand.go).
27+
28+
```go
29+
proc := ld.NewJsonLdProcessor()
30+
options := ld.NewJsonLdOptions("")
31+
32+
// expanding remote document
33+
34+
expanded, err := proc.Expand("http://json-ld.org/test-suite/tests/expand-0002-in.jsonld", options)
35+
if err != nil {
36+
log.Println("Error when expanding JSON-LD document:", err)
37+
return
38+
}
39+
40+
// expanding in-memory document
41+
42+
doc := map[string]interface{}{
43+
"@context": "http://schema.org/",
44+
"@type": "Person",
45+
"name": "Jane Doe",
46+
"jobTitle": "Professor",
47+
"telephone": "(425) 123-4567",
48+
"url": "http://www.janedoe.com",
49+
}
50+
51+
expanded, err = proc.Expand(doc, options)
52+
```
53+
54+
### Compact ###
55+
56+
See complete code in [examples/compact.go](examples/compact.go).
57+
58+
```go
59+
proc := ld.NewJsonLdProcessor()
60+
options := ld.NewJsonLdOptions("")
61+
62+
doc := map[string]interface{}{
63+
"@id": "http://example.org/test#book",
64+
"http://example.org/vocab#contains": map[string]interface{}{
65+
"@id": "http://example.org/test#chapter",
66+
},
67+
"http://purl.org/dc/elements/1.1/title": "Title",
68+
}
69+
70+
context := map[string]interface{}{
71+
"@context": map[string]interface{}{
72+
"dc": "http://purl.org/dc/elements/1.1/",
73+
"ex": "http://example.org/vocab#",
74+
"ex:contains": map[string]interface{}{
75+
"@type": "@id",
76+
},
77+
},
78+
}
79+
80+
compactedDoc, err := proc.Compact(doc, context, options)
81+
```
82+
83+
### Flatten ###
84+
85+
See complete code in [examples/flatten.go](examples/flatten.go).
86+
87+
```go
88+
proc := ld.NewJsonLdProcessor()
89+
options := ld.NewJsonLdOptions("")
90+
91+
doc := map[string]interface{}{
92+
"@context": []interface{}{
93+
map[string]interface{}{
94+
"name": "http://xmlns.com/foaf/0.1/name",
95+
"homepage": map[string]interface{}{
96+
"@id": "http://xmlns.com/foaf/0.1/homepage",
97+
"@type": "@id",
98+
},
99+
},
100+
map[string]interface{}{
101+
"ical": "http://www.w3.org/2002/12/cal/ical#",
102+
},
103+
},
104+
"@id": "http://example.com/speakers#Alice",
105+
"name": "Alice",
106+
"homepage": "http://xkcd.com/177/",
107+
"ical:summary": "Alice Talk",
108+
"ical:location": "Lyon Convention Centre, Lyon, France",
109+
}
110+
111+
flattenedDoc, err := proc.Flatten(doc, nil, options)
112+
```
113+
114+
### Frame ###
115+
116+
See complete code in [examples/frame.go](examples/frame.go).
117+
118+
```go
119+
proc := ld.NewJsonLdProcessor()
120+
options := ld.NewJsonLdOptions("")
121+
122+
doc := map[string]interface{}{
123+
"@context": map[string]interface{}{
124+
"dc": "http://purl.org/dc/elements/1.1/",
125+
"ex": "http://example.org/vocab#",
126+
"ex:contains": map[string]interface{}{"@type": "@id"},
127+
},
128+
"@graph": []interface{}{
129+
map[string]interface{}{
130+
"@id": "http://example.org/test/#library",
131+
"@type": "ex:Library",
132+
"ex:contains": "http://example.org/test#book",
133+
},
134+
map[string]interface{}{
135+
"@id": "http://example.org/test#book",
136+
"@type": "ex:Book",
137+
"dc:contributor": "Writer",
138+
"dc:title": "My Book",
139+
"ex:contains": "http://example.org/test#chapter",
140+
},
141+
map[string]interface{}{
142+
"@id": "http://example.org/test#chapter",
143+
"@type": "ex:Chapter",
144+
"dc:description": "Fun",
145+
"dc:title": "Chapter One",
146+
},
147+
},
148+
}
149+
150+
frame := map[string]interface{}{
151+
"@context": map[string]interface{}{
152+
"dc": "http://purl.org/dc/elements/1.1/",
153+
"ex": "http://example.org/vocab#",
154+
},
155+
"@type": "ex:Library",
156+
"ex:contains": map[string]interface{}{
157+
"@type": "ex:Book",
158+
"ex:contains": map[string]interface{}{
159+
"@type": "ex:Chapter",
160+
},
161+
},
162+
}
163+
164+
framedDoc, err := proc.Frame(doc, frame, options)
165+
```
166+
167+
### To RDF ###
168+
169+
See complete code in [examples/to_rdf.go](examples/to_rdf.go).
170+
171+
```go
172+
proc := ld.NewJsonLdProcessor()
173+
options := ld.NewJsonLdOptions("")
174+
options.Format = "application/nquads"
175+
176+
// this JSON-LD document was taken from http://json-ld.org/test-suite/tests/toRdf-0028-in.jsonld
177+
doc := map[string]interface{}{
178+
"@context": map[string]interface{}{
179+
"sec": "http://purl.org/security#",
180+
"xsd": "http://www.w3.org/2001/XMLSchema#",
181+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
182+
"dc": "http://purl.org/dc/terms/",
183+
"sec:signer": map[string]interface{}{"@type": "@id"},
184+
"dc:created": map[string]interface{}{"@type": "xsd:dateTime"},
185+
},
186+
"@id": "http://example.org/sig1",
187+
"@type": []interface{}{"rdf:Graph", "sec:SignedGraph"},
188+
"dc:created": "2011-09-23T20:21:34Z",
189+
"sec:signer": "http://payswarm.example.com/i/john/keys/5",
190+
"sec:signatureValue": "OGQzNGVkMzVm4NTIyZTkZDYMmMzQzNmExMgoYzI43Q3ODIyOWM32NjI=",
191+
"@graph": map[string]interface{}{
192+
"@id": "http://example.org/fact1",
193+
"dc:title": "Hello World!",
194+
},
195+
}
196+
triples, err := proc.ToRDF(doc, options)
197+
```
198+
199+
### From RDF ###
200+
201+
See complete code in [examples/from_rdf.go](examples/from_rdf.go).
202+
203+
```go
204+
proc := ld.NewJsonLdProcessor()
205+
options := ld.NewJsonLdOptions("")
206+
207+
triples := `
208+
<http://example.com/Subj1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Type> .
209+
<http://example.com/Subj1> <http://example.com/prop1> <http://example.com/Obj1> .
210+
<http://example.com/Subj1> <http://example.com/prop2> "Plain" .
211+
<http://example.com/Subj1> <http://example.com/prop2> "2012-05-12"^^<http://www.w3.org/2001/XMLSchema#date> .
212+
<http://example.com/Subj1> <http://example.com/prop2> "English"@en .
213+
`
214+
215+
doc, err := proc.FromRDF(triples, options)
216+
```
217+
218+
### Normalize ###
219+
220+
See complete code in [examples/normalize.go](examples/normalize.go).
221+
222+
```go
223+
proc := ld.NewJsonLdProcessor()
224+
options := ld.NewJsonLdOptions("")
225+
options.Format = "application/nquads"
226+
options.Algorithm = "URDNA2015"
227+
228+
doc := map[string]interface{}{
229+
"@context": map[string]interface{}{
230+
"ex": "http://example.org/vocab#",
231+
},
232+
"@id": "http://example.org/test#example",
233+
"@type": "ex:Foo",
234+
"ex:embed": map[string]interface{}{
235+
"@type": "ex:Bar",
236+
},
237+
}
238+
239+
normalizedTriples, err := proc.Normalize(doc, options)
240+
```

examples/compact.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// +build ignore
2+
3+
// Copyright 2015-2017 Piprate Limited
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package main
18+
19+
import (
20+
"github.com/piprate/json-gold/ld"
21+
)
22+
23+
func main() {
24+
proc := ld.NewJsonLdProcessor()
25+
options := ld.NewJsonLdOptions("")
26+
27+
doc := map[string]interface{}{
28+
"@id": "http://example.org/test#book",
29+
"http://example.org/vocab#contains": map[string]interface{}{
30+
"@id": "http://example.org/test#chapter",
31+
},
32+
"http://purl.org/dc/elements/1.1/title": "Title",
33+
}
34+
35+
context := map[string]interface{}{
36+
"@context": map[string]interface{}{
37+
"dc": "http://purl.org/dc/elements/1.1/",
38+
"ex": "http://example.org/vocab#",
39+
"ex:contains": map[string]interface{}{
40+
"@type": "@id",
41+
},
42+
},
43+
}
44+
45+
compactedDoc, err := proc.Compact(doc, context, options)
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
ld.PrintDocument("JSON-LD compation succeeded", compactedDoc)
51+
}

0 commit comments

Comments
 (0)