public BatchFieldBuilder Match(Action <BatchMatchBuilder> builder) { var fieldMatch = new FieldMatch(); var fieldBuilder = new BatchMatchBuilder(fieldMatch); builder(fieldBuilder); _fieldMapping.MatchDefinitions.Add(fieldMatch); return(this); }
private FieldMatch DigestFieldMatch(XPathNavigator nav, IFactoryFarm factoryFarm) { nav.MoveToFirstChild(); // sourceField var sourceField = DigestField(nav.Clone(), factoryFarm); nav.MoveToNext(); // targetField var targetField = DigestField(nav.Clone(), factoryFarm); var fieldMatch = new FieldMatch(sourceField, targetField); return(fieldMatch); }
public void ShouldReturnUniqueLocationsInOrder() { var sut = new FieldMatch(1, CompositeMatch(4, 5, 6, 9), TokenMatch(6), CompositeMatch(5, 6), TokenMatch(7)); sut.GetTokenLocations().Should().BeEquivalentTo( new[] { new TokenLocation(4, 4, 4), new TokenLocation(5, 5, 5), new TokenLocation(6, 6, 6), new TokenLocation(7, 7, 7), new TokenLocation(9, 9, 9) }, options => options.WithStrictOrdering()); }
public BatchMatchBuilder(FieldMatch fieldMatch) { _fieldMatch = fieldMatch; }
public IHttpActionResult Run(dynamic args) { int templateId = args.TemplateId, articleId = args.ArticleId; List <FieldMatch> matches = db.FieldMatches .Include("Article") .Where(fm => fm.Article.Id == articleId).ToList(); db.FieldMatches.RemoveRange(matches); db.SaveChanges(); Article article = db.Articles.First(a => a.Id == articleId); Template template = db.Templates .Include("TemplateFields.FieldExpecteds.Article") .First(t => t.Id == templateId); List <Rule> rules = db.Rules.ToList(); foreach (TemplateField field in template.TemplateFields) { string expectedValue = field.FieldExpecteds.First(fe => fe.Article.Id == articleId).Value; foreach (Rule rule in rules) { string expression = rule.Content.Replace("[TAG]", field.FieldName); Regex regex = new Regex(expression); if (regex.IsMatch(article.OriginalContent)) { FieldMatch fm = new FieldMatch(); fm.Article = article; fm.Rule = rule; MatchCollection regMatches = regex.Matches(article.OriginalContent); try { List <string> matchTextList = new List <string>(); foreach (Match match in regMatches) { for (int i = 1; i <= match.Groups.Count; i++) { foreach (Capture capture in match.Groups[i].Captures) { matchTextList.Add(capture.Value); } } } fm.MatchText = String.Join("|", matchTextList.ToArray()); fm.MatchScore = Convert.ToInt32(utils.LevenshteinDistance.Instance.LevenshteinDistancePercent(expectedValue, fm.MatchText) * 100); field.FieldMatches.Add(fm); } catch { // fm.MatchText = string.Empty; // fm.MatchScore = 0; } } //else //{ // fm.MatchText = string.Empty; // fm.MatchScore = 0; //} } } article.Runned = true; db.SaveChanges(); return(Ok()); }
private void ParseFields(String prefix, IEnumerable <String> extractFields, ItemFields fields) { foreach (ItemField field in fields) { String fieldName = String.Concat(prefix, field.Name); String packageName = String.Concat(PackagePrefix, ".", prefix, field.Name); // Verify if the value is not already present in the package if (Package.GetByName(packageName) == null) { FieldMatch fieldMatch = IncludeField(fieldName, extractFields); if (fieldMatch == FieldMatch.Match) { if (field is SingleLineTextField || field is MultiLineTextField || field is ExternalLinkField) { String value = field.StringValue(); if (!String.IsNullOrEmpty(value)) { Package.AddString(packageName, value); } continue; } if (field is DateField) { DateTime value = field.DateValue(); if (value != DateTime.MinValue) { Package.AddDateTime(packageName, value); } continue; } if (field is NumberField) { Double value = field.NumberValue(); if (!Double.IsNaN(value)) { Package.AddNumber(packageName, value); } continue; } if (field is ComponentLinkField) { IList <Component> components = field.ComponentValues(); if (components != null && components.Count > 0) { Package.AddComponents(packageName, components.Select(c => c.Id).ToList()); } continue; } if (field is XhtmlField) { String value = field.XHTMLValue(); if (!String.IsNullOrEmpty(value)) { Package.AddXhtml(packageName, value); } continue; } if (field is KeywordField) { Keyword keyword = field.KeywordValue(); if (keyword != null) { Package.AddLink(packageName, keyword); Package.AddString(String.Concat(packageName, FIELD_SEPERATOR, "Title"), keyword.Title); Package.AddString(String.Concat(packageName, FIELD_SEPERATOR, "Description"), keyword.Description); } continue; } } if (fieldMatch == FieldMatch.PartialMatch) { if (field is EmbeddedSchemaField) { ItemFields itemFields = field.EmbeddedValue(); if (fields != null) { ParseFields(String.Concat(fieldName, FIELD_SEPERATOR), extractFields, itemFields); } continue; } if (field is ComponentLinkField) { Component component = field.ComponentValue(); if (component != null) { ItemFields itemFields = component.Fields(); if (fields != null) { ParseFields(String.Concat(fieldName, FIELD_SEPERATOR), extractFields, itemFields); } continue; } } } } } }
public static List <FieldDeclarationSyntax> SearchForField(this ClassDeclarationSyntax type, FieldMatch fieldMatch) { if (Program.Debug) { Program.WriteLine(ConsoleColor.Yellow, $"Trying to find {{{UsingDirective.BuildFullMemberTag(fieldMatch)}}}"); Program.IndentLevel++; } List <FieldDeclarationSyntax> s = Registry.GetMatchedMember(fieldMatch); if (!Program.SkipOne) { s = type.Members.OfType <FieldDeclarationSyntax>().Where(fieldMatch.Matches) .ToList(); } if (Program.Debug) { Program.IndentLevel--; } return(s); }
[XmlIgnore] public TableTemplate this[FieldMatch match] { get { return(FindAlias(match.TemplateAlias)); } }