public TrainModel(FeatureExtractionType eType, int EuclideanCentroidPointIndex, ClassifierType cType)
 {
     this.cType = cType;
     Trained = false;
     if (eType == FeatureExtractionType.EuclideanDistance)
         featureExtraction = new EuclideanDistance(EuclideanCentroidPointIndex);
 }
Ejemplo n.º 2
0
        // todo: parent group or item should be edited outside classifier fields
        private static ICollection <FieldMetadata> GetCommonFields(ClassifierType type)
        {
            if (type.HierarchyType == HierarchyType.Groups)
            {
                return(new List <FieldMetadata>
                {
                    new ClassifierGroupField
                    {
                        Key = "parentUid",
                        Name = "Группа",
                        Required = true,
                        Props = { TypeCode = type.Code, TreeCode = ClassifierTree.DefaultCode }
                    }
                });
            }

            if (type.HierarchyType == HierarchyType.Items)
            {
                return(new List <FieldMetadata>
                {
                    new ClassifierGroupField
                    {
                        Key = "parentUid",
                        Name = "Родительский элемент",
                        Props = { TypeCode = type.Code }
                    },
                });
            }

            return(null);
        }
Ejemplo n.º 3
0
        private async Task <DataView> GetClassifierForm(ClassifierType type, CancellationToken cancellationToken)
        {
            var metadata = await _metadataRepository.Search(new MetadataSearchRequest
            {
                EntityTypeCode = ClassifierType.TypeCode,
                EntityUid      = type.Uid,
                IsActive       = true
            }, cancellationToken);

            var result = new DataView {
                Fields = metadata.Rows
            };

            foreach (var field in result.Fields)
            {
                if (field.System == false)
                {
                    field.Key = FieldKey.FormatFullKey(field.Key);
                }
            }

            var commonFields = GetCommonFields(type);

            if (commonFields != null)
            {
                result.Fields = commonFields.Union(result.Fields).ToArray();
            }

            return(result);
        }
Ejemplo n.º 4
0
        protected override async Task <SearchResult <Classifier> > SearchInternal(DbContext db,
                                                                                  ClassifierType type, ClassifierSearchRequest request, CancellationToken cancellationToken)
        {
            var classifiers = BuildQuery(db, type, request);

            var dbMessageTemplates = db.GetTable <DbMessageTemplate>().AsQueryable();

            var joined = from classifier in classifiers
                         join dbMessageTemplate in dbMessageTemplates on classifier.Uid equals dbMessageTemplate.Uid
                         select new DbItem {
                Classifier = classifier, MessageTemplate = dbMessageTemplate
            };

            // todo: fix paging - map column to expression
            request.SortColumn ??= nameof(Classifier.Code);
            request.SortColumn = nameof(DbItem.Classifier) + "." + request.SortColumn;

            var data = await joined
                       .Apply(request, x => x.Classifier.Code)
                       .Select(x => Materialize(type, x))
                       .Cast <Classifier>()
                       .ToListAsync(cancellationToken);

            return(new SearchResult <Classifier>
            {
                TotalCount = joined.GetTotalCount(request),
                Rows = data
            });
        }
Ejemplo n.º 5
0
        public static ImageClassifier GetClassifier(ClassifierType type)
        {
            string protoTxtPath = string.Empty;
            string mdlBinPath   = string.Empty;

            switch (type)
            {
            case ClassifierType.Resnet:
            {
                protoTxtPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "resnet_nsfw.prototxt");
                mdlBinPath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "resnet_50_1by2_nsfw.caffemodel");
            }
            break;

            case ClassifierType.Squeezenet:
            {
                protoTxtPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "squeezenet_nsfw.prototxt");
                mdlBinPath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "squeezenet_nsfw.caffemodel");
            }
            break;
            }

            var classifier = new ImageClassifier(protoTxtPath, mdlBinPath, type);

            if (classifier.IsEmpty)
            {
                throw new Exception("Classifier shouldn't be empty. Are you model paths correct?");
            }

            return(classifier);
        }
Ejemplo n.º 6
0
 public Classifier_(String name, ClassifierType type)
 {
     this.name = name;
     this.classifierType = type;
     this.methods = new List<Method_>();
     this.fields = new List<Field_>();
 }
