public void FindAndRegisterValidExtensionPoints_DoesNotRegisterInvalidExtensionPoints()
        {
            CreateExtensionPointsConfiguration(addInvalidExtensionPoints: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IParser parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cs");

            Assert.IsNotNull(parser, "Default parser for '.cs' extension should be used!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.Parser.SrcMLCSharpParser", "Invalid parser returned for '.cs' extension!");

            IWordSplitter wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();

            Assert.IsNotNull(wordSplitter, "Default word splitter should be used!");
            Assert.AreEqual(wordSplitter.GetType().FullName, "Sando.Core.Tools.WordSplitter", "Invalid word splitter returned!");

            IResultsReorderer resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation();

            Assert.IsNotNull(resultsReorderer, "Default results reorderer should be used!");
            Assert.AreEqual(resultsReorderer.GetType().FullName, "Sando.SearchEngine.SortByScoreResultsReorderer", "Invalid results reorderer returned!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.NonExistingParser"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingParser.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingTestElement.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingWordSplitter.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingResultsReorderer"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingQueryWeightsSupplier"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingQueryRewriter"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingIndexFilterManager"), "Log file should contain information about errors occurred during the assembly loading!");
        }
コード例 #2
0
        public static string ToSandoSearchable(this String fieldValue)
        {
            if (String.IsNullOrWhiteSpace(fieldValue))
            {
                return(fieldValue);
            }
            IWordSplitter wordSplitterImplementation = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();
            string        splitWords;

            if (wordSplitterImplementation != null)
            {
                splitWords = String.Join(" ", wordSplitterImplementation.ExtractWords(fieldValue));
            }
            else
            {
                //For testing, should never happend during execution
                splitWords = String.Join(" ", (new WordSplitter()).ExtractWords(fieldValue));
            }
            if (splitWords == fieldValue)
            {
                return(fieldValue);
            }
            string result = fieldValue + Delimiter + splitWords;

            return(result);
        }
コード例 #3
0
        public static RangeSet Split(this IWordSplitter splitter, ByteBlock text)
        {
            RangeSet words = new RangeSet();

            splitter.Split(text.Array, new Range(text.Index, text.Length), words);
            return(words);
        }
コード例 #4
0
ファイル: JudoTestApp.cs プロジェクト: simonjduff/JudoTest
 public JudoTestApp(IFileService fileService, IWordSplitter wordSplitter, IWordCounter wordCounter, IConsole console, ICompoundFilter compoundFilter)
 {
     _compoundFilter = compoundFilter;
     _console = console;
     _wordCounter = wordCounter;
     _wordSplitter = wordSplitter;
     _fileService = fileService;
 }
コード例 #5
0
 public void ClearRepository()
 {
     parsers.Clear();
     wordSplitter = null;
     resultsReorderer = null;
     queryWeightsSupplier = null;
     queryRewriter = null;
     indexFilterManager = null;
 }
コード例 #6
0
 public WordGroupProcessor(
     int targetPosition,
     IWordSplitter wordSplitter)
 {
     this._wordSplitter = wordSplitter;
     this._targetPosition = targetPosition;
     this._wordContainer = new Dictionary<char, HashSet<string>>();
     this._shortWords = new List<string>();
 }
コード例 #7
0
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="textCanvas">Канва.</param>
 /// <param name="factory">Фабрика элементов.</param>
 /// <param name="splitter">Средство разбивки на слова.</param>
 public CanvasTextRenderCommandExecutor(Canvas textCanvas, ICanvasElementFactory factory, IWordSplitter splitter)
 {
     if (textCanvas == null) throw new ArgumentNullException("textCanvas");
     if (factory == null) throw new ArgumentNullException("factory");
     if (splitter == null) throw new ArgumentNullException("splitter");
     TextCanvas = textCanvas;
     Factory = factory;
     Splitter = splitter;
     FirstInLine = true;
 }
