Esempio n. 1
0
        public Indexer(IndexerConfiguration configuration)
        {
            if (configuration.Dictionary == null)
            {
                throw new InvalidDataException("Error creating Indexer. Dictionary cannot be null");
            }

            if (configuration.TextExtractors == null)
            {
                throw new InvalidDataException("Error creating Indexer. Text Extractor cannot be null");
            }

            _configuration = configuration;

            // wrap the notification handler with our default handler just in case user does not want any notification
            _configuration.NotificationHandler = new NotificationHandler(_configuration.NotificationHandler, _configuration.Stemmer != null);

            // set required stuff for splitter
            _tokenDictionary = new TokenDictionary(_configuration.Dictionary);
            if (_configuration.TextCorrector != null)
            {
                _configuration.TextCorrector.SetTokenDictionary(_tokenDictionary);
                _configuration.TextCorrector.UseDictionary(false);
                _configuration.TextCorrector.UseTokenDictionary(true);
            }

            _configuration.Splitter.SetTextCorrector(_configuration.TextCorrector);
            _configuration.Splitter.SetStemmer(_configuration.Stemmer);
            _configuration.Splitter.SetDictionary(_configuration.Dictionary);
            _configuration.Splitter.SetTokenDictionary(_tokenDictionary);
        }
Esempio n. 2
0
 private void ParseTemplate(ITemplate template, ITokenDictionary tokenDictionary)
 {
     foreach (var file in GetInstalledFiles(template).Where(f => f.IsTextFile()))
     {
         var parsed = _templateParser.Parse(tokenDictionary, _fileManager.ReadAllText(file.FullName));
         _fileManager.WriteAllText(file.FullName, parsed);
     }
 }
Esempio n. 3
0
 protected void ParseFile(FileInfo path, ITokenDictionary tokenDictionary)
 {
     foreach (var token in tokenDictionary.Tokens)
     {
         if (path.Name.Contains(token.Key))
         {
             _fileManager.RenameFile(path.FullName, path.Name.Replace(token.Key, token.Value.Invoke()));
         }
     }
 }
Esempio n. 4
0
 protected void ParseDirectory(DirectoryInfo directory, ITokenDictionary tokenDictionary)
 {
     foreach (var token in tokenDictionary.Tokens)
     {
         if (directory.Name.Contains(token.Key))
         {
             _fileManager.RenameDirectory(directory.FullName, directory.Name.Replace(token.Key, token.Value.Invoke()));
         }
     }
 }
Esempio n. 5
0
        private string ParseContextTokens(ITokenDictionary tokenDictionary, string template)
        {
            foreach (var token in tokenDictionary.Tokens)
            {
                if (template.Contains(token.Key))
                {
                    template = template.Replace(token.Key, token.Value.Invoke());
                }
            }

            return(template);
        }
Esempio n. 6
0
 /// <summary>
 /// Removes all merged token item and updates respective identified or unidentified
 /// <param name="tokenDictionary">Token dictionary to get result</param>
 /// </summary>
 internal void UpdateFromMergeToken(ITokenDictionary tokenDictionary)
 {
     foreach (KeyValuePair <string, List <IndexerFile> > item in _mergedTokenList)
     {
         SplitWithIdentification splitWithIdentification = tokenDictionary.GetIdentificationSplitForMergedToken(item.Key);
         foreach (IndexerFile indexerFile in item.Value)
         {
             AddIdentificationToList(splitWithIdentification, indexerFile);
         }
     }
     _mergedTokenList.Clear();
 }
