static void Main()
    {
        InitializeWordsByChar();

        int textLinesCount = int.Parse(Console.ReadLine().ToLower());
        for (int i = 0; i < textLinesCount; i++)
        {
            GetWords(Console.ReadLine().ToLower());
        }

        int wordsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < wordsCount; i++)
        {
            string word = Console.ReadLine();
            string wordLowerCase = word.ToLower();
            HashSet<string> currentWords = new HashSet<string>();
            currentWords.UnionWith(wordsByChar[wordLowerCase[0]]);
            for (int j = 1; j < wordLowerCase.Length; j++)
            {
                currentWords.IntersectWith(wordsByChar[wordLowerCase[j]]);
            }

            Console.WriteLine("{0} -> {1}", word, currentWords.Count);
        }
    }
Example #2
0
        static long searchRtrees(ArrayList words)
        {
            long word_c = 0;

            int ii = 0;
            foreach (String w in words)
            {
                DateTime tt0 = DateTime.Now;
                List<Rectangle> rects = getPoint(w, 1);
                HashSet<string> allwords = new HashSet<string>();
                foreach (string s in words) allwords.Add(s);
                int i = 0;
                foreach (Rectangle r in rects)
                {
                    List<string> objects = rts[i].Intersects(r);
                    i++;
                    HashSet<string> o = new HashSet<string>();
                    foreach (string s in objects) { o.Add(s); }
                    allwords.IntersectWith(o);
                }
                TimeSpan tts1 = DateTime.Now - tt0;
                Console.WriteLine(w + " :" + allwords.Count + " " + tts1);
                word_c += allwords.Count;
                ii++;
                if (ii > 10000) break;
            }
            return word_c;
        }
Example #3
0
		private async void Window_Loaded(object sender, EventArgs e) {
			this.Loaded-=Window_Loaded;
			HashSet<uint> allIds=new HashSet<uint>();
			var selectedIds=new HashSet<uint>(Settings.Default.Channels.Select(c => c.Id));
			Color defaultColor=0x99A2A8.ToColor(); // Retos gadījumos skanošo sarakstā ir kanāls, kuru nerāda ar krāsainām saitēm.
			// Iegūst pamata datus: nosaukumu, īsu aprakstu un identifikatoru.
			foreach (Match match in channelRx.Matches(await client.DownloadStringTaskAsync("http://live.pieci.lv/"))) {
				string idString=match.Groups["id"].Value;
				uint id=idString.Length == 0 ? PieciStation.EmptyId:uint.Parse(idString);
				channels.Add(new ChannelItem(id, match.Groups["caption"].Value, defaultColor,
					match.Groups["description"].Value, match.Groups["name"].Value, selectedIds.Contains(id)));
				allIds.Add(id);
			}
			// Iegūst krāsas. Lielākai daļai kanālu tās ir zināmas (un tāpēc ir iekļautas ikonas), bet dažiem sezonāliem kanāliem nevar paredzēt, tāpēc izgūst no atskaņotāja lapas.
			foreach (Match match in colorRx.Matches(await client.DownloadStringTaskAsync("http://fm.pieci.lv"))) {
				uint id=uint.Parse(match.Groups["id"].Value);
				channels.Single(c => c.Id == id).SetColor(match.Groups["color"].Value);
			}
			list.ItemsSource=channels;

			// Izņem no saraksta zudušos kanālus.
			int beforeCount=selectedIds.Count;
			selectedIds.IntersectWith(allIds);
			HasChanges=beforeCount != selectedIds.Count;
		}
        private double DicesCoeffienct(string in1, string in2)
        {
            HashSet<string> nx = new HashSet<string>();
            HashSet<string> ny = new HashSet<string>();

            for(int i = 0; i < in1.Length - 1; i++)
            {
                char x1 = in1[i];
                char x2 = in1[i + 1];
                string temp = x1.ToString() + x2.ToString();
                nx.Add(temp);
            }
            for(int j = 0; j < in2.Length - 1; j++)
            {
                char y1 = in2[j];
                char y2 = in2[j + 1];
                string temp = y1.ToString() + y2.ToString();
                ny.Add(temp);
            }

            HashSet<string> intersection = new HashSet<string>(nx);
            intersection.IntersectWith(ny);

            double dbOne = intersection.Count;
            return (2 * dbOne) / (nx.Count + ny.Count);
        }
        /// <summary>
        /// Determines whether the interpreter factory contains the specified
        /// modules.
        /// </summary>
        /// <returns>The names of the modules that were found.</returns>
        public static async Task<HashSet<string>> FindModulesAsync(this IPythonInterpreterFactory factory, params string[] moduleNames) {
            var withDb = factory as PythonInterpreterFactoryWithDatabase;
            if (withDb != null && withDb.IsCurrent) {
                var db = withDb.GetCurrentDatabase();
                var set = new HashSet<string>(moduleNames.Where(m => db.GetModule(m) != null));
                return set;
            }

            var expected = new HashSet<string>(moduleNames);

            if (withDb != null) {
                var paths = PythonTypeDatabase.GetCachedDatabaseSearchPaths(withDb.DatabasePath) ??
                    await PythonTypeDatabase.GetUncachedDatabaseSearchPathsAsync(withDb.Configuration.InterpreterPath).ConfigureAwait(false);
                var db = PythonTypeDatabase.GetDatabaseExpectedModules(withDb.Configuration.Version, paths)
                    .SelectMany()
                    .Select(g => g.ModuleName);
                expected.IntersectWith(db);
                return expected;
            }

            return await Task.Run(() => {
                var result = new HashSet<string>();
                foreach (var mp in ModulePath.GetModulesInLib(factory)) {
                    if (expected.Count == 0) {
                        break;
                    }

                    if (expected.Remove(mp.ModuleName)) {
                        result.Add(mp.ModuleName);
                    }
                }
                return result;
            });
        }
