public ActionResult Update(int peopleid, string field, string data)
        {
            var m = new AttributesModel(CurrentDatabase, field, peopleid);

            m.Update(data);
            return(Redirect($"/Person/Attributes/{field}/{peopleid}"));
        }
Exemple #2
0
        private ITerm TryGetPredicate()
        {
            ITerm result = null;

            var verb = AdTree.GetRightSequence().FirstOrDefault(x => AttributesModel.IsVerb(x.Morpheme.Attributes));

            if (verb != null)
            {
                IAdTree predicateAdTree;

                var verbValencies = AttributesModel.GetNumberOfValencies(verb.Morpheme.Attributes);
                if (verbValencies > 0)
                {
                    predicateAdTree = verb.GetSequenceToRoot()
                                      .First(x => x.AdPosition == null || AttributesModel.IsU(x.AdPosition.Morpheme.Attributes))
                                      .MakeDeepCopy();

                    // Remove the subject (i.e. remove the sub-adtree on the first valency)
                    var firstValency = predicateAdTree.GetRightSequence().FirstOrDefault(x => x.Pattern.ValencyPosition == 1);
                    if (firstValency != null)
                    {
                        firstValency.Left = null;
                    }
                }
                else
                {
                    predicateAdTree = verb.MakeDeepCopy();
                    result          = Factory.CreateTerm(verb, StructureAttributes.Term.Predicate);
                }

                result = Factory.CreateTerm(predicateAdTree, StructureAttributes.Term.Predicate);
            }

            return(result);
        }
Exemple #3
0
        private IEnumerable <IClause> TryFindClauses()
        {
            var possibleClauses = AdTree.GetAdTreesInAdTreeOrder().Where(x => AttributesModel.IsU(x.Morpheme.Attributes));

            // If U grammar character is present then there can be multiple clauses.
            if (possibleClauses.Any())
            {
                foreach (var possibleClause in possibleClauses)
                {
                    var isClauseOnRight = Clause.IsClause(possibleClause.Right, AttributesModel);
                    if (isClauseOnRight)
                    {
                        var clauseAdTree = possibleClause.Right.MakeDeepCopy();
                        var clause       = Factory.CreateClause(clauseAdTree, 0);
                        yield return(clause);
                    }

                    var isClauseOnLeft = Clause.IsClause(possibleClause.Left, AttributesModel);
                    if (isClauseOnLeft)
                    {
                        var clauseAdTree = possibleClause.Left.MakeDeepCopy();
                        var clause       = Factory.CreateClause(clauseAdTree, 0);
                        yield return(clause);
                    }
                }
            }
            else
            {
                if (Clause.IsClause(AdTree, AttributesModel))
                {
                    var clause = Factory.CreateClause(AdTree, StructureAttributes.Sentence.SimpleSentence);
                    yield return(clause);
                }
            }
        }
