- Notifications
You must be signed in to change notification settings - Fork40
Automatic summarizer text in Swift
License
fdzsergio/Reductio
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation

Text Summarization and Keyword Extraction for Swift
Features •Requirements •Installation •Usage •Documentation •Contributing
Reductio is a high-performance Swift library that implements theTextRank algorithm for automatic text summarization and keyword extraction. Built with Swift 6's strict concurrency in mind, it provides a modern, safe, and efficient way to analyze and extract meaning from text.
TextRank is an unsupervised graph-based ranking algorithm inspired by Google's PageRank. It builds a graph representation of text where vertices are words or sentences, and edges represent semantic relationships. Through iterative calculation, it identifies the most important elements in the text.
- 📰News Summarization: Extract key points from articles
- 🔍SEO Optimization: Identify important keywords for content
- 📚Academic Research: Summarize research papers and extract key concepts
- 📱Social Media: Analyze and summarize user-generated content
- 🏢Business Intelligence: Process reports and extract insights
- 💬Chatbots: Generate concise responses from knowledge bases
- 🔑 Keyword Extraction: Identify the most relevant keywords using graph-based ranking
- 📝 Text Summarization: Extract key sentences while preserving context
- 🌐 Language Support: Optimized for English with extensible architecture
- ⚡ High Performance: Efficient processing of documents up to 10,000+ words
- 🔒 Thread-Safe: Full Swift 6 strict concurrency compliance
- 📦 Zero Dependencies: Pure Swift implementation
- Modern Swift APIs: Native async/await support
- Value Semantics: Immutable structs for
KeywordandSummarizer - NaturalLanguage Framework: Leverages Apple's ML-powered text processing
- Flexible Configuration: Customizable compression ratios and result counts
- Extension-Friendly: Convenient String extensions for quick access
- Swift: 6.0+
- Xcode: 15.0+
- Platforms:
- iOS 13.0+
- macOS 12.0+
- tvOS 13.0+
- watchOS 6.0+
Add Reductio to yourPackage.swift dependencies:
dependencies:[.package(url:"https://github.com/fdzsergio/Reductio.git", from:"1.6.0")]
Then add it to your target:
targets:[.target( name:"YourApp", dependencies:["Reductio"])]
import Reductiolettext="""Apple Inc. announced groundbreaking updates to its developer tools at WWDC 2024.The company introduced Swift 6 with major improvements to concurrency and performance.Developers praised the new features, particularly the enhanced type safety andasync/await improvements that make concurrent programming more intuitive."""// Extract top keywordsletkeywords=awaitReductio.keywords(from: text, count:5)print(keywords) // ["swift", "developers", "improvements", "concurrency", "features"]// Get a summaryletsummary=awaitReductio.summarize(text: text, count:2)summary.forEach{print("•\($0)")}
// Extract all keywords ranked by importanceletallKeywords=awaitReductio.keywords(from: text)// Get top 10 keywordslettopKeywords=awaitReductio.keywords(from: text, count:10)// Extract keywords with 70% compression (top 30% of keywords)letcompressedKeywords=awaitReductio.keywords(from: text, compression:0.7)
// Synchronous keyword extractionletkeywords= text.keywords// Custom configurationlettopKeywords= text.keywords(count:5)
// Get all sentences ranked by importanceletrankedSentences=awaitReductio.summarize(text: text)// Extract top 3 most important sentencesletsummary=awaitReductio.summarize(text: text, count:3)// Summarize with 80% compression (keep 20% of sentences)letconciseSummary=awaitReductio.summarize(text: text, compression:0.8)
// Quick summarizationletsummary= text.summarize// Custom lengthletshortSummary= text.summarize(count:2)
structDocumentAnalyzer{staticfunc analyze(_ document:String)async->DocumentInsights{asyncletkeywords=Reductio.keywords(from: document, count:10)asyncletsummary=Reductio.summarize(text: document, count:5)returnawaitDocumentInsights( keywords: keywords, summary: summary, readingTime:estimateReadingTime(document))}}
extensionString{func seoAnalysis()async->SEOReport{letkeywords=awaitReductio.keywords(from:self, count:20)letkeywordDensity=calculateDensity(keywords: keywords, in:self)returnSEOReport( primaryKeywords:Array(keywords.prefix(5)), secondaryKeywords:Array(keywords.dropFirst(5)), keywordDensity: keywordDensity, suggestedMetaDescription:self.summarize(count:1).first??"")}}
Get started with documentation athttps://fdzsergio.github.io/Reductio/
Text Preprocessing
- Sentence segmentation using NaturalLanguage framework
- Word tokenization and normalization
- Stopword removal (common words like "the", "is", "at")
- Lemmatization to reduce words to base forms
Graph Construction
- Each word/sentence becomes a vertex
- Edges connect co-occurring elements
- Edge weights represent semantic similarity
Iterative Ranking
- Initial scores assigned to all vertices
- Scores propagate through edges
- Convergence achieved after ~30 iterations
Result Extraction
- Vertices ranked by final scores
- Top elements returned as keywords/summary
| Document Size | Processing Time | Memory Usage |
|---|---|---|
| 100 words | ~10ms | ~1 MB |
| 1,000 words | ~50ms | ~5 MB |
| 10,000 words | ~500ms | ~20 MB |
For optimal performance:
- Process documents under 10,000 words
- Use compression ratios between 0.7-0.9
- Cache results for repeated analysis
- Consider chunking very large documents
We welcome contributions! Please see ourContributing Guide for details.
# Clone the repositorygit clone https://github.com/fdzsergio/Reductio.gitcd Reductio# Build the projectswift build# Run testsswifttest# Generate documentationswift package plugin generate-documentation
- Follow Swift API Design Guidelines
- Use swift-format for consistency
- Write tests for new features
- Update documentation as needed
Reductio is released under the MIT License. SeeLICENSE for details.
- 🎨 Logo design by@cristinareina
- 📚 Based onTextRank by Rada Mihalcea and Paul Tarau
- 🙏 Thanks to allcontributors
Sergio Fernández
📧fdz.sergio@gmail.com
🐦@fdzsergio
💼LinkedIn
Made with ❤️ and Swift
About
Automatic summarizer text in Swift
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.