Ejemplo n.º 7
0
        protected virtual async Task <ApiResult> UpdateInternal(
            DbContext db, ClassifierType type, ClassifierTree tree, Classifier item, CancellationToken cancellationToken = default)
        {
            var validator = new ClassifierValidator(db, type);

            if (await validator.ValidateUpdate(item, cancellationToken) == false)
            {
                return(new ApiResult {
                    Success = false, Errors = validator.Errors
                });
            }

            var affected = await db.GetTable <DbClassifier>()
                           .Where(x => x.Uid == item.Uid)
                           .Set(x => x.Code, item.Code)
                           .Set(x => x.Name, item.Name)
                           .Set(x => x.ParentUid, type.HierarchyType == HierarchyType.Items ? item.ParentUid : null)
                           .Set(x => x.IsActive, item.IsActive)
                           .UpdateAsync(cancellationToken);

            var result = await UpdateHierarchy(db, type, tree, item, cancellationToken);

            if (result.Success == false)
            {
                return(result);
            }

            return(new ApiResult {
                AffectedRows = affected
            });
        }
 public TrainModel(FeatureExtractionType eType, ClassifierType cType)
 {
     this.cType = cType;
     Trained = false;
     if (eType == FeatureExtractionType.EuclideanDistance)
         featureExtraction = new EuclideanDistance(14);
 }
Ejemplo n.º 9
0
 public static RegisterClassifierType GetDefaultMetadata()
 {
     return(new()
     {
         Item = new ClassifierType
         {
             Code = ClassifierTypeCode.MessageTemplate,
             Name = "Message templates",
             HierarchyType = HierarchyType.Groups,
             IsSystem = true
         },
         Fields = new List <FieldMetadata>
         {
             new TextField {
                 Key = "code", Name = "Code", Required = true, DisplayOrder = 10, System = true
             },
             new TextAreaField {
                 Key = "name", Name = "Name", Required = true, DisplayOrder = 20, System = true, Props = new TextAreaField.Properties {
                     Rows = 5
                 }
             },
             new TextField {
                 Key = "subject", Name = "Subject", DisplayOrder = 30, System = true
             },
             // todo: make markdown/html editor control
             new TextAreaField {
                 Key = "body", Name = "Body", DisplayOrder = 40, System = true, Props = new TextAreaField.Properties {
                     Rows = 40
                 }
             }
         }
     });
 }
Ejemplo n.º 10
0
        protected override async Task <ApiResult> DeleteInternal(DbContext db,
                                                                 ClassifierType type, DeleteClassifier request, CancellationToken cancellationToken = default)
        {
            await db.GetTable <DbNumerator>()
            .Where(x => request.Uids.Contains(x.Uid))
            .DeleteAsync(cancellationToken);

            return(await base.DeleteInternal(db, type, request, cancellationToken));
        }
 public TrainModel(FeatureExtractionType eType, ClassifierType cType)
 {
     this.cType = cType;
     Trained    = false;
     if (eType == FeatureExtractionType.EuclideanDistance)
     {
         featureExtraction = new EuclideanDistance(14);
     }
 }
Ejemplo n.º 12
0
        private static DataView GetClassifierTabs(ClassifierType type)
        {
            var panes = new List <DataPane>
            {
                new() { Key = "info", Name = "Информация", Icon = "profile", Component = "panes/TabEditClassifier" },
                new() { Key = "hierarchy", Name = "Иерархия", Component = "panes/TabEditClassifierHierarchy" },
                new() { Key = "dependencies", Name = "Зависимости" },
                new() { Key = "history", Name = "История изменений", Icon = "eye" }
            };

            // todo: register different tabs for different classifiers on startup
            if (type.Code == "questionnaire")
            {
                panes.Insert(panes.FindIndex(x => x.Key == "info") + 1,
                             new DataPane {
                    Key = "questionnaire", Name = "Вопросы", Component = "panes/PaneSearchMetadata"
                });
            }

            if (type.Code == "numerator")
            {
                panes.Insert(panes.FindIndex(x => x.Key == "info") + 1,
                             new DataPane {
                    Key = "usage", Name = "Использование", Component = "panes/TabEditNumeratorEntities"
                });
            }

            if (type.Code == "role")
            {
                panes.Insert(panes.FindIndex(x => x.Key == "info") + 1,
                             new DataPane {
                    Key = "permissions", Name = "Permissions", Component = "components/tab-edit-role-permissions"
                });
            }

            if (type.Code == "user")
            {
                panes.Insert(panes.FindIndex(x => x.Key == "info") + 1,
                             new DataPane {
                    Key = "roles", Name = "Roles", Icon = "solution", Component = "components/tab-edit-user-roles"
                });
            }

            // todo: move to own module
            if (type.Code == "process")
            {
                panes.Insert(panes.FindIndex(x => x.Key == "info") + 1,
                             new DataPane {
                    Key = "steps", Name = "Шаги", Component = "panes/PaneProcessStepList"
                });
            }

            return(new DataView {
                Panes = panes
            });
        }
