Skip to content

Commit

Permalink
Refactor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 6, 2023
1 parent 3827a66 commit 6162e8d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {SKIP, visit} from 'unist-util-visit'
const tagger = new posjs.Tagger()

/**
* Plugin to add part-of-speech (POS) tags.
* Add part-of-speech (POS) tags.
*
* @returns
* Transform.
Expand Down
117 changes: 67 additions & 50 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
This package is a [unified][] ([retext][]) plugin to add part of speech tags
to words.
It uses [`dariusk/pos-js`][posjs] and adds `node.data.partOfSpeech` on
**[Word][]s**.
[`Word`][nlcst-word] nodes.
It works by checking each sentence, so its smarter that just passing one word
through.

Expand All @@ -40,7 +40,7 @@ POS tags!
## Install

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

```sh
npm install retext-pos
Expand All @@ -64,20 +64,22 @@ In browsers with [`esm.sh`][esmsh]:

```js
/**
* @type {import('nlcst').Root} Root
* @typedef {import('nlcst').Root} Root
*/

import {retext} from 'retext'
import {inspect} from 'unist-util-inspect'
import retextPos from 'retext-pos'
import {inspect} from 'unist-util-inspect'

await retext()
.use(retextPos)
.use(myRetextPlugin)
.process('I went to the store, to buy 5.2 gallons of milk.')

