KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
rdf-serialize.js
★ 9
Open GitHub ↗
Serializes RDF to any serialization
Download README (.md)
Explore Similar Repositories
jwp-refactoring
:
No description available.
FixBadRsaEncryption
:
This paper implements the plaintext search algorithm from the paper "Incorrectly Generated RSA Keys"
LiDAR_Camera_Calibration_Preprocess
:
MATLAB and Python tools to extract and synchronize pointclouds and images from a rosbag for extrinsic calibration.
lightning
:
【依賴過舊,不建議使用】關於我用 Laravel 寫 SPA 卻不寫 API 的那檔事 - 系列範例,使用和 Laravel + Vue.js + Inertia.js + Tailwind CSS 構建的簡易部落格平台。
bot-saber
:
A discord bot handy for anyone wanting to spice up their server with Beat Saber features and commands
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
rdf-serialize.js
?
Download (.md)
# RDF Serialize [](https://github.com/rubensworks/rdf-serialize.js/actions?query=workflow%3ACI) [](https://coveralls.io/github/rubensworks/rdf-serialize.js?branch=master) [](https://www.npmjs.com/package/rdf-serialize) This library serializes [RDF/JS](http://rdf.js.org/) quad streams to _RDF streams_ based on _content type_. This is useful in situations where have a stream of RDF/JS quads, and you want to _serialize_ them to a certain RDF serialization. The following RDF serializations are supported: | **Name** | **Content type** | **Extensions** | |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------------- | ------------- | | [TriG 1.2](https://www.w3.org/TR/rdf12-trig/) | `application/trig` | `.trig` | | [N-Quads 1.2](https://www.w3.org/TR/rdf12-n-quads/) | `application/n-quads` | `.nq`, `.nquads` | | [Turtle 1.2](https://www.w3.org/TR/rdf12-turtle/) | `text/turtle` | `.ttl`, `.turtle` | | [N-Triples 1.2](https://www.w3.org/TR/rdf12-n-triples/) | `application/n-triples` | `.nt`, `.ntriples` | | [Notation3](https://www.w3.org/TeamSubmission/n3/) | `text/n3` | `.n3` | | [JSON-LD 1.1](https://json-ld.org/) | `application/ld+json`, `application/json` | `.json`, `.jsonld` | | [SHACL Compact Syntax](https://w3c.github.io/shacl/shacl-compact-syntax/) | `text/shaclc` | `.shaclc`, `.shc` | | [Extended SHACL Compact Syntax](https://github.com/jeswr/shaclcjs#extended-shacl-compact-syntax) | `text/shaclc-ext` | `.shaclce`, `.shce` | Internally, this library makes use of RDF serializers from the [Comunica framework](https://github.com/comunica/comunica), which enable streaming processing of RDF. Internally, the following fully spec-compliant serializers are used: * [N3.js](https://github.com/rdfjs/n3.js) * [jsonld-streaming-serializer.js](https://github.com/rubensworks/jsonld-streaming-serializer.js) * [shaclc-writer](https://github.com/jeswr/shaclc-writer/) ## Installation ```bash $ npm install rdf-serialize ``` or ```bash $ yarn add rdf-serialize ``` This package also works out-of-the-box in browsers via tools such as [webpack](https://webpack.js.org/) and [browserify](http://browserify.org/). ## Require ```typescript import { rdfSerializer } from "rdf-serialize"; ``` _or_ ```javascript const { rdfSerializer } = require("rdf-serialize"); ``` ## Usage ### Serializing by content type The `rdfSerializer.serialize` method takes in an [RDFJS stream](http://rdf.js.org/stream-spec/#stream-interface) emitting RDF quads, and an options object, and outputs text stream containing RDF in a certain serialization. ```javascript const { streamifyArray } = require('streamify-array'); const stringifyStream = require('stream-to-string'); const quad = require('rdf-quad'); const quadStream = streamifyArray([ quad('http://ex.org/s', 'http://ex.org/p', 'http://ex.org/o1'), quad('http://ex.org/s', 'http://ex.org/p', 'http://ex.org/o2'), ]); const textStream = rdfSerializer.serialize(quadStream, { contentType: 'text/turtle' }); // Handle the serialization in the streaming manner textStream.pipe(process.stdout) .on('error', (error) => console.error(error)) .on('end', () => console.log('All done!')); // Or merge it in a single string. console.log(await stringifyStream(textStream)); ``` You may optionally pass prefixes to the serializer: ```javascript rdfSerializer.serialize(quadStream, { contentType: 'text/turtle', prefixes: { ex: 'http://ex.org/' } }); ``` ### Serializing for file name Sometimes, you know the desired path/URL of the serialized RDF document, but not the content type. For those cases, this library allows you to provide the path/URL of the RDF document, using which the content type will be determined. For example, Turtle documents can be detected using the `.ttl` extension. ```javascript const quadStream = streamifyArray([ quad('http://ex.org/s', 'http://ex.org/p', 'http://ex.org/o1'), quad('http://ex.org/s', 'http://ex.org/p', 'http://ex.org/o2'), ]); const textStream = rdfSerializer.serialize(quadStream, { path: 'http://example.org/myfile.ttl' }); ``` ### Getting all known content types With `rdfSerializer.getContentTypes()`, you can retrieve a list of all content types for which a serializer is available. Note that this method returns a promise that can be `await`-ed. `rdfSerializer.getContentTypesPrioritized()` returns an object instead, with content types as keys, and numerical priorities as values. ```javascript // An array of content types console.log(await rdfSerializer.getContentTypes()); // An object of prioritized content types console.log(await rdfSerializer.getContentTypesPrioritized()); ``` ## License This software is written by [Ruben Taelman](http://rubensworks.net/). This code is released under the [MIT license](http://opensource.org/licenses/MIT).