Ejemplo n.º 13
0
        public ClosureTableHandler(DbContext db, ClassifierType type)
        {
            if (type.HierarchyType == HierarchyType.None)
            {
                throw new InvalidOperationException($"Hierarchy type {type.HierarchyType} is not suitable to build closure table.");
            }

            _db   = db;
            _type = type;
        }
Ejemplo n.º 14
0
        protected override async Task <ApiResult> DeleteInternal(DbContext db,
                                                                 ClassifierType type, DeleteClassifier request, CancellationToken cancellationToken = default)
        {
            // todo: validate template is not used
            await db.GetTable <DbMessageTemplate>()
            .Where(x => request.Uids.Contains(x.Uid))
            .DeleteAsync(cancellationToken);

            return(await base.DeleteInternal(db, type, request, cancellationToken));
        }
Ejemplo n.º 15
0
        private MessageTemplate Materialize(ClassifierType type, DbItem dbItem)
        {
            var item = base.Materialize(type, dbItem.Classifier);

            var dbMessageTemplate = dbItem.MessageTemplate;

            item.Subject = dbMessageTemplate.Subject;
            item.Body    = dbMessageTemplate.Body;

            return(item);
        }
 public static ClassifierParams Create(ClassifierType type, ClassificationAlgorithmType algorithmType, string targetTag)
 {
     return new ClassifierParams
     {
         Type = type,
         TargetTag = targetTag,
         SamplingParams = new SamplingParams { NeedSampling = false },
         ClassificationAlgorithmParams = new ClassificationAlgorithmParams { Type = algorithmType},
         FeatureSelectionParams = new FeatureSelectionParams {Type = FeatureSelectorType.Unknown }
     };
 }
Ejemplo n.º 17
0
 public DeviceInformation(string serial, MyoPose pose, ClassifierType classifier, byte classifierIndex,
                          bool customClassifier, byte streamIndicating, DeviceType device)
 {
     this.SerialNumber          = serial;
     this.UnlockPose            = pose;
     this.ActiveClassifierType  = classifier;
     this.ActiveClassifierIndex = classifierIndex;
     this.HasCustomClassifier   = customClassifier;
     this.StreamIndicating      = streamIndicating;
     this.Device = device;
 }
Ejemplo n.º 18
0
 private ISentimentClassifier GetClassifier(ClassifierType type)
 {
     switch (type)
     {
         case ClassifierType.MaxEnt:
             return new MaxEntSentimentClassifier();
         case ClassifierType.Alchemy:
             return new AlchemySentimentClassifier();
     }
     return null;
 }
Ejemplo n.º 19
0
		public DeviceInformation (string serial, MyoPose pose, ClassifierType classifier, byte classifierIndex,
		                          bool customClassifier, byte streamIndicating, DeviceType device)
		{
			this.SerialNumber = serial;
			this.UnlockPose = pose;
			this.ActiveClassifierType = classifier;
			this.ActiveClassifierIndex = classifierIndex;
			this.HasCustomClassifier = customClassifier;
			this.StreamIndicating = streamIndicating;
			this.Device = device;
		}