Example #6
0
        public static HashSet<char> Intersection(IEnumerable<char> a, IEnumerable<char> b)
        {
            var set = new HashSet<char>(a);
            set.IntersectWith(b);

            return set;
        }
Example #7
0
 static void Main(string[] args)
 {
     var letters = new HashSet<char>("the quick brown fox");
     Console.WriteLine(letters.Contains('t')); // true
     Console.WriteLine(letters.Contains('j')); // false
     foreach (char c in letters)
     {
         Console.Write(c); // the quickbrownfx
     }
     letters.IntersectWith("aeiou");
     foreach (char c in letters)
     {
         Console.Write(c); // euio
     }
     var letters2 = new HashSet<char>("the quick brown fox");
     letters2.ExceptWith("aeiou");
     foreach (char c in letters2)
     {
         Console.Write(c); // th qckbrwnfx
     }
     var letters3 = new HashSet<char>("the quick brown fox");
     letters3.SymmetricExceptWith("the lazy brown fox");
     foreach (char c in letters3)
     {
         Console.Write(c); // quicklazy
     }
 }
        public void IntersectWithNullTest()
        {
            HashSet<string> names = new HashSet<string>();
            names.Add("Pesho");
            names.Add("Gosho");

            names.IntersectWith(null);
        }
Example #9
0
        static void Main()
        {
            #if DEBUG
            Console.SetIn(new System.IO.StreamReader("../../input.txt"));
            #endif

            Dictionary<string, HashSet<string>> words = new Dictionary<string, HashSet<string>>();
            for (char i = 'a'; i <= 'z'; i++)
            {
                words[i.ToString()] = new HashSet<string>();
            }

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine().ToLower();
                input += " ";
                string word = string.Empty;

                for (int j = 0; j < input.Length; j++)
                {
                    if (input[j] >= 'a' && input[j] <= 'z')
                    {
                        word += input[j];
                    }
                    else if(word.Length > 0)
                    {
                        foreach (var w in word)
                        {
                            if (w == 'a')
                            {

                            }
                            words[w.ToString()].Add(word);

                            //words.AddSafeReturn(w, new HashSet<string>()).Add(word);
                        }
                        word = string.Empty;
                    }
                }
            }

            n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                string inputToLower = input.ToLower();
                HashSet<string> result = new HashSet<string>(words[inputToLower[0].ToString()]);

                for (int j = 1; j < inputToLower.Length; j++)
                {
                    result.IntersectWith(words[inputToLower[j].ToString()]);
                }

                Console.WriteLine("{0} -> {1}", input, result.Count);
            }
        }
