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

core-functions.mddocs/

0

# Core Factory Functions

1

2

Factory functions for creating and analyzing different text units and linguistic elements. These functions serve as the primary entry points for nlp_compromise operations.

3

4

## Capabilities

5

6

### Text Factory Function

7

8

Creates a Text object for analyzing multi-sentence text with comprehensive NLP operations.

9

10

```javascript { .api }

11

/**

12

* Creates a Text object for multi-sentence analysis

13

* @param {string} str - Input text (can contain multiple sentences)

14

* @param {object} [options] - Optional parsing configuration

15

* @returns {Text} Text object with sentence-level operations

16

*/

17

function text(str, options);

18

```

19

20

**Usage Examples:**

21

22

```javascript

23

const nlp = require('nlp_compromise');

24

25

// Multi-sentence text analysis

26

const doc = nlp.text('Hello world. How are you today? Great weather!');

27

console.log(doc.sentences.length); // 3

28

29

// Extract all people from text

30

const people = nlp.text('Tony Hawk and Elon Musk are innovators').people();

31

console.log(people[0].text); // 'Tony Hawk'

32

```

33

34

### Sentence Factory Function

35

36

Creates a Sentence object for single sentence analysis and transformations.

37

38

```javascript { .api }

39

/**

40

* Creates a Sentence object for single sentence operations

41

* @param {string} str - Input sentence text

42

* @param {object} [options] - Optional parsing configuration

43

* @returns {Sentence} Sentence object with term-level operations

44

*/

45

function sentence(str, options);

46

```

47

48

### Statement Factory Function

49

50

Creates a Statement object specifically for declarative sentences.

51

52

```javascript { .api }

53

/**

54

* Creates a Statement object for declarative sentences

55

* @param {string} str - Declarative sentence text

56

* @returns {Statement} Statement object extending Sentence

57

*/

58

function statement(str);

59

```

60

61

### Question Factory Function

62

63

Creates a Question object specifically for interrogative sentences.

64

65

```javascript { .api }

66

/**

67

* Creates a Question object for interrogative sentences

68

* @param {string} str - Question sentence text

69

* @returns {Question} Question object extending Sentence

70

*/

71

function question(str);

72

```

73

74

**Usage Examples:**

75

76

```javascript

77

// Sentence transformations

78

const stmt = nlp.statement('She walks to school');

79

console.log(stmt.to_past().text()); // 'She walked to school'

80

81

// Question analysis

82

const q = nlp.question('Where did she go?');

83

console.log(q.from()); // 'where'

84

```

85

86

### Term Factory Function

87

88

Creates a Term object for individual word analysis.

89

90

```javascript { .api }

91

/**

92

* Creates a Term object for single word operations

93

* @param {string} str - Individual word or term

94

* @returns {Term} Term object with basic word operations

95

*/

96

function term(str);

97

```

98

99

### Noun Factory Function

100

101

Creates a Noun object with noun-specific inflection methods.

102

103

```javascript { .api }

104

/**

105

* Creates a Noun object with pluralization and classification

106

* @param {string} str - Noun word

107

* @returns {Noun} Noun object with inflection methods

108

*/

109

function noun(str);

110

```

111

112

**Usage Examples:**

113

114

```javascript

115

// Noun operations

116

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

117

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

118

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

119

120

// Check noun properties

121

console.log(nlp.noun('children').is_plural()); // true

122

console.log(nlp.noun('water').is_uncountable()); // true

123

```

124

125

### Verb Factory Function

126

127

Creates a Verb object with conjugation and tense methods.

128

129

```javascript { .api }

130

/**

131

* Creates a Verb object with conjugation capabilities

132

* @param {string} str - Verb word

133

* @returns {Verb} Verb object with tense and conjugation methods

134

*/

135

function verb(str);

136

```

137

138

**Usage Examples:**

139

140

```javascript

141

// Verb conjugation

142

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

143

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

144

console.log(v.conjugate());

145

// { infinitive: 'run', present: 'runs', past: 'ran', gerund: 'running' }

146

147

// Tense analysis

148

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

149

```

150

151

### Adjective Factory Function

152

153

Creates an Adjective object with comparison methods.

154

155

```javascript { .api }

156

/**

157

* Creates an Adjective object with comparative/superlative forms

158

* @param {string} str - Adjective word

159

* @returns {Adjective} Adjective object with comparison methods

160

*/

161

function adjective(str);

162

```

163

164

**Usage Examples:**

165

166

```javascript

167

// Adjective comparisons

168

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

169

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

170

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

171

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

172

```

173

174

### Adverb Factory Function

175

176

Creates an Adverb object with conversion methods.

177

178

```javascript { .api }

179

/**

180

* Creates an Adverb object

181

* @param {string} str - Adverb word

182

* @returns {Adverb} Adverb object with conversion methods

183

*/

184

function adverb(str);

185

```

186

187

### Value Factory Function

188

189

Creates a Value object for numeric values and measurements.

190

191

```javascript { .api }

192

/**

193

* Creates a Value object for parsing numbers and units

194

* @param {string} str - Numeric value with optional unit

195

* @returns {Value} Value object with numeric parsing

196

*/

197

function value(str);

198

```

199

200

**Usage Examples:**

201

202

```javascript

203

// Numeric value parsing

204

const val = nlp.value('five hundred dollars');

205

console.log(val.number); // 500

206

console.log(val.unit); // 'dollar'

207

console.log(val.measurement); // 'Money'

208

209

// Unit conversion awareness

210

const temp = nlp.value('98.6 degrees fahrenheit');

211

console.log(temp.measurement); // 'Temperature'

212

```

213

214

### Person Factory Function

215

216

Creates a Person object for person name analysis.

217

218

```javascript { .api }

219

/**

220

* Creates a Person object for name parsing and analysis

221

* @param {string} str - Person name

222

* @returns {Person} Person object with name parsing

223

*/

224

function person(str);

225

```

226

227

### Date Factory Function

228

229

Creates a Date object for date parsing.

230

231

```javascript { .api }

232

/**

233

* Creates a Date object for temporal parsing

234

* @param {string} str - Date expression

235

* @returns {Date} Date object with date parsing

236

*/

237

function date(str);

238

```

239

240

### Place Factory Function

241

242

Creates a Place object for location analysis.

243

244

```javascript { .api }

245

/**

246

* Creates a Place object for location parsing

247

* @param {string} str - Place name

248

* @returns {Place} Place object with location analysis

249

*/

250

function place(str);

251

```

252

253

### Organization Factory Function

254

255

Creates an Organization object for organization name analysis.

256

257

```javascript { .api }

258

/**

259

* Creates an Organization object for organization parsing

260

* @param {string} str - Organization name

261

* @returns {Organization} Organization object

262

*/

263

function organization(str);

264

```

265

266

**Usage Examples:**

267

268

```javascript

269

// Entity creation and analysis

270

const person = nlp.person('Dr. Jane Smith');

271

console.log(person.firstName); // 'Jane'

272

console.log(person.lastName); // 'Smith'

273

console.log(person.honourific); // 'Dr.'

274

275

const place = nlp.place('New York City');

276

console.log(place.city); // 'New York City'

277

278

const org = nlp.organization('Apple Inc.');

279

console.log(org.text); // 'Apple Inc.'

280

```