How to read data from RDF file from Solid POD?


#1

I’ am able to read rdf file form Solid POD but could’nt find a solution to show data inside the file to fornt-end.


#2

The main tool for parsing RDF data in Solid is rdflib.js. You can use rdflib.js directly by using it’s graph(), load() and parse() methods or you can use it through solid-file-client’s fetchAndParse() method which does the graph, load and parse for you and returns an rdflib graph/kb object that can be queried using rdflib methods like each() and any(). See below for an example of using fetchAndParse() . To read more about rdflib’s methods, see the tutorials listed on https://github.com/linkeddata/rdflib.js/.


#3

Here’s a complete working example of solid-file-client’s fetchAndParse() method:

const fc = require('solid-file-client')
var subject = "https://jeffz.solid.community/profile/card#me"
var predicate = 'http://xmlns.com/foaf/0.1/name'

fc.fetchAndParse( subject ).then( store => {
    subject = store.sym(subject)
    predicate = store.sym(predicate)
    var name = store.any(subject,predicate).value
    if(name==="Jeff Zucker") console.log("fetched and parsed");
    else console.log("fecthed but could not parse as expected");
}, err => console.log("could not fetch : "+err) ) ;

#4

What is the meaning of kb ?


#5

It is the rdflib.js store object created by $rdf.graph(). I think of the “kb” as standing for Knowledge Base, but I have the feeling that may be a personal mnemonic for some other abbreviation I once knew. :slight_smile: Abd I’ve now replaced it with the much clearer “store” in the example, thanks for pointing it out.