/// <summary>
        /// Classifies a file.
        /// </summary>
        /// <param name="api">An object that implements <see cref="IClassifierApiProvider"/>.</param>
        /// <param name="file">The file to be classified.</param>
        /// <param name="modelName">The name of the classification model to be used.</param>
        /// <returns>Результат классификации файла.</returns>
        public static ClassificationResult ClassifyFile(this IClassifierApiProvider api,
			FileContainer file, string modelName)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            return api.ClassifyFile(file, new ClassificationParameters(modelName));
        }
Exemple #2
0
        /// <summary>
        /// Classifies a file.
        /// </summary>
        /// <param name="file">The file to be classified.</param>
        /// <param name="parameters">File classification parameters.</param>
        /// <returns>Результат классификации файла.</returns>
        public ClassificationResult ClassifyFile(FileContainer file, ClassificationParameters parameters)
        {
            if (file == null)
                throw new ArgumentNullException("file");
            if (parameters == null)
                throw new ArgumentNullException("parameters");

            ComprenoTaskSettings settings = convertToTaskSettings(parameters);

            byte[] content = _tasksApi.RunTaskAndWaitResult(file, settings);

            return _resultParser.Parse(content, parameters.CategoriesFilter);
        }
        /// <summary>
        /// Classifies a byte array instance.
        /// </summary>
        /// <param name="api">An object that implements <see cref="IClassifierApiProvider"/>.</param>
        /// <param name="content">The byte array instance to be classified.</param>
        /// <param name="extension">Extension.</param>
        /// <param name="parameters">Byte array classification parameters.</param>
        /// <returns>Результат классификации a byte array instance.</returns>
        public static ClassificationResult ClassifyByteArray(this IClassifierApiProvider api,
			byte[] content, string extension, ClassificationParameters parameters)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            FileContainer container = new FileContainer
            {
                Content = content,
                Extension = extension
            };

            return api.ClassifyFile(container, parameters);
        }
        /// <summary>
        /// Classifies a UTF-8 string instance.
        /// </summary>
        /// <param name="api">An object that implements <see cref="IClassifierApiProvider"/>.</param>
        /// <param name="content">The string instance to be classified.</param>
        /// <param name="extension">Extension.</param>
        /// <param name="parameters">String classification parameters.</param>
        /// <returns>Результат классификации a string instance.</returns>
        public static ClassificationResult ClassifyString(this IClassifierApiProvider api,
			string content, string extension, ClassificationParameters parameters)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            FileContainer container = new FileContainer
            {
                Content = Encoding.UTF8.GetBytes(content),
                Extension = extension
            };

            return api.ClassifyFile(container, parameters);
        }
Exemple #5
0
        private XDocument _analyzeInCompreno(string sentenceText)
        {
            log.InfoFormat("Parsing string '{0}' with Compreno.", sentenceText);
            XDocument result = null;
            string tmpFilePath = "";

            try
            {
                log.Debug("Creating temp file for compreno...");
                tmpFilePath = _createTMPFile(sentenceText);
                log.DebugFormat("Created. Path is {0}", tmpFilePath);
            }
            catch (Exception e)
            {
                tmpFilePath = "";
                var message = "Failed to create temp file for compreno";
                throw new Exception(message + ":" + e.ToString());
            }

            if (File.Exists(tmpFilePath))
            {
                try
                {
                    FileContainer file = new FileContainer(tmpFilePath);
                    var settings = _getComprenoSettings();
            #if !LOCAL_DEBUG
                    log.Info("Sending query to Compreno and waiting for result...");
                    var comprenoResult = client.TasksApi.RunTaskAndWaitResult(file, settings);
                    log.InfoFormat("Done. {0} bytes received", comprenoResult.Length);
            #else

                    var comprenoResult = File.ReadAllBytes(@"d:\Работа\MLT\Linguistic\LWS\4ASBlock3\bin\Debug\ComprenoResults\ComprenoResult_2016.05.20__15.10.09_Креди(305).xml");
                    //var comprenoResult = File.ReadAllBytes(@"c:\Source\LWS\4ASBlock3\bin\Debug\ComprenoResults\ComprenoResult_Обжал(70)_2016.05.18__16.30.15.xml");
            #endif

                    if (Properties.Settings.Default.SaveComprenoResults)
                        _saveComprenoResultToFile(comprenoResult, sentenceText);

                    result = XDocument.Load(new MemoryStream(comprenoResult));
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    File.Delete(tmpFilePath);
                }

            }

            return result;
        }