Ejemplo n.º 20
0
        private static async Task <SearchResult <ClassifierGroup> > GetGroupsByFocus(DbContext db,
                                                                                     ClassifierType type, ClassifierTree tree, ClassifierGroupSearchRequest request, CancellationToken cancellationToken)
        {
            // get all parent uids of focused item
            var path = await(
                from focus in db.GetTable <DbClassifierGroup>()
                join closureUp in db.GetTable <DbClassifierClosure>() on focus.Uid equals closureUp.ChildUid
                join item in db.GetTable <DbClassifierGroup>() on closureUp.ParentUid equals item.Uid
                where /*focus.TypeUid == type.Uid &&*/ focus.Uid == request.FocusUid
                orderby closureUp.Level descending
                select item.ParentUid)
                       .ToListAsync(cancellationToken);

            SearchResult <ClassifierGroup> result = null;

            List <ClassifierGroup> currentLevel = null;

            foreach (var parentUid in path)
            {
                if (parentUid == request.ParentUid)
                {
                    // found requested parent, init result and starting level
                    result = new SearchResult <ClassifierGroup>
                    {
                        Rows = currentLevel = new List <ClassifierGroup>()
                    };
                }

                // if current level is not already inited
                if (currentLevel == null)
                {
                    continue;
                }

                // try to move to deeper level...
                if (parentUid.HasValue)
                {
                    var parent = currentLevel.SingleOrDefault(x => x.Uid == parentUid);

                    if (parent != null)
                    {
                        parent.Children = currentLevel = new List <ClassifierGroup>();
                    }
                }

                // ... and load children
                var chldrn = await GetGroupsByParent(db, type, tree, parentUid, request, false);

                currentLevel.AddRange(chldrn.Rows);
            }

            return(result);
        }
Ejemplo n.º 21
0
        private Numerator Materialize(ClassifierType type, DbItem dbItem)
        {
            var item = base.Materialize(type, dbItem.Classifier);

            var dbNumerator = dbItem.Numerator;

            item.EntityTypeCode = dbNumerator.EntityTypeCode;
            item.Periodicity    = Enum.Parse <NumeratorPeriodicity>(dbNumerator.Periodicity);
            item.Pattern        = dbNumerator.Pattern;
            item.KeyTags        = dbNumerator.KeyTags?.Split(DbNumerator.KeyTagsSeparator, StringSplitOptions.RemoveEmptyEntries);

            return(item);
        }
Ejemplo n.º 22
0
        private User Materialize(ClassifierType type, DbItem dbItem)
        {
            var item = base.Materialize(type, dbItem.Classifier);

            var dbUser = dbItem.User;

            item.UserName    = dbUser.UserName;
            item.FirstName   = dbUser.FirstName;
            item.LastName    = dbUser.LastName;
            item.PhoneNumber = dbUser.PhoneNumber;
            item.Email       = dbUser.Email;

            return(item);
        }
Ejemplo n.º 23
0
Archivo: Role.cs Proyecto: montr/montr
 public static RegisterClassifierType GetDefaultMetadata()
 {
     return(new()
     {
         Item = new ClassifierType
         {
             Code = ClassifierTypeCode.Role,
             Name = "Roles",
             HierarchyType = HierarchyType.Groups,
             IsSystem = true
         },
         Fields = ClassifierMetadata.GetDefaultFields().ToList()
     });
 }
Ejemplo n.º 24
0
        public async Task <IList <FieldMetadata> > GetMetadata(ClassifierType type, CancellationToken cancellationToken)
        {
            var metadata = await _fieldMetadataRepository.Search(new MetadataSearchRequest
            {
                EntityTypeCode = ClassifierType.TypeCode,
                EntityUid      = type.Uid,
                // todo: check flags
                // IsSystem = false,
                IsActive   = true,
                SkipPaging = true
            }, cancellationToken);

            return(metadata.Rows);
        }
Ejemplo n.º 25
0
        private async Task <ApiResult> InsertHierarchy(
            DbContext db, ClassifierType type, Classifier item, CancellationToken cancellationToken)
        {
            if (type.HierarchyType == HierarchyType.Groups)
            {
                // todo: validate group belongs to the same classifier
                // todo: validate selected group belong to default tree

                // what if insert classifier and no groups inserted before?

                /*if (request.TreeUid == null || request.ParentUid == null)
                 * {
                 *      throw new InvalidOperationException("Classifier should belong to one of the default hierarchy group.");
                 * }*/

                // todo: should be linked to at least one main group?
                if (/*request.TreeUid != null &&*/ item.ParentUid != null)
                {
                    // link to selected group
                    await db.GetTable <DbClassifierLink>()
                    .Value(x => x.GroupUid, item.ParentUid)
                    .Value(x => x.ItemUid, item.Uid)
                    .InsertAsync(cancellationToken);
                }

                // if group is not of default hierarchy, link to default hierarchy root

                /*var root = await GetRoot(db, request.ParentUid.Value, cancellationToken);
                 *
                 * if (root.Code != ClassifierTree.DefaultCode)
                 * {
                 *      await LinkToDefaultRoot(db, type, itemUid, cancellationToken);
                 * }*/
            }
            else if (type.HierarchyType == HierarchyType.Items)
            {
                var closureTable = new ClosureTableHandler(db, type);

                // ReSharper disable once PossibleInvalidOperationException
                if (await closureTable.Insert(item.Uid.Value, item.ParentUid, cancellationToken) == false)
                {
                    return(new ApiResult {
                        Success = false, Errors = closureTable.Errors
                    });
                }
            }

            return(new ApiResult());
        }
