public void Upload(string fileName, string contentType)
        {
            FileExtractionParameters fileExtractionParameters = new FileExtractionParameters();
            fileExtractionParameters.Confidence = 0;
            fileExtractionParameters.Context = "context";
            fileExtractionParameters.DocumentId = "documentId";

            IdylE3Client client = new IdylE3Client(endpoint, port);

            EntityExtractionResponse response = client.Upload(fileName, fileExtractionParameters, contentType);

            foreach (Entity entity in response.Entities)
            {
                Console.WriteLine("Entity: " + entity);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Extract entities from a document.
        /// </summary>
        /// <param name="fileName">The path of the file to upload.</param>
        /// <param name="fileExtractionParameters">The parameters of the entity extraction.</param>
        /// <param name="contentType">The mime type of the document such as application/pdf.</param>
        /// <returns></returns>
        public EntityExtractionResponse Upload(string fileName, FileExtractionParameters fileExtractionParameters, string contentType)
        {
            string json = JsonConvert.SerializeObject(fileExtractionParameters);

            RestRequest request = new RestRequest("api/upload", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddFile("parameters", GetBytes(json), "parameters", "application/json");
            request.AddFile("file", fileName, contentType);
            request.AddHeader("Accept", "application/json");

            if (apiKey != string.Empty)
            {
                request.AddHeader("Authorization", apiKey);
            }

            IRestResponse<EntityExtractionResponse> response = restClient.Execute<EntityExtractionResponse>(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return response.Data;
            }
            if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
            {
                LOGGER.Warn("Idyl E3 is not able to accept requests. Received response code " + response.StatusCode.ToString() + ". Check the Idyl E3 log for more information.");
                throw new InvalidOperationException("Query is malformed.");
            }
            else
            {
                LOGGER.Warn("Unable to perform entity extraction from file. Received response code " + response.StatusCode.ToString() + ". Check the Idyl E3 log for more information.");
                throw new InvalidOperationException("Unable to extract entities.");
            }
        }