|
1 | | -# SentimentAnalyzer - On-device (offline) Sentiment Analysis for .NET Standard apps |
2 | | - |
3 | | - This is a library which can be used to consume a model which I created using ML.NET. |
4 | | - |
5 | | - For further information, you can always have a look at my [blog](https://www.arafattehsin.com/blog/sentimentanalyzer-ondevice-machine-learning/) |
6 | | - |
7 | | -## Quick Start |
8 | | - |
9 | | -```c# |
| 1 | +# SentimentAnalyzer |
| 2 | + |
| 3 | +[](https://www.nuget.org/packages/SentimentAnalyzer/) |
| 4 | +[](https://www.nuget.org/packages/SentimentAnalyzer/) |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | + |
| 7 | +**On-device (offline) Sentiment Analysis for .NET applications** |
| 8 | + |
| 9 | +A cross-platform, privacy-first library for sentiment analysis that runs entirely on-device without requiring internet connectivity. Powered by [ML.NET 5.0](https://dot.net/ml). |
| 10 | + |
| 11 | +## ✨ Features |
| 12 | + |
| 13 | +- 🔒 **Privacy-first** - All processing happens on-device, no data leaves your app |
| 14 | +- 📴 **Fully offline** - No internet connection required |
| 15 | +- 🚀 **Cross-platform** - Works on .NET Standard 2.0, .NET 8, .NET 10, MAUI, Blazor, Unity |
| 16 | +- ⚡ **Fast** - Thread-safe singleton pattern for optimal performance |
| 17 | +- 📦 **Lightweight** - Single NuGet package, no external dependencies |
| 18 | + |
| 19 | +## 📦 Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +dotnet add package SentimentAnalyzer |
| 23 | +``` |
| 24 | + |
| 25 | +Or via Package Manager: |
| 26 | + |
| 27 | +```powershell |
| 28 | +Install-Package SentimentAnalyzer |
| 29 | +``` |
| 30 | + |
| 31 | +## 🚀 Quick Start |
| 32 | + |
| 33 | +```csharp |
| 34 | +using SentimentAnalyzer; |
| 35 | + |
| 36 | +// Analyze sentiment |
| 37 | +var result = Sentiments.Predict("This product is amazing!"); |
| 38 | + |
| 39 | +Console.WriteLine($"Sentiment: {(result.Prediction ? "Positive" : "Negative")}"); |
| 40 | +Console.WriteLine($"Confidence: {result.Score:P2}"); |
| 41 | +``` |
| 42 | + |
| 43 | +## 📖 API Reference |
| 44 | + |
| 45 | +### `Sentiments.Predict(string text)` |
| 46 | + |
| 47 | +Analyzes the sentiment of the provided text. |
| 48 | + |
| 49 | +**Parameters:** |
| 50 | + |
| 51 | +- `text` - The text to analyze |
| 52 | + |
| 53 | +**Returns:** `SentimentPrediction` |
| 54 | + |
| 55 | +- `Prediction` (`bool`) - `true` for Positive sentiment, `false` for Negative sentiment |
| 56 | +- `Score` (`float`) - Confidence score (0.0 to 1.0) |
| 57 | + |
| 58 | +### Example Usage |
| 59 | + |
| 60 | +```csharp |
10 | 61 | using SentimentAnalyzer; |
11 | 62 |
|
12 | | -var sentiment = Sentiments.Predict("some string"); |
| 63 | +// Positive sentiment |
| 64 | +var positive = Sentiments.Predict("I love this! Best purchase ever!"); |
| 65 | +// positive.Prediction = true, positive.Score ≈ 0.95 |
| 66 | +
|
| 67 | +// Negative sentiment |
| 68 | +var negative = Sentiments.Predict("Terrible experience, very disappointed."); |
| 69 | +// negative.Prediction = false, negative.Score ≈ 0.12 |
| 70 | +``` |
| 71 | + |
| 72 | +## 🎯 Platform Support |
| 73 | + |
| 74 | +| Platform | Supported | Target Framework | |
| 75 | +| --------------------- | --------- | ---------------- | |
| 76 | +| .NET Framework 4.6.1+ | ✅ | netstandard2.0 | |
| 77 | +| .NET Core 2.0+ | ✅ | netstandard2.0 | |
| 78 | +| .NET 5/6/7 | ✅ | netstandard2.0 | |
| 79 | +| .NET 8 (LTS) | ✅ | net8.0 | |
| 80 | +| .NET 10 (LTS) | ✅ | net10.0 | |
| 81 | +| .NET MAUI | ✅ | All targets | |
| 82 | +| Blazor Server | ✅ | All targets | |
| 83 | +| Blazor WebAssembly | ✅ | netstandard2.0 | |
| 84 | +| Unity | ✅ | netstandard2.0 | |
| 85 | + |
| 86 | +## 📋 Use Cases |
| 87 | + |
| 88 | +- **Customer Feedback Analysis** - Automatically categorize reviews and feedback |
| 89 | +- **Social Media Monitoring** - Track brand sentiment in real-time |
| 90 | +- **Chatbot Intelligence** - Detect user mood and respond appropriately |
| 91 | +- **Content Moderation** - Flag negative or toxic content |
| 92 | +- **IoT/Edge Devices** - Run sentiment analysis on resource-constrained devices |
| 93 | +- **Air-gapped Environments** - Perfect for defense, healthcare, and enterprise use |
| 94 | + |
| 95 | +## 🔄 Migration from v1.x |
| 96 | + |
| 97 | +Version 2.0 maintains **full backward compatibility**. No code changes required: |
| 98 | + |
| 99 | +```xml |
| 100 | +<!-- Just update the version --> |
| 101 | +<PackageReference Include="SentimentAnalyzer" Version="2.0.0" /> |
13 | 102 | ``` |
14 | 103 |
|
15 | | -`Predict` returns a `SentimentPrediction` which contains: |
| 104 | +See [CHANGELOG.md](CHANGELOG.md) for detailed release notes. |
| 105 | + |
| 106 | +## 📚 Learn More |
| 107 | + |
| 108 | +- [Blog Post: On-device Machine Learning with SentimentAnalyzer](https://www.arafattehsin.com/blog/sentimentanalyzer-ondevice-machine-learning/) |
| 109 | +- [ML.NET Documentation](https://docs.microsoft.com/dotnet/machine-learning/) |
| 110 | + |
| 111 | +## 📄 License |
| 112 | + |
| 113 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 114 | + |
| 115 | +## 🤝 Contributing |
16 | 116 |
|
17 | | -- `Prediction` (`bool`) - `true` is Positive sentiment, `false` is Negative sentiment. |
18 | | -- `Score` (`float`) - A score representing the model's accuracy |
| 117 | +Contributions are welcome! Please feel free to submit a Pull Request. |
0 commit comments