コード例 #8
0
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="session">Сессия отрисовки.</param>
 /// <param name="factory">Фабрика.</param>
 /// <param name="splitter">Средство разбики слов.</param>
 /// <param name="renderWidth">Ширина отрисовки.</param>
 public Direct2DCommandExecutor(CanvasDrawingSession session, IDirect2DElementFactory factory, IWordSplitter splitter, double renderWidth)
 {
     if (factory == null) throw new ArgumentNullException(nameof(factory));
     if (session == null) throw new ArgumentNullException(nameof(session));
     if (splitter == null) throw new ArgumentNullException(nameof(splitter));
     Factory = factory;
     Session = session;
     Splitter = splitter;
     RenderWidth = renderWidth;
 }
        public void FindAndRegisterValidExtensionPoints_RemovesInvalidCustomWordSplitterConfiguration()
        {
            CreateExtensionPointsConfiguration(addInvalidWordSplitterConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IWordSplitter wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();

            Assert.IsNotNull(wordSplitter, "Default word splitter should x used!!");
            Assert.AreEqual(wordSplitter.GetType().FullName, "Sando.Core.Tools.WordSplitter", "Invalid word splitter returned!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("Invalid word splitter configuration found - it will be omitted during registration process."), "Log file should contain information about removed invalid word splitter configuration!");
        }
コード例 #10
0
ファイル: Highlighter.cs プロジェクト: sharwell/elfie-arriba
        public ByteBlock Highlight(ByteBlock value, IWordSplitter splitter, List <HighlightTerm> terms)
        {
            if (terms == null)
            {
                throw new ArgumentNullException("terms");
            }
            if (splitter == null)
            {
                throw new ArgumentNullException("splitter");
            }

            ByteBlockAppender appender = new ByteBlockAppender(value);

            // Make a lowercase value copy to compare
            ByteBlock valueLower = value.Copy();

            valueLower.ToLowerInvariant();

            // Split the value and compare words to highlight terms
            RangeSet ranges = splitter.Split(valueLower);

            for (int rangeIndex = 0; rangeIndex < ranges.Count; ++rangeIndex)
            {
                Range     r         = ranges.Ranges[rangeIndex];
                ByteBlock valueWord = new ByteBlock(valueLower.Array, r.Index, r.Length);

                foreach (HighlightTerm term in terms)
                {
                    // If this word in the value starts with a search term...
                    if (term.Matches(valueWord))
                    {
                        // Append to the beginning of the word, if not already past this point
                        if (appender.AppendTo(valueWord.Index))
                        {
                            // Wrap and append the *prefix* of the term from the query
                            appender.Append(_wrapPrefix);
                            appender.AppendTo(valueWord.Index + term.Value.Length);
                            appender.Append(_wrapSuffix);
                        }

                        // If we matched, do not check other HighlightTerms against this word
                        break;
                    }
                }
            }

            // Append the remaining content and return
            appender.AppendRemainder();
            return(appender.Value());
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomWordSplitter()
        {
            CreateExtensionPointsConfiguration(addValidWordSplitterConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IWordSplitter wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();

            Assert.IsNotNull(wordSplitter, "Word splitter should be registered!");
            Assert.AreEqual(wordSplitter.GetType().FullName, "Sando.TestExtensionPoints.TestWordSplitter", "Invalid word splitter returned!");

            string[] splittedWords = null;
            Assert.DoesNotThrow(() => splittedWords = wordSplitter.ExtractWords("FileName"));
            Assert.IsTrue(splittedWords != null && splittedWords.Length == 2, "Invalid results from ExtractWords method!");
            Assert.AreEqual(splittedWords[0], "File", "First splitted word is invalid!");
            Assert.AreEqual(splittedWords[1], "Name", "Second splitted word is invalid!");
        }
コード例 #12
0
ファイル: Highlighter.cs プロジェクト: sharwell/elfie-arriba
        public void Highlight(Array values, IColumn column, SelectQuery query)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            // Get the index for this column, if there is one
            IndexedColumn index = column.FindComponent <IndexedColumn>();

            // Non-indexed columns are not highlighted
            if (index == null)
            {
                return;
            }

            // Get the splitter for this column
            IWordSplitter splitter = index.Splitter;

            // Find all words for this column
            List <HighlightTerm> terms = WordsForColumn(query.Where, column.Name, splitter);

            // Highlight each value in this column
            for (int i = 0; i < values.Length; ++i)
            {
                object rawValue = values.GetValue(i);

                if (rawValue is ByteBlock)
                {
                    values.SetValue(Highlight((ByteBlock)rawValue, splitter, terms), i);
                }
            }
        }
コード例 #13
0
        private static void FindAndRegisterValidWordSplitterExtensionPoints(ExtensionPointsConfiguration extensionPointsConfiguration, ILog logger)
        {
            logger.Info("Reading word splitter extension point configuration started");
            BaseExtensionPointConfiguration wordSplitterConfiguration = extensionPointsConfiguration.WordSplitterConfiguration;

            if (wordSplitterConfiguration != null)
            {
                try
                {
                    logger.Info(String.Format("Word splitter found: {0}, from assembly: {1}", wordSplitterConfiguration.FullClassName, wordSplitterConfiguration.LibraryFileRelativePath));
                    IWordSplitter wordSplitter = CreateInstance <IWordSplitter>(extensionPointsConfiguration.PluginDirectoryPath, wordSplitterConfiguration.LibraryFileRelativePath, wordSplitterConfiguration.FullClassName);
                    ExtensionPointsRepository.Instance.RegisterWordSplitterImplementation(wordSplitter);
                    logger.Info(String.Format("Word splitter {0} successfully registered.", wordSplitterConfiguration.FullClassName));
                }
                catch (Exception ex)
                {
                    logger.Error(String.Format("Word splitter {0} cannot be registered: {1}", wordSplitterConfiguration.FullClassName, ex.Message));
                }
            }
            logger.Info("Reading word splitter extension point configuration finished");
        }
コード例 #14
0
 public void Setup()
 {
     _wordSplitter = new WordSplitter();
 }
コード例 #15
0
        public void Run()
        {
            //INIT add exceptions
            if (Options.IndexOf("-a")>=0)
            {
                if (Options.Replace("-a","").Trim().Length > 0)
                {
                    Output.WriteLine("-A must be the only flag. Terminated");
                    return;
                }
                AddExceptions();
                return;
            }

            //INIT spellcheck
            DistinctMisspeledWords = new HashSet<String>();
            PathConverter = new LinuxToWindowsPathConverter();
            Dictionary = new SimpleSpellDictionary(DictionaryFilePath, SimpleSpellDictionary.HaspelLineToEntriesExtractor);
            WordSplitter = new WordSplitter();
            LineChecker = new LineChecker(Dictionary, WordSplitter);
            FileChecker = new FileChecker(LineChecker,PathConverter);
            CreateDisplays();
            ProcessFilesFromStream(Console.In,Console.Out);
            SummaryDisplay.DisplayWords(DistinctMisspeledWords);
        }
コード例 #16
0
        public void RegisterWordSplitterImplementation(IWordSplitter wordSplitter)
        {
            Contract.Requires(wordSplitter != null, "ExtensionPointsManager:RegisterWordSplitterImplementation - wordSplitter cannot be null!");

            this.wordSplitter = wordSplitter;
        }
コード例 #17
0
ファイル: Highlighter.cs プロジェクト: sharwell/elfie-arriba
        public static List <HighlightTerm> WordsForColumn(IExpression where, string columnName, IWordSplitter splitter)
        {
            List <HighlightTerm> terms = new List <HighlightTerm>();

            // For each term in the query expression...
            IList <TermExpression> matchingTerms = where.GetAllTerms(columnName);

            foreach (TermExpression term in matchingTerms)
            {
                ByteBlock termValue;
                if (term.Value.TryConvert <ByteBlock>(out termValue))
                {
                    ByteBlock termValueLower = termValue.Copy();
                    termValueLower.ToLowerInvariant();

                    if (term.Operator == Operator.MatchesExact)
                    {
                        terms.Add(new HighlightTerm(termValueLower, true));
                    }
                    else if (term.Operator == Operator.Matches)
                    {
                        // Split the term value
                        RangeSet set = splitter.Split(termValueLower);

                        // Add each range as a word to the result [exact when under expand length limit]
                        for (int i = 0; i < set.Count; ++i)
                        {
                            Range     r         = set.Ranges[i];
                            ByteBlock partBlock = new ByteBlock(termValueLower.Array, r.Index, r.Length);
                            terms.Add(new HighlightTerm(partBlock, partBlock.Length < WordIndex.MinimumPrefixExpandLength));
                        }
                    }
                }
            }

            return(terms);
        }
コード例 #18
0
        public void RegisterWordSplitterImplementation(IWordSplitter wordSplitter)
        {
            Contract.Requires(wordSplitter != null, "ExtensionPointsManager:RegisterWordSplitterImplementation - wordSplitter cannot be null!");

            this.wordSplitter = wordSplitter;
        }
コード例 #19
0
 public IndexedColumn(IColumn <ByteBlock> column, IWordSplitter splitter) : base(column)
 {
     this.Splitter = splitter;
     _index        = new WordIndex(splitter);
 }
コード例 #20
0
 public HtmlWordSplitter(IWordSplitter innerSplitter)
 {
     this.InnerSplitter = innerSplitter;
 }
コード例 #21
0
 public WordIndex(IWordSplitter splitter)
 {
     _splitter = splitter;
     _blocks   = new List <WordIndexBlock>();
 }
コード例 #22
0
 public LineChecker(ISpellingDictionary dict,IWordSplitter splitter)
 {
     spellChecker = dict;
     Splitter = splitter;
 }
コード例 #23
0
ファイル: SplitterTest.cs プロジェクト: spati2/FSE-2012-SANDO
        public void SetUp()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();
        }
コード例 #24
0
 public WordSplitterTestBase(IWordSplitter splitter)
 {
     this.splitter = splitter;
 }