当前位置: 首页>>代码示例>>C#>>正文


C# IList.Intersect方法代码示例

本文整理汇总了C#中IList.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# IList.Intersect方法的具体用法?C# IList.Intersect怎么用?C# IList.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IList的用法示例。


在下文中一共展示了IList.Intersect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EvaluateOnline

		/// <summary>Online evaluation for rankings of items</summary>
		/// <remarks>
		/// The evaluation protocol works as follows:
		/// For every test user, evaluate on the test items, and then add the those test items to the training set and perform an incremental update.
		/// The sequence of users is random.
		/// </remarks>
		/// <param name="recommender">the item recommender to be evaluated</param>
		/// <param name="test">test cases</param>
		/// <param name="training">training data (must be connected to the recommender's training data)</param>
		/// <param name="test_users">a list of all test user IDs</param>
		/// <param name="candidate_items">a list of all candidate item IDs</param>
		/// <param name="candidate_item_mode">the mode used to determine the candidate items</param>
		/// <returns>a dictionary containing the evaluation results (averaged by user)</returns>
		static public ItemRecommendationEvaluationResults EvaluateOnline(
			this IRecommender recommender,
			IPosOnlyFeedback test, IPosOnlyFeedback training,
			IList<int> test_users, IList<int> candidate_items,
			CandidateItems candidate_item_mode)
		{
			var incremental_recommender = recommender as IIncrementalItemRecommender;
			if (incremental_recommender == null)
				throw new ArgumentException("recommender must be of type IIncrementalItemRecommender");

			candidate_items = Items.Candidates(candidate_items, candidate_item_mode, test, training);

			test_users.Shuffle();
			var results_by_user = new Dictionary<int, ItemRecommendationEvaluationResults>();
			foreach (int user_id in test_users)
			{
				if (candidate_items.Intersect(test.ByUser[user_id]).Count() == 0)
					continue;

				// prepare data
				var current_test_data = new PosOnlyFeedback<SparseBooleanMatrix>();
				foreach (int index in test.ByUser[user_id])
					current_test_data.Add(user_id, test.Items[index]);
				// evaluate user
				var current_result = Items.Evaluate(recommender, current_test_data, training, current_test_data.AllUsers, candidate_items, CandidateItems.EXPLICIT);
				results_by_user[user_id] = current_result;

				// update recommender
				var tuples = new List<Tuple<int, int>>();
				foreach (int index in test.ByUser[user_id])
					tuples.Add(Tuple.Create(user_id, test.Items[index]));
				incremental_recommender.AddFeedback(tuples);
				// TODO candidate_items should be updated properly
			}

			var results = new ItemRecommendationEvaluationResults();

			foreach (int u in results_by_user.Keys)
				foreach (string measure in Items.Measures)
					results[measure] += results_by_user[u][measure];

			foreach (string measure in Items.Measures)
				results[measure] /= results_by_user.Count;

			results["num_users"] = results_by_user.Count;
			results["num_items"] = candidate_items.Count;
			results["num_lists"] = results_by_user.Count;

			return results;
		}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:63,代码来源:ItemsOnline.cs

示例2: FailDifferentObjects

        private static void FailDifferentObjects(IList<string> expectedFields, IList<string> actualFields,
            JObject expectedObject, JObject actualObject)
        {
            var commonFields = new HashSet<string>(expectedFields.Intersect(actualFields));
            expectedFields = expectedFields.Select(f => commonFields.Contains(f) ? f : "**" + f + "**").ToList();
            actualFields = actualFields.Select(f => commonFields.Contains(f) ? f : "**" + f + "**").ToList();

            var writer = new StringWriter();
            writer.WriteLine("Different fields found in object{0}", expectedObject.Path.WithLeadingWhitespace());
            writer.WriteLine("  expected: {0}", string.Join(", ", expectedFields));
            writer.WriteLine("  but was:  {0}", string.Join(", ", actualFields));
            writer.WriteLine();
            writer.WriteLine("  expected object:");
            writer.WriteLine(expectedObject.ToString(Formatting.Indented));
            writer.WriteLine("  actual object:");
            writer.WriteLine(actualObject.ToString(Formatting.Indented));

            throw new AssertionException(writer.ToString());
        }
开发者ID:vtex,项目名称:specs-owin-pt,代码行数:19,代码来源:JsonComparer.cs

示例3: EditList

 private void EditList(string name, IList<string> listToEdit)
 {
     ListEditor editor = new ListEditor(name, listToEdit);
     List<string> original = listToEdit.ToList<string>();
     editor.ShowDialog();
     int commonCount = listToEdit.Intersect(original).Count<string>();
     if (commonCount != listToEdit.Count || commonCount != original.Count)
     {
         TitleChanges(null, null);
     }
 }
开发者ID:peeboo,项目名称:open-media-library,代码行数:11,代码来源:TitleEditor.cs

