Skip to content

Commit

Permalink
Merge pull request #722 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Feb 29, 2020
2 parents 7ecaa86 + 60b51c2 commit d2ecf95
Show file tree
Hide file tree
Showing 27 changed files with 633 additions and 138 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ name: Build and test
on: [pull_request]

jobs:
build:
build-and-test:
runs-on: ubuntu-latest

env:
CI: true

strategy:
matrix:
node-version: [8.x, 10.x, 13.x]
Expand All @@ -27,18 +30,25 @@ jobs:
${{ runner.os }}-npm-${{ matrix.node-version }}-
${{ runner.os }}-npm-
- name: npm install, build, and test
- name: install
run: |
npm ci
npm i --no-save eslint ts-node typescript
npm run plugins:ci
- name: static checks
run: |
npm run lint
- name: build
run: |
npm run build
npm run plugins:build
- name: test
run: |
npm run test:smoke
npm run testb
npm run test:perf
npm run test:types
# npm run test:stress
env:
CI: true
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
release:
types: [created]

jobs:
release:
runs-on: ubuntu-latest

env:
CI: true

# Note that these steps are *identical* to build-and-test (with the caveat
# that build-and-test uses several versions of Node, and Release only uses
# 10.x) at least until the actual publishing happens. Ideally, we could
# delegate to the build- and-test workflow, but I haven't found a way to do
# that yet.
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v1
with:
node-version: 10.x

- name: cache dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-npm-10.x-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-10.x-
${{ runner.os }}-npm-
- name: install
run: |
npm ci
npm i --no-save eslint ts-node typescript
npm run plugins:ci
- name: static checks
run: |
npm run lint
- name: build
run: |
npm run build
npm run plugins:build
- name: test
run: |
npm run test:smoke
npm run testb
npm run test:perf
npm run test:types
# npm run test:stress
# And finally... publish it! Note that we create the .npmrc file
# "just in time" so that `npm publish` can get the auth token from the
# environment
- name: publish
run: |
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
npm publish --dry-run
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,10 @@ doc.world.hello = "Hello again!"

