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

is there a community group for general questions? #28

Open
pwin opened this issue Jun 8, 2020 · 1 comment
Open

is there a community group for general questions? #28

pwin opened this issue Jun 8, 2020 · 1 comment
Labels

Comments

@pwin
Copy link

pwin commented Jun 8, 2020

Hi. I've a general question and wonder if there's a forum for these questions?

My question is, I am trying to create a dataset from a turtle string "value" in an editor pane using the following

`
function createStream (s) {
const resumer = require('resumer');
var stream = resumer();
stream.queue(s);
return stream;
}
function ingestTurtle(value){
const ttl_read = require('@graphy/content.ttl.read');
const dataset = require('@graphy/memory.dataset.fast');

let y_input_a = dataset();
createStream(value)
.pipe(ttl_read())
.pipe(y_input_a);

}`

Is this a correct interpretation of the code? If so, how can I iterate through the subjects and how in can I then find the predicates and objects for each subject?

@blake-regalia
Copy link
Owner

blake-regalia commented Jun 9, 2020

Thanks for asking, there is now the graphy-js/community chat room on gitter. I should add a badge to the README.

As for your question, you don't need to use createStream, graphy will do this for you. Just pass the string directly to the ttl_read function and pipe it onto the dataset. Then you can iterate the dataset or use Dataset#match method to fetch predicates and objects belonging to a certain subject, etc.

const ttl_read = require('@graphy/content.ttl.read');
const dataset = require('@graphy/memory.dataset.fast');

let y_dataset_a = dataset();
ttl_read(value)
  .pipe(y_dataset_a)
  .on('finish', () => {
    // dataset is now ready in memory, you can iterate using [Symbol.iterator]
    for(let g_quad of y_dataset_a) {
      console.log(g_quad.toString());
    }

    // or match
    for(let g_quad of y_dataset_a.match(factory.namedNode('http://eg.org/subject/A'))) {
       // ...
    }
  });

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

No branches or pull requests

2 participants