Exemple #4
0
        public void IsValid_EqualValue()
        {
            AttributesModel   model   = new AttributesModel();
            ValidationContext context = new ValidationContext(model);

            Assert.Null(attribute.GetValidationResult(model.Sum, context));
        }
        public void IsValid_OnNotEqualValuesReturnsValidationResult()
        {
            AttributesModel model = new AttributesModel { Total = 10 };
            ValidationContext context = new ValidationContext(model);

            ValidationResult expected = new ValidationResult(attribute.FormatErrorMessage(context.DisplayName));
            ValidationResult actual = attribute.GetValidationResult(model.Sum, context);

            Assert.Equal(expected.ErrorMessage, actual.ErrorMessage);
        }
        private IEnumerable <WordConstruct> FindPossibleWordConstructions(
            string word,
            int morphDistance,
            List <Morpheme> localSequence)
        {
            using (Trace.Entering())
            {
                // Find if the word is a lexeme.
                IEnumerable <Morpheme> lexemes = FindLexemes(word, morphDistance);
                foreach (Morpheme lexeme in lexemes)
                {
                    localSequence.Add(lexeme);
                    var wordConstruct = new WordConstruct(localSequence.ToList());
                    yield return(wordConstruct);

                    localSequence.RemoveAt(localSequence.Count - 1);
                }

                // Find if the word is a lexeme with suffixes.
                IEnumerable <IReadOnlyList <Morpheme> > wordSuffixes = FindLexemeAndItsSuffixes(word, morphDistance, new List <Morpheme>());
                foreach (IReadOnlyList <Morpheme> sequence in wordSuffixes)
                {
                    var wordConstruct = new WordConstruct(localSequence.Concat(sequence.Reverse()).ToList());
                    yield return(wordConstruct);
                }

                // Find if the word is a lexeme with prefixes and suffixes.
                for (int i = 1; i < word.Length; ++i)
                {
                    string nonLexeme = word.Substring(0, i);
                    IEnumerable <Morpheme> prefixHomonyms = FindNonLexemes(nonLexeme)
                                                            .Where(x => AttributesModel.IsPrefix(x.Attributes));
                    if (prefixHomonyms.Any())
                    {
                        string newWord = word.Substring(i);

                        foreach (Morpheme prefix in prefixHomonyms)
                        {
                            localSequence.Add(prefix);

                            // Try if there are sub-prefixes.
                            IEnumerable <WordConstruct> sequences = FindPossibleWordConstructions(newWord, morphDistance, localSequence);
                            foreach (var sequence in sequences)
                            {
                                var wordConstruct = new WordConstruct(sequence.Morphemes.ToList());
                                yield return(wordConstruct);
                            }

                            localSequence.RemoveAt(localSequence.Count - 1);
                        }
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// get the initial view for the attributes importer
        /// </summary>
        /// <returns></returns>
        public ActionResult AttributesImporter()
        {
            //create the initial model
            var model = new AttributesModel();

            //prefill the model with dropdown items
            PrepareAttributesModel(model);

            //return the view with the model
            return(View(model));
        }
Exemple #8
0
        public void IsValid_NotEqualValueMessage()
        {
            AttributesModel model = new AttributesModel {
                Total = 10
            };
            ValidationContext context = new ValidationContext(model);

            String expected = String.Format(Validations.EqualTo, context.DisplayName, "Total");
            String actual   = attribute.GetValidationResult(model.Sum, context).ErrorMessage;

            Assert.Equal(expected, actual);
        }
        public void IsValid_SetsOtherPropertyDisplayName()
        {
            AttributesModel model = new AttributesModel { Total = 10 };
            ValidationContext context = new ValidationContext(model);

            attribute.GetValidationResult(model.Sum, context);

            String expected = ResourceProvider.GetPropertyTitle(context.ObjectType, attribute.OtherPropertyName);
            String actual = attribute.OtherPropertyDisplayName;

            Assert.Equal(expected, actual);
        }
Exemple #10
0
        public ActionResult Attributes()
        {
            ViewBag.ActiveLeftBarItem = "attributes";
            FullBreadcrumb.Add("Home|Board/Index");
            FullBreadcrumb.Add("Atributos|Board/Attributes");
            BuildFastBreadCrumb(FullBreadcrumb, 1);

            ViewBag.Title = "Atributos";
            var model = new AttributesModel();

            model.Attributes = db.attributes.ToList();

            return(View(model));
        }
Exemple #11
0
        public ActionResult UpdateAttribute(int id)
        {
            ViewBag.Title             = "Editar atributo";
            ViewBag.ActiveLeftBarItem = "attributes";
            var model = new AttributesModel();

            model.Attribute = db.attributes.FirstOrDefault(x => x.ID == id);

            FullBreadcrumb.Add("Home|Board/Index");
            FullBreadcrumb.Add("Atributos|Board/Attributes");
            FullBreadcrumb.Add("Editar atributo " + model.Attribute.NAME + "|Board/UpdateAttribute/" + id);
            BuildFastBreadCrumb(FullBreadcrumb, 1);

            return(View(model));
        }
        private IEnumerable <IReadOnlyList <Morpheme> > FindLexemeAndItsSuffixes(
            string word,
            int morphDistance,
            List <Morpheme> localSequence)
        {
            using (Trace.Entering())
            {
                // If there is some suffix.
                if (localSequence.Count > 0)
                {
                    // If the word is a lexeme.
                    IEnumerable <Morpheme> lexemes = FindLexemes(word, morphDistance);
                    foreach (Morpheme lexeme in lexemes)
                    {
                        localSequence.Add(lexeme);
                        yield return(localSequence.ToList());

                        localSequence.RemoveAt(localSequence.Count - 1);
                    }
                }

                // Try to find suffixes in the word.
                for (int i = word.Length - 1; i > 0; --i)
                {
                    string nonLexeme = word.Substring(i);
                    IEnumerable <Morpheme> suffixes = FindNonLexemes(nonLexeme)
                                                      .Where(x => AttributesModel.IsSuffix(x.Attributes));
                    if (suffixes.Any())
                    {
                        string newWord = word.Substring(0, i);

                        foreach (Morpheme sufix in suffixes)
                        {
                            localSequence.Add(sufix);

                            IEnumerable <IReadOnlyList <Morpheme> > sequences = FindLexemeAndItsSuffixes(newWord, morphDistance, localSequence);
                            foreach (IReadOnlyList <Morpheme> sequence in sequences)
                            {
                                yield return(sequence);
                            }

                            localSequence.RemoveAt(localSequence.Count - 1);
                        }
                    }
                }
            }
        }
Exemple #13
0
        public ActionResult GetModule(int id)
        {
            ViewBag.RefModule = Guid.NewGuid();
            if (id == 1)
            {
                return(PartialView("~/Views/Board/Modules/Create/_Content.cshtml"));
            }
            else if (id == 2)
            {
                var Model = new AttributesModel();
                Model.Attributes = db.attributes.ToList();

                return(PartialView("~/Views/Board/Modules/Create/_Room.cshtml", Model));
            }
            else
            {
                return(PartialView("~/Views/Board/Modules/Create/_Gallery.cshtml"));
            }
        }
Exemple #14
0
        private ITerm TryGetSubject()
        {
            ITerm result = null;

            var verb = AdTree.RightChildren?.FirstOrDefault(x => AttributesModel.IsVerb(x.Morpheme.Attributes));

            if (verb != null)
            {
                var valencies = AttributesModel.GetNumberOfValencies(verb.Morpheme.Attributes);
                if (valencies >= 1)
                {
                    var valency1 = verb.GetSequenceToRoot().FirstOrDefault(x => x.Pattern.ValencyPosition == 1);
                    if (valency1?.Left != null)
                    {
                        var subjectAdTree = valency1.Left.MakeDeepCopy();
                        result = Factory.CreateTerm(subjectAdTree, StructureAttributes.Term.Subject);
                    }
                }
            }

            return(result);
        }
Exemple #15
0
        public AttributesModel PrepareAttributesModel(AttributesModel model)
        {
            //get the database to use
            var database = Sitecore.Configuration.Factory.GetDatabase("master");

            //get the settings item id
            var atdwSettingsItemId          = _standardHelper.GetItemIdFromConfig("ATDWSettingsItemID");
            var atdwAttributeTypeTemplateId = _standardHelper.GetTemplateIdFromConfig("ATDWAttributeParentTemplateID");

            if (atdwSettingsItemId != ID.Null)
            {
                var atdwSettingsItem = database.GetItem(atdwSettingsItemId);
                if (atdwSettingsItem != null)
                {
                    //get the attribute types list from the settings children
                    var attributeTypesList = atdwSettingsItem.Children
                                             .Where(item => item.TemplateID == atdwAttributeTypeTemplateId).ToList();
                    //check if we have any types
                    if (attributeTypesList.Any())
                    {
                        // add these to our select list
                        foreach (var attributeType in attributeTypesList)
                        {
                            model.AttributeTypesAvailable.Add(
                                new SelectListItem
                            {
                                Text  = attributeType.Name,
                                Value = attributeType.Fields["AttributeTypeId"].ToString()
                            }
                                );
                        }
                    }
                }
            }

            return(model);
        }
        public ActionResult Edit(int pid, string field)
        {
            var m = new AttributesModel(CurrentDatabase, field, pid);

            return(View(m));
        }
Exemple #17
0
        public async Task <ViewResult> AttributesImporter(string attributeType, AttributesModel model)
        {
            //create a the counter for the imported attributes
            var attributeCounter = 0;

            //check if we have a selected attribute type
            if (string.IsNullOrWhiteSpace(model.SelectedAttributeType))
            {
                //prefill the model with dropdown items
                PrepareAttributesModel(model);
                model.ErrorMessage = "Please select the attribute type to import";
                return(View(model));
            }

            //get the selected attribute type
            var selectedAttributeType = model.SelectedAttributeType;

            //create the http client to request the json with
            var httpClient = new HttpClient();

            //create the initial response attributes
            IEnumerable <AttributesJsonModel> responseAttributes;

            // create the api response
            var response =
                await httpClient.GetAsync(
                    "http://atlas.atdw-online.com.au/api/atlas/attributes?key=996325374125&types=" + selectedAttributeType + "&out=json");

            //check if we get a successs status back
            if (response.IsSuccessStatusCode)
            {
                //trya and read the contents and convert them into a json object
                try
                {
                    var responseStream = response.Content.ReadAsStringAsync();
                    //assign the json response to our attributes model
                    responseAttributes = JsonConvert
                                         .DeserializeObject <IEnumerable <AttributesJsonModel> >(responseStream.Result).ToList();
                }
                catch (Exception ex)
                {
                    //catch the error
                    //prefill the model with dropdown items
                    PrepareAttributesModel(model);
                    model.ErrorMessage = "There was an error reading the data from ATDW, please try again, see :" + ex.Message;
                    return(View(model));
                }
            }
            else
            {
                //get the response status code
                var errorStatusCode = response.StatusCode;
                var responseError   = errorStatusCode.ToString();

                PrepareAttributesModel(model);
                model.ErrorMessage = "There was an error reading the data from ATDW, please try again, see :" + responseError;
                return(View(model));
            }

            //now get the attributes from the model
            if (responseAttributes.Any())
            {
                //get the attribute templates to use late
                var atdwSettingsItemId            = _standardHelper.GetItemIdFromConfig("ATDWSettingsItemID");
                var atdwAttributeTemplateId       = _standardHelper.GetTemplateIdFromConfig("ATDWAttributeTemplateID");
                var atdwAttributeParentTemplateId =
                    _standardHelper.GetTemplateIdFromConfig("ATDWAttributeParentTemplateID");

                //check if the templates are valid
                if (atdwAttributeTemplateId.ID != ID.Null && atdwAttributeParentTemplateId.ID != ID.Null)
                {
                    var database = Sitecore.Configuration.Factory.GetDatabase("master");
                    //get the atdw settings item to look for the parent with
                    var atdwSettingsItem = database.GetItem(atdwSettingsItemId);
                    if (atdwSettingsItem != null)
                    {
                        var atdwAttributeParentItem = atdwSettingsItem.Children
                                                      .FirstOrDefault(item => item["AttributeTypeId"].ToString() == selectedAttributeType &&
                                                                      item.TemplateID == atdwAttributeParentTemplateId);

                        //check if the parent to insert on is not null
                        if (atdwAttributeParentItem != null)
                        {
                            var attributeTemplateId = new TemplateID(atdwAttributeTemplateId);
                            // use the security disabler to creae or update items
                            using (new SecurityDisabler())
                            {
                                //go through the attributes to add
                                foreach (var attributeTypeItem in responseAttributes)
                                {
                                    try
                                    {
                                        //initiate the editing
                                        atdwAttributeParentItem.Editing.BeginEdit();
                                        // fill in the parents type and description
                                        atdwAttributeParentItem["AttributeTypeId"] = attributeTypeItem.AttributeTypeId;
                                        atdwAttributeParentItem["Description"]     = attributeTypeItem.Description;
                                        //terminate the editing
                                        atdwAttributeParentItem.Editing.EndEdit();

                                        //get the attribute items from the parent
                                        if (attributeTypeItem.Attributes.Any())
                                        {
                                            foreach (var attribute in attributeTypeItem.Attributes)
                                            {
                                                //check if the parent doesnt alread have the attribute
                                                var attributeCode = attribute.AttributeId;
                                                var hasAttribute  = atdwAttributeParentItem.Children
                                                                    .Any(attributeItem => attributeItem.Fields["Attribute-Id"].Value ==
                                                                         attributeCode);
                                                if (!hasAttribute)
                                                {
                                                    //get a valid name from the description
                                                    var name = ItemUtil.ProposeValidItemName(attribute.Description);
                                                    //create the new attribute to add
                                                    Item attributeItem =
                                                        atdwAttributeParentItem.Add(name, attributeTemplateId);

                                                    //initiate the editing
                                                    attributeItem.Editing.BeginEdit();
                                                    // fill in the attribute properties
                                                    attributeItem["Attribute-Type-Id"] =
                                                        attributeTypeItem.AttributeTypeId;
                                                    attributeItem["Attribute-Id"]          = attribute.AttributeId;
                                                    attributeItem["Attribute-Description"] = attribute.Description;
                                                    attributeItem["Attribute-ATDW-Id"]     = attribute.AttributeId;
                                                    //initiate the editing
                                                    attributeItem.Editing.EndEdit();
                                                    attributeCounter++;
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        atdwAttributeParentItem.Editing.CancelEdit();
                                        //prefill the model with dropdown items
                                        PrepareAttributesModel(model);
                                        model.ErrorMessage = "There was an error reading the data from ATDW, please try again, see :" + ex.Message;
                                        return(View(model));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            PrepareAttributesModel(model);
            model.SuccessMessage = attributeCounter + " attributes for the type: " + model.SelectedAttributeType +
                                   " have been imported successfully";
            return(View(model));
        }