Beispiel #1
0
        public void CalculateTest(double firstValue, double secondValue, double expected)
        {
            var calculator   = new MultiplicationCalculator();
            var actualResult = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
        public void CalculationAdditionTest(double firstArgument, double secondArgument, double result)
        {
            var calculator   = new MultiplicationCalculator();
            var actualResult = calculator.Calculate(firstArgument, secondArgument);

            Assert.AreEqual(result, actualResult);
        }
        public void CalculateTest()

        {
            ITwoArgumentsCalculator calculator = new MultiplicationCalculator();
            double result = calculator.Calculate(1, 2);

            Assert.AreEqual(2, result);
        }
Beispiel #4
0
        public static float[] CalculateInputSentenceTFIDFVector(string sentence, ProcessedDataset processedDataset, int ngramSize)
        {
            // calculate ngrams for the sentence
            var ngSize         = ngramSize == default ? NGramSize : ngramSize;
            var sentenceNGrams = NGramsController.GetSentenceNGrams(sentence, ngSize);

            // calculate ngrams frequencies
            var sentenceNGramFrequencies = NGramFrequencyController.GetNGramFrequency(sentenceNGrams);

            // calculate TF vector
            var sentenceTFVectorDataset = TFController.CalculateTFVector(sentenceNGramFrequencies, processedDataset.UniqueNGramsVector);

            // calculate TF-IDF vector
            return(MultiplicationCalculator.MultiplyVectorsByCell(sentenceTFVectorDataset, processedDataset.IDFVector));
        }
Beispiel #5
0
        public void ShouldReturnCorrectProductOfNumbers()
        {
            var calculator = new MultiplicationCalculator(new List <int> {
                1, 2, 3
            });
            var actualResult = calculator.Calculate();

            Assert.AreEqual(actualResult, 6);

            calculator = new MultiplicationCalculator(new List <int> {
                7, 11, 24
            });
            actualResult = calculator.Calculate();
            Assert.AreEqual(actualResult, 1848);
        }
Beispiel #6
0
        public static float[][] CalculateInputSenenteceTokensTFIDFMatrix(List <TokenMatchInfo> sentenceTokens, ProcessedDataset processedDataset, int ngramSize)
        {
            // CAN BE MADE MORE EFFICIENT SINCE SOME TOKENS ARE SUBTOKENS OF OTHERS
            // TODO: Implement more efficient solution that makes use of Sub-tokens
            // calculate ngrams for tokens
            var ngSize       = ngramSize == default ? NGramSize : ngramSize;
            var tokensNgrams = NGramsController.GetSentenceNGramsBatch(sentenceTokens, ngSize);

            // calculate N-Gram Frequencies
            var inputTokensNGramFrequencies = NGramFrequencyController.GetNGramFrequencyBatch(tokensNgrams);

            // calculate TF Matrix
            var inputTokensTFMaxtrixDataset = TFController.CalculateTFVectorBatch(inputTokensNGramFrequencies, processedDataset.UniqueNGramsVector);

            // calculate TF-IDF Matrix
            var inputTokensTFIDFMatrixDataset = MultiplicationCalculator.MultiplyVectorsByCellBatch(inputTokensTFMaxtrixDataset, processedDataset.IDFVector);

            return(inputTokensTFIDFMatrixDataset);
        }
Beispiel #7
0
        private ICalculator <float> CreateCalculator(CalculateType calculateType, params float[] values)
        {
            ICalculator <float> ret = null;

            switch (calculateType)
            {
            case CalculateType.Addition:
                ret = new AdditionCalculator <float>(values[0], values[1]);
                break;

            case CalculateType.Subtraction:
                ret = new SubtractionCalculator <float>(values[0], values[1]);
                break;

            case CalculateType.Multiplication:
                ret = new MultiplicationCalculator <float>(values[0], values[1]);
                break;

            case CalculateType.Division:
                ret = new DivisionCalculator <float>(values[0], values[1]);
                break;

            case CalculateType.Power:
                ret = new PowerCalculator <float>(values[0], values[1]);
                break;

            case CalculateType.Sine:
                ret = new SineCalculator <float>(values[0]);
                break;

            case CalculateType.Cosine:
                ret = new CosineCalculator <float>(values[0]);
                break;
            }

            return(ret);
        }
Beispiel #8
0
        public static void CalculateDatasetTFIDFValues(List <string> dataset, out string[] uniqueNGramsVector, out float[] datasetIDFVector, out float[][] datasetTFIDFMatrix, int ngramSize = default)
        {
            // calculate ngrams for each sentence
            var ngSize        = ngramSize == default ? NGramSize : ngramSize;
            var datasetNGrams = NGramsController.GetSentenceNGramsBatch(dataset, ngSize);

            // calculate ngram frequencies
            var ngramFrequencies        = NGramFrequencyController.GetNGramFrequencyBatch(datasetNGrams);
            var overallNgramFrequencies = NGramFrequencyController.GetOverallNGramFrequency(datasetNGrams).GetAwaiter().GetResult();

            // get ngrams feature vector
            uniqueNGramsVector = overallNgramFrequencies.Keys.ToArray();

            // calculate TF
            var datasetTFMatrix = TFController.CalculateTFVectorBatch(ngramFrequencies, uniqueNGramsVector);

            // calculate IDF
            int dataLength = dataset.Count + 1;

            datasetIDFVector = IDFController.CalculateIDFVector(uniqueNGramsVector, overallNgramFrequencies, dataLength);

            // calculate TF-IDF
            datasetTFIDFMatrix = MultiplicationCalculator.MultiplyVectorsByCellBatch(datasetTFMatrix, datasetIDFVector);
        }
        public void MultiplicationCalculatorTest()
        {
            MultiplicationCalculator calculator = new MultiplicationCalculator();

            Assert.AreEqual(20, calculator.Calculate(4, 5));
        }