Mapping Turtle files to Javascript/Typescript objects

It does not matter if the turtle in the document and the SPARQL that queries it use different prefixes. All of the prefixes in the SPARQL will be expanded to whatever they were defined as before they perform the query and all of the prefixes in the source document will be expanded before the query is run against it.

1 Like

Thanks for checking it out. Maybe Iā€™ll have to look into this, but when you say ā€œTTLā€ file does that mean youā€™re not using the solid protocol to read the file? Youā€™re trying to read the file directly from disk?

Normally, you should be able to do something like this:

SoukaiSolid.loadSolidModels();
Soukai.loadModels({ SocialAgent });
Soukai.useEngine(new SolidEngine(window.fetch.bind(fetch)));

const agents = await SocialAgent
    .from('http://my-pod.com/ttl/')
    .all({ $in: ['http://my-pod.com/ttl/alice.ttl'] });

console.log(agents);

But if you are not reading the files using HTTP, you probably have to read the file yourself and send it to soukai. I already have a method called newFromJsonLD for this type of thing, so it should be easy to implement one called newFromTurtle to do something like this:

// actually read the turtle file instead of doing this
const turtle = '<#it> a <http://www.w3.org/ns/solid/interop#SocialAgent> .'; 

const agent = await SocialAgent.newFromTurtle(turtle);

console.log(agent);

Engines serve to read/store data in different backends. The SolidEngine reads/stores the data in a Solid POD using HTTP requests. The LocalStorageEngine would read/store data from localStorage, not from disk, thatā€™s why your example is not working.

Yes, this is what I understood, and that is actually how the shex-methods sees it.
Thank you for the confirmation!

Yes, I know this sounds silly :grimacing: I am trying to read from a local file.

I am working on a prototype for my master thesis, and I start from scratch (very little experience in vue and typescript, none in RDF and solid). So, Iā€™m trying to work my way with baby steps.

  1. model RDF data in ts
  2. load RDF data into model (from file)
  3. play with model
  4. write model back to datafile

Thank you for bearing with me in my journey to RDF :innocent:

I see, in that case maybe you shouldnā€™t use soukai because I donā€™t think itā€™s beginner friendly at this point. It uses a design pattern called Active Record and even though it can make developing more enjoyable (depending who you ask xD), it does come with a bit of complexity.

Having said that, even if youā€™re getting started I donā€™t think it should be too much of a leap to read turtle using the Solid protocol. Itā€™s easy to run a Solid POD locally if thatā€™s what youā€™re worried about. And the only additional thing you need to do is to use an authentication library, but I think itā€™s quite easy to use. In case it helps, I suggest that you check out this hello world application that is very simple to help people getting started: Solid Hello World. Also, if you want to find more, hereā€™s a collection of Hello Worlds: Solid Hello Worlds

I see that LDFlex has already been suggested; and second that suggetion. Another really usefully package is rdf-object - Iā€™ve also got a wrapper rdf-object-proxy which has a very similar syntax to what you have suggested for accessing publisher.

Hey @jeswr, sorry for not replying any sooner.

Thank you for your suggestion, but I have decided to go with shex-codegen & shex-method from @anon85132706 (high-five). It generates exactly what I needed, though some features here and there are not supported yet.

Iā€™ll keep an eye out for it still :slightly_smiling_face:

2 Likes