Esempio n. 1
0
        /// <summary>
        /// Annotates a single document publicly available under a given URL.
        /// Returns the annotated document serialized into the specified format
        /// </summary>
        /// <param name="documentUrl">the publicly accessible URL from where the document will be downloaded</param>
        /// <param name="documentMimeType">the MIME type of the document which will be annotated</param>
        /// <param name="serializationFormat">the serialization format of the output</param>
        /// <returns>an {@link InputStream} from where the serialized output can be read</returns>
        public Stream annotateDocumentFromUrlAsStream(Uri documentUrl, SupportedMimeType documentMimeType, ResponseFormat serializationFormat)
        {
            ServiceRequest rq = new ServiceRequest(documentUrl, documentMimeType);

            try
            {
                WebHeaderCollection collection = new WebHeaderCollection();
                collection.Set(HttpRequestHeader.Accept, serializationFormat.ToStringValue());

                return(client.requestForStream("", "POST", rq, collection));
            }
            catch (HttpClientException e)
            {
                JsonObject response = e.getResponse();
                if (response == null)
                {
                    throw new S4ServiceClientException(e.Message, e);
                }
                String msg = response.ToString();
                throw new S4ServiceClientException(msg == null ? e.Message : msg, e);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///Annotates a single document and returns an {@link InputStream} from
        /// which the contents of the serialized annotated document can be read
        /// </summary>
        /// <param name="documentText">the contents of the document which will be annotated</param>
        /// <param name="documentMimeType">the MIME type of the file which will be annotated</param>
        /// <param name="serializationFormat">the format which will be used for serialization of the annotated document</param>
        /// <returns>an {@link InputStream} from which the serialization of the annotated document can be read</returns>
        public Stream annotateDocumentAsStream(String documentText,
                                               SupportedMimeType documentMimeType, ResponseFormat serializationFormat)
        {
            ServiceRequest rq =
                new ServiceRequest(documentText, documentMimeType, null);
            WebHeaderCollection headers = new WebHeaderCollection();

            headers.Add("Accept", serializationFormat.ToStringValue());
            try
            {
                return(client.requestForStream("", "POST", rq, headers));
            }
            catch (HttpClientException e)
            {
                JsonObject response = e.getResponse();
                if (response == null)
                {
                    throw new S4ServiceClientException(e.Message);
                }
                String msg = response.ToString();
                throw new S4ServiceClientException(msg == null ? e.Message : msg.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This low level method allows the user to specify every parameter explicitly by setting the
        /// properties of the OnlineService request object. Returns an object which wraps the classification information for the document.
        /// </summary>
        /// <param name="rq">the request which will be sent to the service</param>
        /// <param name="requestCompression">whether to allow GZIP compression for large documents</param>
        /// <returns>an {@link ClassifiedDocument} containing the original content as well as the annotations produced</returns>
        public ClassifiedDocument classifyRequest(ServiceRequest rq, Boolean requestCompression)
        {
            try
            {
                WebHeaderCollection collection = new WebHeaderCollection();
                collection.Set(HttpRequestHeader.Accept, ResponseFormat.JSON.ToStringValue());

                if (requestCompression)
                {
                    collection.Set(HttpRequestHeader.AcceptEncoding, "gzip");
                }
                return(client.request("", "POST", new ClassifiedDocument(), rq, collection));
            }
            catch (HttpClientException e)
            {
                JsonObject response = e.getResponse();
                if (response == null)
                {
                    throw new S4ServiceClientException(e.Message, e);
                }
                String msg = response.ToString();
                throw new S4ServiceClientException(msg == null ? e.Message : msg, e);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This low level method allows the user to explicitly specify all the parameters sent to the service.
        /// This is done by constructing the appropriate ServiceRequest object. Returns the classification information for the document
        /// </summary>
        /// <param name="rq">the request which will be sent</param>
        /// <param name="serializationFormat">the format in which to output the classified document</param>
        /// <param name="requestCompression">whether to allow GZIP compression for large documents</param>
        /// <returns>an{@link InputStream} for the serialization of the classified document in the specified format</returns>
        public Stream classifyRequestForStream(ServiceRequest rq, ResponseFormat serializationFormat, Boolean requestCompression)
        {
            try
            {
                WebHeaderCollection collection = new WebHeaderCollection();
                collection.Set(HttpRequestHeader.Accept, serializationFormat.ToString());
                if (requestCompression)
                {
                    collection.Set(HttpRequestHeader.AcceptEncoding, "gzip");
                }

                return(client.requestForStream("", "POST", rq, collection));
            }
            catch (HttpClientException e)
            {
                JsonObject response = e.getResponse();
                if (response == null)
                {
                    throw new S4ServiceClientException(e.Message);
                }
                String msg = response.ToString();
                throw new S4ServiceClientException(msg == null ? e.Message : msg, e);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Classifies a single document with the specified MIME type. Returns an object
        /// which allows for convenient access to the classification information for the document.
        /// </summary>
        /// <param name="documentText">the document content to classify</param>
        /// <param name="documentMimeType"> the MIME type of the document which will be classified</param>
        /// <returns>A {@link ClassifiedDocument} containing the original content as well as the classifications produced</returns>
        public ClassifiedDocument classifyDocument(String documentText, SupportedMimeType documentMimeType)
        {
            ServiceRequest rq = new ServiceRequest(documentText, documentMimeType);

            return(classifyRequest(rq, false));
        }
Esempio n. 6
0
        /// <summary>
        /// Annotates a single document with the specified MIME type. Returns an object
        /// which allows for convenient access to the annotations in the annotated document.
        /// </summary>
        /// <param name="documentText">the document content to annotate</param>
        /// <param name="documentMimeType"> the MIME type of the document which will be annotated</param>
        /// <returns>an {@link AnnotatedDocument} containing the original content as well as the annotations produced</returns>
        public AnnotatedDocument annotateDocument(String documentText, SupportedMimeType documentMimeType)
        {
            ServiceRequest rq = new ServiceRequest(documentText, documentMimeType);

            return(processRequest(rq, false));
        }
Esempio n. 7
0
        /// <summary>
        /// Classifies a single document publicly available under a given URL.
        /// Returns an object which allows for convenient access to the classification information for the document
        /// </summary>
        /// <param name="documentUrl">the publicly accessible URL from where the document will be downloaded</param>
        /// <param name="documentMimeType">the MIME type of the document which will be classified</param>
        /// <returns>A {@link ClassifiedDocument} which allows for convenient programmatic access to the classified document</returns>
        public ClassifiedDocument classifyDocumentFromUrl(Uri documentUrl, SupportedMimeType documentMimeType)
        {
            ServiceRequest rq = new ServiceRequest(documentUrl, documentMimeType);

            return(classifyRequest(rq, false));
        }
Esempio n. 8
0
        /// <summary>
        /// Annotates a single document publicly available under a given URL.
        /// Returns an object which allows for convenient access to the annotations in the annotated document
        /// </summary>
        /// <param name="documentUrl">the publicly accessible URL from where the document will be downloaded</param>
        /// <param name="documentMimeType">the MIME type of the document which will be annotated</param>
        /// <returns>an {@link AnnotatedDocument} which allows for convenient programmatic access to the annotated document</returns>
        public AnnotatedDocument annotateDocumentFromUrl(Uri documentUrl, SupportedMimeType documentMimeType)
        {
            ServiceRequest rq = new ServiceRequest(documentUrl, documentMimeType);

            return(processRequest(rq, false));
        }