Get unlimited public & private packages + team-based management with npm Teams.Learn more »

pos-accumulator

1.1.0 • Public • Published

POS Accumulator

Build Status

Collects strings and builds a parts-of-speech lookup table of the contents.

Example

var PosAccumulator = require('pos-accumulator');
 
var pa = new PosAccumulator();
 
pa.put('This is an example string.');
console.log(pa.lookup('example'));
// { pos: 'NN', count: 1 }
 
pa.put('This is another example string. There has been more than one example.');
console.log(pa.lookup('example'));
// { pos: 'NN', count: 3 }
 
console.log(pa.pos('NN'));
// [ { value: 'example', count: 3 }, { value: 'one', count: 1 } ]
 
console.log(pa.toJSON());
// {"configuration":{"insensitive":true},"data":{"DT":[{"value":"this","count":2},{"value":"an","count":1},{"value":"another","count":1}],"VBZ":[{"value":"is","count":2},{"value":"has","count":1}],"NN":[{"value":"example","count":3},{"value":"one","count":1}],"VBG":[{"value":"string","count":2}],".":[{"value":".","count":3}],"EX":[{"value":"there","count":1}],"VBN":[{"value":"been","count":1}],"JJR":[{"value":"more","count":1}],"IN":[{"value":"than","count":1}]}}

Constructor

var PosAccumulator = require('pos-accumulator');
var pa = new PosAccumulator();

Constructor takes an optional configuration object, the only option is insensitive.

insensitive

Configuration option insensitive defaults to true, when enabled the accumulator will treat all strings as lowercase. This can be disabled by setting the configuration object as:

var PosAccumulator = require('pos-accumulator');
var pa = new PosAccumulator({insensitive : false});

.put(string)

Call on accumulator instance to add string content to that accumulator.

.lookup(string)

Call on accumulator instance to find pos tag and instance count of string, will return null if string is not in accumulator. Returned object will be:

{
  pos: *string of pos tag*,
  count: *int # of times string has been added to accumulator*
}

.pos(string)

Call on accumulator instance to get an array of all words associated to that tag string, will return undefined if tag is not found. Array will consist of objects:

[{
 value : *tagged string*
 count: *int # of times string has been added to accumulator*
},
// ...
]

Install

npm i pos-accumulator

DownloadsWeekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • avatar