Example #10
0
 public double GetDistance(string a, string b)
 {
     HashSet<string> seta = new HashSet<string>(StringUtils.GetLuceneTokens(a));
     int na = seta.Count;
     HashSet<string> setb = StringUtils.GetLuceneTokens(b);
     int nb = setb.Count;
     seta.IntersectWith(setb);
     return 1.0d-((double) seta.Count*seta.Count/(na*nb));
 }
        static void Main()
        {
            HashSet<char> firstString = new HashSet<char>(
                Console.ReadLine().ToCharArray());
            HashSet<char> secondString = new HashSet<char>(
                Console.ReadLine().ToCharArray());

            firstString.IntersectWith(secondString);
            Console.WriteLine(firstString.Count > 1 ? "yes" : "no");
        }
Example #12
0
 public double GetDistance(string a, string b)
 {
     List<string> tokensa = new List<string>(StringUtils.GetLuceneTokens(a));
     List<string> tokensb = new List<string>(StringUtils.GetLuceneTokens(b));
     HashSet<string> inter = new HashSet<string>(tokensa);
     inter.IntersectWith(tokensb);
     HashSet<string> union = new HashSet<string>(tokensa);
     union.UnionWith(tokensb);
     return (double) (union.Count-inter.Count);///union.Count;
 }
Example #13
0
 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     d++;
     HashSet<string> delta = new HashSet<string>(expected);
     delta.UnionWith(result);
     HashSet<string> section = new HashSet<string>(expected);
     section.IntersectWith(result);
     delta.ExceptWith(section);
     score += (double) delta.Count;
 }
Example #14
0
 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     HashSet<string> section = new HashSet<string>(result);
     int z = section.Count;
     if(z != 0) {
         d++;
         section.IntersectWith(expected);
         score += (double) section.Count/z;
     }
 }
Example #15
0
 private static HashSet<int> IntersectSets(HashSet<int> set1, HashSet<int> set2)
 {
     HashSet<int> intersection = new HashSet<int>();
     foreach (int element in set1)
     {
         intersection.Add(element);
     }
     intersection.IntersectWith(set2);
     return intersection;
 }
Example #16
0
 public double GetDistance(string a, string b)
 {
     HashSet<string> seta = new HashSet<string>(StringUtils.GetLuceneTokens(a));
     HashSet<string> setb = new HashSet<string>(StringUtils.GetLuceneTokens(b));
     HashSet<string> intersec = new HashSet<string>(seta);
     HashSet<string> union = new HashSet<string>(seta);
     intersec.IntersectWith(setb);
     union.UnionWith(setb);
     return 1.0d-((double) intersec.Count/union.Count);
 }
Example #17
0
 public override bool Equals(object obj)
 {
     UnificationResult otherUnifier = obj as UnificationResult;
       if (otherUnifier == null) return false;
       var substitutionSetOther = new HashSet<Substitution>(otherUnifier.Unifier);
       var subtitutionSetThis = new HashSet<Substitution>(Unifier);
       substitutionSetOther.IntersectWith(subtitutionSetThis);
       return Succeed == otherUnifier.Succeed
     && substitutionSetOther.Count == subtitutionSetThis.Count;
 }
Example #18
0
 public static int Main(string[] args)
 {
     List<List<string>> tags = new List<List<string>>();
     List<string> lines = new List<string>();
     Stream s = File.Open("todos2",FileMode.Open,FileAccess.Read);
     TextReader tr = new StreamReader(s);
     string line = tr.ReadLine();
     string text;
     while(line != null) {
         tags.Add(ParseTags(line,out text));
         lines.Add(text);
         line = tr.ReadLine();
     }
     tr.Close();
     s.Close();
     StringDistanceMetric[] metrics = {new LevenshteinWordDistanceMetric(),new CosineDistanceMetric(),new DiceDistanceMetric(),new JacardDistanceMetric(), new EuclidDistanceMetric()};
     foreach(StringDistanceMetric metric in metrics) {
         double max = double.NegativeInfinity;
         for(int i = 0; i < lines.Count; i++) {
             for(int j = i+1; j < lines.Count; j++) {
                 max = Math.Max((double) metric.GetDistance(lines[i],lines[j]),max);
             }
         }
         s = File.Open("DistanceMetricResults.dat",FileMode.Create,FileAccess.Write);
         TextWriter tw = new StreamWriter(s);
         HashSet<string> xdiff = new HashSet<string>();
         int ndx = 20;
         int ndy = 40;
         int[] vari = new int[ndx+1];
         int[,] chart = new int[ndx+1,ndy+1];
         for(int i = 0; i < lines.Count; i++) {
             for(int j = i+1; j < lines.Count; j++) {
                 xdiff.Clear();
                 xdiff.UnionWith(tags[i]);
                 xdiff.IntersectWith(tags[j]);
                 double xdistance = 2.0d*xdiff.Count/(tags[i].Count+tags[j].Count);
                 double distance = (double) metric.GetDistance(lines[i],lines[j]);
                 chart[(int) Math.Floor(xdistance*ndx),(int) Math.Floor(distance*ndy/max)]++;
                 vari[(int) Math.Floor(xdistance*ndx)]++;
             }
         }
         for(int i = 0; i <= ndx; i++) {
             if(vari[i] == 0) {
                 vari[i] = 1;
             }
             for(int j = 0; j <= ndy; j++) {
                 tw.WriteLine("{0}\t{1}\t{2}",((double) i/ndx).ToString(nfi),((double) j*max/ndy).ToString(nfi),((double) chart[i,j]/vari[i]).ToString(nfi));
             }
             tw.WriteLine();
         }
         tw.Close();
         s.Close();
     }
     return 0;
 }
