Javascript RDF library for browsers and Node.js.
- Reads and writes RDF/XML, Turtle and N3; Reads RDFa and JSON-LD
- Read/Write Linked Data client, using WebDav or SPARQL/Update
- Real-Time Collaborative editing with web sockets and PATCHes
- Local API for querying a store
- Compatible with RDFJS task force spec
- SPARQL queries (not full SPARQL - just graph match and optional)
- Smushing of nodes from
owl:sameAs, andowl:{f,inverseF}unctionProperty - Tracks provenance of triples keeps metadata (in RDF) from HTTP accesses
See:
-
The API documentation is partial but useful
for more information.
npm install rdflibgit clone [email protected]:linkeddata/rdflib.js.git;
cd rdflib.js;
npm install;Generate the dist directory
npm run build:browserMake sure you have Node.js and Node Package Manager (npm) installed.
npm install --save rdflibThe Turtle/N3/JSON‑LD serializers accept an optional flags string to tweak output formatting and abbreviation behavior.
- Pass flags via the options argument to
serialize(...):
import { graph, serialize, sym } from 'rdflib'
const kb = graph()
const doc = sym('http://example.com/doc')
// ... add some statements ...
// Example: prevent dotted local parts in prefixed names
const turtle = serialize(doc, kb, doc.value, 'text/turtle', undefined, { flags: 'o' })Common flags used internally (you can combine them, e.g. 'o k'):
si– used by default for Turtle to suppress=,=>notationsd e i n p r s t u x– used for N-Triples/N-Quads to simplify outputdr– used with JSON‑LD conversion (no default, no relative prefix)o– new: do not abbreviate to a prefixed name when the local part contains a dot. This keeps IRIs likehttp://example.org/ns/subject.examplein<...>form instead ofns:subject.example.
Notes:
- For Turtle and JSON‑LD, user‑provided flags are merged with the defaults so your flags (like
o) are honored. - By contrast, passing
'p'disables prefix abbreviations entirely (all terms are written as<...>IRIs).
dist: Where the bundled libraries are built. Runnpm run buildto generate them.test: Tests are here.lib: Transpiled, non-bundled library is built here when the library is published to npm.
- XMLHTTPRequest (Node.js version)
Thanks to the many contributors who have been involved along the way. LinkedData team & TimBL
MIT