Last active
May 25, 2021 11:50
-
-
Save groupdocs-cloud-gists/f5acc1140040c1044d2b7b1a16457167 to your computer and use it in GitHub Desktop.
Classify Documents and Raw Text 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
Classify Documents and Raw Text | |
1. Programmatically upload a DOCX file on the cloud | |
2. Classify Word Documents using a REST API in C# | |
3. Classify Word Documents with Taxonomy information using a REST API in C# | |
4. Classify Raw Text 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 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); | |
request.BestClassesCount = "3"; | |
// Get classification results | |
ClassificationResponse response = apiInstance.Classify(request); | |
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.BestClassesCount = "3"; | |
// Get classification results | |
var response = apiInstance.Classify(request); | |
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.Document = new GroupDocs.Classification.Cloud.Sdk.Model.FileInfo() | |
{ | |
Name = "sample.docx", | |
Folder = "" | |
}; | |
// Create classification request | |
var request = new ClassifyRequest(baseRequest); | |
request.BestClassesCount = "3"; | |
request.Taxonomy = "documents"; | |
// Get classification results | |
ClassificationResponse response = apiInstance.Classify(request); | |
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 from local/disc. | |
var fileStream = File.Open("C:\\Files\\sample.docx", FileMode.Open); | |
// Create file upload request | |
var request = new UploadFileRequest("sample.docx", fileStream, ""); | |
var response = apiInstance.UploadFile(request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment