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 @ludwigschubi (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