Skip to content

Commit

Permalink
finish adding slashes method
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Jul 29, 2024
1 parent d7c6912 commit 119c790
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 19 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ and how hard it is to actually <b>parse</b> and <i>use</i>?

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

<!--
<!--
it is
<a href="https://docs.compromise.cool/compromise-filesize">small,
<a href="https://docs.compromise.cool/compromise-performance">quick</a>,
Expand Down Expand Up @@ -136,7 +136,7 @@ doc.places().json()
/*
[{
"text": "Milwaukee",
"terms": [{
"terms": [{
"normal": "milwaukee",
"syllables": ["mil", "wau", "kee"]
}]
Expand All @@ -148,7 +148,7 @@ doc.places().json()
<a href="https://docs.compromise.cool/compromise-json">json docs</a>
</div>
<div align="center">
<img height="50px" src="https://user-images.githubusercontent.com/399657/68221814-05ed1680-ffb8-11e9-8b6b-c7528d163871.png"/>
<img height="50px" src="https://user-images.githubusercontent.com/399657/68221814-05ed1680-ffb8-11e9-8b6b-c7528d163871.png"/>
</div>

<!-- spacer -->
Expand Down Expand Up @@ -292,11 +292,11 @@ import nlp from 'compromise/one'

let doc = nlp("Wayne's World, party time")
let data = doc.json()
/* [{
/* [{
normal:"wayne's world party time",
terms:[{ text: "Wayne's", normal: "wayne" },
terms:[{ text: "Wayne's", normal: "wayne" },
...
]
]
}]
*/
```
Expand Down Expand Up @@ -717,6 +717,8 @@ _(these methods are on the main `nlp` object)_
- **[.possessives().strip()](https://observablehq.com/@spencermountain/compromise-selections)** - "Spencer's" -> "Spencer"
- **[.quotations()](https://observablehq.com/@spencermountain/compromise-selections)** - return any terms inside paired quotation marks
- **[.quotations().strip()](https://observablehq.com/@spencermountain/compromise-selections)** - remove quotation marks
- **[.slashes()](https://observablehq.com/@spencermountain/compromise-selections)** - return any terms grouped by slashes
- **[.slashes().split()](https://observablehq.com/@spencermountain/compromise-selections)** - turn 'love/hate' into 'love hate'

<p>
<img height="85px" src="https://user-images.githubusercontent.com/399657/68221862-17ceb980-ffb8-11e9-87d4-7b30b6488f16.png"/>
Expand Down Expand Up @@ -990,7 +992,7 @@ nlpEx('This is type safe!').ngrams({ min: 1 })
</ul>
<p></p>
</details>
</p>
</p>
<p>
<details>
<summary>💃 Can it run on my arduino-watch?</summary>
Expand Down Expand Up @@ -1021,13 +1023,13 @@ nlpEx('This is type safe!').ngrams({ min: 1 })
<p></p>
<ul>
we do offer a <a href="https://observablehq.com/@spencermountain/compromise-filesize">tokenize-only</a> build, which has the POS-tagger pulled-out.
<br/>
<br/>
but otherwise, compromise isn't easily tree-shaken.
<br/>
<br/>
the tagging methods are competitive, and greedy, so it's not recommended to pull things out.
<br/>
<br/>
Note that without a full POS-tagging, the contraction-parser won't work perfectly. (<i>(spencer's cool)</i> vs. <i>(spencer's house)</i>)
<br/>
<br/>
It's recommended to run the library fully.
</ul>
<p></p>
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ While all _Major_ releases should be reviewed, our only _large_ releases are **v
-->

#### 14.14.0 [July 2024]
- **[new]** - .slashes() and .slashes().split() methods #1100
- **[fix]** - #1113 toNumbers() return values
- **[fix]** - (plugins/wikipedia) - fix hard-coded path for #1116
- **[fix]** - (plugins/dates) - limit values in `mm/dd` format
Expand Down
13 changes: 5 additions & 8 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import nlp from './src/three.js'
// nlp.plugin(plg)
// nlp.verbose('tagger')
//
let str = 'they left his/her/their backpack '
// const doc = nlp('IEEE/WIC/ACM')
const doc = nlp(str)
doc.slashes().split().debug()
doc.debug()
// console.log(doc.has('#SlashedTerm'))
// doc.debug()
// let doc = nlp(` `).debug()
const text = 'Worst-case Ontario, you get caught.'

const doc = nlp(text)

doc.match('Ontario').replaceWith('scenario', { keepTags: true })
doc.debug()
// -bury
// -ford
// -ton
Expand Down
31 changes: 31 additions & 0 deletions tests/three/slashes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import test from 'tape'
import nlp from './_lib.js'
const here = '[three/slashes] '

test('slashes.split', function (t) {
let doc = nlp(`i saw him/her yesterday at 2pm.`)
t.equal(doc.has('#SlashedTerm'), true, here + 'has slash-tag')
let m = doc.slashes()
t.equal(m.length, 1, here + '1 slash')
t.equal(m.text(), 'him/her', here + 'slash-text')
m = m.split()
t.equal(m.text(), 'him her', here + 'slash-text-after')
t.equal(m.terms().length, 2, here + 'slash-terms-after')
t.equal(doc.text(), 'i saw him her yesterday at 2pm.', here + 'doc-text-after')
t.equal(doc.has('#SlashedTerm'), false, here + 'has no slash-tag')
t.end()
})

test('three-slashes.split', function (t) {
let doc = nlp(`before. one two/three/four five. after`)
t.equal(doc.has('#SlashedTerm'), true, here + 'has slash-tag')
let m = doc.slashes()
t.equal(m.length, 1, here + '1 slash')
t.equal(m.text(), 'two/three/four', here + 'slash-text')
m = m.split()
t.equal(m.text(), 'two three four', here + 'slash-text-after')
t.equal(m.terms().length, 3, here + 'slash-terms-after')
t.equal(doc.text(), 'before. one two three four five. after', here + 'doc-text-after')
t.equal(doc.has('#SlashedTerm'), false, here + 'has no slash-tag')
t.end()
})
6 changes: 6 additions & 0 deletions types/view/three.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ interface Three extends View {
possessives: (n?: number) => Possessives
/** return any terms inside 'quotation marks' */
quotations: (n?: number) => Quotations
/** return any slashed terms like 'love/hate' */
slashes: (n?: number) => Slashes
/** return words like "clean" */
adjectives: (n?: number) => Adjectives
/** return words like "quickly" */
Expand Down Expand Up @@ -243,6 +245,10 @@ export interface Quotations extends View {
/** remove leading and trailing quotation marks */
strip: () => View
}
export interface Slashes extends View {
/** turn 'love/hate' into 'love hate' */
split: () => View
}

export interface Adjectives extends View {
/** get the words describing this adjective */
Expand Down

0 comments on commit 119c790

Please sign in to comment.