Local hosting and testing

With the index and grammar in place, we can go on to test the service locally. Locally testing the service allows for rapid prototyping, which allows us to define the scheme and grammar quickly.

When we are testing locally, the KES only supports up to 10,000 objects and 10 requests per second. It also terminates after a total of 1,000 requests have been executed. We will learn how to bypass these restrictions in a bit.

To host the KES locally, run the following command:

Kes.exe host_service Academic.grammar Academic.index -port 8080

This will start up the service, running on port 8080. To verify that it is working as intended, open your browser and go to http://localhost:8080.

Doing so should present you with the following screen:

Local hosting and testing

Running the KES as a local service also allows us to use the academic API for testing. We are going to make some modifications to our example application—created for the academic API—in order to support this.

First, we are going to modify the WebRequest.cs file. We need to make sure that we can change the endpoint, so add the following function to the class:

    public void SetEndpoint(string uri) {
        _endpoint = uri;
    }

Next, we need to add a new TextBox element to the MainView.xaml file. This will allow us to enter a URL. This needs a corresponding string property in the MainViewModel.cs file. When changing this property, we need to call SetEndpoint on the _webRequest object. This can look as follows:

    private string _endpoint;
    public string Endpoint {
        get { return _endpoint; }
        set {
            _endpoint = value;
            RaisePropertyChangedEvent("Endpoint");
            _webRequest?.SetEndpoint(value);
        }
    }

Finally, we need to update the constructor of our ViewModel. Change the first line to the following:

    Endpoint = "https://api.projectoxford.ai/academic/v1.0/";
    _webRequest = new WebRequest(Endpoint, "API_KEY_HERE");

This will let the default endpoint be the original API address, but allows us to use the application to test the KES locally.

By testing the application with the local endpoint, the following result can be produced:

Local hosting and testing

Note

Note that evaluate and calchistogram will need to update the attributes in the request of the test application for it to work with the local KES.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset