Giter Site home page Giter Site logo

miguel76 / know-flow Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 1.49 MB

Library to query a knowledge graph (aka linked data source) in a data-flow-oriented template-like way.

License: MIT License

JavaScript 0.19% TypeScript 99.81%
linked-data sparql data-flow rdf template-language

know-flow's Introduction

know-flow

JS(TS) library to query a knowledge graph (aka linked data source) in a data-flow-oriented template-like way.

It enables the development of data-aware modules which encapsulate both query and data-consuming logic. It is based on SPARQL (standard query language for linked data), but its knownledge is not needed for most of the features. It can be potentially used to generate any kind of data structure.

The library know-flow-react allows to use the paradigm in React.

Check the repo wiki for more detailed documentation (in progress).

Installation

Add know-flow as a dependency to your project by executing the following command from the root folder of your project (assumes you are already using npm to manage it).

$ npm install know-flow

Building simple flows

In this example we will build simple flows to generate JSON from a knowledge graph which uses Wikidata schema.

To execute the queries, a query engine is needed. We will be using the Comunica SPARQL engine in this example. Install it with:

$ npm install @comunica/actor-init-sparql

In Javascript/Typescript code, import the flow builder and flow engine, alongside the Comunica query engine:

import { FlowBuilder, FlowEngine } from 'know-flow'
import { newEngine as newComunicaEngine } from '@comunica/actor-init-sparql'

Create an instance of the flow builder:

const tb = new FlowBuilder({
  prefixes: {
    rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
    rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
    wd: 'http://www.wikidata.org/entity/',
    wdt: 'http://www.wikidata.org/prop/direct/'
  }
})

Create a flow to get the label of the current default resource (which will depend on the dynamic context of execution of the flow).

let getLabel = tb.value('rdfs:label')

Create a flow to get basic anagraphic information (the default resource is expected in this case to be a person).

let getPersonInfo = tb.next({
  name: tb.value('wdt:P1559'),
  dateOfBirth: tb.value('wdt:P569'),
  dateOfDeath: tb.value('wdt:P570')
})

Create a flow to list the students of a person (e.g., a philosopher):

let getStudentsInfo = tb.forEach('wdt:P1066').next(getPersonInfo)

Define flows that add some input data:

let hegel = tb.input('wd:Q9235')
let adorno = tb.input('wd:Q152388')

let infoOnHegel = hegel.next(getPersonInfo)
let infoOnAdorno = adorno.next(getPersonInfo)
let hegelStudentsInfo = hegel.next(getStudentsInfo)
let adornoStudentsInfo = adorno.next(getStudentsInfo)

Executing the flows

Create an instance of the flow engine, pointing to the wikidata public endpoint:

let te = new FlowEngine({
  engine: newComunicaEngine(),
  queryContext: {
    sources: [{ type: 'sparql', value: 'https://query.wikidata.org/sparql' }]
  }
})

Execute the flows and print the results when done:

te.run(infoOnHegel).then(console.log, console.error)
// {
//   name: 'Georg Wilhelm Friedrich Hegel',
//   dateOfBirth: '1770-08-27T00:00:00Z',
//   dateOfDeath: '1831-11-14T00:00:00Z'
// }

te.run(infoOnAdorno).then(console.log, console.error)
// {
//   name: 'Theodor Ludwig Wiesengrund Adorno',
//   dateOfBirth: '1903-09-11T00:00:00Z',
//   dateOfDeath: '1969-08-06T00:00:00Z'
// }

te.run(hegelStudentsInfo).then(console.log, console.error)
// [
//   {
//     name: 'Max Stirner',
//     dateOfBirth: '1806-10-25T00:00:00Z',
//     dateOfDeath: '1856-06-26T00:00:00Z'
//   }
// ]

te.run(adornoStudentsInfo).then(console.log, console.error)
// [
//   {
//     name: 'Jürgen Habermas',
//     dateOfBirth: '1929-06-18T00:00:00Z',
//     dateOfDeath: null
//   }
// ]

know-flow's People

Contributors

miguel76 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

know-flow's Issues

Provide SPARQL algebra operators as data operations

Arity-1 operators:

  • Filter
  • Graph
  • Extend
  • Minus
  • Group
  • Aggregation
  • AggregateJoin
  • ToList
  • OrderBy
  • Project
  • Rename *
  • Omit *
  • Distinct
  • Reduced
  • Slice
  • ToMultiSet

Arity-2 operators:

  • Join
  • LeftJoin
  • Union
  • operators not available in SPARQL algebra but potentially useful for our context

Manage in a consistent way the input/output of RDF terms

Term binding data operations (values) and term reading actions (valueReader, termReader) should be consistent and provide ways to manage terms at least in three formats:

  • rdfjs standard format;
  • turtle/SPARQL serialization;
  • JSON-LD serialization (including both extended notation and native types format).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.