/// <summary> /// Loads a dictionary using the <c>IDictionaryLoader</c> and the given arguments. /// </summary> /// <param name="loader">The IDictionaryLoader to load the dictionary with.</param> /// <param name="arguments">The arguments to pass to the IDictionaryLoader.</param> public void LoadDictionary(IDictionaryLoader loader, IDictionary <string, string> arguments) { _ = loader ?? throw new ArgumentNullException(nameof(loader)); _ = arguments ?? throw new ArgumentNullException(nameof(arguments)); this.Dictionary = loader.Load(arguments); }
public static void SetDefaults(IDictionaryLoader loader, IWordSegment wordseg) { dictLoader = loader; wordSegment = wordseg; wordSegment.LoadDictionary(loader, _basePath); wordSegment.LoadNameDictionary(loader, _namePath); wordSegment.LoadNumberDictionary(loader, _numberPath); foreach (string path in _customPaths) wordSegment.AppendDictionary(loader, path); wordSegment.LoadFilterDictionary(loader, _filterPath); initDefs = true; }
/// <summary> /// 根据指定的过滤字符字典文件过滤文本。 /// </summary> /// <param name="text">待处理文本</param> /// <param name="filterFilePath"></param> /// <param name="loader"></param> /// <param name="filterSpaces">是否过滤空格</param> /// <returns></returns> public static string Filter(string text, string filterFilePath, IDictionaryLoader loader, bool filterSpaces) { if (string.IsNullOrEmpty(filterFilePath)) { return ""; } if (loader == null) { return text; } List<string> filters = loader.Load(filterFilePath); return Filter(text, filters, filterSpaces); }
/// <summary> /// Initializes a new instance of the <see cref="RandomWordGenerator"/> /// class thats able to generate random words. /// </summary> /// <param name="dictionaryService">A service for retrieving dictionaries.</param> /// <param name="characterSetProvider">A service for providing a character list.</param> /// <param name="threadService">A service for getting the number of threads.</param> /// <param name="dictionaryConfiguration">The dictionary configuration settings.</param> public RandomWordGenerator( IDictionaryLoader dictionaryService, ICharacterSetProvider characterSetProvider, IThreadBalancer threadService, DictionaryConfiguration dictionaryConfiguration) { // Set member dependencies. this.dictionaryService = dictionaryService; this.threadService = threadService; this.dictionaryConfiguration = dictionaryConfiguration; characterList = characterSetProvider.ToCharArray(); random = RandomProvider.Random; progressPercentage = 0; }
/// <summary> /// Attempts to load a dictionary using the <c>IDictionaryLoader</c> and the given arguments. /// </summary> /// <param name="loader">The IDictionaryLoader to load the dictionary with.</param> /// <param name="arguments">The arguments to pass to the IDictionaryLoader.</param> /// <param name="error">The error which occured while loading the dictionary (if any).</param> /// <returns>True if the dictionary loaded successfully, false otherwise (and sets the <c>error</c> out parameter to the error).</returns> /// <remarks> /// See <c>LoadDictionary</c> for details of how <c>arguments</c> is parsed. /// </remarks> public bool TryLoadDictionary(IDictionaryLoader loader, string arguments, out Exception?error) { _ = loader ?? throw new ArgumentNullException(nameof(loader)); try { this.Dictionary = loader.Load(this.ParseArgumentString(arguments ?? "")); error = null; return(true); } catch (Exception ex) { error = ex; this.Dictionary = new EmptyDictionary(); return(false); } }
public WordsRepository(IDictionaryLoader dictionaryLoader) { _wordsDictionary = dictionaryLoader.LoadDictionary(); }
/// <summary> /// Loads a dictionary using the <c>IDictionaryLoader</c> and the given arguments. /// </summary> /// <param name="loader">The IDictionaryLoader to load the dictionary with.</param> /// <param name="arguments">The arguments to pass to the IDictionaryLoader, parsed like a database connection string.</param> /// <remarks> /// The arguments are parsed like a database connection string. /// An array of semicolon separated key value pairs are expected. /// Whitespace is trimmed. Keys are case-insensitive. /// '=' and ';' are not valid characters. If you need to pass them as arguments, use the <c>IDictionary</c> overload. /// The meaning of arguments is determined by the <c>IDictionaryLoader</c> /// /// Eg: url=http://server.com/file; iscompressed=true; /// </remarks> public void LoadDictionary(IDictionaryLoader loader, string arguments) { _ = loader ?? throw new ArgumentNullException(nameof(loader)); this.LoadDictionary(loader, this.ParseArgumentString(arguments ?? "")); }
public WordsRepository(IDictionaryLoader dictionaryLoader) { parole = dictionaryLoader.LoadDictionary(); }
public WordsRepository(IDictionaryLoader loader) { _words = loader.LoadDictionary(); }
public bool LoadFilterDictionary(IDictionaryLoader dictionaryLoader, string dictionaryPath) { if (dictionaryLoader == null) { return false; } this._filterList = dictionaryLoader.Load(dictionaryPath); return this._filterList != null && this._filterList.Count > 0; }
public bool LoadNumberDictionary(IDictionaryLoader dictionaryLoader, string dictionaryPath) { if (dictionaryLoader == null) { return false; } this._numberSegments = ParseList(dictionaryLoader.Load(dictionaryPath)); return this._numberSegments != null && this._numberSegments.Count > 0; }
public bool AppendDictionary(IDictionaryLoader dictionaryLoader, string dictionaryPath) { if (dictionaryLoader == null) { return false; } //将分词链表存储到字典中 return this.SegmentDictionary.Append(dictionaryLoader.Load(dictionaryPath)); }
public bool LoadDictionary(IDictionaryLoader dictionaryLoader, string dictionaryPath) { if (dictionaryLoader == null) { return false; } return this.SegmentDictionary.Parse(dictionaryLoader.Load(dictionaryPath)); }
/// <summary> /// 根据指定的过滤字符字典文件过滤文本。 /// </summary> /// <param name="text">待处理文本</param> /// <param name="filterFilePath"></param> /// <param name="loader"></param> /// <returns></returns> public static string Filter(string text, string filterFilePath, IDictionaryLoader loader) { return Filter(text, filterFilePath, loader, false); }
public DictionaryParser(IDictionaryLoader dictionaryLoader) { _lines = dictionaryLoader.GetLines(); }