Exemplo n.º 1
0
        /// <summary>
        /// This is used to get the classifier for the given file
        /// </summary>
        /// <param name="filename">The file for which to get a classifier</param>
        /// <param name="spellCheckConfiguration">The spell checker configuration that the classifier can use to
        /// determine what elements to return for spell checking if needed.</param>
        /// <returns>The classifier to use or null if the file should not be processed</returns>
        public static TextClassifier GetClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration)
        {
            ClassifierDefinition definition;
            TextClassifier       classifier = null;
            string id, extension = Path.GetExtension(filename);

            if (extensionMap == null)
            {
                LoadClassifierConfiguration();
            }

            if (!String.IsNullOrWhiteSpace(extension))
            {
                extension = extension.Substring(1);
            }

            if (!extensionMap.TryGetValue(extension, out id))
            {
                id = FileIsXml(filename) ? "XML" : "PlainText";
            }

            if (id != "None" && definitions.TryGetValue(id, out definition))
            {
                switch (definition.ClassifierType)
                {
                case "PlainTextClassifier":
                    classifier = new PlainTextClassifier(filename, spellCheckConfiguration);
                    break;

                case "XmlClassifier":
                    classifier = new XmlClassifier(filename, spellCheckConfiguration);
                    break;

                case "ReportingServicesClassifier":
                    classifier = new ReportingServicesClassifier(filename, spellCheckConfiguration);
                    break;

                case "ResourceFileClassifier":
                    classifier = new ResourceFileClassifier(filename, spellCheckConfiguration);
                    break;

                case "HtmlClassifier":
                    classifier = new HtmlClassifier(filename, spellCheckConfiguration);
                    break;

                case "CodeClassifier":
                    classifier = new CodeClassifier(filename, spellCheckConfiguration, definition.Configuration);
                    break;

                case "RegexClassifier":
                    classifier = new RegexClassifier(filename, spellCheckConfiguration, definition.Configuration);
                    break;

                default:
                    break;
                }
            }

            return(classifier);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is used to get the classifier for the given file
        /// </summary>
        /// <param name="filename">The file for which to get a classifier</param>
        /// <param name="spellCheckConfiguration">The spell checker configuration that the classifier can use to
        /// determine what elements to return for spell checking if needed.</param>
        /// <returns>The classifier to use or null if the file should not be processed</returns>
        public static TextClassifier GetClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration)
        {
            ClassifierDefinition definition;
            TextClassifier classifier = null;
            string id, extension = Path.GetExtension(filename);

            if(extensionMap == null)
                LoadClassifierConfiguration();

            if(!ignoredFilePatterns.Any(p => p.IsMatch(filename)))
            {
                if(!String.IsNullOrWhiteSpace(extension))
                    extension = extension.Substring(1);

                if(!extensionMap.TryGetValue(extension, out id))
                    id = FileIsXml(filename) ? "XML" : "PlainText";

                if(id != "None" && definitions.TryGetValue(id, out definition))
                    switch(definition.ClassifierType)
                    {
                        case "PlainTextClassifier":
                            classifier = new PlainTextClassifier(filename, spellCheckConfiguration);
                            break;

                        case "XmlClassifier":
                            classifier = new XmlClassifier(filename, spellCheckConfiguration);
                            break;

                        case "ReportingServicesClassifier":
                            classifier = new ReportingServicesClassifier(filename, spellCheckConfiguration);
                            break;

                        case "ResourceFileClassifier":
                            classifier = new ResourceFileClassifier(filename, spellCheckConfiguration);
                            break;

                        case "HtmlClassifier":
                            classifier = new HtmlClassifier(filename, spellCheckConfiguration);
                            break;

                        case "CodeClassifier":
                            classifier = new CodeClassifier(filename, spellCheckConfiguration, definition.Configuration);
                            break;

                        case "RegexClassifier":
                            classifier = new RegexClassifier(filename, spellCheckConfiguration, definition.Configuration);
                            break;

                        default:
                            break;
                    }
            }

            return classifier;
        }