示例4: CompareListsNew

        private static void CompareListsNew(IList<Article> list1, List<Article> list2, ListBox lb1, ListBox lb2, ListBox lb3)
        {
            lb1.BeginUpdate();
            lb2.BeginUpdate();
            lb3.BeginUpdate();

            lb1.Items.AddRange(list1.Except(list2).ToArray());
            lb2.Items.AddRange(list2.Except(list1).ToArray());
            lb3.Items.AddRange(list1.Intersect(list2).ToArray());

            lb1.EndUpdate();
            lb2.EndUpdate();
            lb3.EndUpdate();
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:14,代码来源:ListComparer.cs

示例5: Compacting

        /// <summary>
        /// this function performs compacting that is bringing in last sitting group to front as so on
        /// </summary>
        /// <param name="_theatreList"></param>
        /// <returns></returns>
        public IList<Section> Compacting(IList<Customer> customerList)
        {
            for (int i = 0; i < _theatreList.Count; i++)
            {
                for (int j = _theatreList.Count - 1; j >= i; j--)
                {
                    if (_theatreList[i].EmpltySeats >= _theatreList[j].
                        OccupiedSeats && _theatreList[j].OccupiedSeats > 0)
                    {
                        _theatreList[i].AllocateThisSection(_theatreList[j].
                            GivenTo.ToArray(), _theatreList[j].OccupiedSeats);

                        _theatreList[j].DeallocateThisAllocation();

                        var customers = customerList.Intersect(_theatreList[i].GivenTo);
                        customers.ToList().ForEach(x => x.AllocateSeat(_theatreList[i].Rownumber,
                            _theatreList[i].SectionId));
                    }
                }
            }
            return _theatreList;
        }
开发者ID:mrgargashish,项目名称:Ashish_TheatreSeating,代码行数:27,代码来源:ArrangeSeat.cs

示例6: PrepareForUpdateChildrenMasterPages

        public void PrepareForUpdateChildrenMasterPages(PageProperties page, Guid? masterPageId, out IList<Guid> newMasterIds, out IList<Guid> oldMasterIds, out IList<Guid> childrenPageIds, out IList<MasterPage>  existingChildrenMasterPages)
        {
            if ((page.MasterPage != null && page.MasterPage.Id != masterPageId) || (page.MasterPage == null && masterPageId.HasValue))
            {
                newMasterIds = masterPageId.HasValue ? GetPageMasterPageIds(masterPageId.Value) : new List<Guid>(0);

                oldMasterIds = page.MasterPage != null && page.MasterPages != null ? page.MasterPages.Select(mp => mp.Master.Id).Distinct().ToList() : new List<Guid>(0);

                var intersectingIds = newMasterIds.Intersect(oldMasterIds).ToArray();
                foreach (var id in intersectingIds)
                {
                    oldMasterIds.Remove(id);
                    newMasterIds.Remove(id);
                }

                var updatingIds = newMasterIds.Union(oldMasterIds).Distinct().ToList();
                existingChildrenMasterPages = GetChildrenMasterPagesToUpdate(page, updatingIds, out childrenPageIds);
            }
            else
            {
                newMasterIds = null;
                oldMasterIds = null;
                childrenPageIds = null;
                existingChildrenMasterPages = null;
            }
        }
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:26,代码来源:DefaultMasterPageService.cs

示例7: SetRoles

        /// <summary>
        /// Set the roles that are being exported by a port
        /// </summary>
        /// <param name="portInfo">the portinfo object of the port</param>
        /// <param name="roles">the list of roles to bind</param>
        /// <param name="module">the module that own the port</param>
        public void SetRoles(VPortInfo vPortInfo, IList<VRole> roles, VModule module)
        {
            PortInfo storedPortInfo = config.GetMatchingPortInfo(vPortInfo);

            if (storedPortInfo == null)
                throw new Exception(vPortInfo + " not found!");
        
            IList<VRole> oldList = storedPortInfo.GetRoles();

            bool roleListChanged = (roles.Count != oldList.Count ||
                                    roles.Count != roles.Intersect(oldList).Count());
            
            storedPortInfo.SetRoles(roles);

            //update the configuration
            if (roleListChanged)
                config.UpdateRoleList(storedPortInfo);
        }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:24,代码来源:Platform.cs

示例8: ValidateGrammar

        private bool ValidateGrammar(IList<string> terminals, IList<Production> productions)
        {
            var declaredNonTerminals = productions.Select(x => x.ProductionHead).Distinct().ToList();
            var grammarSymbolsInTails = productions.SelectMany(x => x.ProductionTail).Distinct().ToList();

            //check if there are any declared terminals that are used
            //as the head of a production.
            var v = terminals.Intersect(declaredNonTerminals).ToList();
            if(v.Count > 0)
            {
                return false;
            }

            //check if there are any symbols used in a production that are not a terminal
            //and are not the head of some production.
            v = grammarSymbolsInTails.Except(terminals).Except(declaredNonTerminals).ToList();
            if(v.Count > 0)
            {
                return false;
            }

            //check if there are any declared terminals that are not used in any production.
            v = terminals.Except(grammarSymbolsInTails).ToList();
            if(v.Count > 0)
            {
                return false;
            }

            //check that there is only one nonterminal that does not appear in a production
            //this nonterminal is the root of the grammar.
            v = declaredNonTerminals.Except(grammarSymbolsInTails).ToList();
            if(v.Count != 1)
            {
                return false;
            }

            return false;
        }
开发者ID:mattchamb,项目名称:MParse,代码行数:38,代码来源:FileGrammarProvider.cs

示例9: Detect

 /// <summary>
 /// Checks to see if a list of coordinates intersects
 /// with another list of objects
 /// </summary>
 /// <param name="objA">List of coordinates</param>
 /// <param name="objB">List of coordinates to compare with</param>
 /// <returns></returns>
 public static Boolean Detect(IList<Coord> objA, IList<Coord> objB)
 {
     return objA.Intersect(objB).Any();
 }
开发者ID:henningms,项目名称:sneik,代码行数:11,代码来源:CollisionDetector.cs


注:本文中的IList.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。