Ejemplo n.º 26
0
 public ClassifierTypeDto(ClassifierType classifierType, bool addClassifiers = true, bool addRelationships = true)
 {
     Code        = classifierType.Code;
     Name        = classifierType.Name;
     Description = classifierType.Description;
     UpdatedBy   = classifierType.UpdatedBy;
     UpdatedOn   = classifierType.UpdatedOn;
     if (addClassifiers)
     {
         foreach (Classifier classifier in classifierType.GetMembers())
         {
             members.Add(new ClassifierDto(classifier, addRelationships));
         }
     }
 }
Ejemplo n.º 27
0
 public KFoldCrossValidation(List <Data> data, int k_fold, ClassifierType cType, FeatureExtractionType fType, int K = 3)
 {
     Kfold      = k_fold;
     this.K     = K;
     this.cType = cType;
     this.fType = fType;
     Data       = data;
     r          = new Random();
     chunckSize = new List <int>(Kfold);
     for (int i = 0; i < Kfold - 1; ++i)
     {
         chunckSize.Add(Data.Count / Kfold);
     }
     chunckSize.Add(Data.Count - ((Kfold - 1) * (Data.Count / Kfold)));
 }
Ejemplo n.º 28
0
 protected T Materialize(ClassifierType type, DbClassifier dbItem)
 {
     return(new T
     {
         Type = type.Code,
         Uid = dbItem.Uid,
         StatusCode = dbItem.StatusCode,
         Code = dbItem.Code,
         Name = dbItem.Name,
         IsActive = dbItem.IsActive,
         IsSystem = dbItem.IsSystem,
         ParentUid = dbItem.ParentUid,
         Url = $"/classifiers/{type.Code}/edit/{dbItem.Uid}"
     });
 }
Ejemplo n.º 29
0
        private void rbClassifier_CheckChanged(object sender, EventArgs e)
        {
            var rb = sender as RadioButton;

            if (rb != null)
            {
                if (rb.Checked)
                {
                    this._LastClassifierType = (ClassifierType)rb.Tag;
                    this.LoadData();

                    this.nudDecisionTreeDepth.Enabled = false;
                    this.nudForestTrees.Enabled       = false;
                    this.nudRepetitions.Enabled       = false;
                    this.nudBoosts.Enabled            = false;
                    this.nudK.Enabled = false;

                    switch (this._LastClassifierType)
                    {
                    case ClassifierType.DecisionTree:
                        this.nudDecisionTreeDepth.Enabled = true;
                        break;

                    case ClassifierType.RandomForest:
                        this.nudDecisionTreeDepth.Enabled = true;
                        this.nudForestTrees.Enabled       = true;
                        this.nudRepetitions.Enabled       = true;
                        break;

                    case ClassifierType.AdaBoostStump:
                        this.nudBoosts.Enabled = true;
                        break;

                    case ClassifierType.AdaBoostTree:
                        this.nudBoosts.Enabled            = true;
                        this.nudDecisionTreeDepth.Enabled = true;
                        break;

                    case ClassifierType.kNN:
                        this.nudK.Enabled = true;
                        break;
                    }

                    Properties.Settings.Default.ClassifierType = (int)rb.Tag;
                    Properties.Settings.Default.Save();
                }
            }
        }
