public IParser Create(ElementCategory elementType, IEnumerable <IToken> tokens) { return(elementType switch { ElementCategory.Class => new ClassParser(tokens, this), ElementCategory.ClassVariableDeclaration => new ClassVariableDeclarationParser(tokens, this), ElementCategory.AdditionalVariable => new ClassVariableDeclarationParser(tokens, this), ElementCategory.ClassSubroutineDeclaration => new ClassSubroutineDeclarationParser(tokens, this), ElementCategory.Type => new TypeParser(tokens, this), ElementCategory.ParameterList => new ParameterListParser(tokens, this), ElementCategory.SubroutineBody => new SubroutineBodyParser(tokens, this), ElementCategory.ParameterListAdditionalParameter => new ParameterListAdditionalParameterParser(tokens, this), ElementCategory.SubroutineBodyVariableDeclaration => new VariableDeclarationParser(tokens, this), ElementCategory.LetStatement => new LetStatementParser(tokens, this), ElementCategory.IfStatement => new IfStatementParser(tokens, this), ElementCategory.WhileStatement => new WhileStatementParser(tokens, this), ElementCategory.DoStatement => new DoStatementParser(tokens, this), ElementCategory.ReturnStatement => new ReturnStatementParser(tokens, this), ElementCategory.ArrayAccessor => new ArrayAccessorParser(tokens, this), ElementCategory.ElseStatement => new ElseParser(tokens, this), ElementCategory.SubroutineCall => new SubroutineCallParser(tokens, this), ElementCategory.Expression => new ExpressionParser(tokens, this), ElementCategory.Term => new TermParser(tokens, this), ElementCategory.AdditionalExpressionTerm => new AdditionalExpressionParser(tokens, this), ElementCategory.ExpressionList => new ExpressionListParser(tokens, this), ElementCategory.ExpressionListAdditionalElement => new AdditionalExpressionParser(tokens, this), ElementCategory.Statements => new StatementsParser(tokens, this), _ => throw new ArgumentOutOfRangeException(nameof(elementType), elementType, null) });
protected Element(XmlNode node) { this.Name = node.Attributes["name"].Value; this.Category = (ElementCategory)Enum.Parse(typeof(ElementCategory), node.Attributes["category"].Value, true); this.Effectiveness = new Dictionary <Element, decimal>(); this.Immunity = new List <StatusCondition>(); }
internal FunctionalSet(DiscourseFunction func, ElementCategory category, Periphery periphery, params NLGElement[] components) { function = func; this.category = category; this.periphery = periphery; this.components = components.ToList(); }
public Result AddElementCategory(string text, string author, int parentCategoryId) { try { var result = _unitOfWork.ElementCategoryRepository.FindBy(x => x.Name.Trim().ToLower() == text.Trim().ToLower()); if (result.Any()) { return(new Result(ResultStatus.ALREADYEXISTS)); } var model = new ElementCategory { Author = author, Name = text }; if (parentCategoryId != 0) { var categoryResult = _unitOfWork.ElementCategoryRepository.GetById(parentCategoryId); if (categoryResult == null) { return(new Result(ResultStatus.NOT_FOUND)); } model.Parent = categoryResult; } _unitOfWork.ElementCategoryRepository.Add(model); _unitOfWork.SaveChanges(); return(new Result(ResultStatus.OK)); } catch (Exception ex) { return(new Result(ResultStatus.EXCEPTION, ex.Message)); } }
public static void AddProperties(this ElementCategory cate, PropertyValues pvs, VaultAliases vaultAlias, int modelId) { if (cate == null) { return; } var idPV = new PropertyValue { PropertyDef = vaultAlias.PdDict[PD.Id] }; idPV.Value.SetValue(MFDataType.MFDatatypeInteger, cate.Id); pvs.Add(-1, idPV); var namePV = new PropertyValue { PropertyDef = vaultAlias.PdDict[PD.Name] }; namePV.Value.SetValue(MFDataType.MFDatatypeText, cate.Name); pvs.Add(-1, namePV); var modelPV = new PropertyValue { PropertyDef = vaultAlias.PdDict[PD.OwnedModel] }; modelPV.Value.SetValue(MFDataType.MFDatatypeLookup, modelId); pvs.Add(-1, modelPV); }
/** * quick-and-dirty routine for getting morph variants should be replaced by * something better! * * @param word * @return */ private ISet <string> getVariants(WordElement word) { ISet <string> variants = new HashSet <string>(); variants.Add(word.BaseForm); ElementCategory category = word.Category; if (category is LexicalCategory) { switch (((LexicalCategory)category).GetLexicalCategory()) { case LexicalCategory.LexicalCategoryEnum.NOUN: variants.Add(getVariant(word, LexicalFeature.PLURAL, "s")); break; case LexicalCategory.LexicalCategoryEnum.ADJECTIVE: variants.Add(getVariant(word, LexicalFeature.COMPARATIVE, "er")); variants.Add(getVariant(word, LexicalFeature.SUPERLATIVE, "est")); break; case LexicalCategory.LexicalCategoryEnum.VERB: variants.Add(getVariant(word, LexicalFeature.PRESENT3S, "s")); variants.Add(getVariant(word, LexicalFeature.PAST, "ed")); variants.Add(getVariant(word, LexicalFeature.PAST_PARTICIPLE, "ed")); variants.Add(getVariant(word, LexicalFeature.PRESENT_PARTICIPLE, "ing")); break; default: // only base needed for other forms break; } } return(variants); }
public ElementCategory Post(ElementCategory value) { JavaScriptSerializer json_serializer = new JavaScriptSerializer(); var feature = new CategoryCreateFeature(); return(feature.Execute(value)); }
private ElementIcon(ElementCategory category) { resourceQualifier = GetType(); defaultName = string.Join( ExpressionHelper.MemberSeparator, typeof(ElementCategory).FullName, Enum.GetName(typeof(ElementCategory), category)); }
public ElementCategory Execute(ElementCategory elementCategory) { var container = new AppContext(); elementCategory.Id = 1; elementCategory.GuId = Guid.NewGuid(); return(elementCategory); }
protected IElement ParseElement(ElementCategory elementCategory) { var parser = ParserFactory.Create(elementCategory, Tokens); var result = parser.Parse(); Tokens = Tokens.Skip(result.NextTokenIndex); ConsumedTokensCount += result.NextTokenIndex; return(result.Element); }
public void AddElementCategory(ElementCategoryDto elementCategoryDto) { var elementCategory = new ElementCategory { Name = elementCategoryDto.Name }; _quotesDbContext.ElementCategories.Add(elementCategory); _quotesDbContext.SaveChanges(); }
public void AddCategory(string category, string culture) { var key = GetElementCategoryKey(category, culture); var obj = new ElementCategory() { Category = category, Culture = culture }; DataHelper.StoreObject(Site, obj, key, ModelExtensions.LabelCategoryDataType); }
/** * Unwrap word element. * * @param wordElement * the word element * @return the nLG element */ private NLGElement UnwrapWordElement(XmlWordElement wordElement) { NLGElement word = null; if (wordElement != null) { if (true.Equals(wordElement.Canned)) { word = factory.createStringElement(wordElement.Base); } else { LexicalCategory lexCat = new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ANY); ElementCategory cat = UnwrapCategory(wordElement.Cat); if (cat != null && cat is LexicalCategory) { lexCat = (LexicalCategory)cat; } // String baseForm = getBaseWord(wordElement); string baseForm = wordElement.Base; if (!ReferenceEquals(baseForm, null)) { word = factory.createWord(baseForm, lexCat); if (word is InflectedWordElement && ((InflectedWordElement)word).BaseWord.BaseForm.Length == 0) { word = null; // cch TESTING } else if (word is WordElement) { WordElement we = (WordElement)word; // Inflection if (wordElement.Var != null) { Enum.TryParse(wordElement.Var.ToString(), out Inflection defaultInflection); we.setDefaultInflectionalVariant(defaultInflection); } // Spelling variant may have been given as base form in xml. // If so, use that variant. if (!Regex.IsMatch(baseForm, "^" + we.BaseForm + "$")) { we.DefaultSpellingVariant = baseForm; } } } } } return(word); }
public SvgRenderer GetIconRenderer(ElementCategory category) { var categoryIcon = ElementIcon.FromElementCategory(category); if (!TryGetIconRenderer(categoryIcon, out SvgRenderer renderer)) { rendererCache.Add(categoryIcon.Name, renderer); } return(renderer); }
public static FunctionalSet newInstance(DiscourseFunction func, ElementCategory category, Periphery periphery, params NLGElement[] components) { FunctionalSet pair = null; if (components.Length >= 2) { pair = new FunctionalSet(func, category, periphery, components); } return(pair); }
public static PropertyValues UpdateCategory(this ElementCategory cate, VaultAliases vaultAlias, int modelId) { if (cate == null) { return(null); } var pvs = new PropertyValues(); AddProperties(cate, pvs, vaultAlias, modelId); return(pvs); }
/** * This is the main method for performing the morphology. It effectively * examines the lexical category of the element and calls the relevant set * of rules from <code>MorphologyRules</em>. * * @param element * the <code>InflectedWordElement</code> * @return an <code>NLGElement</code> reflecting the correct inflection for * the word. */ private NLGElement doMorphology(InflectedWordElement element) { NLGElement realisedElement = null; if (element.getFeatureAsBoolean(InternalFeature.NON_MORPH)) { realisedElement = new StringElement(element.BaseForm); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); } else { NLGElement baseWord = element.getFeatureAsElement(InternalFeature.BASE_WORD); if (baseWord == null && lexicon != null) { baseWord = lexicon.lookupWord(element.BaseForm); } ElementCategory category = element.Category; if (category is LexicalCategory) { switch (((LexicalCategory)category).GetLexicalCategory()) { case LexicalCategory.LexicalCategoryEnum.PRONOUN: realisedElement = MorphologyRules.doPronounMorphology(element); break; case LexicalCategory.LexicalCategoryEnum.NOUN: realisedElement = MorphologyRules.doNounMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.VERB: realisedElement = MorphologyRules.doVerbMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.ADJECTIVE: realisedElement = MorphologyRules.doAdjectiveMorphology(element, (WordElement)baseWord); break; case LexicalCategory.LexicalCategoryEnum.ADVERB: realisedElement = MorphologyRules.doAdverbMorphology(element, (WordElement)baseWord); break; default: realisedElement = new StringElement(element.BaseForm); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); break; } } } return(realisedElement); }
public JsonResult CreateJson(VmElementCategoryCreate model) { ElementCategory featureResult = null; if (ModelState.IsValid) { HttpResponseMessage response = client.PostAsJsonAsync("api/ElementCategories", model.ElementCategory).GetAwaiter().GetResult(); response.EnsureSuccessStatusCode(); featureResult = response.Content.ReadAsAsync <ElementCategory>().GetAwaiter().GetResult(); } return(Json(featureResult)); }
public void AddCategoriesToBLE(string[] selectedCategories, BucketListElement newBLElement) { if (selectedCategories != null) { foreach (var category in selectedCategories) { var categoryToAdd = new ElementCategory { CategoryID = int.Parse(category) }; newBLElement.ElementCategories.Add(categoryToAdd); } } }
public void CategoryCreateFeatureShouldReturnTrueWhenValidInput() { var createFeature = new CategoryCreateFeature(); ElementCategory elementCategory = new ElementCategory { Name = "testCategory", Description = "test category" }; var result = createFeature.Execute(elementCategory); Assert.IsTrue(result.Id > 0); }
public static ObjVer CreateCategory(this ElementCategory cate, VaultAliases vaultAlias, int modelId, AccessControlList acl) { if (cate == null) { return(null); } var objTypeId = vaultAlias.ObDict[OB.Category]; var classId = vaultAlias.CsDict[CS.Category]; var pvs = new PropertyValues(); AddProperties(cate, pvs, vaultAlias, modelId); return(BaseElementExtensions.CreateBasicObject(objTypeId, classId, pvs, vaultAlias.Vault, acl)); }
public async Task <PartialViewResult> Create(VmElementCategoryCreate model) { ElementCategory featureResult = null; if (ModelState.IsValid) { HttpResponseMessage response = await client.PostAsJsonAsync("api/ElementCategories", model.ElementCategory); response.EnsureSuccessStatusCode(); featureResult = await response.Content.ReadAsAsync <ElementCategory>(); } return(PartialView("CreatePartial", featureResult)); }
protected IElement ParseOptional( Predicate <IToken> predicate, ElementCategory elementCategory, IElement elementToReturnIfPredicateNotSatisfied = null) { if (!predicate(Tokens.FirstOrDefault())) { return(elementToReturnIfPredicateNotSatisfied ?? new VoidElement()); } var parser = ParserFactory.Create(elementCategory, Tokens); var parseResult = parser.Parse(); Tokens = Tokens.Skip(parseResult.NextTokenIndex); ConsumedTokensCount += parseResult.NextTokenIndex; return(parseResult.Element); }
public async Task UpdateBLElementCategoriesAsync(BLContext context, string[] selectedCategories, BucketListElement BLElementToUpdate) { if (selectedCategories == null) { BLElementToUpdate.ElementCategories = new List <ElementCategory>(); return; } //Categories before editing var BLElementCategoriesBeforeEdit = new HashSet <int>(BLElementToUpdate.ElementCategories.Select(ec => ec.Category.CategoryID)); //Categories selected at editing var BLElementCategoriesAfterEdit = new HashSet <string>(selectedCategories); var allCategories = await context.Categories .AsNoTracking() .ToListAsync(); foreach (var category in allCategories) { if (BLElementCategoriesAfterEdit.Contains(category.CategoryID.ToString())) { //Selected categories contain, but old categories don't -> Add if (!BLElementCategoriesBeforeEdit.Contains(category.CategoryID)) { ElementCategory categoryToAdd = new ElementCategory { ElementID = BLElementToUpdate.ElementID, CategoryID = category.CategoryID }; BLElementToUpdate.ElementCategories.Add(categoryToAdd); } } else { //Selected categories don't contain, but old categories do -> Remove if (BLElementCategoriesBeforeEdit.Contains(category.CategoryID)) { ElementCategory categoryToRemove = BLElementToUpdate.ElementCategories.SingleOrDefault(ec => ec.CategoryID == category.CategoryID); BLElementToUpdate.ElementCategories.Remove(categoryToRemove); } } } }
public Result UpdateElementCategory(ElementCategory model) { try { var result = _unitOfWork.ElementCategoryRepository.GetByIdIncluding(model.Id); if (result == null) { return(new Result(ResultStatus.NOT_FOUND)); } _unitOfWork.ElementCategoryRepository.Update(model); _unitOfWork.SaveChanges(); return(new Result(ResultStatus.OK)); } catch (Exception ex) { return(new Result(ResultStatus.EXCEPTION, ex.Message)); } }
public FShellPlaceholderModel(ElementCategory ec) : base(TableEntryType.FShellPlaceholder) { ElementCategory = ec; switch (ec) { case ElementCategory.Lanthanide: _row = 6; Range = "57 - 71"; break; case ElementCategory.Actinide: _row = 7; Range = "89 - 103"; break; default: throw new Exception($"Unexpected category: {ec}"); } }
/** * Unwraps a coordinate phrase. * * @param wps * the <code>simplenlg.xmlrealiser.wrapper.NLGElement</code> * representing the phrase * @return a <code>simplenlg.framework.CoordinatedPhraseElement</code> or * <code>null</code> if the wrapper element is not a coordinate * phrase. */ public virtual NLGElement UnwrapCoordinatePhraseSpec(wrapper.XmlNLGElement wps) { NLGElement ret = null; // CoordinatedPhraseElement if (wps is wrapper.XmlCoordinatedPhraseElement) { wrapper.XmlCoordinatedPhraseElement wp = (wrapper.XmlCoordinatedPhraseElement)wps; CoordinatedPhraseElement cp = new CoordinatedPhraseElement(); ElementCategory cat = UnwrapCategory(wp.Cat); if (cat != null && cat is PhraseCategory) { cp.Category = cat; } if (wp.Conj != null) { string s = wp.Conj; if (!ReferenceEquals(s, null)) { cp.Conjunction = s; } } setCoordinatedPhraseFeatures(wp, cp); foreach (wrapper.XmlNLGElement p in wp.Coord) { NLGElement p1 = UnwrapNLGElement(p); if (p1 != null) { cp.addCoordinate(p1); } } ret = cp; } return(ret); }
/** * Realises a phrase element. * * @param phrase * the element to be realised * @return the realised element. */ private NLGElement realisePhraseElement(PhraseElement phrase) { NLGElement realisedElement = null; if (phrase != null) { ElementCategory category = phrase.Category; if (category is PhraseCategory) { switch (((PhraseCategory)category).GetPhraseCategory()) { case PhraseCategory.PhraseCategoryEnum.CLAUSE: realisedElement = ClauseHelper.realise(this, phrase); break; case PhraseCategory.PhraseCategoryEnum.NOUN_PHRASE: realisedElement = NounPhraseHelper.realise(this, phrase); break; case PhraseCategory.PhraseCategoryEnum.VERB_PHRASE: realisedElement = VerbPhraseHelper.realise(this, phrase); break; case PhraseCategory.PhraseCategoryEnum.PREPOSITIONAL_PHRASE: case PhraseCategory.PhraseCategoryEnum.ADJECTIVE_PHRASE: case PhraseCategory.PhraseCategoryEnum.ADVERB_PHRASE: realisedElement = PhraseHelper.realise(this, phrase); break; default: realisedElement = phrase; break; } } } return(realisedElement); }
public static IList <FunctionalSet> collectFunctionalPairs(NLGElement phrase1, NLGElement phrase2) { IList <NLGElement> children1 = getAllChildren(phrase1); IList <NLGElement> children2 = getAllChildren(phrase2); IList <FunctionalSet> pairs = new List <FunctionalSet>(); if (children1.Count == children2.Count) { Periphery periph = Periphery.LEFT; for (int i = 0; i < children1.Count; i++) { NLGElement child1 = children1[i]; NLGElement child2 = children2[i]; ElementCategory cat1 = child1.Category; ElementCategory cat2 = child2.Category; DiscourseFunction func1 = (DiscourseFunction)child1.getFeature(InternalFeature.DISCOURSE_FUNCTION); DiscourseFunction func2 = (DiscourseFunction)child2.getFeature(InternalFeature.DISCOURSE_FUNCTION); if (cat1 == cat2 && func1 == func2) { pairs.Add(FunctionalSet.newInstance(func1, cat1, periph, child1, child2)); if (cat1 == LexicalCategory.LexicalCategoryEnum.VERB) { periph = Periphery.RIGHT; } } else { pairs.Clear(); break; } } } return(pairs); }
public static ElementIcon FromElementCategory(ElementCategory category) { switch (category) { case ElementCategory.Source: return(Source); case ElementCategory.Condition: return(Condition); case ElementCategory.Transform: return(Transform); case ElementCategory.Sink: return(Sink); case ElementCategory.Nested: return(Nested); case ElementCategory.Property: return(Property); case ElementCategory.Combinator: return(Combinator); case ElementCategory.Workflow: return(Workflow); default: throw new ArgumentException("Invalid category."); } }