Esempio n. 7
0
        public void Parse(DirectoryInfo directory, ITokenDictionary tokenDictionary)
        {
            if (directory.Exists)
            {
                directory.EnumerateFiles("*.*", SearchOption.AllDirectories).ForEach(p => ParseFile(p, tokenDictionary));
            }

            ParseDirectory(directory, tokenDictionary);

            if (directory.Exists)
            {
                directory.EnumerateDirectories("*.*", SearchOption.AllDirectories).ForEach(p => ParseDirectory(p, tokenDictionary));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Updates stemmed
        /// <param name="tokenDictionary">Token dictionary to get result</param>
        /// </summary>
        internal void UpdateFromStemmed(ITokenDictionary tokenDictionary)
        {
            foreach (string key in _stemmedDictionary.Keys.ToList())
            {
                bool?  isToken;
                string stem = tokenDictionary.GetStemmedForText(key, out isToken);
                if (!isToken.HasValue)
                {
                    continue;
                }

                _stemmedDictionary[key].Word = stem;
                SplitWithIdentification splitWithIdentification = new SplitWithIdentification(stem, isToken.Value ? SplitIdentification.Token : SplitIdentification.Identified);
                foreach (IndexerFile file in _stemmedDictionary[key].IndexerFiles)
                {
                    AddIdentificationToList(splitWithIdentification, file);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Updates misspelled
        /// <param name="tokenDictionary">Token dictionary to get result</param>
        /// </summary>
        internal void UpdateFromMisspelled(ITokenDictionary tokenDictionary)
        {
            foreach (string key in _correctedDictionary.Keys.ToList())
            {
                bool?  isToken;
                string correction = tokenDictionary.GetCorrectionForMisspelled(key, out isToken);
                if (!isToken.HasValue)
                {
                    continue;
                }

                _correctedDictionary[key].Word = correction;
                SplitWithIdentification splitWithIdentification = new SplitWithIdentification(correction, isToken.Value ? SplitIdentification.Token : SplitIdentification.Identified);
                foreach (IndexerFile file in _correctedDictionary[key].IndexerFiles)
                {
                    AddIdentificationToList(splitWithIdentification, file);
                }
            }
        }
Esempio n. 10
0
 public string Parse(ITokenDictionary tokenDictionary, string template)
 {
     template = ParseContextTokens(tokenDictionary, template);
     template = ParseGuidTokens(template);
     return(template);
 }
        public void RenamingAFileIgnoresTokenInFolderName(MockContainer <FileAndDirectoryTokenParser> parser,
                                                          DirectoryInfo directoryPath, string directory, ITokenDictionary tokenDictionary)
        {
            "Given I have a file and directory token parser"
            ._(() => parser = B.AutoMock <FileAndDirectoryTokenParser>());

            "And I have a directory on disk"
            ._(() =>
            {
                directory     = ServiceLocator.Resolve <IFileManager>().GetTemporaryDirectory();
                directoryPath = Directory.CreateDirectory("%context.ProjectName%");
            });

            "And I have a file in that directory"
            ._(() => File.Create(Path.Combine(directoryPath.FullName, "Class1.cs")));

            "And I have a token dictionary with the %context.ProjectName% set"
            ._(() => tokenDictionary = BuildA.TokenDictionary.WithToken("%context.ProjectName%", "ServiceStack").Build());


            "When I call parse on the file and directory parser"
            ._(() => parser.Subject.Parse(directoryPath, tokenDictionary));

            "Then is should not try to rename the file"
            ._(
                () =>
                A.CallTo(
                    () => parser.GetMock <IFileManager>().RenameFile(A <string> .Ignored, A <string> .Ignored))
                .MustNotHaveHappened())
            .Teardown(() => Directory.Delete(directory, true));
        }
        public void RenamesDirectoryContainingToken(MockContainer <FileAndDirectoryTokenParser> parser, DirectoryInfo directoryPath, ITokenDictionary tokenDictionary)
        {
            "Given I have a file and directory token parser"
            ._(() => parser = B.AutoMock <FileAndDirectoryTokenParser>());

            "And I have a directory with a token"
            ._(() => directoryPath = new DirectoryInfo(@"%context.ProjectName%"));

            "And I have a token dictionary with the %context.ProjectName% set"
            ._(() => tokenDictionary = BuildA.TokenDictionary.WithToken("%context.ProjectName%", "ServiceStack").Build());

            "When I call parse on the file and directory parser"
            ._(() => parser.Subject.Parse(directoryPath, tokenDictionary));

            "Then is should rename the directory using the current project name"
            ._(
                () =>
                A.CallTo(
                    () => parser.GetMock <IFileManager>().RenameDirectory(directoryPath.FullName, "ServiceStack"))
                .MustHaveHappened());
        }
 /// <summary>
 /// Sets token dictionary to be used
 /// </summary>
 /// <param name="tokenDictionary">Token dictionary to be used. Requiered if use token dictionary is set to true.</param>
 public void SetTokenDictionary(ITokenDictionary tokenDictionary)
 {
     _tokenDictionary = tokenDictionary;
 }
Esempio n. 14
0
 /// <summary>
 /// Sets token dictionary
 /// </summary>
 /// <param name="tokenDictionary">Token Dictionary. Must be set.</param>
 public void SetTokenDictionary(ITokenDictionary tokenDictionary)
 {
     TokenDictionary = tokenDictionary;
     InitialSplitter?.SetTokenDictionary(tokenDictionary);
 }