- **[Geocoding Social Conversations with NLP and JavaScript](http://compromise.cool)** - by Microsoft
- **[Microservice Recipe](https://eventn.com/recipes/text-parsing-with-nlp-compromise)** - by Eventn
- **[Adventure Game Sentence Parsing with Compromise](https://killalldefects.com/2020/02/20/adventure-game-sentence-parsing-with-compromise/)
- **[Building Text-Based Games](https://killalldefects.com/2019/09/24/building-text-based-games-with-compromise-nlp/)** - by Matt Eland
- **[Fun with javascript in BigQuery](https://medium.com/@hoffa/new-in-bigquery-persistent-udfs-c9ea4100fd83#6e09)** - by Felipe Hoffa
- - **[Natural Language Processing... in the Browser???](https://dev.to/charlesdlandau/natural-language-processing-in-the-browser-52hj)** - by Charles Landau
- **[Natural Language Processing... in the Browser???](https://dev.to/charlesdlandau/natural-language-processing-in-the-browser-52hj)** - by Charles Landau

##### Talks:

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

Large diffs are not rendered by default.

175 changes: 129 additions & 46 deletions builds/compromise.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/compromise.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

175 changes: 129 additions & 46 deletions builds/compromise.mjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ compromise uses semver, and pushes to npm frequently

While all _Major_ releases should be reviewed, our only two _large_ releases are **v6** in 2016 and and **v12** in 2019. Others have been mostly incremental, or niche.

#### 13.1.1

- fix `verbs.json()` runtime-error
- improve empty `.lists()` methods
- allow custom tag colors
- test new github action workflow

#### 13.1.0

- significant (~30%) speed up of parsing
Expand Down
2 changes: 1 addition & 1 deletion plugins/scan/builds/compromise-scan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/scan/builds/compromise-scan.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* compromise-scan 0.0.1 MIT */
/* compromise-scan 0.1.0 MIT */
// edited by Spencer Kelly
// credit to https://github.com/BrunoRB/ahocorasick by Bruno Roberto Búrigo.
// object v. array
Expand Down
2 changes: 1 addition & 1 deletion plugins/scan/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "compromise-scan",
"description": "plugin for nlp-compromise",
"version": "0.0.1",
"version": "0.1.0",
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)",
"main": "./builds/compromise-scan.js",
"unpkg": "./builds/compromise-scan.min.js",
Expand Down
13 changes: 11 additions & 2 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@ let txt = require('./scripts/test/speed/_sotu-text.js')
// nlp.extend(require('./plugins/numbers/src'))
// nlp.extend(require('./plugins/dates/src'))

let doc = nlp(txt)
// console.log(doc.dates().json())
// let doc = nlp('i am a modern major general').replace('modern', 'old')
// let doc = nlp('i am a modern major general')
// doc.match('modern').tag('Person')
// // console.log(doc._cache)
// console.log(doc.has('#Person'))

let doc = nlp('i saw red, blue, and green.')
// doc.lists().addOxfordComma()
doc.lists().removeOxfordComma()
console.log(doc.text())
// console.log(arr)
2 changes: 2 additions & 0 deletions src/02-tagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const tagger = function(doc) {
doc.cache()
// wiggle-around the results, so they make more sense
doc = corrections(doc)
// remove our cache, as it's invalidated now
doc.uncache()
// run any user-given tagger functions
doc.world.taggers.forEach(fn => {
fn(doc)
Expand Down
37 changes: 37 additions & 0 deletions src/Doc/match/checkCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// cache the easier conditions up-front
const cacheRequired = function(reg) {
let needTags = []
let needWords = []
reg.forEach(obj => {
if (obj.optional === true || obj.negative === true) {
return
}
if (obj.tag !== undefined) {
needTags.push(obj.tag)
}
if (obj.word !== undefined) {
needWords.push(obj.word)
}
})
return { tags: needTags, words: needWords }
}

const failFast = function(doc, regs) {
if (doc._cache && doc._cache.set === true) {
let { words, tags } = cacheRequired(regs)
//check required words
for (let i = 0; i < words.length; i++) {
if (doc._cache.words[words[i]] === undefined) {
return false
}
}
//check required tags
for (let i = 0; i < tags.length; i++) {
if (doc._cache.tags[tags[i]] === undefined) {
return false
}
}
}
return true
}
module.exports = failFast
19 changes: 18 additions & 1 deletion src/Doc/methods/03-match.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const parseSyntax = require('../match/syntax')
const checkCache = require('../match/checkCache')

/** return a new Doc, with this one as a parent */
exports.match = function(reg, name) {
Expand All @@ -7,6 +8,10 @@ exports.match = function(reg, name) {
if (regs.length === 0) {
return this.buildFrom([])
}
//check our cache, if it exists
if (checkCache(this, regs) === false) {
return this.buildFrom([])
}
//try expression on each phrase
let matches = this.list.reduce((arr, p) => {
return arr.concat(p.match(regs))
Expand All @@ -23,7 +28,7 @@ exports.not = function(reg) {
//parse-up the input expression
let regs = parseSyntax(reg)
//if it's empty, return them all!
if (regs.length === 0) {
if (regs.length === 0 || checkCache(this, regs) === false) {
return this
}
//try expression on each phrase
Expand All @@ -36,6 +41,10 @@ exports.not = function(reg) {
/** return only the first match */
exports.matchOne = function(reg) {
let regs = parseSyntax(reg)
//check our cache, if it exists
if (checkCache(this, regs) === false) {
return this.buildFrom([])
}
for (let i = 0; i < this.list.length; i++) {
let match = this.list[i].match(regs, true)
return this.buildFrom(match)
Expand All @@ -46,6 +55,10 @@ exports.matchOne = function(reg) {
/** return each current phrase, only if it contains this match */
exports.if = function(reg) {
let regs = parseSyntax(reg)
//consult our cache, if it exists
if (checkCache(this, regs) === false) {
return this.buildFrom([])
}
let found = this.list.filter(p => p.has(regs) === true)
return this.buildFrom(found)
}
Expand All @@ -60,6 +73,10 @@ exports.ifNo = function(reg) {
/**Return a boolean if this match exists */
exports.has = function(reg) {
let regs = parseSyntax(reg)
//consult our cache, if it exists
if (checkCache(this, regs) === false) {
return false
}
return this.list.some(p => p.has(regs) === true)
}

Expand Down
17 changes: 2 additions & 15 deletions src/Doc/methods/07-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports.cache = function(options) {
this._cache.set = true
this.list.forEach((p, i) => {
p.cache = p.cache || {}
//p.terms get cached automatically
let terms = p.terms()
// cache all the terms
terms.forEach(t => {
Expand All @@ -21,26 +22,12 @@ exports.cache = function(options) {
tags[tag] = tags[tag] || []
tags[tag].push(i)
})
// Object.assign(this._cache.tags, t.tags)

// words[t.clean] = true
// words[t.text.toLowerCase()] = true
// if (t.implicit) {
// words[t.implicit] = true
// }
// if (t.root) {
// words[t.root] = true
// }
// if (t.alias !== undefined) {
// words = Object.assign(words, t.alias)
// }
// cache root-form on Term, too
if (options.root) {
t.setRoot(this.world)
words[t.root] = true
}
// })
// delete words['']
// p.cache.words = words
})
})
return this
Expand Down
11 changes: 5 additions & 6 deletions src/Doc/methods/output/_debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const tagset = require('../../../World/tags')

// https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
const reset = '\x1b[0m'

Expand Down Expand Up @@ -27,6 +25,7 @@ const css = {
}

const logClientSide = function(doc) {
let tagset = doc.world.tags
doc.list.forEach(p => {
console.log('\n%c"' + p.text() + '"', 'color: #e6d7b3;')
let terms = p.terms()
Expand Down Expand Up @@ -74,12 +73,12 @@ const cli = {
},
}

const tagString = function(tags) {
const tagString = function(tags, world) {
tags = tags.map(tag => {
if (!tagset.hasOwnProperty(tag)) {
if (!world.tags.hasOwnProperty(tag)) {
return tag
}
const c = tagset[tag].color || 'blue'
const c = world.tags[tag].color || 'blue'
return cli[c](tag)
})
return tags.join(', ')
Expand All @@ -106,7 +105,7 @@ const debug = function(doc) {
}
let word = "'" + text + "'"
word = padEnd(word, 18)
let str = cli.blue(' | ') + word + ' - ' + tagString(tags)
let str = cli.blue(' | ') + word + ' - ' + tagString(tags, doc.world)
console.log(str)
})
})
Expand Down
Loading

0 comments on commit d2ecf95

Please sign in to comment.