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

Any way to query nodes and links? #16

Open
alimoabd2127 opened this issue Feb 17, 2020 · 1 comment
Open

Any way to query nodes and links? #16

alimoabd2127 opened this issue Feb 17, 2020 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@alimoabd2127
Copy link

Is there any way to query nodes and links? Or would you have to know what kind of data you're receiving beforehand?

@vsimko vsimko self-assigned this May 5, 2020
@vsimko vsimko added the question Further information is requested label May 5, 2020
@vsimko
Copy link
Owner

vsimko commented May 5, 2020

All nodes and links from jsonld are then inside the result object.
Example:

const graph = await jsonld2obj([
      {
        "@id": "http://my/Agent",
        "@type": "http://other/AgentType",
        "x:some": 0.9
      },
      {
        "@id": "http://my/Agent2",
        "@type": "http://other/AgentType",
        "x:some": 0.9
      }
    ])

console.log(graph)

{
      'http://my/Agent': {
        'http://my/Agent': [Circular],
        'x:some': 0.9,
        '$id': 'http://my/Agent',
        '$type': MultiVal { 'http://other/AgentType': [Object] }
      },
      'http://other/AgentType': { '$id': 'http://other/AgentType' },
      'http://my/Agent2': {
        'http://my/Agent2': [Circular],
        'x:some': 0.9,
        '$id': 'http://my/Agent2',
        '$type': MultiVal { 'http://other/AgentType': [Object] }
      }
    }
  • URIs of all nodes: console.log(Object.keys(graph))
  • URIs of all links: new Set(Object.values(graph).flatMap(o => Object.keys(o)).filter(x => !graph[x]))

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

No branches or pull requests

2 participants