/** @type {import('unified').Plugin<[], Root>} */
function myRetextPlugin() {
/**
* @param {Root} tree
*/
return function (tree) {
console.log(inspect(tree))
}
Expand All @@ -90,75 +92,86 @@ Yields:
RootNode[1] (1:1-1:49, 0-48)
└─0 ParagraphNode[1] (1:1-1:49, 0-48)
└─0 SentenceNode[23] (1:1-1:49, 0-48)
├─0 WordNode[1] (1:1-1:2, 0-1)
│ │ data: {"partOfSpeech":"PRP"}
│ └─0 TextNode "I" (1:1-1:2, 0-1)
├─1 WhiteSpaceNode " " (1:2-1:3, 1-2)
├─2 WordNode[1] (1:3-1:7, 2-6)
│ │ data: {"partOfSpeech":"VBD"}
│ └─0 TextNode "went" (1:3-1:7, 2-6)
├─3 WhiteSpaceNode " " (1:7-1:8, 6-7)
├─4 WordNode[1] (1:8-1:10, 7-9)
│ │ data: {"partOfSpeech":"TO"}
│ └─0 TextNode "to" (1:8-1:10, 7-9)
├─5 WhiteSpaceNode " " (1:10-1:11, 9-10)
├─6 WordNode[1] (1:11-1:14, 10-13)
│ │ data: {"partOfSpeech":"DT"}
│ └─0 TextNode "the" (1:11-1:14, 10-13)
├─7 WhiteSpaceNode " " (1:14-1:15, 13-14)
├─8 WordNode[1] (1:15-1:20, 14-19)
│ │ data: {"partOfSpeech":"NN"}
│ └─0 TextNode "store" (1:15-1:20, 14-19)
├─9 PunctuationNode "," (1:20-1:21, 19-20)
├─0 WordNode[1] (1:1-1:2, 0-1)
│ data: {"partOfSpeech":"PRP"}
└─0 TextNode "I" (1:1-1:2, 0-1)
├─1 WhiteSpaceNode " " (1:2-1:3, 1-2)
├─2 WordNode[1] (1:3-1:7, 2-6)
│ data: {"partOfSpeech":"VBD"}
└─0 TextNode "went" (1:3-1:7, 2-6)
├─3 WhiteSpaceNode " " (1:7-1:8, 6-7)
├─4 WordNode[1] (1:8-1:10, 7-9)
│ data: {"partOfSpeech":"TO"}
└─0 TextNode "to" (1:8-1:10, 7-9)
├─5 WhiteSpaceNode " " (1:10-1:11, 9-10)
├─6 WordNode[1] (1:11-1:14, 10-13)
│ data: {"partOfSpeech":"DT"}
└─0 TextNode "the" (1:11-1:14, 10-13)
├─7 WhiteSpaceNode " " (1:14-1:15, 13-14)
├─8 WordNode[1] (1:15-1:20, 14-19)
│ data: {"partOfSpeech":"NN"}
└─0 TextNode "store" (1:15-1:20, 14-19)
├─9 PunctuationNode "," (1:20-1:21, 19-20)
├─10 WhiteSpaceNode " " (1:21-1:22, 20-21)
├─11 WordNode[1] (1:22-1:24, 21-23)
│ │ data: {"partOfSpeech":"TO"}
│ └─0 TextNode "to" (1:22-1:24, 21-23)
│ data: {"partOfSpeech":"TO"}
└─0 TextNode "to" (1:22-1:24, 21-23)
├─12 WhiteSpaceNode " " (1:24-1:25, 23-24)
├─13 WordNode[1] (1:25-1:28, 24-27)
│ │ data: {"partOfSpeech":"VB"}
│ └─0 TextNode "buy" (1:25-1:28, 24-27)
│ data: {"partOfSpeech":"VB"}
└─0 TextNode "buy" (1:25-1:28, 24-27)
├─14 WhiteSpaceNode " " (1:28-1:29, 27-28)
├─15 WordNode[3] (1:29-1:32, 28-31)
│ │ data: {"partOfSpeech":"CD"}
│ ├─0 TextNode "5" (1:29-1:30, 28-29)
│ ├─1 PunctuationNode "." (1:30-1:31, 29-30)
│ └─2 TextNode "2" (1:31-1:32, 30-31)
│ data: {"partOfSpeech":"CD"}
├─0 TextNode "5" (1:29-1:30, 28-29)
├─1 PunctuationNode "." (1:30-1:31, 29-30)
└─2 TextNode "2" (1:31-1:32, 30-31)
├─16 WhiteSpaceNode " " (1:32-1:33, 31-32)
├─17 WordNode[1] (1:33-1:40, 32-39)
│ │ data: {"partOfSpeech":"NNS"}
│ └─0 TextNode "gallons" (1:33-1:40, 32-39)
│ data: {"partOfSpeech":"NNS"}
└─0 TextNode "gallons" (1:33-1:40, 32-39)
├─18 WhiteSpaceNode " " (1:40-1:41, 39-40)
├─19 WordNode[1] (1:41-1:43, 40-42)
│ │ data: {"partOfSpeech":"IN"}
│ └─0 TextNode "of" (1:41-1:43, 40-42)
│ data: {"partOfSpeech":"IN"}
└─0 TextNode "of" (1:41-1:43, 40-42)
├─20 WhiteSpaceNode " " (1:43-1:44, 42-43)
├─21 WordNode[1] (1:44-1:48, 43-47)
│ │ data: {"partOfSpeech":"NN"}
│ └─0 TextNode "milk" (1:44-1:48, 43-47)
│ data: {"partOfSpeech":"NN"}
└─0 TextNode "milk" (1:44-1:48, 43-47)
└─22 PunctuationNode "." (1:48-1:49, 47-48)
```

## API

This package exports no identifiers.
The default export is `retextPos`.
The default export is [`retextPos`][api-retext-pos].

### `unified().use(retextPos)`

Add POS (part of speech) tags to words.
Add part-of-speech (POS) tags.

###### Parameters

There are no parameters.

###### Returns

Transform ([`Transformer`][unified-transformer]).

## Types

This package is fully typed with [TypeScript][].
It does not export additional types.
It exports no additional types.

## Compatibility

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
Our projects sometimes work with older versions, but this is not guaranteed.

When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `retext-pos@^4`, compatible
with Node.js 12.

## Contribute

Expand Down Expand Up @@ -188,9 +201,9 @@ abide by its terms.

[downloads]: https://www.npmjs.com/package/retext-pos

[size-badge]: https://img.shields.io/bundlephobia/minzip/retext-pos.svg
[size-badge]: https://img.shields.io/bundlejs/size/retext-pos

[size]: https://bundlephobia.com/result?p=retext-pos
[size]: https://bundlejs.com/?q=retext-pos

[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

Expand Down Expand Up @@ -222,10 +235,14 @@ abide by its terms.

[author]: https://wooorm.com

[unified]: https://github.com/unifiedjs/unified
[nlcst-word]: https://github.com/syntax-tree/nlcst#word

[posjs]: https://github.com/dariusk/pos-js

[retext]: https://github.com/retextjs/retext

[word]: https://github.com/syntax-tree/nlcst#word
[unified]: https://github.com/unifiedjs/unified

[posjs]: https://github.com/dariusk/pos-js
[unified-transformer]: https://github.com/unifiedjs/unified#transformer

[api-retext-pos]: #unifieduseretextpos

0 comments on commit 6162e8d

Please sign in to comment.