/// <summary>Gets all of the word instances in the sequence of ILexicals.</summary> /// <param name="elements">The source sequence of ILexical instances.</param> /// <returns>All of the word instances in the sequence of ILexicals.</returns> public static ParallelQuery <Word> OfWord(this ParallelQuery <ILexical> elements) => elements.SelectMany(e => e.Match() .Case((Clause c) => c.Words) .Case((Phrase p) => p.Words) .Case((Word w) => new[] { w }) .Case((IAggregateLexical <ILexical> a) => a.OfWord()) .Result().EmptyIfNull());
public static void GrowNewBranches(ParallelQuery <Module> allModules) { // SelectMany will join all of the new modules returned by each module (if any) into a single list allModules.SelectMany(module => { return(module.nodes // Grow module off of it if not grown and vigor is greater than vigorRootMins .Where(node => node.main == null && node.lateral == null && node.v > module.plant.plantConfig.vigorRootMin) .Select(node => { UnityEngine.Debug.Log("Growing new branch at pos " + Node.GetGlobalPos(node)); float lambda = module.plant.plantConfig.lambda; float dPrime = module.root.v * module.plant.plantConfig.D / module.plant.plantConfig.vigorRootMax; ModulePrototype closestPrototype = PlantConfig.ClosestPrototype(module.plant.plantConfig, lambda, dPrime); Module newModule = ModulePrototype.CreateInstance(module.plant, closestPrototype, Node.GetPose(node)); node.main = newModule.root; // connect main to root so the trickle of q and v can work properly newModule.root.parent = node.main; return newModule; })); }) // Do last piece not in parallel, since we are appending to lists that is not thread safe .ToList() .ForEach(newModule => { newModule.plant.modules.Add(newModule); }); }
/// <summary>Implements a map-reduce operation.</summary> /// <typeparam name="TSource">Specifies the type of the source elements.</typeparam> /// <typeparam name="TMapped">Specifies the type of the mapped elements.</typeparam> /// <typeparam name="TKey">Specifies the type of the element keys.</typeparam> /// <typeparam name="TResult">Specifies the type of the results.</typeparam> /// <param name="source">The source elements.</param> /// <param name="map">A function used to get an enumerable of target data from a source element.</param> /// <param name="keySelector">A function used to get a key from target data.</param> /// <param name="reduce">A function used to reduce a group of elements to an enumerable of results.</param> /// <returns>The result elements of the reductions.</returns> public static ParallelQuery <TResult> MapReduce <TSource, TMapped, TKey, TResult>( this ParallelQuery <TSource> source, Func <TSource, IEnumerable <TMapped> > map, Func <TMapped, TKey> keySelector, Func <IGrouping <TKey, TMapped>, IEnumerable <TResult> > reduce) { return(source.SelectMany(map).GroupBy(keySelector) .SelectMany(reduce)); }
protected SampleSet <T> ApplyCrossValidated <P>(P preprocessor, Func <T, P, T> sampleProcessing, int xValidationStart, int xValidationLength) where P : Preprocessor { // you need to train your Trainable preprocessor externally if you aren't using cross validation (cross validation will apply its own training) if (!IsCrossValidatedSampleSet() && preprocessor is ITrainable && !((ITrainable)preprocessor).IsTrained()) { throw new ArgumentException("Trainable preprocessor must be trained for non-cross validated sets"); } Preprocessor copy = preprocessor.Copy(); // perform preprocessor training in parallel // TODO - include imposterTrainingSize ParallelQuery <int> crossValidationRange = Enumerable.Range(xValidationStart, xValidationLength).AsParallel(); Dictionary <int, Preprocessor> trainedPreprocessors = crossValidationRange.Select(x => new { x, preprocessorHead = preprocessor.Copy() }) .Select(p => new { p.x, trainablePreprocessor = p.preprocessorHead as ITrainable, p.preprocessorHead }) .Select(t => new { t.x, preprocessorHead = t.trainablePreprocessor != null && IsCrossValidatedSampleSet() ? t.trainablePreprocessor.Train <P>(SampleSetHelpers.GetSampleSetTrainingSamples(this, trainingSize.Value, t.x)) : t.preprocessorHead }) // only do training when cross validated .Select(trained => new { trained.x, preprocessorHead = trained.preprocessorHead.SetPredecessor(preprocessorHeads.ContainsKey(trained.x) ? preprocessorHeads[trained.x] : null) }) // set the current preprocessor as the predecessor to the newly applied one for initializing the new SampleSet .ToDictionary(trained => trained.x, trained => trained.preprocessorHead); // apply preprocessor head to each cross validation (or total sample set if this is not a cross validated set) SampleSet <T> preprocessedSampleSet = new SampleSet <T>(trainedPreprocessors, trainingSize); if (IsCrossValidatedSampleSet()) { preprocessedSampleSet.AddRange(crossValidationRange .SelectMany(x => SampleSetHelpers.GetCrossValidation(this as SampleSet <CrossValidatedSample>, x).Cast <T>().Select(sample => sampleProcessing.Invoke(sample, (P)trainedPreprocessors[x])))); } else { preprocessedSampleSet.AddRange(this.Select(sample => sampleProcessing.Invoke(sample, (P)trainedPreprocessors[DEFAULT_PREPROCESSOR_KEY]))); } return(preprocessedSampleSet); }
/// <summary> /// The GetHashCode. /// </summary> /// <param name="obj">The obj<see cref="ParallelQuery{IEnumerable{long}}"/>.</param> /// <returns>The <see cref="int"/>.</returns> public int GetHashCode(ParallelQuery <IEnumerable <long> > obj) { unchecked { return(obj.SelectMany(o => o.Select(x => x)).Aggregate(17, (a, b) => (a + (int)b) * 23)); } }
// See https://msdn.microsoft.com/en-us/library/bb397687.aspx - Lambdas with the standard query operators // The return value is always specified in the last type parameter. // E.g. Func<int, string, bool> defines a delegate with two input parameters, int and string, and a return type of bool public static ParallelQuery <TResult> MapReduce <TSource, TMapped, TKey, TResult>( this ParallelQuery <TSource> source, Func <TSource, IEnumerable <TMapped> > map, Func <TMapped, TKey> keySelector, Func <IGrouping <TKey, TMapped>, IEnumerable <TResult> > reduce) { // ============================================================== // COMMENT IN TO GET INSTRUMENTED VERSION OF MapReduce() // ============================================================== Console.WriteLine("TSource: {0}", typeof(TSource)); Console.WriteLine("TMapped: {0}", typeof(TMapped)); Console.WriteLine("TKey: {0}", typeof(TKey)); Console.WriteLine("TResult: {0}", typeof(TResult)); var selectManyFromSourceResult = source.SelectMany(map); foreach (var mapped in selectManyFromSourceResult) { Console.WriteLine("mapped: {0}", mapped); } var grouped = selectManyFromSourceResult.GroupBy(keySelector); foreach (var grouping in grouped) { Console.Write("grouped: {0}: ", grouping.Key); foreach (var groupItem in grouping) { Console.Write("{0}, ", groupItem); } Console.WriteLine(); } var reduced = grouped.SelectMany(reduce); foreach (var r in reduced) { Console.WriteLine("reduced: {0}", r); } return(reduced); return(source .SelectMany(map) .GroupBy(keySelector) .SelectMany(reduce)); }
public static void SelectMany_Unordered_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion); Assert.All(query.SelectMany(x => expand(x, expansion)).ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public static void SelectMany_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; int seen = 0; Assert.All(query.SelectMany(x => expand(x, expansion)).ToList(), x => Assert.Equal(seen++, x)); Assert.Equal(count * expansion, seen); }
public static ParallelQuery <TResult> MapReduce <TSource, TMapped, TKey, TResult>( this ParallelQuery <TSource> source, Func <TSource, IEnumerable <TMapped> > map, Func <TMapped, TKey> keySelector, Func <IGrouping <TKey, TMapped>, IEnumerable <TResult> > reduce) { return(source.SelectMany(map) //将初始序列转换为需要应用于Map函数的序列 .GroupBy(keySelector) //分组,并且使用该键以及GroupBy来产生一个中间键/值序列 .SelectMany(reduce)); //应用Reduce函数来得到结果 }
public static void SelectMany_Unordered(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion); foreach (int i in query.SelectMany(x => expand(x, expansion))) { seen.Add(i); } seen.AssertComplete(); }
public static void SelectMany(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; int seen = 0; foreach (int i in query.SelectMany(x => expand(x, expansion))) { Assert.Equal(seen++, i); } Assert.Equal(count * expansion, seen); }
public static void SelectMany_Indexed(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; int seen = 0; foreach (var pIndex in query.SelectMany((x, index) => expand(x, expansion).Select(y => KeyValuePair.Create(index, y)))) { Assert.Equal(seen++, pIndex.Value); Assert.Equal(pIndex.Key, pIndex.Value / expansion); } Assert.Equal(count * expansion, seen); }
public static void SelectMany_Unordered_ResultSelector(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion); foreach (var p in query.SelectMany(x => expand(x, expansion), (original, expanded) => KeyValuePair.Create(original, expanded))) { seen.Add(p.Value); Assert.Equal(p.Key, p.Value / expansion); } seen.AssertComplete(); }
public static void SelectMany_ResultSelector(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; int seen = 0; foreach (var p in query.SelectMany(x => expand(x, expansion), (original, expanded) => KeyValuePair.Create(original, expanded))) { Assert.Equal(seen++, p.Value); Assert.Equal(p.Key, p.Value / expansion); } Assert.Equal(count * expansion, seen); }
public static void SelectMany_ResultSelector_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; int seen = 0; Assert.All(query.SelectMany(x => expand(x, expansion), (original, expanded) => KeyValuePair.Create(original, expanded)).ToList(), p => { Assert.Equal(seen++, p.Value); Assert.Equal(p.Key, p.Value / expansion); }); Assert.Equal(count * expansion, seen); }
internal static ParallelQuery <int> MakeSelectMany(bool orderPreserved) { int[] a = Enumerable.Range(0, 10).ToArray(); int[] b = Enumerable.Range(0, 10).ToArray(); ParallelQuery <int> ipe = a.AsParallel(); if (orderPreserved) { ipe = ipe.AsOrdered(); } return(ipe.SelectMany(i => b, (i, j) => (10 * i + j))); }
public static void SelectMany_Indexed_Unordered(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion) { // For unordered collections, which element is at which index isn't actually guaranteed, but an effect of the implementation. // If this test starts failing it should be updated, and possibly mentioned in release notes. ParallelQuery <int> query = labeled.Item; Func <int, int, IEnumerable <int> > expand = expander.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion); foreach (var pIndex in query.SelectMany((x, index) => expand(x, expansion).Select(y => KeyValuePair.Create(index, y)))) { seen.Add(pIndex.Value); Assert.Equal(pIndex.Key, pIndex.Value / expansion); } seen.AssertComplete(); }
/// <summary> /// Converts a collection of SpotifyTrackInfos (from the Spotify API) to a collection of SpotifyTrack, in parallel /// using Map-Reduce. /// Note: This method returns a Task but it does not use asynchronous method invocation in the iterations, it can only /// be awaited so it wont have to be waited to /// </summary> /// <param name="spotifyTrackInfos">Source SpotifyTrackInfo collection</param> /// <returns>Task of collection of converted SpotifyTracks</returns> /// <see cref="SpotifyTrackInfo" /> /// <see cref="SpotifyTrack" /> public async Task <IEnumerable <SpotifyTrack> > CreateSpotifyTracksAsync(IEnumerable <SpotifyTrackInfo> spotifyTrackInfos) { List <SpotifyTrackInfo> infosList = spotifyTrackInfos.ToList(); // Partition (Map) int batches = this.Config.OperationsPerThread > 0 ? this.Config.OperationsPerThread : 1; ParallelQuery <IGrouping <int, KeyValuePair <int, SpotifyTrackInfo> > > parallelBatches = SplitToBatches(infosList, this.Config.ConcurrentPoolSize, batches); // Reduce (using conversion between SpotifyTrackInfo to SpotifyTrack return(parallelBatches.SelectMany( dictionary => dictionary.Select( pair => this.CreateSpotifyTrackAsync(pair.Value, false) .ConfigureAwait(false) .GetAwaiter() .GetResult()))); }
static ParallelQuery <TResult> MapReduce <TSource, TMapped, TKey, TResult>( this ParallelQuery <TSource> source, Func <TSource, IEnumerable <TMapped> > map, Func <TMapped, TKey> keySelector, Func <IGrouping <TKey, TMapped>, IEnumerable <TResult> > reduce) { //return source.SelectMany(map).GroupBy(keySelector).SelectMany(reduce); ParallelQuery <TMapped> mapRes = source.SelectMany(map); //List<TMapped> debug1 = mapRes.ToList(); ParallelQuery <IGrouping <TKey, TMapped> > groupByRes = mapRes.GroupBy(keySelector); //List<TKey> debug2 = groupByRes.Select(item => item.Key).ToList(); ParallelQuery <TResult> res = groupByRes.SelectMany(reduce); //List<TResult> debug3 = res.ToList(); return(res); }
public void ModifyNameTest1() { // Arrange IEnumerable <XElement> elements = new XElement[] { new XElement("root", new XElement("A", 0), new XElement("B", 1), new XElement("C", 2), new XElement("A", 3)) }; // Act ParallelQuery <XElement> t = elements.AsParallel().ChangeXNames("A", "AA"); string test = string.Join("|", t.SelectMany(x => x.Elements()).Select(x => x.Name)); // Assert Assert.True(elements.First().Elements().Count(x => x.Name == "AA") == 2); Assert.Equal("AA|B|C|AA", test); }
/// <summary> /// Gets the parallel aggregation of all Clause instances contained within the sequence of textual sources. /// </summary> /// <param name="textual">A sequence of textual sources.</param> /// <returns>The parallel aggregation of all Clause instances contained within the sequence of textual sources.</returns> public static ParallelQuery <Clause> Clauses(this ParallelQuery <IReifiedTextual> textual) => textual.SelectMany(s => s.Clauses);
/// <summary> /// Gets the parallel aggregation of all Phrase instances contained within the sequence of textual sources. /// </summary> /// <param name="textual">A sequence of textual sources.</param> /// <returns>The parallel aggregation of all Phrase instances contained within the sequence of textual sources.</returns> public static ParallelQuery <Phrase> Phrases(this ParallelQuery <IReifiedTextual> textual) => textual.SelectMany(p => p.Phrases);
/// <summary> /// Gets the parallel aggregation of all Word instances contained within the sequence of textual sources. /// </summary> /// <param name="textual">A sequence of textual sources.</param> /// <returns>The parallel aggregation of all Word instances contained within the sequence of textual sources.</returns> public static ParallelQuery <Word> Words(this ParallelQuery <IReifiedTextual> textual) => textual.SelectMany(p => p.Words);
private static void RunAllTests( TestTracker result, ParallelQuery <int> q, bool orderPreserved, string leftOpName, bool leftOrderDefined) { LogTestRun(leftOpName, "All1", orderPreserved); result.MustEqual( q.All(i => i > 100), q.ToArray().Any(i => i > 100)); LogTestRun(leftOpName, "All2", orderPreserved); result.MustEqual( q.All(i => i == 75), q.ToArray().All(i => i == 75)); LogTestRun(leftOpName, "Any1", orderPreserved); result.MustEqual( q.Any(i => i > 100), q.ToArray().Any(i => i > 100)); LogTestRun(leftOpName, "Any2", orderPreserved); result.MustEqual( q.Any(i => i == 75), q.ToArray().Any(i => i == 75)); LogTestRun(leftOpName, "Concat", orderPreserved); result.MustSequenceEqual( q.Concat(q).Concat(new int[] { 1, 2, 3 }.AsParallel()), q.Reverse().Reverse().ToArray().Concat(q.Reverse().Reverse()).Concat(new int[] { 1, 2, 3 }), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "DefaultIfEmpty", orderPreserved); result.MustSequenceEqual( q.DefaultIfEmpty(), q.ToArray().DefaultIfEmpty(), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "ElementAt", orderPreserved); IEnumerable <int> q2 = q.ToArray(); int count1 = q.Count(), count2 = q2.Count(); List <int> list1 = new List <int>(); List <int> list2 = new List <int>(); for (int i = 0; i < count1; i++) { list1.Add(q.ElementAt(i)); } for (int i = 0; i < count2; i++) { list2.Add(q2.ElementAt(i)); } result.MustSequenceEqual(list1, list2, leftOrderDefined); LogTestRun(leftOpName, "Except", orderPreserved); result.MustSequenceEqual( q.Except(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Except(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "First", orderPreserved); CheckFirstOrLast( result, q.First(), q.ToArray().First(), leftOrderDefined); LogTestRun(leftOpName, "GroupBy", orderPreserved); result.MustGroupByEqual( q.GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e)), q.ToArray().GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e))); LogTestRun(leftOpName, "GroupJoin", orderPreserved); result.MustSequenceEqual( q.GroupJoin(q, i => i, i => i, (i, e) => e.FirstOrDefault()), q.ToArray().GroupJoin(q.ToArray(), i => i, i => i, (i, e) => e.FirstOrDefault()), false); LogTestRun(leftOpName, "Intersect", orderPreserved); result.MustSequenceEqual( q.Intersect(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Intersect(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "Join1", orderPreserved); result.MustSequenceEqual( q.Join((new int[] { 1, 1, 2, 3, 3 }).AsParallel(), i => i, i => i, (i, j) => i + j), q.ToArray().Join(new int[] { 1, 1, 2, 3, 3 }, i => i, i => i, (i, j) => i + j), false); LogTestRun(leftOpName, "Join2", orderPreserved); result.MustSequenceEqual( q.Join((new int[] { 1, 1, 100, 3, 3 }).AsParallel(), i => new String('a', i), i => new String('a', i), (i, j) => i + j), q.ToArray().Join(new int[] { 1, 1, 100, 3, 3 }, i => new String('a', i), i => new String('a', i), (i, j) => i + j), false); LogTestRun(leftOpName, "Last", orderPreserved); CheckFirstOrLast( result, q.Last(), q.ToArray().Last(), leftOrderDefined); LogTestRun(leftOpName, "Min", orderPreserved); CheckFirstOrLast( result, q.Min(), q.ToArray().Min(), leftOrderDefined); LogTestRun(leftOpName, "Max", orderPreserved); CheckFirstOrLast( result, q.Min(), q.ToArray().Min(), leftOrderDefined); LogTestRun(leftOpName, "OrderBy-ThenBy", orderPreserved); result.MustSequenceEqual( q.Concat(q).OrderBy(i => i % 5).ThenBy(i => - i), q.ToArray().Concat(q).OrderBy(i => i % 5).ThenBy(i => - i), true); LogTestRun(leftOpName, "OrderByDescending-ThenByDescending", orderPreserved); result.MustSequenceEqual( q.Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i), q.ToArray().Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i), true); LogTestRun(leftOpName, "Reverse", orderPreserved); result.MustSequenceEqual( q.Concat(q).Reverse(), q.ToArray().Concat(q).Reverse(), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "Select", orderPreserved); result.MustSequenceEqual( q.Select(i => 5 * i - 17), q.ToArray().Select(i => 5 * i - 17), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "SelectMany", orderPreserved); result.MustSequenceEqual( q.SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j), q.ToArray().SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j), false); LogTestRun(leftOpName, "SequenceEqual", orderPreserved); if (orderPreserved && leftOrderDefined) { result.MustEqual(q.SequenceEqual(q), true); } else { // We don't check the return value as it can be either true or false q.SequenceEqual(q); } LogTestRun(leftOpName, "Skip", orderPreserved); CheckTakeSkip( result, q.Skip(10), q.ToArray().Skip(10), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "SkipWhile", orderPreserved); CheckTakeSkip( result, q.SkipWhile(i => i < 30), q.ToArray().SkipWhile(i => i < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "SkipWhileIndexed", orderPreserved); CheckTakeSkip( result, q.SkipWhile((i, j) => j < 30), q.ToArray().SkipWhile((i, j) => j < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "Take", orderPreserved); CheckTakeSkip( result, q.Take(10), q.ToArray().Take(10), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "TakeWhile", orderPreserved); CheckTakeSkip( result, q.TakeWhile(i => i < 30), q.ToArray().TakeWhile(i => i < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "TakeWhileIndexed", orderPreserved); CheckTakeSkip( result, q.TakeWhile((i, j) => j < 30), q.ToArray().TakeWhile((i, j) => j < 30), leftOrderDefined && orderPreserved); LogTestRun(leftOpName, "Union", orderPreserved); result.MustSequenceEqual( q.Union(Enumerable.Range(90, 50).AsParallel()), q.ToArray().Union(Enumerable.Range(90, 50)), false); LogTestRun(leftOpName, "Where", orderPreserved); result.MustSequenceEqual( q.Where(i => i < 20 || i > 80), q.ToArray().Where(i => i < 20 || i > 80), orderPreserved && leftOrderDefined); LogTestRun(leftOpName, "Zip", orderPreserved); IEnumerable <KeyValuePair <int, int> > zipQ = q.Zip(q, (i, j) => new KeyValuePair <int, int>(i, j)); result.MustSequenceEqual( zipQ.Select(p => p.Key), q.Reverse().Reverse().ToArray(), orderPreserved && leftOrderDefined); result.MustSequenceEqual( zipQ.Select(p => p.Value), q.Reverse().Reverse().ToArray(), orderPreserved && leftOrderDefined); }
/// <summary> /// Gets a parallel aggregation of all Paragraph instances contained within the parallel sequence of Document.Page instances. /// </summary> /// <param name="documents">A parallel sequence of Document.Page instances.</param> /// <returns>The parallel aggregation of all Paragraph instances contained within the parallel sequence of Document.Page instances.</returns> public static ParallelQuery <Paragraph> Paragraphs(this ParallelQuery <Document.Page> documents) => documents.SelectMany(p => p.Paragraphs);
/// <summary> /// The Equals. /// </summary> /// <param name="x">The x<see cref="ParallelQuery{IEnumerable{long}}"/>.</param> /// <param name="y">The y<see cref="ParallelQuery{IEnumerable{long}}"/>.</param> /// <returns>The <see cref="bool"/>.</returns> public bool Equals(ParallelQuery <IEnumerable <long> > x, ParallelQuery <IEnumerable <long> > y) { return(x.SelectMany(a => a.Select(b => b)).SequenceEqual(y.SelectMany(a => a.Select(b => b)))); }
/// <summary> /// Gets a parallel aggregation of all Sentence instances contained within the parallel sequence of Document instances. /// </summary> /// <param name="documents">A parallel sequence of Document instances.</param> /// <returns>The parallel aggregation of all Sentence instances contained within the parallel sequence of Document instances.</returns> public static ParallelQuery <Sentence> Sentences(this ParallelQuery <Document> documents) => documents .SelectMany(d => d.Paragraphs .SelectMany(p => p.Sentences));
/// <summary> /// Gets a parallel aggregation of all Paragraph instances contained within the parallel sequence of Document instances. /// </summary> /// <param name="documents">A sequence of Document instances.</param> /// <returns>The parallel aggregation of all Paragraph instances contained within the parallel sequence of Document instances.</returns> public static ParallelQuery <Paragraph> Paragraphs(this ParallelQuery <Document> documents) => documents.SelectMany(d => d.Paragraphs);
/// <summary>Gets all of the Phrase instances in the sequence of ILexicals.</summary> /// <param name="elements">The source sequence of ILexical instances.</param> /// <returns>All of the Phrase instances in the sequence of ILexicals.</returns> private static ParallelQuery <Phrase> OfPhrase(this ParallelQuery <ILexical> elements) => elements.SelectMany(e => e.Match() .Case((Clause c) => c.Phrases) .Case((Phrase p) => new[] { p }) .Result().EmptyIfNull());
/// <summary> /// Evaluates a PLINQ <c>SelectMany</c> method over a sequence of <see cref="IDocument"/> and traces any exceptions. /// </summary> /// <param name="query">The source query.</param> /// <param name="context">The execution context.</param> /// <param name="selector">The selector function.</param> /// <returns>The result query.</returns> public static ParallelQuery <IDocument> SelectMany( this ParallelQuery <IDocument> query, IExecutionContext context, Func <IDocument, IEnumerable <IDocument> > selector) => query.SelectMany(x => context.TraceExceptions(x, selector));