Created
April 6, 2022 09:13
-
-
Save cristianvasquez/d5ae826f7f48861b47b232fb3a13d3af to your computer and use it in GitHub Desktop.
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
// https://www.npmjs.com/package/@rdfjs-elements/formats-pretty | |
import prefixes from '@zazuko/rdf-vocabularies/prefixes' | |
import { turtle } from '@rdfjs-elements/formats-pretty/serializers' | |
import rdf from '@rdfjs/data-model' | |
import { Readable } from 'readable-stream' | |
import getStream from 'get-stream' | |
// Example data | |
const data = [ | |
rdf.quad(rdf.namedNode('http://ex.org/s1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Alice')), | |
rdf.quad(rdf.namedNode('http://ex.org/s1'), rdf.namedNode('http://ex.org/p1'), rdf.namedNode('http://ex.org/o1')), | |
rdf.quad(rdf.namedNode('http://ex.org/o1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Bob')) | |
] | |
// Setting up the prettifier | |
const { schema } = prefixes | |
const prettifier = await turtle({ | |
prefixes: { schema, ex: 'http://ex.org/' } | |
}) | |
// Prettify | |
const stream = await prettifier.import(Readable.from(data)) | |
console.log(await getStream(stream)) | |
// @prefix schema: <http://schema.org/> . | |
// @prefix ex: <http://ex.org/> . | |
// | |
// ex:s1 schema:name "Alice" ; | |
// ex:p1 ex:o1 . | |
// | |
// ex:o1 schema:name "Bob" . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment