or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-functions.mdentity-recognition.mdindex.mdplugin-system.mdsentence-processing.mdtext-analysis.mdword-operations.md

word-operations.mddocs/

0

# Word-Level Operations

1

2

Individual word and term analysis with part-of-speech specific methods for inflection, conjugation, and classification. The Term hierarchy provides specialized functionality for different grammatical categories.

3

4

## Capabilities

5

6

### Term Class

7

8

Base class for individual word analysis with core linguistic operations.

9

10

```javascript { .api }

11

/**

12

* Term class for individual word analysis and transformation

13

*/

14

class Term {

15

/** Original word text */

16

text: string;

17

/** Normalized word text */

18

normal: string;

19

/** Expanded form (for contractions) */

20

expansion: string;

21

/** Part-of-speech flags object */

22

pos: object;

23

/** Primary POS tag */

24

tag: string;

25

/** Surrounding whitespace information */

26

whitespace: {

27

preceding: string;

28

trailing: string;

29

};

30

}

31

```

32

33

### Term Analysis Methods

34

35

Core methods for analyzing and manipulating individual terms.

36

37

```javascript { .api }

38

/**

39

* Get the root/lemma form of the word

40

* @returns {string} Root form of the word

41

*/

42

root(): string;

43

44

/**

45

* Change the term text and rebuild derived properties

46

* @param {string} str - New text for the term

47

*/

48

changeTo(str): void;

49

50

/**

51

* Check if term matches a pattern

52

* @param {string} pattern - Pattern to match against

53

* @param {object} [options] - Matching options

54

* @returns {boolean} True if pattern matches

55

*/

56

match(pattern, options): boolean;

57

58

/**

59

* Get all inflection forms for this term

60

* @returns {object} Object containing available forms

61

*/

62

forms(): object;

63

```

64

65

### Term Classification Methods

66

67

Methods for checking term properties and classifications.

68

69

```javascript { .api }

70

/**

71

* Check if term is capitalized

72

* @returns {boolean} True if first letter is uppercase

73

*/

74

is_capital(): boolean;

75

76

/**

77

* Check if term is an acronym

78

* @returns {boolean} True if term appears to be an acronym

79

*/

80

is_acronym(): boolean;

81

82

/**

83

* Check if term is a word (not punctuation)

84

* @returns {boolean} True if term contains letters

85

*/

86

is_word(): boolean;

87

88

/**

89

* Check if term ends with a comma

90

* @returns {boolean} True if term has trailing comma

91

*/

92

has_comma(): boolean;

93

94

/**

95

* Check if term has possessive apostrophe

96

* @returns {boolean} True if term has apostrophe

97

*/

98

has_abbreviation(): boolean;

99

```

100

101

**Usage Examples:**

102

103

```javascript

104

const nlp = require('nlp_compromise');

105

106

const term = nlp.term('running');

107

console.log(term.root()); // 'run'

108

console.log(term.is_word()); // true

109

console.log(term.is_capital()); // false

110

111

const acronym = nlp.term('NASA');

112

console.log(acronym.is_acronym()); // true

113

console.log(acronym.is_capital()); // true

114

```

115

116

### Noun Class

117

118

Specialized term class for nouns with inflection and classification methods.

119

120

```javascript { .api }

121

/**

122

* Noun class extending Term with noun-specific operations

123

*/

124

class Noun extends Term {

125

/**

126

* Convert noun to plural form

127

* @returns {string} Plural form of the noun

128

*/

129

pluralize(): string;

130

131

/**

132

* Convert noun to singular form

133

* @returns {string} Singular form of the noun

134

*/

135

singularize(): string;

136

137

/**

138

* Check if noun is in plural form

139

* @returns {boolean} True if plural

140

*/

141

is_plural(): boolean;

142

143

/**

144

* Check if noun is uncountable

145

* @returns {boolean} True if uncountable (water, information, etc.)

146

*/

147

is_uncountable(): boolean;

148

149

/**

150

* Get appropriate article for noun

151

* @returns {string} Article: 'a', 'an', or 'the'

152

*/

153

article(): string;

154

155

/**

156

* Get appropriate pronoun for noun

157

* @returns {string} Pronoun: 'it', 'they', 'he', 'she'

158

*/

159

pronoun(): string;

160

}

161

```

162

163

### Noun Classification Methods

164

165

Methods for checking noun entity types.

166

167

```javascript { .api }

168

/**

169

* Check if noun represents a person

170

* @returns {boolean} True if person noun

171

*/

172

is_person(): boolean;

173

174

/**

175

* Check if noun represents a place

176

* @returns {boolean} True if place noun

177

*/

178

is_place(): boolean;

179

180

/**

181

* Check if noun represents an organization

182

* @returns {boolean} True if organization noun

183

*/

184

is_organization(): boolean;

185

186

/**

187

* Check if noun represents a date

188

* @returns {boolean} True if date noun

189

*/

190

is_date(): boolean;

191

192

/**

193

* Check if noun represents a value/measurement

194

* @returns {boolean} True if value noun

195

*/

196

is_value(): boolean;

197

```

198

199

**Usage Examples:**

200

201

```javascript

202

// Basic noun operations

203

const noun = nlp.noun('cat');

204

console.log(noun.pluralize()); // 'cats'

205

console.log(noun.article()); // 'a'

206

console.log(noun.pronoun()); // 'it'

207

208

// Plural nouns

209

const plural = nlp.noun('children');

210

console.log(plural.is_plural()); // true

211

console.log(plural.singularize()); // 'child'

212

213

// Uncountable nouns

214

const uncountable = nlp.noun('water');

215

console.log(uncountable.is_uncountable()); // true

216

217

// Entity classification

218

const person = nlp.noun('doctor');

219

console.log(person.is_person()); // true

220

```

221

222

### Verb Class

223

224

Specialized term class for verbs with conjugation and tense methods.

225

226

```javascript { .api }

227

/**

228

* Verb class extending Term with verb-specific operations

229

* Note: Tense conversion methods (to_past, to_present, to_future) both modify the verb object and return the new form

230

*/

231

class Verb extends Term {

232

/**

233

* Convert verb to past tense

234

* @returns {string} Past tense form

235

*/

236

to_past(): string;

237

238

/**

239

* Convert verb to present tense

240

* @returns {string} Present tense form

241

*/

242

to_present(): string;

243

244

/**

245

* Convert verb to future tense

246

* @returns {string} Future tense form

247

*/

248

to_future(): string;

249

250

/**

251

* Get all conjugation forms

252

* @returns {object} Object with all verb forms

253

*/

254

conjugate(): object;

255

256

/**

257

* Get current tense of verb

258

* @returns {string} Tense: 'present', 'past', or 'future'

259

*/

260

tense(): string;

261

262

/**

263

* Get specific conjugation tag

264

* @returns {string} Conjugation tag

265

*/

266

conjugation(): string;

267

268

/**

269

* Negate the verb

270

* @returns {Verb} Negated verb

271

*/

272

negate(): Verb;

273

274

/**

275

* Check if verb is negated

276

* @returns {boolean} True if negative

277

*/

278

isNegative(): boolean;

279

280

/**

281

* Convert verb to adjective form

282

* @returns {string} Adjective form if available

283

*/

284

to_adjective(): string;

285

}

286

```

287

288

**Usage Examples:**

289

290

```javascript

291

// Basic verb operations

292

const verb = nlp.verb('run');

293

console.log(verb.to_past()); // 'ran'

294

console.log(verb.to_future()); // 'will run'

295

console.log(verb.tense()); // 'present'

296

297

// Full conjugation

298

const conjugation = verb.conjugate();

299

console.log(conjugation);

300

// {

301

// infinitive: 'run',

302

// present: 'runs',

303

// past: 'ran',

304

// gerund: 'running',

305

// actor: 'runner'

306

// }

307

308

// Negation

309

const negated = verb.negate();

310

console.log(negated.text); // 'doesn\'t run'

311

console.log(negated.isNegative()); // true

312

313

// Adjective conversion

314

const perfect = nlp.verb('perfect');

315

console.log(perfect.to_adjective()); // 'perfect'

316

```

317

318

### Adjective Class

319

320

Specialized term class for adjectives with comparison methods.

321

322

```javascript { .api }

323

/**

324

* Adjective class extending Term with adjective-specific operations

325

*/

326

class Adjective extends Term {

327

/**

328

* Convert to comparative form

329

* @returns {string} Comparative form (bigger, more beautiful)

330

*/

331

to_comparative(): string;

332

333

/**

334

* Convert to superlative form

335

* @returns {string} Superlative form (biggest, most beautiful)

336

*/

337

to_superlative(): string;

338

339

/**

340

* Convert to noun form

341

* @returns {string} Noun form if available

342

*/

343

to_noun(): string;

344

345

/**

346

* Convert to adverb form

347

* @returns {string} Adverb form

348

*/

349

to_adverb(): string;

350

351

/**

352

* Get all adjective forms

353

* @returns {object} Object with all forms

354

*/

355

conjugate(): object;

356

}

357

```

358

359

**Usage Examples:**

360

361

```javascript

362

// Basic adjective operations

363

const adj = nlp.adjective('big');

364

console.log(adj.to_comparative()); // 'bigger'

365

console.log(adj.to_superlative()); // 'biggest'

366

console.log(adj.to_adverb()); // 'bigly'

367

368

// Complex adjective

369

const beautiful = nlp.adjective('beautiful');

370

console.log(beautiful.to_comparative()); // 'more beautiful'

371

console.log(beautiful.to_superlative()); // 'most beautiful'

372

console.log(beautiful.to_adverb()); // 'beautifully'

373

374

// Get all forms

375

const forms = adj.conjugate();

376

console.log(forms);

377

// {

378

// comparative: 'bigger',

379

// superlative: 'biggest',

380

// adverb: 'bigly',

381

// noun: 'bigness'

382

// }

383

```

384

385

### Adverb Class

386

387

Specialized term class for adverbs with conversion methods.

388

389

```javascript { .api }

390

/**

391

* Adverb class extending Term with adverb-specific operations

392

*/

393

class Adverb extends Term {

394

/**

395

* Convert to adjective form

396

* @returns {string} Adjective form if available

397

*/

398

to_adjective(): string;

399

}

400

```

401

402

**Usage Examples:**

403

404

```javascript

405

// Adverb operations

406

const adverb = nlp.adverb('quickly');

407

console.log(adverb.to_adjective()); // 'quick'

408

409

const beautifully = nlp.adverb('beautifully');

410

console.log(beautifully.to_adjective()); // 'beautiful'

411

```

412

413

### Forms Objects

414

415

The forms returned by different term types have specific structures:

416

417

```javascript { .api }

418

// Noun forms

419

interface NounForm {

420

singular: string;

421

plural: string;

422

}

423

424

// Verb forms

425

interface VerbForm {

426

infinitive: string;

427

present: string;

428

past: string;

429

gerund: string;

430

actor?: string;

431

}

432

433

// Adjective forms

434

interface AdjectiveForm {

435

comparative: string;

436

superlative: string;

437

adverb: string;

438

noun?: string;

439

}

440

441

// Adverb forms

442

interface AdverbForm {

443

adjective: string;

444

}

445

```