private Expression ExecuteProjection(DbProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values, bool isTopLevel)
        {
            okayToDefer &= this.receivingMember != null && this.policy.IsDeferLoaded(this.receivingMember);

            var saveScope = this.scope;
            var reader    = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);

            this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);

            var projector = Expression.Lambda(this.Visit(projection.Projector), reader);

            this.scope = saveScope;

            var entity = EntityFinder.Find(projection.Projector);

            var methExecute = okayToDefer ? nameof(QueryExecutor.ExecuteDeferred) : nameof(QueryExecutor.Execute);

            var result = Expression.Call(this.executor, methExecute, new Type[] { projector.Body.Type }, Expression.Constant(command), projector, Expression.Constant(entity, typeof(MappingEntity)), Expression.NewArrayInit(typeof(object), values)) as Expression;

            if (projection.Aggregator != null)
            {
                result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result);
            }

            return(result);
        }
Esempio n. 2
0
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values)
        {
            okayToDefer &= (this.receivingMember != null && this.policy.IsDeferLoaded(this.receivingMember));

            var saveScope = this.scope;
            ParameterExpression reader = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);

            this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);
            LambdaExpression projector = Expression.Lambda(this.Visit(projection.Projector), reader);

            this.scope = saveScope;

            var entity = EntityFinder.Find(projection.Projector);

            string methExecute = okayToDefer
                ? "ExecuteDeferred"
                : "Execute";

            // call low-level execute directly on supplied DbQueryProvider
            Expression result = Expression.Call(this.executor, methExecute, new Type[] { projector.Body.Type },
                                                Expression.Constant(command),
                                                projector,
                                                Expression.Constant(entity, typeof(MappingEntity)),
                                                Expression.NewArrayInit(typeof(object), values)
                                                );

            if (projection.Aggregator != null)
            {
                // apply aggregator
                result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result);
            }
            return(result);
        }
        protected virtual Expression BuildExecuteBatch(DbBatchExpression batch)
        {
            var operation   = this.Parameterize(batch.Operation.Body);
            var commandText = this.linguist.Format(operation);
            var namedValues = DbNamedValueGatherer.Gather(operation);
            var command     = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));
            var values      = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray() as Expression[];

            var paramSets = Expression.Call
                            (
                typeof(Enumerable), nameof(Enumerable.Select), new Type[] { batch.Operation.Parameters[1].Type, typeof(object[]) },
                batch.Input,
                Expression.Lambda(Expression.NewArrayInit(typeof(object), values), new[] { batch.Operation.Parameters[1] })
                            );

            var plan       = null as Expression;
            var projection = ProjectionFinder.FindProjection(operation);

            if (projection != null)
            {
                var saveScope = this.scope;
                var reader    = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);

                this.scope = new Scope(this.scope, reader, projection.Select.Alias, projection.Select.Columns);

                var projector = Expression.Lambda(this.Visit(projection.Projector), reader);

                this.scope = saveScope;

                var entity = EntityFinder.Find(projection.Projector);

                command = new QueryCommand(command.CommandText, command.Parameters);

                plan = Expression.Call
                       (
                    this.executor, nameof(QueryExecutor.ExecuteBatch), new Type[] { projector.Body.Type },
                    Expression.Constant(command),
                    paramSets,
                    projector,
                    Expression.Constant(entity, typeof(MappingEntity)),
                    batch.BatchSize,
                    batch.Stream
                       );
            }
            else
            {
                plan = Expression.Call
                       (
                    this.executor, nameof(QueryExecutor.ExecuteBatch), null,
                    Expression.Constant(command),
                    paramSets,
                    batch.BatchSize,
                    batch.Stream
                       );
            }

            return(plan);
        }
        private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, QueryCommand command, Expression[] values)
        {
            okayToDefer &= (this.receivingMember != null) && this.policy.IsDeferLoaded(this.receivingMember);
            Scope scope = this.scope;
            ParameterExpression fieldReader = Expression.Parameter(typeof(FieldReader), "r" + this.nReaders++);

            this.scope = new Scope(this.scope, fieldReader, projection.Select.Alias, projection.Select.Columns);
            LambdaExpression expression2 = Expression.Lambda(this.Visit(projection.Projector), new ParameterExpression[] { fieldReader });

            this.scope = scope;
            MappingEntity entity      = EntityFinder.Find(projection.Projector);
            string        methodName  = okayToDefer ? "ExecuteDeferred" : "Execute";
            Expression    replaceWith = Expression.Call(this.executor, methodName, new Type[] { expression2.Body.Type }, new Expression[] { Expression.Constant(command), expression2, Expression.Constant(entity, typeof(MappingEntity)), Expression.NewArrayInit(typeof(object), values) });

            if (projection.Aggregator != null)
            {
                replaceWith = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], replaceWith);
            }
            return(replaceWith);
        }
