コード例 #1
0
        /// <summary>
        /// Returns the scores in each tag the provided input
        /// </summary>
        /// <param name="input">Input to be classified</param>
        public Dictionary <TTagType, double> Classify(string input)
        {
            var tokens = _tokenizer.Tokenize(input).ToList();
            var tags   = CreateCacheAnsGetTags();

            var stats = new Dictionary <TTagType, double>();

            foreach (var tag in tags.Items)
            {
                var probs = GetProbabilities(tag.Value, tokens).ToList();
                if (probs.Count() != 0)
                {
                    stats[tag.Key] = _combiner.Combine(probs);
                }
            }
            return(stats.OrderByDescending(s => s.Value).ToDictionary(s => s.Key, pair => pair.Value));
        }
コード例 #2
0
        public T Combine <T>(ICombiner context, T x, T y)
        {
            object combine;

            if (_funcMap.TryGetValue(typeof(T), out combine))
            {
                return(((ChildCombineDefinition <T>)combine)(new Context(_parent, context), x, y));
            }

            return(_parent.Combine(context, x, y));
        }
コード例 #3
0
                public void DoWork(string text)
                {
                    Logger.log(text);

                    var result = Combiner.Combine(text, text + "1");

                    Logger.log("result is " + result);


                    Storage.Save(result);
                    Logger.log("saved " + result);
                }
コード例 #4
0
ファイル: BuildUtils.cs プロジェクト: forki/NConfiguration
 internal static T?RecursiveNullableCombine <T>(Predicate <T?> supressValue, ICombiner combiner, T?x, T?y) where T : struct
 {
     if (supressValue(x))
     {
         return(y);
     }
     if (supressValue(y))
     {
         return(x);
     }
     return(combiner.Combine <T>(x.Value, y.Value));
 }
コード例 #5
0
        public static void IterAlgoBackward <T>(IEnumerable <IVertex <T> > vertexes, ITransferer tr, ICombiner comb)
        {
            bool ok = true;

            while (ok)
            {
                ok = false;
                foreach (var v in vertexes)
                {
                    ok |= v.UpdateOut(tr.Transfer(comb.Combine(v.Next().Select(vv => vv.In())), v));
                }
            }
        }
コード例 #6
0
 private byte[] GenerateChecksum(
     byte[] key,
     byte[] ciphertext,
     byte[] additional)
 {
     return(Utils
            .CreateCounter(this.transformer.BlockSize, key)
            .SelectMany(this.transformer.Transform)
            .Zip(
                combiner.Combine(
                    additional,
                    ciphertext),
                ByteXor)
            .ToArray());
 }
コード例 #7
0
        public void Combine(ICombiner combiner, ImageSourcesConfig other)
        {
            var resultGroups = new List <QualityGroupConfig>();

            var groupsByType      = QualityGroups.ToDictionary(_ => _.Name ?? _.Quality);
            var otherGroupsByType = other.QualityGroups.ToDictionary(_ => _.Name ?? _.Quality);

            foreach ((string name, QualityGroupConfig grp) in otherGroupsByType)
            {
                if (groupsByType.TryGetValue(name, out var group))
                {
                    var combined = combiner.Combine(group, grp);
                    resultGroups.Add(combined);
                }
                else
                {
                    resultGroups.Add(grp);
                }
            }

            QualityGroups = resultGroups.ToArray();
        }
コード例 #8
0
        public void Combine(ICombiner combiner, ImageSourcesConfig other)
        {
            var resultGroups = new List <QualityGroupConfig>();

            var groupsByType      = QualityGroups.ToDictionary(_ => _.Quality);
            var otherGroupsByType = other.QualityGroups.ToDictionary(_ => _.Quality);

            foreach (var entry in otherGroupsByType)
            {
                var otherGroup = entry.Value;

                if (groupsByType.TryGetValue(entry.Key, out var group))
                {
                    var combined = combiner.Combine(group, otherGroup);
                    resultGroups.Add(combined);
                }
                else
                {
                    resultGroups.Add(otherGroup);
                }
            }

            QualityGroups = resultGroups.ToArray();
        }
コード例 #9
0
 /// <summary>
 /// Set custom combiner
 /// </summary>
 /// <typeparam name="T">required type</typeparam>
 /// <param name="combiner">combiner</param>
 public ChildCombiner SetCombiner <T>(ICombiner <T> combiner)
 {
     return(SetCombiner <T>((ctx, prev, next) => combiner.Combine(ctx.Current, prev, next)));
 }
コード例 #10
0
 public static T Combine <T>(this ICombiner combiner, T x, T y)
 {
     return(combiner.Combine <T>(combiner, x, y));
 }
コード例 #11
0
        public void Run()
        {
            try
            {
                if (parent.Context != null)
                {
                    if (parent.Context.NCacheLog.IsInfoEnabled)
                    {
                        parent.Context.NCacheLog.Info("CombinerTask(" + parent.TaskId + ").Start", "Combiner task is started");
                    }
                }

                bool completedSuccessfully = true;
                while (isAlive)
                {
                    try
                    {
                        object currObj = null;
                        lock (CombinerInputQueue)
                        {
                            if (CombinerInputQueue.Count == 0 && isMapperAlive)
                            {
                                Monitor.Wait(CombinerInputQueue);
                            }
                            if (CombinerInputQueue.Count > 0)
                            {
                                currObj = CombinerInputQueue.Dequeue();
                            }
                        }

                        if (currObj != null)
                        {
                            if (currObj.GetType().Equals(typeof(bool)))
                            {
                                bool finalizeChunk = (bool)currObj;
                                if (finalizeChunk)
                                {
                                    FinalizeCombiners();
                                    parent.SendReducerData();

                                    lock (mutex)
                                    {
                                        foreach (ICombiner cc in combiners.Values)
                                        {
                                            cc.Dispose();
                                        }
                                        combiners.Clear();
                                    }
                                }
                            }
                            else
                            {
                                DictionaryEntry entry = (DictionaryEntry)currObj;
                                object          key   = entry.Key;
                                ICombiner       c     = null;
                                lock (mutex)
                                {
                                    if (!combiners.ContainsKey(key))
                                    {
                                        c = combinerFactory.Create(key);
                                        c.BeginCombine();
                                        combiners.Add(key, c);
                                    }
                                    else
                                    {
                                        c = (ICombiner)combiners[key];
                                    }
                                }

                                c.Combine(entry.Value);
                                totalKeysCombined++;
                                if (parent.Context.PerfStatsColl != null)
                                {
                                    parent.Context.PerfStatsColl.IncrementCombinedPerSecRate();
                                }
                            }
                        }
                        else
                        {
                            if (!IsMapperAlive)
                            {
                                FinalizeCombiners();
                                parent.SendReducerData();
                                lock (mutex)
                                {
                                    foreach (ICombiner cc in combiners.Values)
                                    {
                                        cc.Dispose();
                                    }
                                    combiners.Clear();
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (parent.ExceptionCount < parent.MaxExceptions)
                        {
                            if (parent.Context.NCacheLog != null)
                            {
                                parent.Context.NCacheLog.Error("CombinerTask (" + parent.TaskId + ").Run", " Exception: " + ex.Message);
                            }
                            parent.ExceptionCount = parent.ExceptionCount + 1;
                        }
                        else
                        {
                            completedSuccessfully = false;
                            parent.LocalCombinerFailed();
                        }
                    }
                }

                if (completedSuccessfully && isAlive)
                {
                    if (parent.Context.NCacheLog != null)
                    {
                        if (parent.Context.NCacheLog.IsInfoEnabled)
                        {
                            parent.Context.NCacheLog.Info("CombinerTask (" + parent.TaskId + ").Run", "Total Keys Combined : " + totalKeysCombined);
                        }
                    }
                    parent.LocalCombinerCompleted();
                }
            }
            catch (Exception e)
            {
                try
                {
                    parent.LocalCombinerFailed();
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #12
0
 public T Combine <T>(ICombiner combiner, T x, T y)
 {
     return(_combiner.Combine <T>(combiner, x, y));
 }