Git Product home page Git Product logo

csharp's Introduction

Rosette by Babel Street


NuGet version

Rosette uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across hundreds of language-script combinations, revealing valuable information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. Rosette Server is the on-premises installation of Rosette, with access to Rosette's functions as RESTful web service endpoints. This solves cloud security worries and allows customization (models/indexes) as needed for your business.

Rosette API Access

Quick Start

Installation

If you use Nuget, you may use either Visual Studio's Nuget package manager or command line to install the Rosette API binding.

In Visual Studio: search for the rosette_api package in Nuget and follow the installation instructions.

Using Nuget Command Line: nuget install rosette_api.

To check your installed version:

nuget list rosette_api

Examples

View small example programs for each Rosette endpoint in the examples directory.

Documentation & Support

Concurrency

The C# binding uses HttpClient to manage connectivity and concurrency. By default, .NET sets the default connection limit to 2, which is the same as the Rosette API default limit. For Rosette API plans that allow for higher concurrency, the internal HTTP client will adjust automatically to the higher number. If a user chooses to provide their own HTTP client, no adjustment will be made. In this case it is up to the user to set ServicePointManager.DefaultConnectionLimit to the Rosette API concurrency level prior to instantiating the CAPI object.

For multithreaded operations, do not instantiate a new CAPI object for each thread. The objects will not share the connection limit and 429 too many requests errors are likely to occur. Rather, so that the underlying HttpClient can manage the queueing of the requests across all threads, instantiate a CAPI object and pass it to each thread. If it is necessary to instantiate a CAPI object on each thread, first create an HttpClient object, either by retrieving it from an instance of CAPI via the Client property or by creating your own HTTP client and passing it into each thread for use by the CAPI constructor.

Example of using a common CAPI object for each thread:

    static void Main(string[] args) {
        TestConcurrency().GetAwaiter().GetResult();
    }

    private static async Task TestConcurrency() {
        int threads = 5;
        var tasks = new List<Task>();
        CAPI api = new CAPI("rosette api key");
        foreach (int task in Enumerable.Range(0, threads)) {
            Console.WriteLine("Starting task {0}", task);
            tasks.Add(Task.Factory.StartNew( () => runLookup(task, api) ));
        }
        await Task.WhenAll(tasks);
        Console.WriteLine("Test complete");
    }

    private static Task runLookup(int taskId, CAPI api) {
        int calls = 5;
        string contentUri = "http://www.foxsports.com/olympics/story/chad-le-clos-showed-why-you-never-talk-trash-to-michael-phelps-080916";
        for (int i = 0; i < calls; i++) {
            Console.WriteLine("Task ID: {0} call {1}", taskId, i);
            try {
                var result = api.Entity(contentUri: contentUri);
                Console.WriteLine("Concurrency: {0}, Result: {1}", api.Concurrency, result);
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
        return Task.CompletedTask;
    }

Example of retrieving a client object and using it in each thread:

    static void Main(string[] args) {
        TestConcurrency().GetAwaiter().GetResult();
    }

    private static async Task TestConcurrency() {
        int threads = 5;
        var tasks = new List<Task>();

        CAPI api = new CAPI("rosette api key");
        HttpClient client = api.Client;
        foreach (int task in Enumerable.Range(0, threads)) {
            Console.WriteLine("Starting task {0}", task);
            tasks.Add(Task.Factory.StartNew( () => runLookup(task, client) ));
        }
        await Task.WhenAll(tasks);
        Console.WriteLine("Test complete");
    }

    private static Task runLookup(int taskId, HttpClient client) {
        int calls = 5;
        string contentUri = "http://www.foxsports.com/olympics/story/chad-le-clos-showed-why-you-never-talk-trash-to-michael-phelps-080916";
        for (int i = 0; i < calls; i++) {
            Console.WriteLine("Task ID: {0} call {1}", taskId, i);
            try {
                CAPI api = new CAPI("rosette api key", client: client);

                var result = api.Entity(contentUri: contentUri);
                Console.WriteLine("Concurrency: {0}, Result: {1}", api.Concurrency, result);
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
        return Task.CompletedTask;
    }

Binding Developer Information

If you are modifying the binding code, please refer to the developer README file.

csharp's People

Contributors

bwsawyer avatar cp2boston avatar dependabot[bot] avatar fhasanaj avatar hgaudet avatar iredpath avatar jkho avatar karin-basis avatar katsuya-tomioka avatar kbailey-basistech avatar lauren12292 avatar matt-l-01 avatar nnagyprecognoxcom avatar samhausmann avatar seth-mg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csharp's Issues

.NET Standard or Core Version

Are there plans to make this .NET Standard or Core compatible.

According to your NuGet page, this code is only compatible up to .NET Framework 4.5.

Passing options per request

I'm looking at the Entity extraction features right now.

It seems the only ways to pass options right now are

  1. Set it on the client itself (SetOption, works)
  2. Pass a RosetteFile (not sure about that actually - but that one has a way to pass 'options')

Would it be possible to pass either a complete request (JSON, including content and options) or to pass the options per call (say another overload of the Entity method maybe?) as an argument?

Entity with trailing dot "."?

Hi Rosette,

I'm testing your API from .Net and I'm wondering if this result as expected/correct:

  • It is a Dutch sentence so language is set to Dutch
  • Input text is: "Michelle is getrouwd met Peter."

Rosette returns two entities, the second being "Peter." I didn't expect the trailing "." dot.

Is this expected behavior?

Kind regards,

Peter Rakké

C# client 1.7.0 failing to install via nuget

Greetings -

Quick note to let you know that the nuget installation of the rosette API client fails with an error messaging saying:

Failed to add reference to 'System.IO'. Please make sure it is in the Global Assembly Cache.

I don't believe there is a System.IO.dll assembly in the .NET Framework that one can even add as a reference. It certainly is not found anywhere in the GAC. There is a System.IO namespace but I think it is in the System.dll assembly.

This is in a C# project targeting the .NET Framework 4.6.1.

Thanks

C# Rosette Client binds to a specific version of System.Net.Http?

I am in a Class Library project (targeting the .NET Framework 4.6.1) and already referencing System.Net.Http 4.3.2 (a nuget package).

But the Rosette C# Client is throwing this exception:
System.IO.FileLoadException: Could not load file or assembly 'System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Wikidata links missing from some entities, salience score from all

Using the latest version of the API and my test key, I send a document to the Entity extraction endpoint.

I enable all features (testing coverage, evaluating Rosette atm) using

entitiesCAPI.SetOption("calculateConfidence", true);
entitiesCAPI.SetOption("calculateSalience", true);
entitiesCAPI.SetOption("includeDBpediaType", true);
entitiesCAPI.SetOption("linkEntities", true);

Results include

{"mention":"JAPAN","normalized":"JAPAN","entityId":"T5","type":"LOCATION","count":8,"confidence":0.85243988}
{"mention":"SWITZERLAND","normalized":"Switzerland","entityId":"Q39","type":"LOCATION","count":4,"confidence":0.93196756,"dbpediaType":"Place/PopulatedPlace/Country"}
  1. Why a temporary ID for Japan? I have a lot more entities with a T ID (say, Tokyo, some more examples of nonworking results below)

  2. Why no salience score for any value?

More missing wikidata links in my samples:

{"mention":"TOKYO","normalized":"TOKYO","entityId":"T10","type":"LOCATION","count":3,"confidence":0.95691532}
{"mention":"FRIBOURG","normalized":"FRIBOURG","entityId":"T13","type":"LOCATION","count":1,"confidence":0.18674469}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.