An open API service indexing awesome lists of open source software.

https://github.com/parmentf/node-concept-network

Concept Network is weighted directed graph, in which activation values are propagated. Written in Node.js.
https://github.com/parmentf/node-concept-network

Last synced: 8 months ago
JSON representation

Concept Network is weighted directed graph, in which activation values are propagated. Written in Node.js.

Awesome Lists containing this project

README

          

# concept-network [![Build Status](https://img.shields.io/travis/parmentf/node-concept-network.svg?style=flat-square)](http://travis-ci.org/parmentf/node-concept-network) [![codecov coverage](https://img.shields.io/codecov/c/github/parmentf/node-concept-network.svg?style=flat-square)](https://codecov.io/github/parmentf/node-concept-network) [![NPM version](https://img.shields.io/npm/v/concept-network.svg?style=flat-square)](http://badge.fury.io/js/concept-network)

Concept Network is weighted directed graph, in which activation values are propagated. Written in [Node.js](http://nodejs.org).

## Getting Started

Install the module with: `npm install concept-network`

```javascript
import { cnAddNode, cnAddLink } from 'concept-network/lib/concept-network';
import { cnsActivate, cnsPropagate } from 'concept-network/lib/concept-network-state';

let cn = cnAddNode({}, 'ECTOR');
cn = cnAddNode(cn, 'knows');
cn = cnAddNode(cn, 'Achille');

cn = cnAddLink(cn, 'ECTOR', 'knows');
cn = cnAddLink(cn, 'knows', 'Achille');

let cns = cnsActivate({}, 'ECTOR');
cns = cnsPropagate(cn, cns);
```

which gives:

```js
{ ECTOR: { value: 59.500004166625004, age: 1, old: 100 },
knows: { value: 63.40844023393148, old: 0, age: 0 } }
```

## Functions

#### Table of Contents

- [cnsActivate](#cnsactivate)
- [Parameters](#parameters)
- [cnsGetActivationValue](#cnsgetactivationvalue)
- [Parameters](#parameters-1)
- [cnsGetOldActivationValue](#cnsgetoldactivationvalue)
- [Parameters](#parameters-2)
- [cnsGetMaxActivationValue](#cnsgetmaxactivationvalue)
- [Parameters](#parameters-3)
- [cnsGetActivatedTypedNodes](#cnsgetactivatedtypednodes)
- [Parameters](#parameters-4)
- [cnsSetActivationValue](#cnssetactivationvalue)
- [Parameters](#parameters-5)
- [cnsPropagate](#cnspropagate)
- [Parameters](#parameters-6)
- [cnAddNode](#cnaddnode)
- [Parameters](#parameters-7)
- [cnDecrementNode](#cndecrementnode)
- [Parameters](#parameters-8)
- [cnRemoveNode](#cnremovenode)
- [Parameters](#parameters-9)
- [cnAddLink](#cnaddlink)
- [Parameters](#parameters-10)
- [cnRemoveLink](#cnremovelink)
- [Parameters](#parameters-11)
- [cnRemoveLinksOfNode](#cnremovelinksofnode)
- [Parameters](#parameters-12)
- [cnDecrementLink](#cndecrementlink)
- [Parameters](#parameters-13)
- [cnGetNode](#cngetnode)
- [Parameters](#parameters-14)
- [cnGetLink](#cngetlink)
- [Parameters](#parameters-15)
- [cnGetLinksFrom](#cngetlinksfrom)
- [Parameters](#parameters-16)
- [cnGetLinksTo](#cngetlinksto)
- [Parameters](#parameters-17)
- [cnGetNodeIndex](#cngetnodeindex)
- [Parameters](#parameters-18)
- [cnGetLinkIndex](#cngetlinkindex)
- [Parameters](#parameters-19)
- [cnGetLinkIndex2](#cngetlinkindex2)
- [Parameters](#parameters-20)

### cnsActivate

Set the activation value of the node which `label` is given to 100.

#### Parameters

- `cns` **ConceptNetworkState**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **ConceptNetworkState**

### cnsGetActivationValue

Get the activation value of a node (which `label` is given)

#### Parameters

- `cns` **ConceptNetworkState**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**

### cnsGetOldActivationValue

Get the activation value of a node (which `label` is given)

#### Parameters

- `cns` **ConceptNetworkState**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**

### cnsGetMaxActivationValue

Get the maximum activation value of all nodes which label start with
`beginning`.

#### Parameters

- `cns` **ConceptNetworkState**
- `beginning` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `''`)

Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**

### cnsGetActivatedTypedNodes

Return an object associating nodes labels with their activation values, but
only for labels starting with `beginning` and activation values greater or
equal to `threshold`.

#### Parameters

- `cns` **ConceptNetworkState**
- `beginning` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `''`)
- `threshold` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** (optional, default `95`)

### cnsSetActivationValue

Set the activation `value` of a node `label`.

#### Parameters

- `cns` **ConceptNetworkState** (optional, default `{}`)
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `value` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**

Returns **ConceptNetworkState**

### cnsPropagate

Propagate the activation values along the links.

#### Parameters

- `cn` **ConceptNetwork**
- `cns` **ConceptNetworkState**
- `options` (optional, default `{decay:40,memoryPerf:100}`)

Returns **ConceptNetworkState**

### cnAddNode

Create a node in `cn` or increment its occurrence.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **ConceptNetwork** the new ConceptNetwork

### cnDecrementNode

Decrement the `occ` of the node which `label` is given by one.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **ConceptNetwork** the new ConceptNetwork

### cnRemoveNode

Remove the node which `label` is given (and the links to it)

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **ConceptNetwork** the new ConceptNetwork

### cnAddLink

Create a link between `from` and `to`, and increment `coOcc` by one.

#### Parameters

- `cn` **ConceptNetwork**
- `from` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `to` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**

Returns **ConceptNetwork** the new ConceptNetwork

### cnRemoveLink

Remove the link from `from` to `to`

#### Parameters

- `cn` **ConceptNetwork**
- `from` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the outgoing node
- `to` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the ingoing node

Returns **ConceptNetwork** the new ConceptNetwork

### cnRemoveLinksOfNode

Remove all links of the node which `label` is given.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node which links are to be removed

Returns **ConceptNetwork** new ConceptNetwork

### cnDecrementLink

Decrement the coOcc of the link from `from` to `to` by one.

#### Parameters

- `cn` **ConceptNetwork**
- `from` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the from node
- `to` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the to node

Returns **ConceptNetwork** new ConceptNetwork

### cnGetNode

Get the node matching `label`.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node to get

Returns **(ConceptNetworkNode | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**

### cnGetLink

Get the link from `from` to `to`.

#### Parameters

- `cn` **ConceptNetwork**
- `from` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node from
- `to` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node to

Returns **(ConceptNetworkLink | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**

### cnGetLinksFrom

Get the links from `label` node.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node from

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<ConceptNetworkLink>**

### cnGetLinksTo

Get the links to `label` node.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node to

Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<ConceptNetworkLink>**

### cnGetNodeIndex

Get the index of the node matching `label`.

#### Parameters

- `cn` **ConceptNetwork**
- `label` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node to get

Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-1 when not found

### cnGetLinkIndex

Get the index of the link from `from` to `to`.

#### Parameters

- `cn` **ConceptNetwork**
- `from` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node from
- `to` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** label of the node to

Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-1 when not found

### cnGetLinkIndex2

Get the index of the link from `fromIndex` to `toIndex`.

#### Parameters

- `cn` **ConceptNetwork**
- `fromIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** label of the node from
- `toIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** label of the node to

Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-1 when not found

## Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint, and test your code using `npm test`.

## Release History

See also [Releases](https://github.com/parmentf/node-concept-network/releases)

- 2019/01/04: version 2.0.0: Change all API to something more functional
- 2018/12/27: version 1.2.2: Go back to synchronous ConceptNetwork
- 2015/11/28: version 1.2.1: Update dependencies versions
- 2015/02/20: version 1.2.0: Add options to propagate()
- 2015/02/07: version 1.1.0: Make getLink accept two parameters
- 2015/02/07: version 1.0.0: Go to semantic versioning, add increments to addLink and addNode
- 2014/08/07: version 0.1.4: fix some error cases with injector
- 2013/01/05: version 0.1.3: add ConceptNetworkState.getMaximumValue() and ConceptNetworkState.getActivatedTypedNodes()
- 2013/01/03: version 0.1.2: add ConceptNetworkState

Warning: this is a work in progress.

## License

Copyright (c) 2012 François Parmentier
Licensed under the MIT license.