Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
362907c
README: Mention how to install/run
jonnor Mar 4, 2017
d6424fd
Update all NoFlo dependencies
jonnor Mar 4, 2017
78c2968
Travis: Only test nodejs 6 LTS
jonnor Mar 4, 2017
a0a5795
index: Split out spelling data to a JSON file
jonnor Mar 4, 2017
9351e3b
fbpspec: Don't catch output from noflo-nodejs
jonnor Mar 4, 2017
8523bf4
package.json: Update repo location
jonnor Mar 4, 2017
2b20c51
fbp-spec: Update to latest
jonnor Mar 4, 2017
cb4d810
tests: Fix compatibilty with NoFlo 0.8
jonnor Mar 4, 2017
c4524f9
tests: Fix noflo-tester setup
jonnor Mar 4, 2017
6da39d1
TestDetermineEmotion: Remove workarounds for pre-NoFlo-0.8
jonnor Mar 4, 2017
891bb6f
Fix more workarounds from pre-NoFlo-0.8 times
jonnor Mar 4, 2017
7b40ae8
Merge pull request #1 from noflo/update
jonnor Mar 4, 2017
3c6dfb3
components: TestDetermineEmotion -> ArrayToStream
jonnor Mar 4, 2017
8557511
tests: Bump timeout for component loading
jonnor Mar 4, 2017
0a440ca
tests: Don't duplicate spellings everywhere
jonnor Mar 4, 2017
c1e7dfd
tests: Bring back fbp-spec timeouts to something more sane
jonnor Mar 4, 2017
8db7f76
Merge pull request #2 from noflo/cleanup
jonnor Mar 4, 2017
9aac008
README: Add Travis CI badge
jonnor Mar 4, 2017
e3041e7
components: Add Markdown annotations for docs
jonnor Mar 5, 2017
c4a86c7
tests: Remove noflo-tester use
jonnor Mar 6, 2017
1e29a1a
index: Expose API and implement CLI
jonnor Mar 6, 2017
38c7576
tests: Test the JavaScript API in JS
jonnor Mar 6, 2017
b63124b
tests: Prettier names
jonnor Mar 6, 2017
ec9e62a
Merge pull request #3 from noflo/annotate-components
jonnor Mar 6, 2017
1686292
WordScore: Clean up old input handling
jonnor Mar 6, 2017
1f3481f
API: Use noflo.asCallback helper
jonnor Mar 6, 2017
56863da
Merge pull request #4 from noflo/asCallback
jonnor Mar 6, 2017
5f985d6
Remove Grunt and start ES6 port
bergie Nov 13, 2017
5996d8f
Port components to ES6
bergie Nov 13, 2017
1618a04
Add eslint
bergie Nov 13, 2017
1b23c9d
No need to require chai
bergie Nov 13, 2017
afdef09
Make linter happy
bergie Nov 13, 2017
0fed614
Fix emotion matching
bergie Nov 13, 2017
7508d5b
Simplify
bergie Nov 13, 2017
b2aef1e
Update natural lib
bergie Nov 13, 2017
4aa6c88
Ensure Mocha quits
bergie Nov 13, 2017
e1c3612
Disable debug
bergie Nov 13, 2017
2a41094
Merge pull request #5 from noflo/updates
bergie Nov 13, 2017
ccdb5a1
Simplify index
bergie Nov 13, 2017
53994bd
chore(package): update dependencies
greenkeeper[bot] Nov 27, 2017
e6006aa
docs(readme): add Greenkeeper badge
greenkeeper[bot] Nov 27, 2017
32b6623
Move badges
bergie Nov 27, 2017
72924e5
Test on latest Node.js
bergie Nov 27, 2017
10cd0bf
Merge pull request #6 from noflo/greenkeeper/initial
bergie Nov 27, 2017
2f113d1
chore(package): update mocha to version 5.0.0
greenkeeper[bot] Jan 18, 2018
bf7cae4
Merge pull request #7 from noflo/greenkeeper/mocha-5.0.0
bergie Jan 18, 2018
6fbff57
chore(package): update noflo-nodejs to version 0.10.0
greenkeeper[bot] Mar 22, 2018
fb81a7c
Merge pull request #8 from noflo/greenkeeper/noflo-nodejs-0.10.0
bergie Mar 22, 2018
af37801
chore(package): update fbp-spec to version 0.6.2
greenkeeper[bot] Mar 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "airbnb-base"
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/node_modules/
spec/*.js
spec/browser/*.js
npm-debug.log
.DS_Store
.noflo.json
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: node_js
sudo: false
node_js:
- '0.12'
- '4.2'
- '6.2'
- 'lts/*'
script: npm test
32 changes: 0 additions & 32 deletions Gruntfile.coffee

This file was deleted.

17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Canadianness
## Example program using noflo
# Canadianness [![Build Status](https://travis-ci.org/noflo/canadianness.svg?branch=master)](https://travis-ci.org/noflo/canadianness) [![Greenkeeper badge](https://badges.greenkeeper.io/noflo/canadianness.svg)](https://greenkeeper.io/)

Basic example of programming with [NoFlo](https://noflojs.org).

## Prerequisites

You need to have [Node.js](http://nodejs.org) 6.10 or newer installed.

## Install

npm install

## Run tests

npm test
47 changes: 47 additions & 0 deletions components/ArrayToStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const noflo = require('noflo');

exports.getComponent = () => {
const c = new noflo.Component({
description: 'Convert input array to a NoFlo stream',
inPorts: {
in: {
datatype: 'array',
description: 'data we want to send',
required: true,
},
},
outPorts: {
out: {
datatype: 'string',
description: 'the data wrapped in brackets',
required: true,
},
},
});

c.process((input, output) => {
if (!input.hasData('in')) { return; }

let datas = input.getData('in');
if (!Array.isArray(datas)) {
datas = [datas];
}

output.send({
out: new noflo.IP('openBracket'),
});

datas.forEach((data) => {
output.send({
out: new noflo.IP('data', data),
});
});

output.send({
out: new noflo.IP('closeBracket'),
});
output.done();
});

return c;
};
75 changes: 0 additions & 75 deletions components/DetermineEmotion.coffee

This file was deleted.

113 changes: 113 additions & 0 deletions components/DetermineEmotion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// ## Import libraries
const noflo = require('noflo');

// ## Useful functions
//
// Function to calculate most common value (the [mode](https://en.wikipedia.org/wiki/Mode_(statistics))
function findMode(array) {
const frequency = {};
let maxFrequency = 0;
let result;
array.forEach((v) => {
frequency[v] = (frequency[v] || 0) + 1;
if (frequency[v] > maxFrequency) {
maxFrequency = frequency[v];
result = v;
}
});
return result;
}

// ## Component declaration
//
// Define the input and output ports, and describe their function
exports.getComponent = () => {
const c = new noflo.Component({
description: 'Find all of the instances of `word` in `content` and send them out in a stream',
inPorts: {
content: {
datatype: 'string',
description: 'the content which we look for the word in',
required: true,
},
},
outPorts: {
emotion: {
datatype: 'string',
description: 'the emotion based the content in ehs',
required: true,
},
error: {
datatype: 'object',
},
},
});

// Since we want to work with a full stream, we disable bracket forwarding
c.forwardBrackets = {};

// ## Processing function
//
c.process((input, output) => {
// ### Receiving input
//
// We expect a [stream](noflojs.org/documentation/process-api/#full-stream)
// Will also accept a single (non-bracketed) input packet, returned as a stream of length 1
if (!input.hasStream('content')) { return; }

// The output will be a single packet (not a stream),
// hence we drop the `openBracket` and `closeBracket`
// and extract the data payload from the IP objects
const contents = input.getStream('content').filter(ip => ip.type === 'data').map(ip => ip.data);

// ### Component business logic
//
// First find which emotions are present, then calculate which one is most common.
// This could alternatively be split into two dedicate components.

// to hold the emotions found
const matches = [];

// the emotions we will use
const emotions = {
joy: ['eh!'],
neutral: ['eh'],
amusement: ['eh?', 'Eh?', 'Eh??'],
fear: ['eH??', 'eh??'],
surprise: ['eh !?', 'EH!?'],
anticipation: ['eh?!'],
excitment: ['EH!', 'eH!'],
sadness: ['...eh', '...eh...', '..eh', 'eh..', '..eh..'],
anger: ['EH!?', 'EH?'],
};

// go through our content and our emotions
// then add them to our `matches`
contents.forEach((content) => {
Object.keys(emotions).forEach((emotion) => {
const data = emotions[emotion];
if (data.indexOf(content) !== -1) {
matches.push(emotion);
}
});
});

// if we didn't get any emotions, it default to 'neutral'
let mode;
if (matches.length === 0) {
mode = 'neutral';
// if we did, we need to find the emotion that was the most common
} else {
mode = findMode(matches);
}

// ### Send output
//
// Also signals completion by using `sendDone()`
output.sendDone({
emotion: mode,
});
});

return c;
};
78 changes: 0 additions & 78 deletions components/FindWords.coffee

This file was deleted.

Loading