Ejemplo n.º 30
0
        protected override async Task <ApiResult> InsertInternal(DbContext db,
                                                                 ClassifierType type, Classifier item, CancellationToken cancellationToken = default)
        {
            var result = await base.InsertInternal(db, type, item, cancellationToken);

            if (result.Success)
            {
                // var numerator = (Numerator)item;

                await db.GetTable <DbDocumentType>()
                .Value(x => x.Uid, item.Uid)
                .InsertAsync(cancellationToken);
            }

            return(result);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Filter by all parameters except FocusUid
        /// </summary>
        protected virtual async Task <SearchResult <Classifier> > SearchInternal(DbContext db,
                                                                                 ClassifierType type, ClassifierSearchRequest request, CancellationToken cancellationToken)
        {
            var query = BuildQuery(db, type, request);

            var data = await query
                       .Apply(request, x => x.Code)
                       .Select(x => Materialize(type, x))
                       .Cast <Classifier>()
                       .ToListAsync(cancellationToken);

            return(new SearchResult <Classifier>
            {
                TotalCount = query.GetTotalCount(request),
                Rows = data
            });
        }
Ejemplo n.º 32
0
        protected override async Task <ApiResult> UpdateInternal(DbContext db,
                                                                 ClassifierType type, ClassifierTree tree, Classifier item, CancellationToken cancellationToken = default)
        {
            var result = await base.UpdateInternal(db, type, tree, item, cancellationToken);

            /*if (result.Success)
             * {
             *      var numerator = (Numerator)item;
             *
             *      await db.GetTable<DbDocumentType>()
             *              .Where(x => x.Uid == item.Uid)
             *              .Set(x => x.Pattern, numerator.Pattern)
             *              .UpdateAsync(cancellationToken);
             * }*/

            return(result);
        }
Ejemplo n.º 33
0
        public async Task <ApiResult> Register(ClassifierType item, ICollection <FieldMetadata> fields, CancellationToken cancellationToken)
        {
            var type = await _classifierTypeService.TryGet(item.Code, cancellationToken);

            // todo: compare fields of registered classifier and fields from parameters to update them in db
            if (type != null)
            {
                _logger.LogDebug("Classifier type {code} already registered.", item.Code);

                return(new ApiResult {
                    AffectedRows = 0
                });
            }

            // todo: register numerator (get default from settings)

            using (var scope = _unitOfWorkFactory.Create())
            {
                var insertTypeResult = await _classifierTypeService.Insert(item, cancellationToken);

                insertTypeResult.AssertSuccess(() => $"Failed to register classifier type \"{item.Code}\"");

                // todo: throw if empty fields or get default fields?
                if (fields != null)
                {
                    var insertFieldResult = await _metadataService.Insert(new ManageFieldMetadataRequest
                    {
                        EntityTypeCode = ClassifierType.TypeCode,
                        // ReSharper disable once PossibleInvalidOperationException
                        EntityUid = insertTypeResult.Uid.Value,
                        Items     = fields
                    }, cancellationToken);

                    insertFieldResult.AssertSuccess(() => $"Failed to register classifier type \"{item.Code}\"");
                }

                scope.Commit();

                _logger.LogInformation("Classifier type {code} successfully registered.", item.Code);

                return(new ApiResult {
                    AffectedRows = 1, Uid = insertTypeResult.Uid
                });
            }
        }
Ejemplo n.º 34
0
        protected override async Task <SearchResult <Classifier> > SearchInternal(DbContext db,
                                                                                  ClassifierType type, ClassifierSearchRequest request, CancellationToken cancellationToken)
        {
            var classifiers = BuildQuery(db, type, request);

            var numerators = db.GetTable <DbNumerator>().AsQueryable();

            var numeratorRequest = request as NumeratorSearchRequest;

            if (numeratorRequest?.EntityTypeCode != null && numeratorRequest.EntityTypeUid != null)
            {
                var numeratorEntities = db.GetTable <DbNumeratorEntity>().Where(x => x.EntityUid == numeratorRequest.EntityTypeUid);

                if (numeratorRequest.IsAutoNumbering != null)
                {
                    numeratorEntities = numeratorEntities.Where(x => x.IsAutoNumbering == numeratorRequest.IsAutoNumbering);
                }

                numerators = from n in numerators.Where(x => x.EntityTypeCode == numeratorRequest.EntityTypeCode)
                             join ne in numeratorEntities on n.Uid equals ne.NumeratorUid
                             select n;
            }

            var joined = from classifier in classifiers
                         join numerator in numerators on classifier.Uid equals numerator.Uid
                         select new DbItem {
                Classifier = classifier, Numerator = numerator
            };

            // todo: fix paging - map column to expression
            request.SortColumn ??= nameof(Classifier.Code);
            request.SortColumn = nameof(DbItem.Classifier) + "." + request.SortColumn;

            var data = await joined
                       .Apply(request, x => x.Classifier.Code)
                       .Select(x => Materialize(type, x))
                       .Cast <Classifier>()
                       .ToListAsync(cancellationToken);

            return(new SearchResult <Classifier>
            {
                TotalCount = joined.GetTotalCount(request),
                Rows = data
            });
        }
Ejemplo n.º 35
0
        private async Task ValidateDuplicateCode(ClassifierType item, CancellationToken cancellationToken)
        {
            var duplicate = await _db.GetTable <DbClassifierType>()
                            .Where(x => x.Uid != item.Uid && x.Code == item.Code)
                            .FirstOrDefaultAsync(cancellationToken);

            if (duplicate != null)
            {
                Errors.Add(new ApiResultError
                {
                    Key      = "code",
                    Messages = new[]
                    {
                        $"Код «{duplicate.Code}» уже используется в классификаторе «{duplicate.Name}»."
                    }
                });
            }
        }
Ejemplo n.º 36
0
        protected override async Task <ApiResult> UpdateInternal(DbContext db,
                                                                 ClassifierType type, ClassifierTree tree, Classifier item, CancellationToken cancellationToken = default)
        {
            var result = await base.UpdateInternal(db, type, tree, item, cancellationToken);

            if (result.Success)
            {
                var template = (MessageTemplate)item;

                await db.GetTable <DbMessageTemplate>()
                .Where(x => x.Uid == item.Uid)
                .Set(x => x.Subject, template.Subject)
                .Set(x => x.Body, template.Body)
                .UpdateAsync(cancellationToken);
            }

            return(result);
        }
Ejemplo n.º 37
0
 private string GetFileNameFromClassifierType(ClassifierType classifierType)
 {
     string classifierFileName = string.Empty;
     switch (this.ClassifierType)
     {
         case ClassifierType.Eyes:
             classifierFileName = "haarcascade_eye.xml";
             break;
         case ClassifierType.Front:
             classifierFileName = "haarcascade_frontalface_default.xml";
             break;
         case ClassifierType.ProfileFace:
             classifierFileName = "haarcascade_profileface.xml";
             break;
         case ClassifierType.FullBody:
             classifierFileName = "haarcascade_fullbody.xml";
             break;
         case ClassifierType.UpperBody:
             classifierFileName = "haarcascade_upperbody.xml";
             break;
         case ClassifierType.LowerBody:
             classifierFileName = "haarcascade_lowerbody.xml";
             break;
     }
     classifierFileName = System.IO.Path.Combine(this.ClassifierDir.FullName, classifierFileName);
     return classifierFileName;
 }
Ejemplo n.º 38
0
 private void InitClassifiers(ClassifierType classifierType, System.IO.DirectoryInfo classifierDir)
 {
     string faceClassifierFileName = GetFileNameFromClassifierType(classifierType);
     string eyesClassifierFileName = GetFileNameFromClassifierType(ClassifierType.Eyes);
     managedHaarFace = HaarClassifierCascade.Parse(XDocument.Load(faceClassifierFileName));
     managedHaarEyes = HaarClassifierCascade.Parse(XDocument.Load(eyesClassifierFileName));
     unmanagedHaarFace = new HaarCascade(faceClassifierFileName);
     unmanagedHaarEyes = new HaarCascade(eyesClassifierFileName);
 }
Ejemplo n.º 39
0
 public FaceDetector(ClassifierType classifierType, System.IO.DirectoryInfo classifierDir)
 {
     this.classifierType = classifierType;
     this.ClassifierDir = classifierDir;
     InitClassifiers(classifierType, classifierDir);
 }
Ejemplo n.º 40
0
 public JsonResult SetClassifier(ClassifierType type)
 {
     ClassifierType = type;
     return Json(new { });
 }
Ejemplo n.º 41
0
 public static extern IntPtr imaqReadClassifierFile(ref IntPtr session, [MarshalAs(UnmanagedType.LPStr)] string fileName, ReadClassifierFileMode mode, ref ClassifierType type, ref ClassifierEngineType engine, String255 description);
Ejemplo n.º 42
0
 public static extern IntPtr imaqCreateClassifier(ClassifierType type);