Last active
August 4, 2021 03:35
-
-
Save groupdocs-cloud-gists/9cd70ffc89cbaa3845201b03fcb4c1b1 to your computer and use it in GitHub Desktop.
Classify Text with Sentiment Analysis using a REST API in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Sentiment Analysis of Documents using a REST API in C# | |
2. Classify Text with Sentiment Analysis using a REST API in C# | |
3. Classify Batch of Text with Sentiment Analysis using a REST API in C# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
var apiInstance = new ClassificationApi(configuration); | |
// create batch text request | |
var batchRequest = new BatchRequest | |
{ | |
Batch = new List<string> { { "Now that is out of the way, this thing is a beast. It is fast and runs cool." }, | |
{ "Experience is simply the name we give our mistakes" }, | |
{ "When I used compressed air a cloud of dust bellowed out from the card (small scuffs and scratches)." }, | |
{ "This is Pathetic." }, | |
{ "Excellent work done!" } | |
} | |
}; | |
// create classify batch request | |
var request = new ClassifyBatchRequest(batchRequest, taxonomy: "sentiment"); | |
// get classification results | |
var response = apiInstance.ClassifyBatch(request); | |
// show results | |
for (int x=0; x<response.Results.Count; x++) | |
{ | |
var res = response.Results[x]; | |
Console.WriteLine("Text : " + batchRequest.Batch[x]); | |
Console.WriteLine("ClassName : " + res.BestClassName); | |
Console.WriteLine("ClassProbability : " + res.BestClassProbability); | |
Console.WriteLine("--------------------------------"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
var apiInstance = new ClassificationApi(configuration); | |
// create base request | |
BaseRequest baseRequest = new BaseRequest(); | |
baseRequest.Document = new GroupDocs.Classification.Cloud.Sdk.Model.FileInfo() | |
{ | |
Name = "sample.docx", | |
Folder = "" | |
}; | |
// create classification request | |
var request = new ClassifyRequest(baseRequest); | |
// sentiment analysis taxonomy | |
request.Taxonomy = "sentiment3"; | |
// get classification results | |
ClassificationResponse response = apiInstance.Classify(request); | |
// show results | |
foreach(var r in response.BestResults) | |
{ | |
Console.WriteLine("ClassName :" + r.ClassName); | |
Console.WriteLine("ClassProbability :" + r.ClassProbability); | |
Console.WriteLine("--------------------------------"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
var apiInstance = new ClassificationApi(configuration); | |
// create base request | |
BaseRequest baseRequest = new BaseRequest(); | |
baseRequest.Description = "We support some of the most popular file formats in business, " | |
+ "including Microsoft Word documents, Excel spreadsheets, PowerPoint presentations, " | |
+ "Outlook emails and archives, Visio diagrams, Project files, and Adobe Acrobat PDF documents.."; | |
// create classification request | |
var request = new ClassifyRequest(baseRequest); | |
request.Taxonomy = "sentiment3"; | |
// get classification results | |
var response = apiInstance.Classify(request); | |
// show results | |
foreach (var r in response.BestResults) | |
{ | |
Console.WriteLine("ClassName : " + r.ClassName); | |
Console.WriteLine("ClassProbability : " + r.ClassProbability); | |
Console.WriteLine("--------------------------------"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var configuration = new Configuration(); | |
configuration.ClientId = "659fe7da-715b-4744-a0f7-cf469a392b73"; | |
configuration.ClientSecret = "b377c36cfa28fa69960ebac6b6e36421"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
var apiInstance = new FileApi(configuration); | |
// open file in IOStream | |
var fileStream = File.Open("C:\\Files\\Classification\\sample.docx", FileMode.Open); | |
// create file upload request | |
var request = new UploadFileRequest("sample.docx", fileStream, ""); | |
// upload file | |
var response = apiInstance.UploadFile(request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment