Struct for define RegexType
Example #1
0
		public void ContainsPersonIsaacNewton()
		{
			var page = GetPage();

			var item = page.Infoboxes[0];

			var key = new RegexKeyType("Meno", NamedEntityType.Person);
			var value = "Isaac Newton";
			
			Assert.AreEqual(item.Items[key][0], value);
		}
Example #2
0
		public void ContainsLocationWoolsthorpeByColsterworth()
		{
			var page = GetPage();

			var item = page.Infoboxes[0];

			var key = new RegexKeyType("Miesto narodenia", NamedEntityType.Location);
			var value = "Woolsthorpe-by-Colsterworth";

			Assert.AreEqual(item.Items[key][0], value);
		}
Example #3
0
        /// <summary>
        /// Load items from KnowledgeData part - split by '|' and decoding type of item
        /// </summary>
        /// <returns></returns>
        private Dictionary <RegexKeyType, string[]> LoadItems()
        {
            var items = new Dictionary <RegexKeyType, string[]>();

            this.Content = this.Content.Replace("|", " | ");

            Regex.Split(this.Content, @"\s\| ")
            .Where(word => word.Contains("=")).ToList()
            .ForEach(item =>
            {
                var word = Regex.Split(item, "=");
                if (word.Count() == 2)
                {
                    var key   = WordUtils.TrimWhiteSpaces(word[0]);
                    var value = WordUtils.TrimWhiteSpaces(word[1]);

                    if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
                    {
                        var values = SplitMultipleValues(value);
                        var type   = new RegexKeyType();
                        type.Value = key;

                        try
                        {
                            items.Add(type, values);
                        }
                        catch { }
                    }
                }
            });

            return(items.Where(i => Attributes.Any(a => Regex.IsMatch(i.Key.Value, a.Value)))
                   .ToDictionary(i => {
                var key = i.Key;
                key.Type = Attributes.FirstOrDefault(a => Regex.Match(key.Value, a.Value).Success).Type;
                return key;
            },
                                 i => i.Value));
            //Attributes.FirstOrDefault(a => Regex.Match(i.Key, a).Success)
        }
Example #4
0
		/// <summary>
		/// Load items from KnowledgeData part - split by '|' and decoding type of item
		/// </summary>
		/// <returns></returns>
		private Dictionary<RegexKeyType, string[]> LoadItems()
		{
			var items = new Dictionary<RegexKeyType, string[]>();
			this.Content = this.Content.Replace("|", " | ");

			Regex.Split(this.Content, @"\s\| ")
						.Where(word => word.Contains("=")).ToList()
						.ForEach(item =>
						{
							var word = Regex.Split(item, "=");
							if (word.Count() == 2)
							{
								var key = WordUtils.TrimWhiteSpaces(word[0]);
								var value = WordUtils.TrimWhiteSpaces(word[1]);

								if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
								{
									var values = SplitMultipleValues(value);
									var type = new RegexKeyType();
									type.Value = key;

									try
									{
										items.Add(type, values);
									}
									catch { }
								}
							}
						});

			return items.Where(i => Attributes.Any(a => Regex.IsMatch(i.Key.Value, a.Value)))
						.ToDictionary(i => {
												var key = i.Key;
												key.Type = Attributes.FirstOrDefault(a => Regex.Match(key.Value, a.Value).Success).Type;
												return key;
											},
									  i => i.Value);
			//Attributes.FirstOrDefault(a => Regex.Match(i.Key, a).Success)
		}