public void TestWordNotFound() { WordCount word_counter = new WordCount(getFileReader("word1count1.txt"), getTrie()); word_counter.count(); int count = (word_counter.getDict())["word3"]; }
public void SwapTest() { var structArray = new WordCount[] { new WordCount("abc", 2), new WordCount("bca", 1) }; var expectedArray = new WordCount[] { new WordCount("bca", 1), new WordCount("abc", 2) }; Swap(ref structArray[0], ref structArray[1]); CollectionAssert.AreEqual(expectedArray, structArray); }
public WordCount[] SortByTextNrOfRepetition(string textToSort) { string[] array = textToSort.Split(' '); WordCount[] wordCount = new WordCount[0]; string[] tempArray = new string[0]; while (array.Length > 0) { int count = 1; for (int j = 1; j < array.Length; j++) { if (array[0] == array[j]) count++; else { Array.Resize(ref tempArray, tempArray.Length + 1); tempArray[tempArray.Length - 1] = array[j]; } } Array.Resize(ref wordCount, wordCount.Length + 1); wordCount[wordCount.Length - 1] = new WordCount(array[0], count); array = tempArray; tempArray = new string[0]; } Sort(ref wordCount); return wordCount; }
public override int GetHashCode() { unchecked { var hashCode = 47; hashCode = (hashCode * 53) ^ Id.GetHashCode(); hashCode = (hashCode * 53) ^ ResolvedId.GetHashCode(); if (GivenUrl != null) { hashCode = (hashCode * 53) ^ GivenUrl.GetHashCode(); } if (GivenTitle != null) { hashCode = (hashCode * 53) ^ GivenTitle.GetHashCode(); } hashCode = (hashCode * 53) ^ IsFavorite.GetHashCode(); hashCode = (hashCode * 53) ^ (int)Status; hashCode = (hashCode * 53) ^ TimeAdded.GetHashCode(); hashCode = (hashCode * 53) ^ TimeUpdated.GetHashCode(); hashCode = (hashCode * 53) ^ TimeRead.GetHashCode(); hashCode = (hashCode * 53) ^ TimeFavorited.GetHashCode(); hashCode = (hashCode * 53) ^ TimeSyncDatabaseAdded.GetHashCode(); hashCode = (hashCode * 53) ^ TimeSyncDatabaseUpdated.GetHashCode(); if (ResolvedTitle != null) { hashCode = (hashCode * 53) ^ ResolvedTitle.GetHashCode(); } if (ResolvedUrl != null) { hashCode = (hashCode * 53) ^ ResolvedUrl.GetHashCode(); } if (Excerpt != null) { hashCode = (hashCode * 53) ^ Excerpt.GetHashCode(); } hashCode = (hashCode * 53) ^ IsArticle.GetHashCode(); hashCode = (hashCode * 53) ^ IsIndex.GetHashCode(); hashCode = (hashCode * 53) ^ ImageContent.GetHashCode(); hashCode = (hashCode * 53) ^ VideoContent.GetHashCode(); hashCode = (hashCode * 53) ^ WordCount.GetHashCode(); if (AmpUrl != null) { hashCode = (hashCode * 53) ^ AmpUrl.GetHashCode(); } if (Encoding != null) { hashCode = (hashCode * 53) ^ Encoding.GetHashCode(); } if (MimeType != null) { hashCode = (hashCode * 53) ^ MimeType.GetHashCode(); } if (LeadImage != null) { hashCode = (hashCode * 53) ^ LeadImage.GetHashCode(); } return(hashCode); } }
public override IPoint Read(BinaryReader reader, WordCount origin) { return(new Point() { X = X.Read(reader, origin), Y = Y.Read(reader, origin) }); }
public void Test5() { string[] input = FileIO.ReadLines("../../Tests/test1.in"); var t1 = new WordCount(input); var t2 = new WordCount(input); Assert.IsTrue(t1.WordCountMap.IsEqual(t2.WordCountMap)); }
public void appearsThrice() { WordCount count = new WordCount("Law", "There is no law except the law that there is no law."); int correctCount = 3; int returnCount = count.GetCount(); Assert.AreEqual(correctCount, returnCount); }
public void stringValues3() { WordCount stringKeys3 = new WordCount(); Dictionary <string, int> result3 = stringKeys3.GetCount(new string[] { }); CollectionAssert.AreEquivalent(new Dictionary <string, int> { }, result3); }
public override IShxRecord Read(BinaryReader reader, WordCount origin) { return(new ShxRecord() { ContentLength = ContentLengthField.Read(reader, origin), Offset = OffsetField.Read(reader, origin) }); }
static void Main(string[] args) { var eingabe = UserInteraktion.Bitte_User_um_Eingabe(); var wordCounter = WordCount.Count_words(eingabe); UserInteraktion.Gebe_Ergebnis_aus(wordCounter); }
public void Teste_Count_Words() { WordCount wordCount = new WordCount(); wordCount.Count_Words(); Assert.That(5); }
public void EmptySetTest_ExpectEmptySet() { //Arrange WordCount exercises = new WordCount(); //Assert CollectionAssert.AreEqual(new Dictionary <string, int>(), exercises.GetCount(new string[] { })); }
private static byte[] GenerateEntropy(WordCount wordCount) { var ms = (int)wordCount; if(!CorrectWordCount(ms)) throw new ArgumentException("Word count should be equal to 12,15,18,21 or 24", "wordCount"); int i = Array.IndexOf(msArray, (int)wordCount); return RandomUtils.GetBytes(entArray[i] / 8); }
private void UpdateTotalWordCount(WordCount wordCount, WordCount totalWordCount) { totalWordCount.Segments += wordCount.Segments; totalWordCount.Words += wordCount.Words; totalWordCount.Characters += wordCount.Characters; totalWordCount.Placeables += wordCount.Placeables; totalWordCount.Tags += wordCount.Tags; }
public override IBoundingBox <IPoint> Read(BinaryReader reader, WordCount origin) { return(new BoundingBox <IPoint>() { Min = Min.Read(reader, origin), Max = Max.Read(reader, origin) }); }
private void InitialiseSeed(Wordlist wordlist, WordCount wordCount, string seedPassword = null) { var mneumonic = new Mnemonic(wordlist, wordCount); Seed = mneumonic.DeriveSeed(seedPassword); Words = mneumonic.Words; IsMneumonicValidChecksum = mneumonic.IsValidChecksum; }
/// <summary> /// Appends header specific attributes to <paramref name="attributes"/> dictionary. /// </summary> /// <param name="attributes">Dictionary to append header specific attributes to.</param> internal void AppendHeaderAttributes(Dictionary <string, string> attributes) { attributes.Add("Frame Type", (ushort)TypeID + ": " + TypeID); attributes.Add("Using Phasor File Format", UsePhasorDataFileFormat.ToString()); attributes.Add("Frame Length", FrameLength.ToString()); attributes.Add("Packet Number", PacketNumber.ToString()); attributes.Add("Word Count", WordCount.ToString()); }
public override IMultiPartGeometry <IPointM> Read(BinaryReader reader, WordCount origin) { var box = Box.Read(reader, origin); var numParts = NumParts.Read(reader, origin); var numPoints = NumPoints.Read(reader, origin); var pointStartIndices = new List <int>(); for (var i = 0; i < numParts; i++) { var pointStartIndex = Part(i).Read(reader, origin); pointStartIndices.Add(pointStartIndex); } var parts = new List <IMultiPointGeometry <IPointM> >(); var pointsOffset = OffsetPoints(numParts); for (var i = 0; i < pointStartIndices.Count; i++) { var startIndex = pointStartIndices[i]; var endIndex = (pointStartIndices.Count > (i + 1) ? pointStartIndices[i + 1] : numPoints) - 1; var part = new MultiPointGeometry <IPointM>(); for (var iPointIndex = startIndex; iPointIndex <= endIndex; iPointIndex++) { var point = Point(pointsOffset, numPoints, iPointIndex).Read(reader, origin); part.Points.Add(point); } parts.Add(part); } var minM = MinM(pointsOffset, numPoints).Read(reader, origin); var maxM = MaxM(pointsOffset, numPoints).Read(reader, origin); var boxM = new BoundingBox <IPointM>() { Min = new PointM() { X = box.Min.X, Y = box.Min.Y, M = minM }, Max = new PointM() { X = box.Max.X, Y = box.Max.Y, M = maxM } }; return(new MultiPartGeometry <IPointM>() { Box = boxM, Parts = parts }); }
public override IPointShape <IPoint> Read(BinaryReader reader, WordCount origin) { var point = Point.Read(reader, origin); return(new PointShape() { Point = point }); }
public int CountWords(WordCount wc) { int count; var wordList = new List <string>(); wordList = wc.Input.Split().ToList(); count = wordList.Count(); return(count); }
public void InvalidArgumentsTest() { ICommand command = new WordCount(); var commandResult = command.Execute(null); Assert.IsNotNull(commandResult); Assert.IsTrue(commandResult.Count() == 1); Assert.AreEqual("Invalid arguments", commandResult.First()); }
public ActionResult Result() { string findWord = Request.Form["find-word"]; string inputPhrase = Request.Form["input-phrase"]; WordCount newWordCount = new WordCount(inputPhrase, findWord); int displayCount = newWordCount.RepeatCounter(); return(View("Index", displayCount)); }
//[TestCase("Marry had a little lamb.", 4)] //[TestCase("", 0)] public void Teste_Marry_Erwarte_Erfolg(string eingabe, int erwartetesErgebnis) { Words words = new Words(); StopwordsProvider stopwordsProvider = new StopwordsProvider(); int cntWords = new WordCount().Count_Words(eingabe); Assert.That(cntWords, Is.EqualTo(erwartetesErgebnis)); }
public SyndicationItemWrapper(SyndicationItem si) { Title = si.Title.Text; Link = si.Links.Count > 0 ? si.Links[0].Uri.AbsoluteUri : null; Summary = si.Summary.Text; PublishDate = si.PublishDate.DateTime; _wc = new WordCount(Summary, Model.WordCount.Exclude.Prepositions | Model.WordCount.Exclude.Articles); }
private PointMField Point(WordCount pointsOffset, int numPoints, int pointIndex) { var xyOffset = pointsOffset + (pointIndex * PointField.FieldLength); //MaxM.Offset + MaxM.Length + Nth M Value var mOffset = OffsetMaxM(pointsOffset, numPoints) + DoubleField.FieldLength + (pointIndex * DoubleField.FieldLength); return(new PointMField(xyOffset, mOffset)); }
public void stringValues() { WordCount stringKeys = new WordCount(); Dictionary <string, int> result = stringKeys.GetCount(new string[] { "ba", "ba", "black", "sheep" }); CollectionAssert.AreEquivalent(new Dictionary <string, int> { { "ba", 2 }, { "black", 1 }, { "sheep", 1 } }, result); }
public void stringValues4() { WordCount stringKeys4 = new WordCount(); Dictionary <string, int> result4 = stringKeys4.GetCount(new string[] { "c", "b", "a" }); CollectionAssert.AreEquivalent(new Dictionary <string, int> { { "b", 1 }, { "c", 1 }, { "a", 1 } }, result4); }
public void stringValues2() { WordCount stringKeys2 = new WordCount(); Dictionary <string, int> result2 = stringKeys2.GetCount(new string[] { "a", "b", "a", "c", "b" }); CollectionAssert.AreEquivalent(new Dictionary <string, int> { { "b", 2 }, { "c", 1 }, { "a", 2 } }, result2); }
private PointZField Point(WordCount pointsOffset, int numPoints, int pointIndex) { var xOffset = OffsetX(pointsOffset, pointIndex); var yOffset = xOffset + DoubleField.FieldLength; var zOffset = OffsetZ(pointsOffset, numPoints, pointIndex); var mOffset = OffsetM(pointsOffset, numPoints, pointIndex); return(new PointZField(xOffset, yOffset, zOffset, mOffset)); }
public void TestWordCountGivenNulls() { WordCount testWordCount = new WordCount(); Dictionary <string, int> emptyDict = new Dictionary <string, int>(); string[] emptyArray = null; CollectionAssert.AreEqual(emptyDict, testWordCount.GetCount(emptyArray)); }
public void CountThreeTest() { WordCount output = new WordCount(); Dictionary <string, int> expected = new Dictionary <string, int>() { { "sheep", 3 }, }; CollectionAssert.AreEqual(expected, output.GetCount(new string[] { "sheep", "sheep", "sheep" })); }
public static void Main(string[] args) { var wordCount = new WordCount(); var consoleUi = new ConsoleUi(); var text = consoleUi.GetText(); var numberOfWords = wordCount.CountWordsInText(text); consoleUi.ShowNumberOfWords(numberOfWords); }
public override IPolyLineShape <IPoint> Read(BinaryReader reader, WordCount origin) { var geometry = Geometry.Read(reader, origin); return(new PolyLineShape() { Box = geometry.Box, Lines = geometry.Parts }); }
public void Count_one_word() { var actual = WordCount.CountWords("word"); var expected = new Dictionary <string, int> { ["word"] = 1 }; Assert.Equal(expected, actual); }
private string GetWebpage(string url) { WebClient client = new WebClient(); var myWordCount = new WordCount(); var content = client.DownloadString(url); content += $"THAT'S ALL FOLKS!!!-Quantity:{myWordCount.CountWords(content)}"; return(content); }
public void TestCount2() { WordCount word_counter = new WordCount(getFileReader("word1count2.txt"), getTrie()); word_counter.count(); int actual = (word_counter.getDict())["word1"]; int expected = 2; Assert.AreEqual(expected, actual, "expected :" + expected + " did not match actual :" + actual); }
public void Sort(ref WordCount[] wordCount) { for (int i = 0; i < wordCount.Length; i++) { for (int j = wordCount.Length - 1; j > i; j--) { if (wordCount[i].repetitions < wordCount[j].repetitions) { Swap(ref wordCount[i], ref wordCount[j]); } } } }
public WordsFrequencyViewModel(ISentenceAnalyzerService sentenceAnalyzer) { if (sentenceAnalyzer == null) { throw new ArgumentNullException(nameof(sentenceAnalyzer)); } WordsCount = new WordCount[0]; _sentenceAnalyzer = sentenceAnalyzer; CalculateWordsCommand = new DelegateCommand(OnCalculateWords, OnCanExecuteCalculateWords); PropertyChanged += OnViewModelPropertyChanged; }
public void TestsTheStructCountForTwoElementsWithMoreRepetitions() { var structArray = new WordCount[] { new WordCount("abc", 4), new WordCount("bca", 2) }; CollectionAssert.AreEqual(structArray, SortByTextNrOfRepetition("abc bca abc bca abc abc")); }
public Mnemonic(Wordlist wordList, WordCount wordCount) : this(wordList, GenerateEntropy(wordCount)) { }
public static void Main( string [] args) { bool traceOn = false; //There is a code block about foreach in P14 bool spyOn = false; string file_name = null; //code from p17 string defaultfile = @"wordCount.txt";//N.0204 Console.WriteLine("Beginning WordCount program ... "); //��������жϿ� if (args.Length == 0 ) { display_usage(); return; }else{ foreach ( string option in args ) { if ( option.Equals ( "-t" )) traceOn = true; else if (option.Equals ( "-s" )) spyOn = true; else if (option.Equals ( "-h" )) {display_usage(); return;} else { Console.WriteLine( @"check_valid_file_type( option );" ); file_name = option; } } } /*�������ģ���ж����������е�-t��-s���أ������� if ( traceOn ) Console.WriteLine( "traceOn = true" ); else Console.WriteLine( "traceOn = false" ); if ( spyOn ) Console.WriteLine( "spyOn = true" ); else Console.WriteLine( "spyOn = false" ); */ //transmit filename into processFile //theObj.processFile();����ѡ�ݸ�������������ݸ����캯���ĵȵ��˺����ڿ��� //���������ʽ�Ƚϼ���һ���汾��ʹ�ù��캯�� /* WordCount theObj = new WordCount(); theObj.processFile( file_name ); */ WordCount theObj = new WordCount( file_name, spyOn, traceOn ); //N.0204 if ( theObj.OutFile == null ) theObj.OutFile = defaultfile; theObj.processFile( ); //N.20501 //ʹ��getConsoleInput����ʵ��WC֮index�ĵ��� if ( getConsoleInput() == "q" ) return; Console.WriteLine ( " {0} line(s) match: ", theObj[ getConsoleInput() ] ); Console.WriteLine( "Ending WordCount program ... "); }
static void Main(string[] args) { Console.SetIn(new StreamReader("../../App_Data/gene.counts")); Console.SetOut(new StreamWriter("../../App_Data/gene.counts.out")); /* string line; while ((line = Console.ReadLine()) != null) { if (line != "") { var spts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (spts[1] == "WORDTAG") { //"1 WORDTAG O mind" //_RARE_ O WORDTAG 29683 if (int.Parse(spts[0]) < 5) { Console.WriteLine("{0} WORDTAG {1} _RARE_", spts[0], spts[2]); } else { Console.WriteLine(line); } } } else { Console.WriteLine(line); } } */ List<WordCount> counts = new List<WordCount>(); Dictionary ngrams = new Dictionary(); string line; while ((line = Console.ReadLine()) != null) { if (line != "") { var spts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (spts[1] == "WORDTAG") { //"1 WORDTAG O mind" //_RARE_ O WORDTAG 29683 var wc = counts.FirstOrDefault(p => p.word == spts[3]); if (wc == null) { wc = new WordCount { word = spts[3], cntG = 0, cntO = 0 }; counts.Add(wc); } if (spts[2] == "O") { wc.cntO += int.Parse(spts[0]); } else { wc.cntG += int.Parse(spts[0]); } //counts.AddSafely(string.Format("{1} {0} WORDTAG", spts[2], spts[3]), spts[0]); } else { //749 3-GRAM * * I-GENE //* * O 3-GRAM 13047 ngrams.AddSafely(string.Format("{0} {1}", string.Join(" ", spts.Skip(2)), spts[1]), spts[0]); } } } var words = counts.Where(p => p.sum >= 5); var rareWords = counts.Where(p => p.sum < 5); foreach (var word in words.OrderBy(p => p.word).OrderByDescending(p => p.sum)) { if (word.cntO != 0) { Console.WriteLine(string.Format("{0} O WORDTAG\t{1}", word.word, word.cntO)); } if (word.cntG != 0) { Console.WriteLine(string.Format("{0} I-GENE WORDTAG\t{1}", word.word, word.cntG)); } } var rares = rareWords.GroupBy(p => { if (Regex.IsMatch(p.word, "\\d+")) { return "NUMERIC"; } else if (p.word.ToUpper() == p.word) { return "ALL_CAPITAL"; } else if (p.word.Last().ToString().ToUpper() == p.word.Last().ToString()) { return "LAST_CAPITAL"; } else { return "RARE"; } }); foreach (var rare in rares) { Console.WriteLine(string.Format("_RARE_{0}_ O WORDTAG\t{1}", rare.Key, rare.Sum(p => p.cntO))); Console.WriteLine(string.Format("_RARE_{0}_ I-GENE WORDTAG\t{1}", rare.Key, rare.Sum(p => p.cntG))); } /* Console.WriteLine(string.Format("_RARE_ O WORDTAG\t{0}", rareWords.Sum(p => p.cntO))); Console.WriteLine(string.Format("_RARE_ I-GENE WORDTAG\t{0}", rareWords.Sum(p => p.cntG))); */ foreach (var kvp in ngrams.OrderBy(p => p.Key).OrderByDescending(p => p.Value)) { Console.WriteLine(string.Format("{0}\t{1}", kvp.Key, kvp.Value)); } Console.Out.Close(); }
private void Swap(ref WordCount first, ref WordCount second) { WordCount temp = first; first = second; second = temp; }