concept-network

2.0.0 • Public • Published

concept-network Build Status codecov coverage NPM version

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

Getting Started

Install the module with: npm install concept-network

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:

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

Functions

Table of Contents

cnsActivate

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

Parameters

  • cns ConceptNetworkState
  • label string

Returns ConceptNetworkState

cnsGetActivationValue

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

Parameters

  • cns ConceptNetworkState
  • label string

Returns (number | undefined)

cnsGetOldActivationValue

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

Parameters

  • cns ConceptNetworkState
  • label string

Returns (number | undefined)

cnsGetMaxActivationValue

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

Parameters

  • cns ConceptNetworkState
  • beginning string (optional, default '')

Returns 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 (optional, default '')
  • threshold number (optional, default 95)

cnsSetActivationValue

Set the activation value of a node label.

Parameters

  • cns ConceptNetworkState (optional, default {})
  • label string
  • value 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

Returns ConceptNetwork the new ConceptNetwork

cnDecrementNode

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

Parameters

  • cn ConceptNetwork
  • label string

Returns ConceptNetwork the new ConceptNetwork

cnRemoveNode

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

Parameters

  • cn ConceptNetwork
  • label string

Returns ConceptNetwork the new ConceptNetwork

cnAddLink

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

Parameters

Returns ConceptNetwork the new ConceptNetwork

cnRemoveLink

Remove the link from from to to

Parameters

  • cn ConceptNetwork
  • from string label of the outgoing node
  • to 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 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 label of the from node
  • to string label of the to node

Returns ConceptNetwork new ConceptNetwork

cnGetNode

Get the node matching label.

Parameters

  • cn ConceptNetwork
  • label string label of the node to get

Returns (ConceptNetworkNode | undefined)

cnGetLink

Get the link from from to to.

Parameters

  • cn ConceptNetwork
  • from string label of the node from
  • to string label of the node to

Returns (ConceptNetworkLink | undefined)

cnGetLinksFrom

Get the links from label node.

Parameters

  • cn ConceptNetwork
  • label string label of the node from

Returns Array<ConceptNetworkLink>

cnGetLinksTo

Get the links to label node.

Parameters

  • cn ConceptNetwork
  • label string label of the node to

Returns Array<ConceptNetworkLink>

cnGetNodeIndex

Get the index of the node matching label.

Parameters

  • cn ConceptNetwork
  • label string label of the node to get

Returns number -1 when not found

cnGetLinkIndex

Get the index of the link from from to to.

Parameters

  • cn ConceptNetwork
  • from string label of the node from
  • to string label of the node to

Returns number -1 when not found

cnGetLinkIndex2

Get the index of the link from fromIndex to toIndex.

Parameters

  • cn ConceptNetwork
  • fromIndex number label of the node from
  • toIndex number label of the node to

Returns 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

  • 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.

Package Sidebar

Install

npm i concept-network

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

255 kB

Total Files

34

Last publish

Collaborators

  • parmentf