DEV Community

Bruce Axtens
Bruce Axtens

Posted on

Google's Natural Language API, Content Classification, in C#

I've written about this before, in the context of ASP.NET. Here's a link to the revised project on Github from which a DLL may be derived.

We started off with classifying Html and went on to classifying Text. Thus we have

  • Classify()
  • ClassifyHtml()
  • ClassifyText() which emit JSON.

Recently we added XML serialization and the functions

  • ClassifyHtmlAsXml()
  • ClassifyTextAsXml()

Both serialization methods emit an Error/Cargo tuple. If Error is null, then there's no error and Cargo contains the result of the classification. If Error is a string, then there is an error (in Error) and Cargo is null/indefinite.

Below is from a REPL session in one of our javascript-on-steroids tools, demonstrating the outputs of the DLL:

Attached C

{"Error":null,"Cargo":[{"Name":"/Reference/Language Resources","Confidence":0.6}]}

<?xml version="1.0" encoding="utf-16"?>
<Classification xmlns:xsi="" xmlns:xsd="">
      <Name>/Reference/Language Resources</Name>
Enter fullscreen mode Exit fullscreen mode

Acknowledgements: Google Cloud Language v1, Newtonsoft.Json

Top comments (0)