### Install de-compromise using npm
Source: https://github.com/nlp-compromise/de-compromise/blob/master/README.md
This command installs the de-compromise library, a German NLP tool, via npm. It can then be imported into your JavaScript project.
```bash
npm install de-compromise
```
--------------------------------
### Noun Pluralization API (Node.js)
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Illustrates the noun pluralization features of de-compromise. It covers getting noun conjugations (singular/plural), converting words to plural or singular forms, and checking if a noun is plural.
```javascript
import nlp from 'de-compromise'
let doc = nlp('Das Kind spielt im Park')
// Get noun conjugations
let nouns = doc.nouns().conjugate()
console.log(nouns[0])
// Output: { singular: 'Kind', plural: 'Kinder' }
// Convert to plural
doc.nouns().toPlural()
doc.text()
// Output: 'Das Kinder spielt im Park'
// Convert to singular
let doc2 = nlp('Die Kinder spielen')
doc2.nouns().toSingular()
doc2.text()
// Output: 'Die Kind spielen'
// Check if plural
let doc3 = nlp('Die Bücher sind neu')
doc3.nouns().isPlural().found
// Output: true
```
--------------------------------
### Extract Sentences and Terms using de-compromise
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Provides examples for extracting and manipulating sentences and individual terms from German text using de-compromise. It covers accessing specific sentences, iterating through all sentences, retrieving terms as an array, navigating to the first/last term, getting word counts, and accessing individual terms by index.
```javascript
import nlp from 'de-compromise'
let doc = nlp('Das ist super. Wir lieben es. Sehr gut!')
// Get specific sentence
doc.sentences(0).text()
// Output: 'Das ist super.'
doc.sentences(1).text()
// Output: 'Wir lieben es.'
// Iterate sentences
doc.sentences().forEach(s => {
console.log(s.text())
})
// Output: 'Das ist super.', 'Wir lieben es.', 'Sehr gut!'
// Get individual terms
doc.terms().out('array')
// Output: ['Das', 'ist', 'super', 'Wir', 'lieben', 'es', 'Sehr', 'gut']
// Term navigation
doc.first().text()
// Output: 'Das'
doc.last().text()
// Output: 'gut'
// Word count
doc.wordCount()
// Output: 8
// Get specific term
doc.eq(2).text()
// Output: 'super'
```
--------------------------------
### Navigate Matches with de-compromise API
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Demonstrates advanced match navigation features in de-compromise. Examples include finding context before and after a match, growing a match to the left or right based on specific patterns (like adjectives or adverbs), splitting text based on delimiters, and performing conditional matching using 'has'.
```javascript
import nlp from 'de-compromise'
let doc = nlp('Der große braune Hund läuft schnell')
// Find context before/after matches
doc.match('Hund').before().text()
// Output: 'Der große braune'
doc.match('Hund').after().text()
// Output: 'läuft schnell'
// Grow matches left/right
doc.match('Hund').growLeft('#Adjective+').text()
// Output: 'große braune Hund'
doc.match('läuft').growRight('#Adverb').text()
// Output: 'läuft schnell'
// Split on patterns
let doc2 = nlp('Hunde und Katzen und Vögel')
doc2.splitOn('und').forEach(s => {
console.log(s.text())
})
// Output: 'Hunde', 'Katzen', 'Vögel'
// Conditional matching
let doc3 = nlp('sehr gut')
if (doc3.has('#Adverb')) {
console.log('Contains adverb')
}
// Output: 'Contains adverb'
```
--------------------------------
### Verb Conjugation API (Node.js)
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Explains how to use de-compromise's verb conjugation API to get various forms of verbs from German text. It shows how to conjugate verbs and extract specific matches.
```javascript
import nlp from 'de-compromise'
// Conjugate verbs from any form
let doc = nlp('Die Kinder waren geschwommen')
let conjugations = doc.verbs().conjugate()
console.log(conjugations[0])
/* Output:
{
infinitive: 'schwimmen',
presentTense: {
first: 'schwimme',
second: 'schwimmst',
third: 'schwimmt',
firstPlural: 'schwimmen',
secondPlural: 'schwimmt',
thirdPlural: 'schwimmen'
},
pastTense: {
first: 'schwamm',
second: 'schwammst',
third: 'schwamm',
firstPlural: 'schwammen',
secondPlural: 'schwammt',
thirdPlural: 'schwammen'
},
subjunctive1: {
first: 'schwimme',
second: 'schwimmest',
third: 'schwimme',
firstPlural: 'schwimmen',
secondPlural: 'schwimmet',
thirdPlural: 'schwimmen'
},
subjunctive2: {
first: 'schwämme',
second: 'schwämmest',
third: 'schwämme',
firstPlural: 'schwämmen',
secondPlural: 'schwämmet',
thirdPlural: 'schwämmen'
},
imperative: {
secondSingular: 'schwimme',
secondPlural: 'schwimmt'
},
pastParticiple: 'geschwommen',
presentParticiple: 'schwimmend'
}
*/
// Extract just verb matches
doc.verbs().text()
// Output: 'geschwommen'
```
--------------------------------
### Pattern Matching in German Text with de-compromise
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Illustrates various pattern matching techniques using Part-of-Speech (POS) tags in de-compromise. Examples include matching simple sentence structures, extracting specific entities like persons, handling contractions, identifying ordinals, and performing named entity recognition for cities, countries, and months.
```javascript
import nlp from 'de-compromise'
// Match by POS tags
let doc = nlp('Wir gehen in den Park')
doc.match('#Pronoun #Verb #Preposition #Determiner #Noun').found
// Output: true
// Extract specific patterns
let doc2 = nlp('Spencer geht zum Laden')
doc2.match('#Person').text()
// Output: 'Spencer'
// Match with multiple tags
let doc3 = nlp('einer blauen Höhle des Eises')
doc3.match('#Determiner #Adjective #Noun').text()
// Output: 'einer blauen Höhle'
// Match contractions
let doc4 = nlp('zum')
doc4.match('zu dem').found
// Output: true
// Match ordinals
let doc5 = nlp('64. Hund')
doc5.match('#Ordinal #Noun').found
// Output: true
// Complex pattern matching
let doc6 = nlp('Er kocht für die Kinder.')
doc6.match('#Pronoun #Verb #Preposition #Determiner #Noun').found
// Output: true
// Named entity recognition
let doc7 = nlp('chicago')
doc7.match('#City').found
// Output: true
let doc8 = nlp('Jamaika')
doc8.match('#Country').found
// Output: true
let doc9 = nlp('juni')
doc9.match('#Month').found
// Output: true
```
--------------------------------
### Number Parsing and Manipulation with de-compromise (JavaScript)
Source: https://github.com/nlp-compromise/de-compromise/blob/master/README.md
Shows how to parse numbers written in natural language and perform arithmetic operations. This example parses a German number, subtracts 10, and returns the modified text.
```javascript
let doc = ldv('Ich habe einhunderteinundzwanzig Euro')
doc.numbers().minus(10)
doc.text()
// 'Ich habe einhundertelf Euro'
```
--------------------------------
### Structured JSON Output with de-compromise
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Explains how to obtain structured data from German text processed by de-compromise in JSON format. It shows how to get detailed JSON for the entire document, specific JSON for numbers, and demonstrates various output format options for text representation.
```javascript
import nlp from 'de-compromise'
let doc = nlp('234 Hunde laufen schnell')
// Get detailed JSON
let json = doc.json()
console.log(json[0])
/* Output:
{
text: '234 Hunde laufen schnell',
terms: [
{ text: '234', tags: ['Value', 'Cardinal', 'NumericValue'], ... },
{ text: 'Hunde', tags: ['Noun', 'Plural'], ... },
{ text: 'laufen', tags: ['Verb', 'PresentTense'], ... },
{ text: 'schnell', tags: ['Adverb'], ... }
]
}
*/
// Get number-specific JSON
let numJson = doc.numbers().json()
console.log(numJson[0])
/* Output:
{
text: '234',
number: {
prefix: '',
num: 234,
suffix: '',
hasComma: false
},
terms: [...]
}
*/
// Output format options
doc.text('normal') // Normal text
doc.text('root') // Root forms
doc.out('array') // Array of strings
```
--------------------------------
### Number Parsing and Formatting (Node.js)
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Details de-compromise's capabilities in parsing and formatting numbers within German text. Examples include converting text numbers to numeric values, performing arithmetic, converting between text and numeric formats, and handling ordinal numbers.
```javascript
import nlp from 'de-compromise'
// Parse text numbers to numeric
let doc = nlp('Ich habe einhunderteinundzwanzig Euro')
doc.numbers().get()
// Output: [121]
// Perform arithmetic
doc.numbers().minus(10)
doc.text()
// Output: 'Ich habe einhundertelf Euro'
// Convert to numeric format
let doc2 = nlp('dreihundertachtundsiebzig')
doc2.numbers().toNumber()
doc2.text()
// Output: '378'
// Convert to text format
let doc3 = nlp('342')
doc3.numbers().toText()
doc3.text()
// Output: 'dreihundertzweiundvierzig'
// Convert to ordinal
doc3 = nlp('342')
doc3.numbers().toOrdinal()
doc3.text()
// Output: '342.'
// Filter by value
let doc4 = nlp('Er hat fünf Äpfel und zehn Birnen')
doc4.numbers().greaterThan(7).text()
// Output: 'zehn'
doc4.numbers().between(4, 6).text()
// Output: 'fünf'
// Set specific value
let doc5 = nlp('Ich habe drei Hunde')
doc5.numbers().set(5)
doc5.text()
// Output: 'Ich habe fünf Hunde'
// Increment/decrement
doc5.numbers().increment()
doc5.text()
// Output: 'Ich habe sechs Hunde'
```
--------------------------------
### Parse German Text and Extract Nouns (Node.js)
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Demonstrates parsing German text and extracting nouns using de-compromise in a Node.js environment. It shows how to import the library, process text, match patterns like '#Noun', and output results as an array or JSON.
```javascript
import nlp from 'de-compromise'
// Parse German text
let doc = nlp('Werden wir Helden für einen Tag.')
// Extract nouns
doc.match('#Noun').out('array')
// Output: ['wir', 'Helden', 'Tag.']
// Get JSON representation
doc.json()
// Output: { text: 'Werden wir Helden...', terms: [...] }
```
--------------------------------
### Browser Usage: Parse Text and Extract Verbs
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Shows how to integrate and use de-compromise directly in a web browser via a script tag. It demonstrates parsing text, accessing specific sentences, and extracting verbs from the provided German sentences.
```html
```
--------------------------------
### Basic Text Analysis with de-compromise (JavaScript)
Source: https://github.com/nlp-compromise/de-compromise/blob/master/README.md
Demonstrates how to import and use de-compromise for basic text analysis. It parses a German sentence and extracts all nouns.
```javascript
import ldv from 'de-compromise'
let dok = ldv('Werden wir Helden für einen Tag.')
dok.match('#Noun').out('array')
// [ 'wir', 'Helden', 'Tag.' ]
```
--------------------------------
### Verb Conjugation with de-compromise (JavaScript)
Source: https://github.com/nlp-compromise/de-compromise/blob/master/README.md
Demonstrates how to conjugate German verbs using de-compromise. It takes a sentence with a past participle verb and outputs its various conjugated forms.
```javascript
txt =
let doc = nlp('Die Kinder waren geschwommen')
console.log(doc.verbs().conjugate())
/*
[{
presentTense: {
first: 'schwimme',
second: 'schwimmst',
third: 'schwimmt',
firstPlural: 'schwimmen',
secondPlural: 'schwimmt',
thirdPlural: 'schwimmen'
},
pastTense: {
first: 'schwamm',
second: 'schwammst',
third: 'schwamm',
firstPlural: 'schwammen',
secondPlural: 'schwammt',
thirdPlural: 'schwammen'
},
subjunctive1: {
first: 'schwimme',
second: 'schwimmest',
third: 'schwimme',
firstPlural: 'schwimmen',
secondPlural: 'schwimmet',
thirdPlural: 'schwimmen'
},
subjunctive2: {
first: 'schwämme',
second: 'schwämmest',
third: 'schwämme',
firstPlural: 'schwämmen',
secondPlural: 'schwämmet',
thirdPlural: 'schwämmen'
},
imperative: { secondSingular: 'schwimme', secondPlural: 'schwimmt' },
pastParticiple: 'geschwommen',
presentParticiple: 'schwimmend'
}]
*/
```
--------------------------------
### Inflect German Adjectives with de-compromise
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Demonstrates how to conjugate German adjectives to their different forms (infinitive, singular, plural, etc.) using the de-compromise library. It extracts adjective forms from a given text and also shows how to directly retrieve adjective text.
```javascript
import nlp from 'de-compromise'
// Get adjective forms
let doc = nlp('das schönere Lied')
let adjectives = doc.adjectives().conjugate()
console.log(adjectives[0])
/* Output:
{
infinitive: 'schön',
one: 'schöner',
two: 'schönen',
three: 'schöne',
four: 'schönes'
}
*/
// Extract adjectives
doc.adjectives().text()
// Output: 'schönere'
```
--------------------------------
### Using de-compromise in the Browser (HTML/JavaScript)
Source: https://github.com/nlp-compromise/de-compromise/blob/master/README.md
Illustrates how to include de-compromise in an HTML file using a script tag and then use it to process text. It logs the JSON representation of the second sentence.
```html
```
--------------------------------
### Enable/Disable Verbose Debugging and Check Version in de-compromise
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Demonstrates how to enable and disable verbose debugging for specific de-compromise modules like 'tagger' and 'match', as well as enabling all debugging modes. It also shows how to process text with debugging enabled and how to retrieve the library's version.
```javascript
import nlp from 'de-compromise'
// Enable debugging
lp.verbose('tagger') // Show tagging decisions
lp.verbose('match') // Show matching logic
lp.verbose(true) // Enable all debugging
// Process with debugging
let doc = nlp('Das ist ein Test')
// Console will show tagging process
// Disable debugging
lp.verbose(false)
// Check version
console.log(nlp.version)
// Output: '0.0.11' (or current version)
```
--------------------------------
### JavaScript Part-of-Speech Tagging with de-compromise
Source: https://github.com/nlp-compromise/de-compromise/blob/master/demo/index.html
This JavaScript code snippet utilizes the de-compromise library to perform part-of-speech tagging on German text. It takes input from a textarea, processes it using the de-compromise NLP engine, and then displays the tagged text with specific HTML highlighting for different word categories (nouns, verbs, adjectives, etc.).
```javascript
var nlp = window.deCompromise;
function tagger() {
var present = document.getElementById('text').value || '';
var doc = nlp(present)
doc.debug()
let highlight = {
nouns: doc.match('#Noun'),
verbs: doc.match('#Verb'),
adj: doc.match('#Adjective'),
adv: doc.match('#Adverb'),
det: doc.match('#Determiner'),
conj: doc.match('#Conjunction'),
prep: doc.match('#Preposition'),
num: doc.match('#Value'),
}
document.getElementById('result').innerHTML = doc.html(highlight)
}
tagge r();//fire!
```
--------------------------------
### Manipulate German Text with de-compromise API
Source: https://context7.com/nlp-compromise/de-compromise/llms.txt
Showcases the text manipulation capabilities of de-compromise, including changing text case (uppercase, lowercase, title case), inserting text at the beginning or end, replacing specific words, removing matches, and adding text before or after a matched pattern.
```javascript
import nlp from 'de-compromise'
let doc = nlp('Das ist ein Test')
// Case transformations
doc.toUpperCase().text()
// Output: 'DAS IST EIN TEST'
doc.toLowerCase().text()
// Output: 'das ist ein test'
doc.toTitleCase().text()
// Output: 'Das Ist Ein Test'
// Text insertion
doc.append(' heute').text()
// Output: 'Das ist ein Test heute'
doc.prepend('Ja, ').text()
// Output: 'Ja, Das ist ein Test'
// Find and replace
let doc2 = nlp('Der Hund läuft schnell')
doc2.match('Hund').replaceWith('Katze')
doc2.text()
// Output: 'Der Katze läuft schnell'
// Remove matches
let doc3 = nlp('Er ist sehr sehr müde')
doc3.match('sehr').first().remove()
doc3.text()
// Output: 'Er ist sehr müde'
// Add before/after
let doc4 = nlp('schnell laufen')
doc4.match('laufen').insertBefore('sehr ')
doc4.text()
// Output: 'schnell sehr laufen'
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.