Skip to content

Commit

Permalink
Merge pull request #779 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Sep 10, 2020
2 parents 04a8a79 + ce87bd7 commit 7376f02
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ _(these methods are on the `nlp` object)_
- **[.verbose()](https://observablehq.com/@spencermountain/compromise-constructor-methods)** - log our decision-making for debugging
- **[.version()](https://observablehq.com/@spencermountain/compromise-constructor-methods)** - current semver version of the library
- **[.world()](https://observablehq.com/@spencermountain/compromise-constructor-methods)** - grab all current linguistic data
- **[.parseMatch()](https://observablehq.com/@spencermountain/compromise-constructor-methods)** - pre-parse any match statements for faster lookups

##### Utils

Expand Down
2 changes: 1 addition & 1 deletion builds/compromise-tokenize.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions builds/compromise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* compromise 13.4.0 MIT */
/* compromise 13.5.0 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -3440,7 +3440,7 @@

var fromJSON_1 = fromJSON;

var _version = '13.4.0';
var _version = '13.5.0';

var _data = {
"Comparative": "true¦better",
Expand Down Expand Up @@ -13906,6 +13906,12 @@
nlp.world = function () {
return world;
};
/** pre-parse any match statements */


nlp.parseMatch = function (str) {
return syntax_1(str);
};
/** current version of the library */


Expand Down
2 changes: 1 addition & 1 deletion builds/compromise.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions builds/compromise.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* compromise 13.4.0 MIT */
/* compromise 13.5.0 MIT */
function _typeof(obj) {
"@babel/helpers - typeof";

Expand Down Expand Up @@ -3434,7 +3434,7 @@ var fromJSON = function fromJSON(json, world) {

var fromJSON_1 = fromJSON;

var _version = '13.4.0';
var _version = '13.5.0';

var _data = {
"Comparative": "true¦better",
Expand Down Expand Up @@ -13900,6 +13900,12 @@ function instance(worldInstance) {
nlp.world = function () {
return world;
};
/** pre-parse any match statements */


nlp.parseMatch = function (str) {
return syntax_1(str);
};
/** current version of the library */


Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ While all _Major_ releases should be reviewed, our only two _large_ releases are

#### [Unreleased]

#### 13.5.0

- **[new]** add `.parseMatch()` method for pre-parsing match statements

#### 13.4.0

- **[change]** stop including adverbs and some auxiliaries in `.conjugate()` results
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)",
"name": "compromise",
"description": "modest natural language processing",
"version": "13.4.0",
"version": "13.5.0",
"main": "./builds/compromise.js",
"unpkg": "./builds/compromise.min.js",
"module": "./builds/compromise.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '13.4.0'
module.exports = '13.5.0'
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Phrase = require('./Phrase/Phrase')
const Term = require('./Term/Term')
const Pool = require('./01-tokenizer/Pool')
const tinyTagger = require('./02-tagger/tiny')
const parseMatch = require('./Doc/match/syntax')

function instance(worldInstance) {
//blast-out our word-lists, just once
Expand Down Expand Up @@ -65,6 +66,10 @@ function instance(worldInstance) {
nlp.world = function () {
return world
}
/** pre-parse any match statements */
nlp.parseMatch = function (str) {
return parseMatch(str)
}

/** current version of the library */
nlp.version = version
Expand Down
33 changes: 29 additions & 4 deletions tests/constructor.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const test = require('tape')
const nlp = require('./_lib')

test('extra exports:', function(t) {
test('extra exports:', function (t) {
t.ok(nlp.version, 'version number exported')

t.doesNotThrow(function() {
t.doesNotThrow(function () {
nlp.verbose(true)
nlp.verbose(false)
}, 'can set verbosity')

t.end()
})

test('tokenize() runs without pos-tagging', function(t) {
test('tokenize() runs without pos-tagging', function (t) {
const str = 'Miss Hoover, I glued my head to my shoulder.'
const r = nlp.tokenize(str)
t.equal(r.out('text'), str, 'tokenize output is same')
Expand All @@ -25,7 +25,7 @@ test('tokenize() runs without pos-tagging', function(t) {
t.end()
})

test('tokenize() accepts lexicon param', function(t) {
test('tokenize() accepts lexicon param', function (t) {
let doc = nlp.tokenize('spencer kelly is working here', {
'spencer kelly': 'Person',
working: 'NotFun',
Expand All @@ -36,3 +36,28 @@ test('tokenize() accepts lexicon param', function(t) {
t.equal(doc.has('#Verb'), false, 'not a full tag')
t.end()
})

test('parseMatch() results are symmetric', function (t) {
const doc = nlp(`Why doesnt ross, the largest friend, simply eat the other 5?`)
let matches = [
'#MaleName the #Adjective friend',
'^why',
'#Value$',
null,
['simply', 'eat'],
'why',
'.',
'. simply?',
'simply eat',
'tornado alley #Hoover',
]
matches.forEach(str => {
let match = nlp.parseMatch(str)
let a = doc.match(match).json()
let b = doc.match(str).json()
a = JSON.stringify(a)
b = JSON.stringify(b)
t.equal(a, b, str)
})
t.end()
})
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ declare interface nlp<D extends object, W extends object, Ph extends Object> {
clone(): nlp<D, W, Ph>
/** current semver version of the library */
version: nlp.ExtendedDocument<D, W, Ph>
/** grab the document's context data */
world(): W
/** pre-parse a match statement, for faster lookups*/
parseMatch(str: string): nlp<D, W, Ph>
}

declare function nlp(text?: string, lexicon?: Lexicon): nlp.DefaultDocument
Expand Down

0 comments on commit 7376f02

Please sign in to comment.