-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from zazuko/migrate-formats
Migrate formats package
- Loading branch information
Showing
27 changed files
with
2,417 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"barnard59-formats": patch | ||
--- | ||
|
||
The package would use `rdf-ext` but it was not a dependency. Using `@zazuko/env` instead |
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# v1.0.0 | ||
|
||
## 1.4.0 | ||
|
||
### Minor Changes | ||
|
||
- f09e8b0: Forward n3 step options to parser (closes #24). For example, to parse n3 rules | ||
|
||
```turtle | ||
[ | ||
a :Step ; | ||
code:implementedBy | ||
[ | ||
a code:EcmaScriptModule ; | ||
code:link <node:barnard59-formats/n3.js#parse> | ||
] ; | ||
code:arguments | ||
[ | ||
code:name "format" ; | ||
code:value "text/n3" ; | ||
] ; | ||
] | ||
``` | ||
|
||
## 1.3.1 | ||
|
||
### Patch Changes | ||
|
||
- 59d713f: Updated RDF/JS packages to v2 | ||
- 396d36e: Correct rdf/xml usage in manifest (closes #20) | ||
|
||
- Moved to JavaScript modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# barnard59-formats | ||
|
||
This package provides support for various formats like CSV on the Web, JSON-LD and N-Triples for Barnard59 Linked Data pipelines. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sinkToDuplex from '@rdfjs/sink-to-duplex' | ||
import CsvwParser from 'rdf-parser-csvw' | ||
import tracer from './lib/tracer.js' | ||
import { toDataset } from './lib/stream.js' | ||
|
||
function parse(args) { | ||
let metadata | ||
let relaxColumnCount = false | ||
let skipLinesWithError = false | ||
let timezone = 'local' | ||
|
||
if (args.metadata) { | ||
metadata = args.metadata | ||
|
||
if (typeof args.relaxColumnCount !== 'undefined') { | ||
relaxColumnCount = Boolean(args.relaxColumnCount) | ||
} | ||
|
||
if (typeof args.skipLinesWithError !== 'undefined') { | ||
skipLinesWithError = Boolean(args.skipLinesWithError) | ||
} | ||
|
||
if (typeof args.timezone !== 'undefined') { | ||
timezone = args.timezone | ||
} | ||
} else { | ||
metadata = args | ||
} | ||
|
||
return tracer.startActiveSpan('csvw:parse', async span => { | ||
try { | ||
const dataset = await toDataset(metadata) | ||
span.addEvent('metadata') | ||
return sinkToDuplex(new CsvwParser({ | ||
metadata: dataset, | ||
relaxColumnCount, | ||
skipLinesWithError, | ||
timezone, | ||
}), { | ||
readableObjectMode: true, | ||
}) | ||
} finally { | ||
span.end() | ||
} | ||
}) | ||
} | ||
|
||
export { | ||
parse, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { parse as csvwParse } from './csvw.js' | ||
export { parse as jsonldParse, parseObject as jsonldParseObject, serialize as jsonldSerialize } from './jsonld.js' | ||
export { parse as n3Parse } from './n3.js' | ||
export { serialize as ntriplesSerialize } from './ntriples.js' | ||
export { parse as rdfxmlParse } from './rdf-xml.js' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { SpanStatusCode } from '@opentelemetry/api' | ||
import Parser from '@rdfjs/parser-jsonld' | ||
import FsDocumentLoader from '@rdfjs/parser-jsonld/FsDocumentLoader.js' | ||
import Serializer from '@rdfjs/serializer-jsonld' | ||
import sinkToDuplex from '@rdfjs/sink-to-duplex' | ||
import { combine, jsonStringify } from 'barnard59-base' | ||
import tracer from './lib/tracer.js' | ||
|
||
function parse({ localContext } = {}) { | ||
let documentLoader = null | ||
|
||
if (localContext) { | ||
if (typeof localContext === 'string') { | ||
localContext = JSON.parse(localContext) | ||
} | ||
|
||
documentLoader = new FsDocumentLoader(localContext) | ||
} | ||
|
||
return tracer.startActiveSpan('jsonld:parse', span => { | ||
const stream = sinkToDuplex(new Parser({ documentLoader }), { objectMode: true }) | ||
stream.on('error', err => { | ||
span.recordException(err) | ||
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message }) | ||
span.end() | ||
}) | ||
stream.on('finish', () => span.end()) | ||
return stream | ||
}) | ||
} | ||
|
||
const parseObject = () => { | ||
return tracer.startActiveSpan('jsonld:parse.object', span => { | ||
const stream = combine([jsonStringify(), parse()], { objectMode: true }) | ||
stream.on('error', err => { | ||
span.recordException(err) | ||
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message }) | ||
span.end() | ||
}) | ||
stream.on('finish', () => span.end()) | ||
return stream | ||
}) | ||
} | ||
|
||
parse.object = parseObject | ||
|
||
function serialize() { | ||
return sinkToDuplex(new Serializer(), { objectMode: true }) | ||
} | ||
|
||
export { parse, parseObject, serialize } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import fromStream from 'rdf-dataset-ext/fromStream.js' | ||
import rdf from '@zazuko/env' | ||
|
||
export function toDataset(streamOrDataset) { | ||
if (!streamOrDataset.readable) { | ||
return Promise.resolve(streamOrDataset) | ||
} | ||
|
||
return fromStream(rdf.dataset(), streamOrDataset) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { trace } from '@opentelemetry/api' | ||
|
||
// TODO: set library version here | ||
const tracer = trace.getTracer('barnard59-formats') | ||
|
||
export default tracer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@base <http://barnard59.zazuko.com/operations/formats/> . | ||
@prefix code: <https://code.described.at/> . | ||
@prefix p: <https://pipeline.described.at/> . | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
|
||
<csvw/parse> a p:Operation, p:Writable, p:ReadableObjectMode; | ||
rdfs:label "Parse CSV on the Web"; | ||
rdfs:comment "Parses the given CSV stream using the given metadata."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/csvw.js#parse> | ||
]. | ||
|
||
<jsonld/parse> a p:Operation, p:Writable, p:ReadableObjectMode; | ||
rdfs:label "Parse JSON-LD"; | ||
rdfs:comment "Parses the given JSON-LD stream."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/jsonld.js#parse> | ||
]. | ||
|
||
<jsonld/parse/object> a p:Operation, p:WritableObjectMode, p:ReadableObjectMode; | ||
rdfs:label "Parse JSON-LD (Object)"; | ||
rdfs:comment "Parses the given JSON-LD stream."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/jsonld.js#parseObject> | ||
]. | ||
|
||
<jsonld/serialize> a p:Operation, p:WritableObjectMode, p:Readable; | ||
rdfs:label "Serialize JSON-LD"; | ||
rdfs:comment "Serializes the given RDF/JS Quads to JSON-LD."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/jsonld.js#serialize> | ||
]. | ||
|
||
<n3/parse> a p:Operation, p:Writable, p:ReadableObjectMode; | ||
rdfs:label "Parse N3"; | ||
rdfs:comment "Parses the given N3 stream."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/n3.js#parse> | ||
]. | ||
|
||
<ntriples/serialize> a p:Operation, p:WritableObjectMode, p:Readable; | ||
rdfs:label "Serialize N-Triples"; | ||
rdfs:comment "Serializes the given RDF/JS Quads to N-Triples."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/ntriples.js#serialize> | ||
]. | ||
|
||
<rdf-xml/parse> a p:Operation, p:Writable, p:ReadableObjectMode; | ||
rdfs:label "Parse RDF/XML"; | ||
rdfs:comment "Parses the given RDF/XML stream."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/rdf-xml.js#parse> | ||
]. | ||
|
||
<xlsx/parse> a p:Operation, p:Writable, p:ReadableObjectMode; | ||
rdfs:label "Parse XSLX files based on the CSV on the Web standard"; | ||
rdfs:comment "Parses the given XLSX stream using the given metadata."; | ||
code:implementedBy [ a code:EcmaScript; | ||
code:link <node:barnard59-formats/xlsx.js#parse> | ||
]. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Parser from '@rdfjs/parser-n3' | ||
import sinkToDuplex from '@rdfjs/sink-to-duplex' | ||
|
||
function parse(args) { | ||
return sinkToDuplex(new Parser(args), { | ||
readableObjectMode: true, | ||
writableObjectMode: true, | ||
}) | ||
} | ||
|
||
export { parse } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Serializer from '@rdfjs/serializer-ntriples' | ||
import sinkToDuplex from '@rdfjs/sink-to-duplex' | ||
|
||
function serialize() { | ||
return sinkToDuplex(new Serializer(), { | ||
readableObjectMode: true, | ||
writableObjectMode: true, | ||
}) | ||
} | ||
|
||
export { serialize } |
Oops, something went wrong.