Example #19
0
		/// <summary>
		/// Gets all the names of the columns common to all tables in a unordered fashion.
		/// </summary>
		/// <returns>The names of all the columns common to all tables in a unordered fashion</returns>
		public HashSet<string> GetCommonColumnNamesUnordered()
		{
			if (_tables.Count == 0)
				return new HashSet<string>();

			// now determine which columns are common to all selected tables.
			var commonColumnNames = new HashSet<string>(_tables[0].DataColumns.GetColumnNames());
			for (int i = 1; i < _tables.Count; i++)
				commonColumnNames.IntersectWith(_tables[i].DataColumns.GetColumnNames());
			return commonColumnNames;
		}
Example #20
0
 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     HashSet<string> section = new HashSet<string>(expected);
     int nx = section.Count;
     List<string> other = new List<string>(result);
     int ny = other.Count;
     section.IntersectWith(result);
     int x = section.Count;
     d++;
     score += (double) 2.0d*x/(nx+ny);
 }
        internal static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Presenting the functionality of the data structure 'Hash set'***");
            Console.Write(decorationLine);

            HashSet<int> years = new HashSet<int>();

            Console.WriteLine("---Add operation---");
            years.Add(1990);
            years.Add(1992);
            years.Add(2013);
            years.Add(2016);
            years.Add(2022);
            Console.WriteLine("Count = " + years.Count);
            Console.WriteLine();

            Console.WriteLine("---Iterator functionality---");
            PrintYears(years);
            Console.WriteLine();

            Console.WriteLine("---Contains operation---");
            Console.WriteLine("Does years set contain {0}? - {1}", 1992, years.Contains(1992));
            Console.WriteLine("Does years set contain {0}? - {1}", 2012, years.Contains(2012));
            Console.WriteLine();

            Console.WriteLine("---Remove operation---");
            Console.WriteLine("Is {0} removed from years set? - {1}", 1996, years.Remove(1996));
            Console.WriteLine("Years set count: " + years.Count);
            Console.WriteLine("Is {0} removed from years set? - {1}", 1990, years.Remove(1990));
            Console.WriteLine("Years set count: " + years.Count);
            Console.WriteLine();

            Console.WriteLine("---UnionWith operation---");
            int[] yearsToUnionWith = new int[] { 2005, 2009, 2021, 2016, 1992, 2013 };
            years.UnionWith(yearsToUnionWith);
            Console.WriteLine("All years after a union with: {0}", string.Join(", ", yearsToUnionWith));
            PrintYears(years);
            Console.WriteLine("Years set count: " + years.Count);
            Console.WriteLine();

            Console.WriteLine("---IntersectWith operation---");
            int[] yearsToIntersectWith = new int[] { 2045, 2025, 2021, 2016, 1999, 2017, 2013 };
            years.IntersectWith(yearsToIntersectWith);
            Console.WriteLine("All years after an intersect with: {0}", string.Join(", ", yearsToIntersectWith));
            PrintYears(years);
            Console.WriteLine("Years set count: " + years.Count);
            Console.WriteLine();

            Console.WriteLine("---Clear operation---");
            years.Clear();
            Console.WriteLine("Years count after clearing: " + years.Count);
        }
