Skip to content

Commit

Permalink
Merge pull request #773 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Aug 7, 2020
2 parents 63fad56 + cff5783 commit 3fffa74
Show file tree
Hide file tree
Showing 19 changed files with 1,136 additions and 888 deletions.
58 changes: 10 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div align="center">
<sub>
by
<a href="https://github.com/spencermountain">Spencer Kelly</a> and
<a href="https://spencermounta.in/">Spencer Kelly</a> and
<a href="https://github.com/spencermountain/compromise/graphs/contributors">
many contributors
</a>
Expand Down Expand Up @@ -50,12 +50,6 @@
<!-- spacer -->
<img height="50px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>

<div align="right">
<code>
Welcome to v12! - <a href="https://github.com/spencermountain/compromise/wiki/v12-Release-Notes">Release Notes here 👍</a>
</code>
</div>

<!-- spacer -->
<img height="50px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>

Expand Down Expand Up @@ -145,17 +139,11 @@ grab subjects in a text:

```js
let doc = nlp(buddyHolly)
doc
.people()
.if('mary')
.json()
doc.people().if('mary').json()
// [{text:'Mary Tyler Moore'}]

let doc = nlp(freshPrince)
doc
.places()
.first()
.text()
doc.places().first().text()
// 'West Phillidelphia'

doc = nlp('the opera about richard nixon visiting china')
Expand Down Expand Up @@ -230,8 +218,10 @@ or if you don't care about POS-tagging, you can use the tokenize-only build: (90
<script src="https://unpkg.com/compromise/builds/compromise-tokenize.js"></script>
<script>
var doc = nlp('No, my son is also named Bort.')
//you can see the text has no tags
console.log(doc.has('#Noun')) //false
//but the whole api still works
console.log(doc.has('my .* is .? named /^b[oa]rt/')) //true
</script>
Expand Down Expand Up @@ -311,7 +301,7 @@ nlp.extend((Doc, world) => {
})

// add a whole new method
Doc.prototype.kermitVoice = function() {
Doc.prototype.kermitVoice = function () {
this.sentences().prepend('well,')
this.match('i [(am|was)]').prepend('um,')
return this
Expand Down Expand Up @@ -660,50 +650,22 @@ this plugin creates a wrapper around the default sentence objects.

### Typescript

Typescript support is still a work in progress. So far support for plugins has been mostly complete, and can be used to type-safely extend NLP.
we're committed to typescript/deno support, both in main and in the official-plugins:

```ts
import nlp from 'compromise'
import ngrams from 'compromise-ngrams'
import numbers from 'compromise-numbers'

// .extend() can be chained
const nlpEx = nlp.extend(ngrams).extend(numbers)

nlpEx('This is type safe!').ngrams({ min: 1 })
nlpEx('This is type safe!').numbers()
```

#### Type-safe Plugins

The `.extend()` function returns an nlp type with updated Document and World types (Phrase, Term and Pool are not currently supported). While the global nlp also recieves the plugin from a runtime perspective; it's type will not be updated - this is a limitation of Typescript.

Typesafe plugins can be created by using the `nlp.Plugin` type:

```ts
interface myExtendedDoc {
sayHello(): string
}

interface myExtendedWorld {
hello: string
}

const myPlugin: nlp.Plugin<myExtendedDoc, myExtendedWorld> = (Doc, world) => {
world.hello = 'Hello world!'

Doc.prototype.sayHello = () => world.hello
}

const _nlp = nlp.extend(myPlugin)
const doc = _nlp('This is safe!')
doc.sayHello()
doc.world.hello = 'Hello again!'
```

#### Known Issues

- `compromise_1.default is not a function` - This is a problem with your `tsconfig.json` it can be solved by adding `"esModuleInterop": true`. Make sure to run `tsc --init` when starting a new Typescript project.
<div align="right">
<a href="https://docs.compromise.cool/compromise-typescript">typescript docs</a>
</div>

### Docs:

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

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions builds/compromise.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

31 changes: 20 additions & 11 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 @@ -12,6 +12,13 @@ While all _Major_ releases should be reviewed, our only two _large_ releases are

-move (some) contractions into tokenizer?

#### 13.3.2

- fix for offset issue #771
- fix for `{min,max}` syntax #767
- typescript fixes
- update deps

#### 13.3.1

-support unicode spaces for #759
Expand Down
1 change: 1 addition & 0 deletions data/people/lastnames.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ module.exports = [
'picasso',
'pichler',
'powell',
'putin',
'ramirez',
'ramos',
'reagan',
Expand Down
1 change: 1 addition & 0 deletions data/people/maleNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ module.exports = [
'vincent',
'virgil',
'vivaan',
'vladimir',
'wade',
'wallace',
'wally',
Expand Down
Loading

0 comments on commit 3fffa74

Please sign in to comment.