Esempio n. 5
0
        /// <summary>
        /// Processes the specified text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>The resulting document object.</returns>
        public Document Process(string text)
        {
            var TempText = NormalizerManager.Normalize(text);
            var Tokens   = Tokenizer.Tokenize(TempText, TokenizerLanguage);

            Tokens = NormalizerManager.Normalize(Tokens);
            Tokens = Stemmer.Stem(Tokens, StemmerLanguage);
            Tokens = StopWordsManager.MarkStopWords(Tokens, StopWordsLanguage);

            var Sentences = SentenceDetector.Detect(Tokens, SentenceDetectorLanguage);

            for (int x = 0; x < Sentences.Length; ++x)
            {
                var Sentence = Sentences[x];
                Sentence.Tokens = POSTagger.Tag(Sentence.Tokens, POSTaggerLanguage);
            }
            Tokens    = EntityFinder.Find(Tokens, EntityFinderType);
            Sentences = SentenceDetector.Detect(Tokens, SentenceDetectorLanguage);

            return(new Document(Sentences, Tokens, text, FeatureExtractor, TextSummarizer, Tokenizer, TokenizerLanguage));
        }
Esempio n. 6
0
        protected virtual Expression BuildExecuteBatch(BatchExpression batch)
        {
            // parameterize query
            Expression operation = Parameterize(batch.Operation.Body);

            string commandText = linguist.Format(operation);
            ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(operation);
            var command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType)));

            Expression[] values = namedValues.Select(v => Expression.Convert(Visit(v.Value), typeof(object))).ToArray();

            Expression paramSets = Expression.Call(typeof(Enumerable), "Select", new[] { batch.Operation.Parameters[1].Type, typeof(object[]) }, batch.Input,
                                                   Expression.Lambda(Expression.NewArrayInit(typeof(object), values), new[] { batch.Operation.Parameters[1] }));

            Expression plan = null;

            ProjectionExpression projection = ProjectionFinder.FindProjection(operation);

            if (projection != null)
            {
                Scope saveScope            = scope;
                ParameterExpression reader = Expression.Parameter(typeof(FieldReader), "r" + nReaders++);
                scope = new Scope(scope, reader, projection.Select.Alias, projection.Select.Columns);
                LambdaExpression projector = Expression.Lambda(Visit(projection.Projector), reader);
                scope = saveScope;

                EntryMapping entity = EntityFinder.Find(projection.Projector);
                command = new QueryCommand(command.CommandText, command.Parameters);

                plan = Expression.Call(executor, "ExecuteBatch", new[] { projector.Body.Type }, Expression.Constant(command), paramSets, projector, Expression.Constant(entity, typeof(EntryMapping)),
                                       batch.BatchSize, batch.Stream);
            }
            else
            {
                plan = Expression.Call(executor, "ExecuteBatch", null, Expression.Constant(command), paramSets, batch.BatchSize, batch.Stream);
            }

            return(plan);
        }
        protected virtual Expression BuildExecuteBatch(BatchExpression batch)
        {
            Expression expression  = this.Parameterize(batch.Operation.Body);
            string     commandText = this.linguist.Format(expression);
            ReadOnlyCollection <NamedValueExpression> onlys = NamedValueGatherer.Gather(expression);
            QueryCommand command = new QueryCommand(commandText, from v in onlys select new QueryParameter(v.Name, v.Type, v.QueryType));

            Expression[]         initializers = (from v in onlys select Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray <UnaryExpression>();
            Expression           expression2  = Expression.Call(typeof(Enumerable), "Select", new Type[] { batch.Operation.Parameters[1].Type, typeof(object[]) }, new Expression[] { batch.Input, Expression.Lambda(Expression.NewArrayInit(typeof(object), initializers), new ParameterExpression[] { batch.Operation.Parameters[1] }) });
            ProjectionExpression expression4  = ProjectionFinder.FindProjection(expression);

            if (expression4 != null)
            {
                Scope scope = this.scope;
                ParameterExpression fieldReader = Expression.Parameter(typeof(FieldReader), "r" + this.nReaders++);
                this.scope = new Scope(this.scope, fieldReader, expression4.Select.Alias, expression4.Select.Columns);
                LambdaExpression expression6 = Expression.Lambda(this.Visit(expression4.Projector), new ParameterExpression[] { fieldReader });
                this.scope = scope;
                MappingEntity entity = EntityFinder.Find(expression4.Projector);
                command = new QueryCommand(command.CommandText, command.Parameters);
                return(Expression.Call(this.executor, "ExecuteBatch", new Type[] { expression6.Body.Type }, new Expression[] { Expression.Constant(command), expression2, expression6, Expression.Constant(entity, typeof(MappingEntity)), batch.BatchSize, batch.Stream }));
            }
            return(Expression.Call(this.executor, "ExecuteBatch", (Type[])null, new Expression[] { Expression.Constant(command), expression2, batch.BatchSize, batch.Stream }));
        }