W3C home > Mailing lists > Public > semantic-web@w3.org > June 2018

"rdf" JavaScript package major release

From: Austin William Wright <aaa@bzfx.net>
Date: Fri, 8 Jun 2018 03:14:35 -0700
Message-ID: <CANkuk-W69gCVgFpP=DXpgfS+Ac8K1w0HHO6VYf4i+4D3_OWhcA@mail.gmail.com>
To: Semantic Web <semantic-web@w3.org>, public-rdfjs@w3.org
Hello SWIG + RDFJS,

I've just published a new major version of the "rdf" package
<https://www.npmjs.com/package/rdf>. By "major", I mean it's includes some
breaking changes to bring in RDF 1.1 semantics and align with <
http://rdf.js.org/>, features I've needed to work on an isomorphic RDFa
parser (by "isomorphic" I mean taking an RDF graph and producing an
RDFa-annotated HTML file based on the data--more on that soon, hopefully).

"rdf" is the JavaScript/ECMAScript package aimed at making it
straightforward and simple to deal with the RDF data model in a programming
environment, in a way that makes sense for JavaScript.

Suppose you've got a foaf:Person, and you want to look up everyone they
know, then sum their ages.

const fs = require('fs'), rdf = require('rdf');
const foaf = rdf.ns('http://xmlns.com/foaf/0.1/');
function sumAges(graph, person){
   return graph.reference(person) // Get a reference to a set with a single
starting node, associated with a graph
      .rel(foaf('knows')) // traverse all the foaf:knows link relations
  .rel(foaf('age')) // then traverse all the foaf:age relations
  .reduce(function(a, b){ return a.valueOf() + b; }, 0); // sum each of the
nodes, reducing the set to a single value
}
console.log(sumAges(rdf.TurtleParser.parse(fs.readFileSync('party.ttl')).graph,
'http://example.com/Alice'));

That's all there is to it!

A complete list of features is available on the GitHub page
<https://github.com/awwright/node-rdf>.

The package includes representations for:

- RDF graphs, edges (triples), and nodes (IRIs, literals, and bnodes)
- RDF patterns and variable nodes (for e.g. SPARQL)
- prefix maps and term maps (for documents that use CURIEs)
- RDF node sets

Functionality/methods include:

- querying triples from RDF graphs
- walking edges/triples in graphs
- converting between native and lexical value spaces
- comparing nodes, triples, and graphs for equality and sorting order
- parsing an object tree as a document into an RDF graph
- writing nodes to N-Triples or Turtle
- lightweight Turtle parser for consuming most kinds of documents

Other features include:

- Implements and enforces RDF semantics
- Functional, where possible: non-pure functions always return undefined
- Alignment with the RDF Representation <http://rdf.js.org/> publication
for Term, NamedNode, BlankNode, Literal, Variable, and Triple interfaces.
- Alignment with RDF Interfaces <https://www.w3.org/TR/rdf-interfaces/>
where possible
- All Public Domain code

Changes include:

- Greatly expanded API test suite with Mocha
- Fixes for 100% passage of the Turtle test suite
- Graph isomorphism testing via Graph#isomorphic
- The ResultSet interface for walking link relationships in a graph
- Graph#merge is now called Graph#union as a more accurate description of
what the method does
- Variable and TriplePattern interfaces for representing patterns (e.g.
SPARQL queries)
- Reworked Object#graphify to work without monkeypatching native prototypes
- Numerous changes to align with RDF Interfaces and RDF Representation,
preferring the latter
- plain strings are allowed wherever a NamedNode is and would otherwise be
invalid

Go give it a spin, and please let me know if you have any feedback, or what
sort of functionality you're expecting.

GitHub: https://github.com/awwright/node-rdf
npm: https://www.npmjs.com/package/rdf


Cheers,

Austin Wright.
Received on Friday, 8 June 2018 10:15:18 UTC

This archive was generated by hypermail 2.3.1 : Friday, 8 June 2018 10:15:26 UTC