Esempio n. 1
0
        public ExpressionResult RunExpression(MathOperator op, string expression)
        {
            long result = 0;
            var  values = tokenizer.Parse(expression);

            switch (op)
            {
            case MathOperator.Add:
                result = math.Add(values.ToArray());
                break;

            case MathOperator.Subtract:
                result = math.Subtract(values.ToArray());
                break;

            case MathOperator.Divide:
                result = math.Divide(values.ToArray());
                break;

            case MathOperator.Multiply:
                result = math.Multiply(values.ToArray());
                break;
            }
            return(new ExpressionResult(result, values.ToArray()));
        }
        public int Indexing(string indexName, IEnumerable <Doc> docs)
        {
            var ngram         = _iNGramRepository.Get(indexName, 1);
            var vocabulary    = _vocabularyRepository.Get(indexName);
            var documentStore = _documentStoreRepository.Get(indexName);
            var reverseIndex  = _searchRespository.Get(indexName, vocabulary);

            foreach (var doc in docs)
            {
                foreach (var field in doc.fields)
                {
                    foreach (var sentence in _tokenizer.Parse(field.value))
                    {
                        var sentenceId = documentStore.Insert(doc.id, sentence.Word);
                        var tokens     = vocabulary.Add(sentence.Tokens);
                        //index sentence
                        ngram.Add(sentence.Tokens);
                        reverseIndex.Index(sentenceId.ToString(), tokens);
                    }
                }
            }
            _iNGramRepository.Set(indexName, ngram);
            _vocabularyRepository.Set(indexName, vocabulary);
            _searchRespository.Set(indexName, reverseIndex);
            return(0);
        }