Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit 0e637ba

Browse files
committed
Add JS usage examples
1 parent 2e715fd commit 0e637ba

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

displacy/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,21 @@ name.
114114
| `start` | number | Character offset the entity *starts on*. |
115115
| `end` | number | Character offset the entity *ends after*. |
116116
| `label` | string | Entity label. |
117+
118+
## Usage Example (JavaScript)
119+
120+
```javascript
121+
function getEntities(text, model) {
122+
const options = {
123+
method: 'POST',
124+
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
125+
credentials: 'same-origin',
126+
body: JSON.stringify({ text, model })
127+
};
128+
fetch('/ent', options)
129+
.then(res => res.json())
130+
.then(entities => {
131+
console.log(entities);
132+
});
133+
}
134+
```

matcher/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,21 @@ Match a pattern and return the matches and tokens.
209209
| `start` | number | Character offset the match or token *starts on*. |
210210
| `end` | number | Character offset the match or token *ends after*. |
211211
| `label` | string | `"MATCH"` for matched span, `"TOKEN"` for token span. |
212+
213+
## Usage Example (JavaScript)
214+
215+
```javascript
216+
function getMatches(text, model, pattern) {
217+
const options = {
218+
method: 'POST',
219+
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
220+
credentials: 'same-origin',
221+
body: JSON.stringify({ text, model, pattern })
222+
};
223+
fetch('/match', options)
224+
.then(res => res.json())
225+
.then(({ tokens, matches }) => {
226+
console.log(tokens, matches);
227+
});
228+
}
229+
```

sense2vec/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,21 @@ Find similar terms for a given term and optional sense.
8787
| `results` | list | The most similar terms. |
8888
| `score` | number | The similarity score. |
8989
| `count` | number | The total frequency count. |
90+
91+
## Usage Example (JavaScript)
92+
93+
```javascript
94+
function findSimilar(word, sense = 'auto') {
95+
const options = {
96+
method: 'POST',
97+
headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },
98+
credentials: 'same-origin',
99+
body: JSON.stringify({ word, sense })
100+
};
101+
fetch('/find', options)
102+
.then(res => res.json())
103+
.then(({ results }) => {
104+
console.log(results);
105+
});
106+
}
107+
```

0 commit comments

Comments
 (0)