Esempio n. 1
0
		public SemanticRule(Notion.INameBase subOut, Notion.INameBase subIn, IReadOnlyCollection<Notion.INameBase> antecedents, IReadOnlyCollection<Notion.INameBase> corollaries)
		{
			this.SubOut = subOut;
			this.SubIn = subIn;
			this.Antecedents = antecedents;
			this.Corollaries = corollaries;
		}
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description,LastUpdated,MinThreshold,Quantity,Title")] Notion notion)
        {
            var user = _userManger.GetUserName(HttpContext.User);

            notion.LastUpdated = DateTime.Now;
            if (id != notion.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(notion);
                    await _context.SaveChangesAsync();

                    logger.Info(user + " edited " + notion.Title + " Quantity to: " + notion.Quantity);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NotionExists(notion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(notion));
        }
Esempio n. 3
0
        /// <summary>
        /// Проверка совпадения ответа с верным ответом
        /// </summary>
        /// <param name="answer">Ответ игрока</param>
        /// <param name="rightAnswer">Верный ответ</param>
        /// <returns></returns>
        internal static bool IsAnswerRight(string answer, string rightAnswer)
        {
            var res  = Notion.AnswerValidatingCommon2(answer.NotDigitPart(), rightAnswer.NotDigitPart());
            var res2 = Notion.AnswerValidatingCommon2(answer.DigitPart(), rightAnswer.DigitPart());

            return(res > 0.81 && res2 > 0.99);
        }
Esempio n. 4
0
		public override bool Contains(Notion element, Set set)
		{
			//an element e could be found to be in some set S 
			//-   if the set that contains e is a (proper) subset of S
			//-   if e is known to be in S by an enumeration rule

			return set.Supersets(element.Domain) || enumerationRelations.Contains(element, set);
		}
Esempio n. 5
0
		public override void Append(Notion element, Set set)
		{
			Contract.Requires(element != null);
			Contract.Requires(set != null);
			Contract.Requires(set.IsAppendable);
			Contract.Requires(set.IsConstant, "You can only append elements to constant sets");

			enumerationRelations.Append(element, set);
		}
Esempio n. 6
0
		public static void InitializeDefaultSemanticRules()
		{
			//constructs the following expression: Booleans = { True, False }
			var notions = new Notion[] { Booleans, EqualityOperator, SetBuilderOpeningBraces, True, SetBuilderEnumerationDelimiters, False, SetBuilderClosingBraces };
			var names = notions.Select(GetDefaultName).ToReadOnlyList();
			var expression = new CompositeName(names, RootPosition.Instance, Booleans);

			//states that that expression is true
			new SemanticRule2(True.GetDefaultName(), expression, null, null);
		}
Esempio n. 7
0
 public static Concept ConceptNetGetConcept(Memory memory, Verbs verbs, Notion notion, Concept.Kind kind)
 {
     if (kind == Concept.Kind.Event)
     {
         return(memory.NewConcept(verbs.InputToBase(notion.Canonical), kind));
     }
     else
     {
         return(memory.NewConcept(notion.Canonical, kind));
     }
 }
Esempio n. 8
0
			public void Apply(Notion applicant, string description = null)
			{
				Contract.Requires(applicant != null);
				Contract.Requires(notionsUnderConversionToLinear.ContainsKey(applicant));
				Contract.Requires(Associativity != defaultAssociativity);
				Contract.Requires(PrecedenceComparisonToken != defaultPrecedenceToken);
				Contract.Requires(DomainKind != defaultDomainKind);
				Contract.Requires(IsApplicable);

				applicant.ExtendDomain(LinearSet.From(applicant.Domain, DomainKind, Associativity, PrecedenceComparisonToken, description));
				notionsUnderConversionToLinear.Remove(applicant);
			}
Esempio n. 9
0
		public void SetRelationsTest1()
		{
			SetRelations relations = new SetRelations();

			Set s1 = new Set(workspace, "1", false);
			Notion n1 = new Notion(s1, "1", true);

			relations.Add(s1);

			Contract.Assert(relations.Subsets(EmptySet, s1));
			Contract.Assert(relations.Subsets(s1, s1));
		}
Esempio n. 10
0
		/// <summary> Adds the specified operator to the respective appendable sets regarding domainKind, associativity and precedence. </summary>
		public static void Add(Notion @operator, DomainKind domainKind, Associativity associativity, Set precedenceSet)
		{
			Contract.Requires(@operator != null);
			Contract.RequiresEnumIsDefined(domainKind);
			Contract.Requires(domainKind != DomainKind.Operand);
			Contract.RequiresEnumIsDefined(associativity);
			Contract.Requires(precedenceSet != null);
			Contract.Requires(ReferenceEquals(precedenceSet.Workspace, @operator.Workspace));
			Contract.Requires(Precedences.Contains(precedenceSet));
			Contract.Requires(AllAppendableSetsRelationToLinearNotions.All(linearAppendableSet => !linearAppendableSet.Contains(@operator)));
			Contract.Requires(precedenceSet.IsAppendable);

			var workspace = @operator.Workspace;
			precedenceSet.Append(@operator);

			switch (domainKind)
			{
				case DomainKind.UnaryPrefix:
					UnaryPreOperators.Append(@operator);
					break;
				case DomainKind.UnaryPostfix:
					UnaryPostOperators.Append(@operator);
					break;
				case DomainKind.Binary:
					BinaryOperators.Append(@operator);
					break;
				case DomainKind.Nullary:
					NullaryOperators.Append(@operator);
					break;
				case DomainKind.Operand:
				default:
					throw new Exception();
			}

			switch (associativity)
			{
				case Associativity.Left:
					LeftAssociativeOperators.Append(@operator);
					break;
				case Associativity.Right:
					RightAssociativeOperators.Append(@operator);
					break;
				case Associativity.Undefined:
					UnassociativeOperators.Append(@operator);
					break;
				case Associativity.Associative:
					AssociativeOperators.Append(@operator);
					break;
				default:
					throw new Exception();
			}
		}
        public async Task <IActionResult> Create([Bind("Id,Description,LastUpdated,MinThreshold,Quantity,Title")] Notion notion)
        {
            var user = _userManger.GetUserName(HttpContext.User);

            notion.LastUpdated = DateTime.Now;
            if (ModelState.IsValid)
            {
                _context.Add(notion);
                await _context.SaveChangesAsync();

                logger.Info(user + " created Notion: " + notion.Title);
                return(RedirectToAction("Index"));
            }
            return(View(notion));
        }
Esempio n. 12
0
        /// <summary>
        /// Объявить суммы
        /// </summary>
        public void AnnounceSums()
        {
            var s     = new StringBuilder(LO[nameof(R.Score)]).Append(": ");
            var total = _gameData.Players.Count;

            for (var i = 0; i < total; i++)
            {
                s.Append(Notion.FormatNumber(_gameData.Players[i].Sum));
                if (i < total - 1)
                {
                    s.Append("; ");
                }
            }

            SystemReplic(s.ToString());
        }
Esempio n. 13
0
		public void SetRelationsTest2()
		{
			SetRelations relations = new SetRelations();

			Set s1 = new Set(workspace, "1");
			Notion n1 = new Notion(s1, "1", true);

			relations.Add(s1);
			relations.Add(Booleans);

			Contract.Assert(relations.Subsets(EmptySet, s1));
			Contract.Assert(relations.Subsets(s1, s1));
			Contract.Assert(relations.Subsets(EmptySet, Booleans));
			Contract.Assert(relations.Subsets(Booleans, Booleans));
			Contract.Assert(relations.IsUnknown(Booleans, s1));
		}
Esempio n. 14
0
		/// <summary> Appends the specified element to the specified set. </summary>
		public void Append(Notion element, Set set)
		{
			Contract.Requires(element != null);
			Contract.Requires(set != null);
			Contract.Requires(set.IsAppendable);

			EnumerationRelation enumeration = TryGetEnumeration(set);
			if (enumeration == null)
			{
				relations.Add(new EnumerationRelation(element.ToSingletonList(), set));
			}
			else
			{
				Contract.Assert(enumeration.elements != null, "This shouldn't be null for appendable sets, since this mutable list allows to append elements to the enumeration relation");
				Contract.Assert(!enumeration.elements.Contains(element, ReferenceEqualityComparer), "The specified notion is already an element in the set to append it to");
				enumeration.elements.Add(element);
			}
		}
Esempio n. 15
0
		public void SetRelationsTest3()
		{
			SetRelations relations = new SetRelations();

			Set s1 = new Set(workspace, "1");
			Notion n1 = new Notion(s1, "1", true);

			Set s12 = new Set(workspace, "12");
			Notion n2 = new Notion(s12, "2", true);
			relations.Add(s1);
			relations.Add(s12);

			relations.AddSubsetRelation(s1, s12);

			Contract.Assert(relations.Subsets(EmptySet, s1));
			Contract.Assert(relations.Subsets(s1, s1));
			Contract.Assert(relations.Subsets(EmptySet, s12));
			Contract.Assert(relations.Subsets(s12, s12));
			Contract.Assert(relations.Subsets(s1, s12));
		}
        public async Task <IActionResult> EditQuantity(int id, [Bind("Id,Quantity")] Notion notion)
        {
            var updateNotion = _context.Notion.Where(x => x.Id == id).FirstOrDefault();

            updateNotion.LastUpdated = DateTime.Now;
            updateNotion.Quantity    = notion.Quantity;

            var user = _userManger.GetUserName(HttpContext.User);

            if (id != notion.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(updateNotion);
                    await _context.SaveChangesAsync();

                    logger.Info(user + " edited " + notion.Title + " quantity to: " + notion.Quantity);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NotionExists(notion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("SupplyInventory", "Home", new { id = notion.Id }));
            }
            return(View(notion));
        }
Esempio n. 17
0
		public override bool Contains(Notion notion)
		{
			if (!base.Contains(notion))
				return false;
			if (!(notion.Domain is LinearSet))
				return false;

			LinearSet operatorNotion = (LinearSet)notion.Domain;


			Contract.Assert(operatorNotion.Associativity != AnyAssociativity);
			Contract.Assert(operatorNotion.precedenceComparisonToken != NoPrecedence);
			Contract.Assert(operatorNotion.DomainKind != Unary);
			AssertOnlyOneIsSpecified();

			if (Associativity != defaultAssociativity)
				return operatorNotion.Associativity == this.Associativity;
			else if (DomainKind != defaultDomainKind)
				return operatorNotion.DomainKind == this.DomainKind;
			else
				return operatorNotion.precedenceComparisonToken == this.PrecedenceComparisonToken;
		}
Esempio n. 18
0
		public override void Remove(Notion notion)
		{
			base.Add(notion);
			if (notion is Set)
				SetRelations.Remove((Set)notion);
		}
Esempio n. 19
0
		public override void Add(Notion notion)
		{
			base.Add(notion);
			if (notion is Set && notion.IsConstant)
				SetRelations.Add((Set)notion);
		}
Esempio n. 20
0
		/// <summary> Adds the specified operator to the respective appendable sets regarding domainKind and associativity, and creates a new precedence token at the specified index in precedences. </summary>
		/// <param name="index"> The index in workspace.Precedences at which to insert a new EqualPrecedenceOperators set in which to insert the specified operator. Hence 0 is highest precedence (except for operands, which have -1 precedence). </param>
		public static void Add(Notion @operator, DomainKind domainKind, Associativity associativity, int index = 0)
		{
			Contract.Requires(@operator != null);
			Contract.Requires(0 <= index && index <= PrecedenceElements.Count);
			if (index != 0)
				throw new NotImplementedException();//this has to do with the non-set nature of the precedences, since it's actually a list so we need to distinguish insertion from appendage

			Set newPrecedenceContainer = new LinearAPSet(@operator.Workspace, (IComparable)0);// Precedences.DefinitionSet.Clone("binary |", appendable: true, isConstant: true);
			Precedences.Append(newPrecedenceContainer);

			Add(@operator, domainKind, associativity, newPrecedenceContainer);
		}
Esempio n. 21
0
		/// <summary> Defines the specified name instance to be a representation of a new element in the specified set. </summary>
		public void Add(NameInstance toBeDefined, Set toBeDefinedIn)
		{
			var newNotion = new Notion(toBeDefinedIn, "No description available", false);
			//newNotion.Add(toBeDefined);
			base.Add(newNotion);
		}
Esempio n. 22
0
		public virtual void Append(Notion element)
		{
			Contract.Requires(this.IsAppendable);
			var elementSuperset = (element as Set)?.Superset;
			//Contract.Requires(this.Supersets(element.Domain) || (element is Set && ((Set)element).Superset != null && this.Supersets(((Set)element).Superset)));


			this.Workspace.Append(element, this);
		}
Esempio n. 23
0
		public bool Contains(Notion element, Set set)
		{
			return TryGetElements(set).Contains(element) == true;
		}
Esempio n. 24
0
		/// <summary> Returns whether the specified notion is in (a subset of) this set. Takes generacy into account. </summary>
		public virtual bool Contains(Notion notion)
		{
			//asks whether this set contains the specified element, i.e. the mathematical relation ∈
			//we can retrieve this information by checking directly if all elements in this set are finitely enumerable
			//or if we can prove that the set in which the notion resides is a subset of this set
			//in both cases this set is a constant set. If this set is a variable set, then asking for containment is asking a yet unknown set whether it contains some element, which must be unknown yet (represented by returning false)
			if (this.IsVariable)
				return false;

			//if (this == DefaultNotions.Unknown)
			//	return true;
			//if (this == DefaultNotions.OverarchingSet)
			//	return true;
			//if (notion.Domain == null)//i.e. whether any set contains the overarching set or the unknown set
			//	return false;
			//TODO: implement enumeration
			var enumerableElements = Workspace.TryGetElements(this);
			if (enumerableElements != null && enumerableElements.Contains(notion, ReferenceEqualityComparer))//also takes care of appendables
				return true;

			return this.Supersets(notion.Domain);//whether the specified notion is in (a subset of) this set

			//think about variance and containment 
		}
Esempio n. 25
0
 public override int GetHashCode()
 {
     return(Notion.GetHashCode() ^ Type.GetHashCode());
 }
Esempio n. 26
0
		public void SetRelationsTest6()
		{
			SetRelations relations = new SetRelations();

			Set s1 = new Set(workspace, "1");
			Notion n1 = new Notion(s1, "1", true);

			Set s12 = new Set(workspace, "12");
			Notion n2 = new Notion(s12, "2", true);

			Set s3 = new Set(workspace, "3");
			Notion n3 = new Notion(s3, "3", true);

			Set s123 = new Set(workspace, "123");

			relations.Add(s1);
			relations.Add(s12);
			relations.Add(s3);
			relations.Add(s123);

			relations.AddSubsetRelation(s1, s12);
			relations.AddSubsetRelation(s12, s123);

			Contract.Assert(relations.Subsets(s1, s12));
			Contract.Assert(relations.Subsets(s1, s123));
			Contract.Assert(relations.Subsets(s12, s123));
			Contract.Assert(relations.IsUnknown(s12, s3));

			relations.AddOverlapRelation(s123, s3);

			Contract.Assert(relations.Subsets(s1, s12));
			Contract.Assert(relations.Subsets(s1, s123));
			Contract.Assert(relations.Subsets(s12, s123));
			Contract.Assert(relations.Intersects(s123, s3));
		}
Esempio n. 27
0
		/// <summary> Creates a test notion, namely a binary operator |: bool×bool→bool. </summary>
		/// <param name="orName"> Will contain the name for the or operator. </param>
		private static Notion CreateOrNotion(out Name orName)
		{
			char orOpChar = '|';
			var x = DefaultNotions.Subset;

			Notion orNotion = new Notion(Signature.From(Booleans, Booleans, Booleans), orOpChar.ToString(), true);
			LinearNotions.Add(orNotion, DomainKind.Binary, Associativity.Left, 0);//TODO: do this via workspace rather than static method
			Contract.Assert(orNotion.Domain is LinearSet);
			orName = new AtomicName(new AtomicNameInstance(orOpChar, new LinearPosition(0)), orNotion).Finalize();
			return orNotion;
		}
Esempio n. 28
0
		public override void Append(Notion element)
		{
			base.Append(element);
			LinearAPConstruction construction = notionsUnderConversionToLinear.GetOrAdd(element, _ => new LinearAPConstruction());

			this.AssertOnlyOneIsSpecified();

			if (DomainKind != defaultDomainKind)
				construction.DomainKind = DomainKind;
			else if (Associativity != defaultAssociativity)
				construction.Associativity = Associativity;
			else
				construction.PrecedenceComparisonToken = PrecedenceComparisonToken;

			if (construction.IsApplicable)
				construction.Apply(element);
		}
Esempio n. 29
0
		public void SetRelationsTest7()
		{
			SetRelations relations = new SetRelations();

			Set s1 = new Set(workspace, "1");
			Notion n1 = new Notion(s1, "1", true);

			Set s12 = new Set(workspace, "12");
			Notion n2 = new Notion(s12, "2", true);

			Set s3 = new Set(workspace, "3");
			Notion n3 = new Notion(s3, "3", true);

			Set s123 = new Set(workspace, "123");

			Set true1 = new Set(workspace, "true1");

			relations.Add(s1);
			relations.Add(s12);
			relations.Add(s3);
			relations.Add(s123);
			relations.Add(Booleans);
			relations.Add(true1);

			relations.AddSubsetRelation(s1, s12);
			relations.AddSubsetRelation(s12, s123);//should be able to infer s1 \in s123
			relations.AddSubsetRelation(s3, s123);
			relations.AddOverlapRelation(true1, Booleans);
			relations.AddSubsetRelation(s1, true1);

			Contract.Assert(relations.Subsets(s1, s12));
			Contract.Assert(relations.Subsets(s1, s123));
			Contract.Assert(relations.Subsets(s12, s123));
			Contract.Assert(relations.IsUnknown(s12, s3));
			Contract.Assert(relations.Intersects(true1, s12));//this one is nice
			Contract.Assert(relations.Intersects(true1, s123));
			Contract.Assert(relations.Intersects(true1, Booleans));

			relations.AddNoOverlapRelation(s12, s3);
			Contract.Assert(relations.Subsets(s1, s12));
			Contract.Assert(relations.Subsets(s1, s123));
			Contract.Assert(relations.Subsets(s12, s123));
			Contract.Assert(relations.Disjoins(s12, s3));
			Contract.Assert(relations.Intersects(true1, s12));
			Contract.Assert(relations.Intersects(true1, s123));
			Contract.Assert(relations.Intersects(true1, Booleans));
		}
Esempio n. 30
0
        public IActionResult Merge([FromBody] MergeSymbolsData mergeSymbolsData)
        {
            var symbol1 = _context.Set <Symbol>()
                          .Include(sym => sym.Synonyms)
                          .Include(sym => sym.BehaviouralResponses)
                          .Include(sym => sym.Notions)
                          .Include(sym => sym.Comments)
                          .ThenInclude(comment => comment.SymbolComments)
                          .Include(sym => sym.SymbolLikes)
                          .FirstOrDefault(s => s.Id == mergeSymbolsData.Symbol1Id);
            var symbol2 = _context.Set <Symbol>()
                          .Include(sym => sym.Synonyms)
                          .Include(sym => sym.BehaviouralResponses)
                          .Include(sym => sym.Notions)
                          .Include(sym => sym.Comments)
                          .ThenInclude(comment => comment.SymbolComments)
                          .Include(sym => sym.SymbolLikes)
                          .FirstOrDefault(s => s.Id == mergeSymbolsData.Symbol2Id);
            var newMergedSymbol = new Symbol();

            newMergedSymbol.Name         = mergeSymbolsData.Name;
            newMergedSymbol.Category     = symbol1.Category;
            newMergedSymbol.LELProjectId = symbol1.LELProjectId;
            newMergedSymbol.AuthorId     = mergeSymbolsData.AuthorId;
            foreach (var bh in symbol1.BehaviouralResponses)
            {
                BehaviouralResponse newBh = new BehaviouralResponse();
                newBh.AuthorId   = bh.AuthorId;
                newBh.Expression = bh.Expression;
                newBh.Symbol     = newMergedSymbol;
                newMergedSymbol.BehaviouralResponses.Add(newBh);
            }
            foreach (var bh in symbol2.BehaviouralResponses)
            {
                if (!newMergedSymbol.BehaviouralResponses.Any(b => bh.Expression == b.Expression))
                {
                    BehaviouralResponse newBh = new BehaviouralResponse();
                    newBh.AuthorId   = bh.AuthorId;
                    newBh.Expression = bh.Expression;
                    newBh.Symbol     = newMergedSymbol;
                    newMergedSymbol.BehaviouralResponses.Add(newBh);
                }
            }
            foreach (var comment in symbol1.Comments.Where(c => c.SymbolId > 0))
            {
                SymbolComment newComment = new SymbolComment();
                newComment.UserId  = comment.UserId;
                newComment.Content = comment.Content;
                newComment.Symbol  = newMergedSymbol;
                foreach (var reply in symbol1.Comments.Where(c => c.SymbolCommentId == comment.Id))
                {
                    SymbolComment newReply = new SymbolComment();
                    newReply.UserId             = reply.UserId;
                    newReply.Content            = reply.Content;
                    newReply.SymbolCommentReply = reply.SymbolCommentReply;
                    newReply.SymbolComments.Add(newReply);
                }
                newMergedSymbol.Comments.Add(newComment);
            }
            foreach (var comment in symbol2.Comments.Where(c => c.SymbolId > 0))
            {
                if (!newMergedSymbol.Comments.Any(c => c.Content == comment.Content))
                {
                    SymbolComment newComment = new SymbolComment();
                    newComment.UserId  = comment.UserId;
                    newComment.Content = comment.Content;
                    newComment.Symbol  = newMergedSymbol;
                    foreach (var reply in symbol2.Comments.Where(c => c.SymbolCommentId == comment.Id))
                    {
                        SymbolComment newReply = new SymbolComment();
                        newReply.UserId             = reply.UserId;
                        newReply.Content            = reply.Content;
                        newReply.SymbolCommentReply = reply.SymbolCommentReply;
                        newReply.SymbolComments.Add(newReply);
                    }
                    newMergedSymbol.Comments.Add(newComment);
                }
            }
            foreach (var notion in symbol1.Notions)
            {
                Notion newNotion = new Notion();
                newNotion.AuthorId   = notion.AuthorId;
                newNotion.Symbol     = newMergedSymbol;
                newNotion.Expression = notion.Expression;
                newMergedSymbol.Notions.Add(newNotion);
            }
            foreach (var notion in symbol2.Notions)
            {
                if (!newMergedSymbol.Notions.Any(n => n.Expression == notion.Expression))
                {
                    Notion newNotion = new Notion();
                    newNotion.AuthorId   = notion.AuthorId;
                    newNotion.Symbol     = newMergedSymbol;
                    newNotion.Expression = notion.Expression;
                    newMergedSymbol.Notions.Add(newNotion);
                }
            }

            foreach (var symbolLike in symbol1.SymbolLikes)
            {
                SymbolLike newLike = new SymbolLike();
                newLike.AuthorId = symbolLike.AuthorId;
                newLike.IsLike   = symbolLike.IsLike;
                newLike.Symbol   = newMergedSymbol;
                newMergedSymbol.SymbolLikes.Add(newLike);
            }
            foreach (var symbolLike in symbol2.SymbolLikes)
            {
                if (!newMergedSymbol.SymbolLikes.Any(sl => sl.AuthorId == symbolLike.AuthorId))
                {
                    SymbolLike newLike = new SymbolLike();
                    newLike.AuthorId = symbolLike.AuthorId;
                    newLike.IsLike   = symbolLike.IsLike;
                    newLike.Symbol   = newMergedSymbol;
                    newMergedSymbol.SymbolLikes.Add(newLike);
                }
            }

            foreach (var synonym in symbol1.Synonyms)
            {
                Synonym syn = new Synonym();
                syn.Name   = syn.Name;
                syn.Symbol = synonym.Symbol;
                newMergedSymbol.Synonyms.Add(syn);
            }
            foreach (var synonym in symbol2.Synonyms)
            {
                if (!newMergedSymbol.Synonyms.Any(sl => sl.Name == synonym.Name))
                {
                    Synonym syn = new Synonym();
                    syn.Name   = syn.Name;
                    syn.Symbol = synonym.Symbol;
                    newMergedSymbol.Synonyms.Add(syn);
                }
            }

            _context.Symbol.Remove(symbol1);
            _context.Symbol.Remove(symbol2);
            _context.Symbol.Add(newMergedSymbol);
            _context.SaveChanges();
            string pattern1 = "({.*?" + mergeSymbolsData.Symbol1Id.ToString() + ".*?})";
            string pattern2 = "({.*?" + mergeSymbolsData.Symbol2Id.ToString() + ".*?})";

            foreach (var notion in _context.Notion)
            {
                if (Regex.IsMatch(notion.Expression, pattern1))
                {
                    notion.Expression.Replace(mergeSymbolsData.Symbol1Id.ToString(), newMergedSymbol.Id.ToString());
                }
                if (Regex.IsMatch(notion.Expression, pattern2))
                {
                    notion.Expression.Replace(mergeSymbolsData.Symbol2Id.ToString(), newMergedSymbol.Id.ToString());
                }
            }
            foreach (var behaviouralResponse in _context.BehaviouralResponse)
            {
                if (Regex.IsMatch(behaviouralResponse.Expression, pattern1))
                {
                    behaviouralResponse.Expression.Replace(mergeSymbolsData.Symbol1Id.ToString(), newMergedSymbol.Id.ToString());
                }
                if (Regex.IsMatch(behaviouralResponse.Expression, pattern2))
                {
                    behaviouralResponse.Expression.Replace(mergeSymbolsData.Symbol2Id.ToString(), newMergedSymbol.Id.ToString());
                }
            }
            _context.SaveChanges();
            return(Ok());
        }
Esempio n. 31
0
		private static Name CreateBoolean(char c)
		{
			var notion = new Notion(Booleans, c.ToString(), true);
			return new AtomicName(new AtomicNameInstance(c, new LinearPosition(0)), notion).Finalize();
		}
Esempio n. 32
0
		static DefaultNotions()
		{
			workspace = (Workspace)AppDomain.CurrentDomain.CreateInstance("ASDE.SemanticsEngine", "JBSnorro.Reas.SemanticsEngine.Workspace2").Unwrap();

			//defines the only two sets with null parent set. The
			Unknown = Set.CreateOverarchingOrUnknownSet(workspace, "?", appendable: false, setSelfAsDomain: false);
			OverarchingSet = Set.CreateOverarchingOrUnknownSet(workspace, "set", appendable: true, setSelfAsDomain: OverarchingSetContainsItself);
			EmptySet = new Set(workspace, "∅");

			var variableSet = new VariableSet(OverarchingSet, "var<set>");
			SetDefinition = new GenericSet(variableSet, EmptyCollection<ISet>.ReadOnlyList, variableSet.ToSingletonReadOnlyList(), Variance.Covariant.ToSingletonReadOnlyList(), "set<>");

			//AllAppendables is defined by     appendable : set<var appendable>, just like set : set<set> (well, actually, set : appendable<set>)
			//in what set would the variable appendables then be? Could be OverarchingSet: then we have the consistent appendable ⊆ set<var<appendable>> ⊆ var<appendable> ⊆ OverarchingSet
			//alternatively, I can create it just as appendable : set<set>. I'll do that for now, as it's simpler. 
			//Anyway, this does not impose the constraint that any set appended to appendables is in fact appendable (just like any other constraint isn't implemented at the moment).
			//Anyway, we can choose the above consistent more convoluted definition of appendables by uncommenting:
			//var variableAppendableSet = Set.CreateGenericSetParameter(workspace, "var<appendable>", OverarchingSet, appendable: true); //hmmm?
			//AllAppendables = new GenericSet(SetDefinition, variableAppendableSet.ToSingletonReadOnlyList(), "AllAppendables", appendable: true);

			//Another alternative, yet less elegant, is to have AllAppendables as singleton (per workspace) type deriving from generic set, such that it can have a variable itself as generic set parameter
			AllAppendables = new GenericSet(SetDefinition, OverarchingSet.ToSingletonReadOnlyList<ISet>(), "AllAppendables", appendable: true);

			workspace.Add(SetRelationType.Subset, SetDefinition, OverarchingSet);
			workspace.Add(SetRelationType.Subset, OverarchingSet, SetDefinition);

			//defines the sets that will contain ∈, × and →
			InDefiningSet = Signature.From(Unknown, OverarchingSet, OverarchingSet);//?×set→set
			CartesianAndSignatureProductType = Signature.From(OverarchingSet, OverarchingSet, OverarchingSet);//set×set→set

			//defines the notions of ∈, × and → (not their implementations)
			InDefining = new Notion(InDefiningSet, "∈");
			CartesianProduct = new Notion(CartesianAndSignatureProductType, "×");
			SignatureProduct = new Notion(CartesianAndSignatureProductType, "→");

			NaturalNumbers = new Set(workspace, "Gets the notion representing the natural numbers");

			GenericTypeOpeningDelimiterSet = new Set(workspace, "⟨");//Contains the single name that represents the opening delimiter of the special construct in which you can specify type arguments");
			GenericTypeClosingDelimiterSet = new Set(workspace, "⟩");//Contains the single name that represents the closing delimiter of the special construct in which you can specify type arguments");
																	 //GenericTypeOpeningDelimiter = new Notion(GenericTypeOpeningDelimiterSet, true, "The type argument/parameter list opening delimiter");
																	 //GenericTypeClosingDelimiter = new Notion(GenericTypeClosingDelimiterSet, true, "The type argument/parameter list closing delimiter");

			Booleans = Set.Create(workspace, "Booleans",
								  _ => new Notion(_, "true"),
								  _ => new Notion(_, "false"));

			BinarySetRelations = Signature.From(OverarchingSet, OverarchingSet, Booleans);//set×set→bool
			ProperSubset = new Notion(BinarySetRelations, "⊂");
			Subset = new Notion(BinarySetRelations, "⊆");
			ProperSuperset = new Notion(BinarySetRelations, "⊃");
			Superset = new Notion(BinarySetRelations, "⊇");



			Intersect = new Notion(CartesianAndSignatureProductType, "∩");

			//I believe these two are so far only used in sets (not say integer), hence are in set×set→bool
			EqualityOperator = new Notion(BinarySetRelations, "=");
			InequalityOperator = new Notion(BinarySetRelations, "≠");

			SetBuilderOpeningBraces = new Set(workspace, "Opening set builder braces. ");
			SetBuilderClosingBraces = new Set(workspace, "Closing set builder braces. ");
			SetBuilderEnumerationDelimiters = new Set(workspace, "Enumeration delimiters");

			//the set that contains the information on the precedence of linear notations
			//it is an appendable set of appendable sets of sets: Appendable<Appendable<Set>>

			//is this the actual set or just its signature?

			//the operator sets accept all functions of their respective signatures. The LinearAPSet makes sure these functions are transformed into operators
			//binary operators : set<LHS×RHS→TResult>
			BinaryOperators = LinearAPSet.Create(Signature.From(new VariableSet(workspace, "LHS"), new VariableSet(workspace, "RHS"), new VariableSet(workspace, "TResult")), DomainKind.Binary);
			UnaryOperators = LinearAPSet.Create(Signature.From(new VariableSet(workspace, "TOperand"), new VariableSet(workspace, "TResult")), LinearSet.Unary);
			UnaryPreOperators = LinearAPSet.Create((Signature)UnaryOperators.GenericSetArguments[0], DomainKind.UnaryPrefix);
			UnaryPostOperators = LinearAPSet.Create((Signature)UnaryOperators.GenericSetArguments[0], DomainKind.UnaryPostfix);
			//generic operators : ?   nothing?
			NullaryOperators = new LinearAPSet(workspace, "nullary");

			workspace.Add(SetRelationType.Subset, UnaryOperators, UnaryPostOperators);
			workspace.Add(SetRelationType.Subset, UnaryOperators, UnaryPreOperators);

			Operators = new Set(workspace, "Binary, unary and nullary operators");//Operators is not appendable, even though elements can be appended to it (indirectly). TODO: think about that: hence even a set that is not appendable may not be static
			workspace.Add(SetRelationType.Subset, BinaryOperators, Operators);
			workspace.Add(SetRelationType.Subset, UnaryOperators, Operators);//contains unary pre and unary post operators
			workspace.Add(SetRelationType.Subset, NullaryOperators, Operators);

			//It is the actual set, but the generic type argument should also be constant. The fact that the generic type argument is specified, is unrelated to appending the generic type argument "as element" (which we don't want to do)
			//the associativity sets accept all functions of their respective signatures. The LinearAPSet makes sure these functions are transformed into operators
			AssociativeOperators = new LinearAPSet(workspace, Associativity.Associative);
			LeftAssociativeOperators = new LinearAPSet(workspace, Associativity.Left);
			RightAssociativeOperators = new LinearAPSet(workspace, Associativity.Right);
			UnassociativeOperators = new LinearAPSet(workspace, Associativity.Undefined);

			//the equal precedence sets accept all functions of operator signature. The LinearAPSet makes sure these functions are transformed into operators.
			//The function appending to Precedences should do that
			//Precedences = Operators.CreateSubset("appendable set of operators", isConstant: false).CreateSubset("appendable set of appendable sets of operators", appendable: true, isConstant: true);
			Precedences = new GenericSet(SetDefinition, Operators.CreateSubset(appendable: true, isConstant: true).ToSingletonReadOnlyList(), "Precedences", appendable: true);
			PrecedenceElements = new FacadeMapCollection<Notion, Set>((IReadOnlyList<Notion>)workspace.TryGetElements(Precedences), equalPrecOperators => (Set)equalPrecOperators);


			//THE INNER CONSTRUCT DOESN'T CONSTRUCT AN ACTUAL SET, BUT JUST THE 'TYPE' OF ONE. Does that mean it constructs the canonical one? Well, it refers to the canonical one

			//AllAppendables it an example of a generic appendable set 
			//the equal precedence operator sets (the elements of Precedences) exemplify a constructed appendable set (which also implies there is a generic appendable set right?)
			//Precedences is an example of a set containing a reference to a set but not necessarily needing that type (namely Appendable<operators>)
			//
			//I could constructing a type always yield the canonical one (i.e. a constant inappendable one), and then you could clone it and set make the clone variable or appendable
			//only generic sets (i.e. those that have generic parameters) are constructible in this way
			//then what I now call cloning could in that case also be named constructing: you could then construct some set from the canonical one
			//however, construct conveys that a new one ie created: by specifying generic argument sets we don't necessarily create a new set since the Set.From method is called
			//we could adopt "substitute" for constructing generic sets?
			//we would adopt "adopt" for constructing generic sets? that's better, it doesn't convey necessarily creating a new one
			//Then cloning it while changing some properties (isConstant, appendable) could then very well be called construct, since it always creates a new one

			//but suppose that a generic set argument is appendable, then only appendable subsets can be used there (may depend on variance: if it's contravariant, could then also non-appendable sets be used in case an appendable is required? dunno)
			//but then it seems like adopting a set shouldn't change its appendibility
		}