示例#1
0
        IScorable <IResolver, Binding> IScorableFactory <IResolver, Binding> .ScorableFor(IEnumerable <MethodInfo> methods)
        {
            var specs =
                from method in methods
                from bind in InheritedAttributes.For <MethodBindAttribute>(method)
                select new { method, bind };

            var scorables = from spec in specs
                            select new MethodScorable(spec.method);

            var all = scorables.ToArray().Fold(Binding.ResolutionComparer.Instance);

            return(all);
        }
        IScorable <IResolver, Match> IScorableFactory <IResolver, Match> .ScorableFor(IEnumerable <MethodInfo> methods)
        {
            var specs =
                from method in methods
                from pattern in InheritedAttributes.For <RegexPatternAttribute>(method)
                select new { method, pattern };

            var scorableByMethod = methods.ToDictionary(m => m, m => new MethodScorable(m));

            // for a given regular expression pattern, fold the corresponding method scorables together to enable overload resolution
            var scorables =
                from spec in specs
                group spec by spec.pattern into patterns
                let method                         = patterns.Select(m => scorableByMethod[m.method]).ToArray().Fold(BindingComparer.Instance)
                                         let regex = this.make(patterns.Key.Pattern)
                                                     select new RegexMatchScorable <IBinding, IBinding>(regex, method);

            var all = scorables.ToArray().Fold(MatchComparer.Instance);

            return(all);
        }
示例#3
0
        IScorable <Item, Score> IScorableFactory <Item, Score> .ScorableFor(IEnumerable <MethodInfo> methods)
        {
            var levels = from method in methods
                         // note, this is non-deterministic across executions, which seems lame
                         let defaultOrder = method.Name.GetHashCode()
                                            let attributes = InheritedAttributes.For <ScorableGroupAttribute>(method)
                                                             let orders = attributes.Select(order => order.Order).DefaultIfEmpty(defaultOrder)
                                                                          from order in orders
                                                                          group method by order into g
                                                                          orderby g.Key
                                                                          select g;

            var scorables = from level in levels
                            from factory in this.factories
                            let scorable = factory.ScorableFor(level)
                                           where Scorable.Keep(scorable)
                                           select scorable;

            var winner = scorables.ToArray().Fold(this.comparer, this.onStage);

            return(winner);
        }
示例#4
0
        IScorable <IResolver, IntentRecommendation> IScorableFactory <IResolver, IntentRecommendation> .ScorableFor(IEnumerable <MethodInfo> methods)
        {
            var scorableByMethod = methods.ToDictionary(m => m, m => new MethodScorable(m));

            var specs =
                from method in methods
                from model in InheritedAttributes.For <LuisModelAttribute>(method)
                from intent in InheritedAttributes.For <LuisIntentAttribute>(method)
                select new { method, intent, model };

            // for a given LUIS model and intent, fold the corresponding method scorables together to enable overload resolution
            var scorables =
                from spec in specs
                group spec by new { spec.model, spec.intent } into modelIntents
            let method = modelIntents.Select(m => scorableByMethod[m.method]).ToArray().Fold(Binding.ResolutionComparer.Instance)
                         let service = this.make(modelIntents.Key.model)
                                       select new LuisIntentScorable <Binding, Binding>(service, modelIntents.Key.model, modelIntents.Key.intent, method);

            var all = scorables.ToArray().Fold(IntentComparer.Instance);

            return(all);
        }