Saving triples in Node.js

I am developing an application in Node.js and I have data in the json representation of a triple like this:

{ subject:"Hello", predicate:"Knows", object:"World" } 

I would like to be able to store my data in the [data | triple] in a relatively simple way.

The data values ​​in the tuple must also be searchable.

I looked at using an existing RDF server and accessing it via HTTP, but would like to avoid using Sparql (a workaround might be to have a separate javascript module that wraps around Sparql).

Are there any existing Node modules that store triples? If not, what would be a pragmatic solution for storing triples?

+4
source share
4 answers

If you only need access to data using a key (for example, a user ID), use a key value store, such as Redis , and connect to it using node_redis .

If you need to search the data in triple form, use MongoDB and connect to it using something like Mongoose .

+2
source

Admittedly, I do not know any data storage that is optimized for storing 3 tuples (triples) for Node.js. Without knowing more about the problem you are solving and the corresponding domain, it is difficult to give specific recommendations. Given the current information that you provided, for each triple I would create a key. Then select MongoDB (possibly brute force), Redis (Hash or Set) or an associative array of JavaScript, depending on your requirements.

If you are looking for performance among many Node.js clients, then using Redis with a feature would be great.

+2
source

To get started, your example is not a valid triple RDF, so if you really want to switch to / RDF, you will have to be more strict with your data.

With that said, there are several options that I know, this framework implements the proposed RDF interface standard in Javascript. You don’t know if you can connect it to the existing tri-core storage or what, but it can work to represent your data. This library works with jQuery to provide some RDF support. Finally, this library , which tried to be a compact representation of RDF in Javascript.

Another option is the RDF / JSON LD specification , which with its JSON representation is quite suitable for use in Javascript.

+2
source

I just created a very lightweight JS framework to do exactly what you want:

https://www.npmjs.com/package/hexastore

Add triples:

 mydb.putAll([ ["hexastore","is","nice"], ["hexastore","speed","fast"], ["javascript","is","nice"] ]); 

Three triples:

 var result = db.search([ [["what"],"is","nice"] ]); // result == [{what:hexastore},{what:javascript}] 
+1
source

Source: https://habr.com/ru/post/1401610/


All Articles