public static PathOptimizer <string> ForXPaths(XElement xml, string xpath, XPathPartGenerator[] nodeReplacers, XPathScoreRule[] scoreRules, int desiredCount) { int i = 0; int len = XPathFinder.Split(xpath).Length; int timesFindAllShortenedPathsCalled = 0; return(new PathOptimizer <string>( nextNodesGetter: (p) => { if (i < len) { var results = XPathFinder.FindXpathsWithReplacedNode(XPathFinder.Split(p), i, xml, nodeReplacers); return results.Select(r => XPathFinder.Merge(r)); } else { var results = XPathFinder.FindAllShortenedPaths(p, xml); return results; } }, scoreMeasurer: (p) => XPathScorer.GetScore(p, scoreRules), onIterationFinished: () => { if (i < len) { i++; } else { timesFindAllShortenedPathsCalled++; } }, checkFinished: () => timesFindAllShortenedPathsCalled >= desiredCount)); }
private static IEnumerable <string> DoOptiize(XElement xml, string path, int count, XPathPartGenerator[] xPathPartGenerators, XPathScoreRule[] scoreRules) { PathOptimizer <string> pathOptimizer = PathOptimizerFactory.ForXPaths(xml, path, xPathPartGenerators, scoreRules, count); var bestPaths = pathOptimizer.FindBest(path, count); foreach (var scoredPath in XPathScorer.GetScoredXPaths(bestPaths, bestPaths.Count(), scoreRules)) { yield return(string.Format("{0:0.000} => {1}", scoredPath.Value, scoredPath.Key)); } }