### Case-Sensitive SnowballStemmer Example Source: https://github.com/japborst/dart_stemmer/blob/master/README.md Demonstrates stemming with original casing preserved by using SnowballStemmer. Note: The example incorrectly uses PorterStemmer in the code, but the intent is case-sensitive stemming. ```dart import 'package:stemmer/stemmer.dart'; SnowballStemmer stemmer = PorterStemmer(); stemmer.stem('Running'); // outputs: Run ``` -------------------------------- ### stem() Method Usage with PorterStemmer and SnowballStemmer Source: https://context7.com/japborst/dart_stemmer/llms.txt Illustrates the usage of the stem() method from both PorterStemmer and SnowballStemmer classes, highlighting the default lowercase conversion and the option to preserve original casing. Includes a practical example of building a search normalizer function. ```dart import 'package:stemmer/stemmer.dart'; void main() { PorterStemmer porter = PorterStemmer(); SnowballStemmer snowball = SnowballStemmer(); // Method signature: String stem(String word, {bool toLowerCase = true}) // Default behavior - converts to lowercase before stemming String result1 = porter.stem('RUNNING'); print(result1); // Output: run // Preserve original casing String result2 = porter.stem('RUNNING', toLowerCase: false); print(result2); // Output: RUN // Both stemmers have the same interface String result3 = snowball.stem('RUNNING'); print(result3); // Output: run String result4 = snowball.stem('RUNNING', toLowerCase: false); print(result4); // Output: RUN // Practical example: Building a simple search normalizer String normalizeForSearch(String text) { final stemmer = SnowballStemmer(); return text .toLowerCase() .split(RegExp(r'\s+')) .where((word) => word.isNotEmpty) .map((word) => stemmer.stem(word)) .join(' '); } print(normalizeForSearch('The users are connecting to servers')); // Output: the user are connect to server } ``` -------------------------------- ### Initialize and Use PorterStemmer Source: https://github.com/japborst/dart_stemmer/blob/master/README.md Instantiate PorterStemmer and stem a word. Ensure the 'stemmer' package is imported. ```dart import 'package:stemmer/stemmer.dart'; PorterStemmer stemmer = PorterStemmer(); stemmer.stem('running'); // outputs: run ``` -------------------------------- ### Command-Line Stemming with SnowballStemmer Source: https://context7.com/japborst/dart_stemmer/llms.txt Provides a Dart script for command-line usage of the SnowballStemmer, allowing users to stem words directly from the terminal. Shows how to handle command-line arguments and print the stemmed output. ```dart // File: bin/SnowballStemmer_simple.dart import 'package:stemmer/SnowballStemmer.dart'; import 'dart:io'; main(List args) { var stemmer = SnowballStemmer(); if (args.length == 0) { print('Usage:'); print('${Platform.script.path} '); return; } for (var arg in args) { String result = stemmer.stem(arg); print(result); } } ``` -------------------------------- ### Initialize and Use SnowballStemmer Source: https://github.com/japborst/dart_stemmer/blob/master/README.md Instantiate SnowballStemmer and stem a word. Ensure the 'stemmer' package is imported. ```dart import 'package:stemmer/stemmer.dart'; SnowballStemmer stemmer = SnowballStemmer(); stemmer.stem('running'); // outputs: run ``` -------------------------------- ### Stemming a word with PorterStemmer Source: https://github.com/japborst/dart_stemmer/blob/master/example/README.md Initializes the PorterStemmer and applies the stem method to a string input. ```dart import 'package:stemmer/stemmer.dart'; PorterStemmer stemmer = PorterStemmer(); stemmer.stem('running'); // run ``` -------------------------------- ### PorterStemmer Usage in Dart Source: https://context7.com/japborst/dart_stemmer/llms.txt Demonstrates basic and advanced usage of the PorterStemmer class, including handling irregular forms, preserving case, and processing lists of words. Short words (<=2 chars) are returned unchanged. ```dart import 'package:stemmer/stemmer.dart'; void main() { // Create a PorterStemmer instance PorterStemmer stemmer = PorterStemmer(); // Basic stemming - returns lowercase by default print(stemmer.stem('running')); // Output: run print(stemmer.stem('caresses')); // Output: caress print(stemmer.stem('ponies')); // Output: poni print(stemmer.stem('agreed')); // Output: agre print(stemmer.stem('plastered')); // Output: plaster print(stemmer.stem('motoring')); // Output: motor // Stemming with preserved case print(stemmer.stem('Running', toLowerCase: false)); // Output: Run print(stemmer.stem('RUNNING', toLowerCase: false)); // Output: RUN // Irregular forms are handled automatically print(stemmer.stem('skies')); // Output: sky print(stemmer.stem('dying')); // Output: die print(stemmer.stem('lying')); // Output: lie print(stemmer.stem('tying')); // Output: tie // Special cases preserved print(stemmer.stem('proceed')); // Output: proceed print(stemmer.stem('exceed')); // Output: exceed print(stemmer.stem('succeed')); // Output: succeed // Short words (<=2 chars) are returned unchanged print(stemmer.stem('is')); // Output: is print(stemmer.stem('a')); // Output: a // Processing a list of words List words = ['connecting', 'connected', 'connection', 'connections']; List stems = words.map((word) => stemmer.stem(word)).toList(); print(stems); // Output: [connect, connect, connect, connect] } ``` -------------------------------- ### SnowballStemmer Basic Usage in Dart Source: https://context7.com/japborst/dart_stemmer/llms.txt Demonstrates the basic functionality of the SnowballStemmer class, including stemming words, handling case preservation, apostrophes, special words, and verb forms. Also shows processing a sentence for search indexing. ```dart import 'package:stemmer/stemmer.dart'; void main() { // Create a SnowballStemmer instance SnowballStemmer stemmer = SnowballStemmer(); // Basic stemming - returns lowercase by default print(stemmer.stem('running')); // Output: run print(stemmer.stem('generalization')); // Output: gener print(stemmer.stem('communication')); // Output: commun print(stemmer.stem('beautiful')); // Output: beauti // Stemming with preserved case print(stemmer.stem('Running', toLowerCase: false)); // Output: Run // Handles apostrophes and possessives print(stemmer.stem("John's")); // Output: john print(stemmer.stem("cat's")); // Output: cat // Special words are handled correctly print(stemmer.stem('skis')); // Output: ski print(stemmer.stem('skies')); // Output: sky print(stemmer.stem('dying')); // Output: die print(stemmer.stem('lying')); // Output: lie print(stemmer.stem('tying')); // Output: tie print(stemmer.stem('idly')); // Output: idl print(stemmer.stem('gently')); // Output: gentl // Preserved special words print(stemmer.stem('atlas')); // Output: atlas print(stemmer.stem('cosmos')); // Output: cosmos print(stemmer.stem('bias')); // Output: bias print(stemmer.stem('news')); // Output: news // Verb forms converge to same stem print(stemmer.stem('proceed')); // Output: proceed print(stemmer.stem('proceeds')); // Output: proceed print(stemmer.stem('proceeded')); // Output: proceed print(stemmer.stem('proceeding')); // Output: proceed // Short words (<=2 chars) are returned unchanged print(stemmer.stem('by')); // Output: by // Processing text for search indexing String text = "The cats are running quickly through the beautiful gardens"; List tokens = text.toLowerCase().split(' '); List stems = tokens.map((word) => stemmer.stem(word)).toList(); print(stems.join(' ')); // Output: the cat are run quick through the beauti garden } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.