Example #22
0
 /**
  * and :
  * Returns new Set of nodes  which is the intersection of the @param predicates results
  * Example let predicate_1 output be  {A,B,C} and predicate_2 output be  {A,D} then the "and" result is {A}
  * @param predicates
  * @return
  */
 public static Predicate and(params Predicate[] predicates)
 {
     return delegate(HashSet<Node> nodes)
         {
             HashSet<Node> result=new HashSet<Node>();
             foreach( Predicate predicate in predicates){
                 result.IntersectWith(predicate(nodes));
             }
             return result;
         } ;
 }
		public void TestIntersectWith ()
		{
			var aSet = new HashSet<int> { 1, 2 };  
			var bSet = new HashSet<int> { 1 };  

			aSet.IntersectWith (bSet);

			Assert.IsTrue (aSet.Contains (1));
			Assert.IsFalse (aSet.Contains (2));
			Assert.AreEqual (1, aSet.Count);
		}
Example #24
0
 public override bool Equals(object other)
 {
     var typedOther = other as TrsLimitStatement;
       if (typedOther == null
     || !typedOther.TypeDefinition.Equals(this.TypeDefinition)) return false;
       var otherVars = new HashSet<TrsVariable>(typedOther.Variables);
       var thisVars = new HashSet<TrsVariable>(this.Variables);
       otherVars.IntersectWith(thisVars);
       if (otherVars.Count != thisVars.Count) return false;
       else return true;
 }
Example #25
0
 public double GetDistance(string a, string b)
 {
     HashSet<string> ta = new HashSet<string>(StringUtils.GetLuceneTokens(a));
     HashSet<string> tb = new HashSet<string>(StringUtils.GetLuceneTokens(b));
     HashSet<string> xor = new HashSet<string>(ta);
     xor.UnionWith(tb);
     HashSet<string> intersec = new HashSet<string>(ta);
     intersec.IntersectWith(tb);
     xor.ExceptWith(intersec);
     return Math.Sqrt(xor.Count);
 }
        private static double ComputeDiceCoefficient(string arg1, string arg2)
        {
            var nx = GetBigramms(arg1);
            var ny = GetBigramms(arg2);

            var intersection = new HashSet<string>(nx);
            intersection.IntersectWith(ny);

            double dbOne = intersection.Count;
            return (2 * dbOne) / (nx.Count + ny.Count);
        }
        private void GuardAgainstFieldOverlap(Entity entity) {

            var entityKeys = new HashSet<string>(entity.Fields.WithOutput().WithoutPrimaryKey().Aliases());
            var processKeys = new HashSet<string>(_process.Entities.SelectMany(e2 => e2.Fields.WithOutput().Aliases()));

            entityKeys.IntersectWith(processKeys);

            if (!entityKeys.Any()) return;

            var count = entityKeys.Count;
            _process.Logger.EntityWarn(entity.Name, "field overlap error in {3}.  The field{1}: {0} {2} already defined in previous entities.  You must alias (rename) these.", string.Join(", ", entityKeys), count.Plural(), count == 1 ? "is" : "are", entity.Alias);
        }
Example #28
0
 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     HashSet<string> section = new HashSet<string>(expected);
     HashSet<string> union = new HashSet<string>(expected);
     union.UnionWith(result);
     int n = union.Count;
     if(n != 0) {
         section.IntersectWith(result);
         score += (double) section.Count/union.Count;
         d++;
     }
 }
        //计算两个List的Jaccard距离
        public static double getJaccardDistance(List<string> source, List<string> target)
        {
            HashSet<string> set1 = new HashSet<string>(source);
            HashSet<string> set2 = new HashSet<string>(target);

            HashSet<string> intersection = new HashSet<string>(set1);
            HashSet<string> union = new HashSet<string>(set1);

            intersection.IntersectWith(set2);
            union.UnionWith(set2);

            return intersection.Count / (double)union.Count;
        }
Example #30
0
		public UnitWithLimitedPrefixes(IUnit unit, IEnumerable<SIPrefix> allowedPrefixes)
		{
			if (null == unit)
				throw new ArgumentNullException("unit must not be null");
			_unit = unit;

			if (null != allowedPrefixes)
			{
				var l = new HashSet<SIPrefix>(_unit.Prefixes);
				l.IntersectWith(allowedPrefixes);
				_prefixes = new SIPrefixList(l);
			}
		}