Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader and Writer for Concise Triples Missing #26

Open
houghtonap opened this issue May 6, 2020 · 3 comments
Open

Reader and Writer for Concise Triples Missing #26

houghtonap opened this issue May 6, 2020 · 3 comments

Comments

@houghtonap
Copy link

Concise Triples (C3) are useful, but I noticed that there are no reader or writer for them:

const reader = require( '@graphy/content.c3.read' ) ;
const writer = require( '@graphy/content.c3.write' ) ;

This makes it more difficult to stream data, for example, one would really like to do:

fs.createReadStream( './c3.js' )
  .pipe ( reader(  ) )
;
@blake-regalia
Copy link
Owner

@houghtonap the readers and writers are for serialization formats, whereas c3 is more about programmatically creating RDF.

Based on your example, I think what you might be after are the factory methods for generating triples/quads. For example, factory.c3 accepts a c3 object and yields triples.

const factory = require('@graphy/core.data.factory');
let prefixes = {
  rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
  dbo: 'http://dbpedia.org/ontology/',
  dbr: 'http://dbpedia.org/resource/',
};

let triples = factory.c3({
  'dbr:Banana': {
    'a': 'dbo:Fruit',
    'rdfs:label': [
      'Banana@en',
      'Bananae@fr',
    ],
  },
}, prefixes);

for(let triple of triples) {
  console.log(triple+'');
}

If you had something else in mind, could you expand on your use case a bit more?

@houghtonap
Copy link
Author

I have a large database (millions of rows) and need to pull select data subsets out and combine with other RDF data. I can pull this data subset by creating JSON-LD or Concise Triples. IMHO Concise Triples are simpler to deal with than JSON-LD and I would also like to use graphy, quadstore and quadstore-sparql to handle loading and analysis of the data. Graphy has support for Concise Triples, but not JSON-LD. I pulled the data subset and created Concise Triples and would prefer to stream that data, but it looks like graphy's implementation of Concise Triples wasn't meant for this use case :(

I had a question on the above snippet using core.data.factory. Does it produce RDFJS compatible triples/quads?

@blake-regalia
Copy link
Owner

I had a question on the above snippet using core.data.factory. Does it produce RDFJS compatible triples/quads?

Yes, triple from the example is an instance of Quad which implements RDFJS Quad. In fact, every available RDFJS interface is implemented in graphy where applicable.

Concise triples are about constructing RDF programmatically either for passing Quads around in memory or for serializing to some RDF format such as Turtle, RDF/XML, etc. Concise triples are not a serialization format but more of an API.

I am still a little unclear about your use case. Do you need to serialize the data to disk between selects and reads or can you pass objects in memory? If you can pass them in memory, using the factory.c3 iterator will give you the fastest results and keep a very low memory profile. If you need to serialize RDF and then deserialize it later, you will need to choose a serialization format (and can still use c3 to create the quads in memory before passing them to the serializer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants