npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jairo-parser

v0.0.6

Published

Simplified RDF/XML parser

Downloads

2

Readme

jairo-parser

Simplified RDF/XML parser

Jairo Parser is built on the powerful rdf parser library rdf-ext. You can use it inside Node.js application. Jairo Parser gives you a simpler way to parse RDF/XML by passing output into a simplified JSON object (Jairo Object ).

Installation

npm install jairo-parser

Usage

Parsing RDF/XML data from a string

var jairo = require('jairo-parser');

var prefixesOfInterest = [
        { 'prefix' : 'rdf' , 'uri' : 'http://www.w3.org/1999/02/22-rdf-syntax-ns##' },
        { 'prefix' : 'dcterms' , 'uri' : 'http://purl.org/dc/terms/' },
        { 'prefix' : 'foaf' , 'uri' : 'http://xmlns.com/foaf/0.1/' }
    ];

var rdf =  
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##" ' + 
' xmlns:dcterms="http://purl.org/dc/terms/" ' + 
' xmlns:foaf="http://xmlns.com/foaf/0.1/"> ' + 
' <rdf:Description rdf:about="http://example.org/123"> ' + 
'  <dcterms:creator> ' + 
'   <foaf:Person rdf:about="http://example.org/person45"> ' + 
'    <rdf:value>John Smith</rdf:value> ' + 
'    <foaf:phone rdf:resource="tel:+358-555-1234567"/> ' + 
'   </foaf:Person> ' + 
'  </dcterms:creator>  ' + 
' </rdf:Description> ' + 
'</rdf:RDF>';

jairo.parse( 'rdfxml' , rdf , prefixesOfInterest , function( parsedData ){
    console.log( parsedData );
    jairo.printHumanReadbleResult( parsedData );
});
Parsing RDF/XML data from a file

File: test.rdf

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##" 
 xmlns:dcterms="http://purl.org/dc/terms/" 
 xmlns:foaf="http://xmlns.com/foaf/0.1/">  
 <rdf:Description rdf:about="http://example.org/123"> 
  <dcterms:creator> 
   <foaf:Person rdf:about="http://example.org/person45"> 
    <rdf:value>John Smith</rdf:value> 
    <foaf:phone rdf:resource="tel:+358-555-1234567"/> 
   </foaf:Person> 
  </dcterms:creator>  
 </rdf:Description>  
</rdf:RDF>

Load RDF/XML data from a file

var jairo = require('jairo-parser');
var fs = require('fs');

var prefixesOfInterest = [
        { 'prefix' : 'rdf' , 'uri' : 'http://www.w3.org/1999/02/22-rdf-syntax-ns##' },
        { 'prefix' : 'dcterms' , 'uri' : 'http://purl.org/dc/terms/' },
        { 'prefix' : 'foaf' , 'uri' : 'http://xmlns.com/foaf/0.1/' }
    ];

fs.readFile( 'test.rdf', 'utf8', function (err, fileContent) {
    if (err) throw err;
    jairo.parse( 'rdfxml' , fileContent , prefixesOfInterest , function( parsedData ){
        console.log( parsedData );
        jairo.printHumanReadbleResult( parsedData );
    });
});
Output of console.log( parsedData );

Logo

Output of jairo.printHumanReadbleResult( parsedData );

Logo

Iterating over Jairo objects

Based on the example code, you can iterate triples by following code.

    jairo.parse( 'rdfxml' , rdf , prefixesOfInterest , function( parsedData ){
        console.log( parsedData );

        for (var i = 0; i < parsedData.triples.length; i++) {
            // Get properties on each triple
        };

        for (var prop in parsedData.prefixesParsed ) {
            // List all parsed prefixes 
        }

        for (var prop in parsedData.prefixesParsedStat ) {
            // Count number of prefixes
        }

    });  
Access each triple
    for (var i = 0; i < parsedData.triples.length; i++) {
        var triple = parsedData.triples[i];
        console.log('subject_uri=' + triple.subject_uri);
        console.log('subject_qn=' + triple.subject_qn);
        console.log('predicate_uri=' + triple.predicate_uri);
        console.log('predicate_qn=' + triple.predicate_qn);
        console.log('object_uri=' + triple.object_uri);
        console.log('object_qn=' + triple.object_qn);
        console.log('subject_uri=' + triple.subject_uri);
        console.log('subject_uri=' + triple.subject_uri);
    };

Output

    subject_uri=<http://example.org/123>
    subject_qn=123
    predicate_uri=<http://purl.org/dc/terms/creator>
    predicate_qn=dcterms:creator
    object_uri=<http://example.org/person45>
    object_qn=person45

    subject_uri=<http://example.org/person45>
    subject_qn=person45
    predicate_uri=<http://www.w3.org/1999/02/22-rdf-syntax-ns##type>
    predicate_qn=rdf:type
    object_uri=<http://xmlns.com/foaf/0.1/Person>
    object_qn=Person

    subject_uri=<http://example.org/person45>
    subject_qn=person45
    predicate_uri=<http://www.w3.org/1999/02/22-rdf-syntax-ns##value>
    predicate_qn=rdf:value
    object_uri=John Smith
    object_qn=John Smith

    subject_uri=<http://example.org/person45>
    subject_qn=person45
    predicate_uri=<http://xmlns.com/foaf/0.1/phone>
    predicate_qn=foaf:phone
    object_uri=tel:+358-555-1234567
    object_qn=tel:+358-555-1234567
List all parsed prefixes
    for (var prop in parsedData.prefixesParsed ) {
        console.log('prefix=' + prop + ' uri=' + parsedData.prefixesParsed[prop]);
    }
Output
    prefix=dcterms:creator uri=http://purl.org/dc/terms/
    prefix=rdf:type uri=http://www.w3.org/1999/02/22-rdf-syntax-ns##
    prefix=rdf:value uri=http://www.w3.org/1999/02/22-rdf-syntax-ns##
    prefix=foaf:phone uri=http://xmlns.com/foaf/0.1/
Count number of prefixes
    for (var prop in parsedData.prefixesParsedStat ) {
        console.log('prefix=' + prop + ' count=' + parsedData.prefixesParsedStat[prop]);
    }
Output
    prefix=dcterms:creator count=1
    prefix=rdf:type count=1
    prefix=rdf:value count=1
    prefix=foaf:phone count=1