Skip to content

Parsers and serializers for common RDF formats

License

Notifications You must be signed in to change notification settings

rdfjs-base/formats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@rdfjs/formats

build status npm version

This module bundles parsers and serializers for the most common RDF formats. Instances of SinkMap are used to handle different media types.

Usage

The formats object has a parsers and serializers property. Each is an instance of SinkMap with the most common RDF media types as key. The formats object is exported as default and can be imported like this:

import formats from '@rdfjs/formats'

Pretty-Print Serializers

The default bundle of serializers is optimized for streaming. The pretty-print formats bundle can be used if a more human-readable output is required. It can be imported like this:

Factory

A factory that takes care of parsers and serializers. An additional .formats object will be attached to the environment. That object is compatible with the data structure of @rdfjs/formats-common. The .formats object has an additional .import() function to import other format bundles. The following code shows how to import the @rdfjs/formats-common bundle:

import formats from '@rdfjs/formats/pretty.js'

Example

The following example uses the parser for the media type text/turtle to parse the given string. The quads emitted by the data event are written to the console:

import formats from '@rdfjs/formats'
import { Readable } from 'readable-stream'

const input = Readable.from([`
  PREFIX s: <http://schema.org/>

  [] a s:Person;
    s:jobTitle "Professor";
    s:name "Jane Doe";
    s:telephone "(425) 123-4567";
    s:url <http://www.janedoe.com>.
`])

const output = formats.parsers.import('text/turtle', input)

output.on('data', quad => {
  console.log(`quad: ${quad.subject.value} - ${quad.predicate.value} - ${quad.object.value}`)
})

output.on('prefix', (prefix, ns) => {
  console.log(`prefix: ${prefix} ${ns.value}`)
})

About

Parsers and serializers for common RDF formats

Resources

License

Stars

Watchers

Forks

Packages

No packages published