public ElementBuilder AddLinkedConcept(IConcept concept)
        {
            throw new NotImplementedException();

            //LinkedConceptsInternal.Add(concept);
            //return this;
        }
Esempio n. 2
0
        public void Update(String id, IConcept leftValue, IConcept rightValue, IConcept comparisonSign)
        {
            if (leftValue == null)
            {
                throw new ArgumentNullException(nameof(leftValue));
            }
            if (rightValue == null)
            {
                throw new ArgumentNullException(nameof(rightValue));
            }
            if (comparisonSign == null)
            {
                throw new ArgumentNullException(nameof(comparisonSign));
            }
            if (!leftValue.HasAttribute <IsValueAttribute>())
            {
                throw new ArgumentException("Left value concept has to be marked as IsValue Attribute.", nameof(leftValue));
            }
            if (!rightValue.HasAttribute <IsValueAttribute>())
            {
                throw new ArgumentException("Right value concept has to be marked as IsValue Attribute.", nameof(rightValue));
            }
            if (!comparisonSign.HasAttribute <IsComparisonSignAttribute>())
            {
                throw new ArgumentException("Comparison Sign concept has to be marked as IsComparisonSign Attribute.", nameof(comparisonSign));
            }

            Update(id);
            LeftValue      = leftValue;
            RightValue     = rightValue;
            ComparisonSign = comparisonSign;
        }
Esempio n. 3
0
        public Relation([NotNull] IConcept from, [NotNull] IConcept to, Relationship relationship)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }

            if (relationship == Relationship.Unknown)
            {
                throw new ArgumentException($"Concepts cannot be related using the unknown relationship.");
            }

            if (from == to)
            {
                throw new ArgumentException($"A concept may not be related to itself: {from.Name}");
            }

            From         = from;
            Relationship = relationship;
            To           = to;
        }
Esempio n. 4
0
        private IEnumerable <NestedQuestion> GetNestedQuestions(IQuestionProcessingContext <ComparisonQuestion> context)
        {
            foreach (var statement in context.SemanticNetwork.Statements.Enumerate <ComparisonStatement>(context.ActiveContexts))
            {
                IConcept newLeftValue = null;
                if (statement.LeftValue == LeftValue)
                {
                    newLeftValue = statement.RightValue;
                }
                else if (statement.RightValue == LeftValue)
                {
                    newLeftValue = statement.LeftValue;
                }

                if (newLeftValue != null)
                {
                    var involvedValues = new HashSet <IConcept>(context.ActiveContexts
                                                                .OfType <IQuestionProcessingContext <ComparisonQuestion> >()
                                                                .Select(c => c.Question.LeftValue));

                    if (!involvedValues.Contains(newLeftValue))
                    {
                        yield return(new NestedQuestion(new ComparisonQuestion(newLeftValue, RightValue), new IStatement[] { statement }));
                    }
                }
            }
        }
        public static SignValueStatement IsSignValue(this StatementBuilder builder, IConcept concept, IConcept sign)
        {
            var statement = new SignValueStatement(null, concept, sign, builder.Subject);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
Esempio n. 6
0
        public void AddRelation(IConcept descendant, IConcept ancestor, Relationship relationship)
        {
            if (descendant == null)
            {
                throw new ArgumentNullException(nameof(descendant));
            }

            if (ancestor == null)
            {
                throw new ArgumentNullException(nameof(ancestor));
            }
            var relation = new Relation(descendant, ancestor, relationship);
            var key      = (string.Compare(descendant.Name, ancestor.Name, StringComparison.InvariantCultureIgnoreCase) > 0)?
                           $"{ancestor.Name}\0${descendant.Name}":
                           $"{descendant.Name}\0${ancestor.Name}";

            // Needs lock and backout
            if (_relations.TryAdd(key, relation))
            {
                descendant.Relations.Add(relation);
                ancestor.Relations.Add(relation);
            }
            else
            {
                throw new StateException($"Relation between {descendant.Name} and {ancestor.Name} already exists.");
            }
        }
        public static HasSignStatement IsSignOf(this StatementBuilder builder, IConcept concept)
        {
            var statement = new HasSignStatement(null, concept, builder.Subject);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
        public static HasPartStatement IsPartOf(this StatementBuilder builder, IConcept whole)
        {
            var statement = new HasPartStatement(null, whole, builder.Subject);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
        public static HasSignStatement HasSign(this StatementBuilder builder, IConcept sign)
        {
            var statement = new HasSignStatement(null, builder.Subject, sign);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
        public static GroupStatement IsSubjectAreaOf(this StatementBuilder builder, IConcept concept)
        {
            var statement = new GroupStatement(null, builder.Subject, concept);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
        public static HasPartStatement HasPart(this StatementBuilder builder, IConcept part)
        {
            var statement = new HasPartStatement(null, builder.Subject, part);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
Esempio n. 12
0
        public void Update(String id, IConcept concept, IConcept sign, IConcept value)
        {
            if (concept == null)
            {
                throw new ArgumentNullException(nameof(concept));
            }
            if (sign == null)
            {
                throw new ArgumentNullException(nameof(sign));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!sign.HasAttribute <IsSignAttribute>())
            {
                throw new ArgumentException("Sign concept has to be marked as IsSign Attribute.", nameof(sign));
            }
            if (!value.HasAttribute <IsValueAttribute>())
            {
                throw new ArgumentException("Value concept has to be marked as IsValue Attribute.", nameof(value));
            }

            Update(id);
            Concept = concept;
            Sign    = sign;
            Value   = value;
        }
Esempio n. 13
0
        private System.Boolean isCyclic(IEnumerable <IsStatement> allClasifications, IConcept concept, List <IConcept> chain)
        {
            if (chain.Contains(concept))
            {
                return(true);
            }

            var clasifications = allClasifications.Where(c => c.Descendant == concept).ToList();

            if (clasifications.Count == 0)
            {
                return(false);
            }
            else
            {
                foreach (var clasification in clasifications)
                {
                    if (isCyclic(allClasifications, clasification.Ancestor, new List <IConcept>(chain)
                    {
                        clasification.Descendant
                    }))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
Esempio n. 14
0
        protected Boolean SetCombination(IConcept left, IConcept right, IConcept sign)
        {
            Boolean updated = false;

            // get "row" using LEFT value as key, return true if row is added
            Dictionary <IConcept, HashSet <IConcept> > combinations;

            if (!AllSigns.TryGetValue(left, out combinations))
            {
                AllSigns[left] = combinations = new Dictionary <IConcept, HashSet <IConcept> >();
                updated        = true;
            }

            // get "column" using RIGHT value as key, return true if column is added
            HashSet <IConcept> signs;

            if (!combinations.TryGetValue(right, out signs))
            {
                combinations[right] = signs = new HashSet <IConcept>();
                updated             = true;
            }

            // add value to list, return true if added (= new unique)
            Int32 countBefore = signs.Count;

            signs.Add(sign);
            if (signs.Count > countBefore)
            {
                updated = true;
            }

            return(updated);
        }
Esempio n. 15
0
        public static IConcept CompareThreeValues(IConcept firstSign, IConcept secondSign)
        {
            ensureSuits(firstSign);
            ensureSuits(secondSign);

            if (firstSign == IsEqualTo)
            {
                return(secondSign);
            }
            else if (secondSign == IsEqualTo)
            {
                return(firstSign);
            }
            else if ((secondSign == IsGreaterThan || secondSign == IsGreaterThanOrEqualTo) && (firstSign == IsGreaterThan || firstSign == IsGreaterThanOrEqualTo))
            {
                return((secondSign == IsGreaterThanOrEqualTo && firstSign == IsGreaterThanOrEqualTo) ? IsGreaterThanOrEqualTo : IsGreaterThan);
            }
            else if ((secondSign == IsLessThan || secondSign == IsLessThanOrEqualTo) && (firstSign == IsLessThan || firstSign == IsLessThanOrEqualTo))
            {
                return((secondSign == IsLessThanOrEqualTo && firstSign == IsLessThanOrEqualTo) ? IsLessThanOrEqualTo : IsLessThan);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 16
0
 public Concept(IConcept concept)
 {
     Name       = new LocalizedString(concept.Name);
     Hint       = new LocalizedString(concept.Hint);
     Attributes = concept.Attributes.Select(a => Attribute.Save(a)).ToList();
     ID         = concept.ID;
 }
        public static IsStatement IsAncestorOf(this StatementBuilder builder, IConcept descendant)
        {
            var statement = new IsStatement(null, builder.Subject, descendant);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
Esempio n. 18
0
        public static ICollection <IConcept> Consequently(this IConcept sign)
        {
            ensureSuits(sign);

            if (sign == StartsBeforeOtherStarted)
            {
                return(new[] { StartsBeforeOtherFinished });
            }
            else if (sign == FinishesBeforeOtherStarted)
            {
                return(new[] { StartsBeforeOtherStarted, StartsBeforeOtherFinished, FinishesBeforeOtherFinished });
            }
            else if (sign == StartsAfterOtherFinished)
            {
                return(new[] { FinishesAfterOtherFinished, FinishesAfterOtherStarted, StartsAfterOtherStarted });
            }
            else if (sign == FinishesAfterOtherFinished)
            {
                return(new[] { FinishesAfterOtherStarted });
            }
            else
            {
                return(Array.Empty <IConcept>());
            }
        }
Esempio n. 19
0
 private static void ensureSuits(this IConcept value)
 {
     if (!All.Contains(value))
     {
         throw new InvalidOperationException("This method can work only with logical values.");
     }
 }
        public void ConceptWithSubjectAreaCanFindIt()
        {
            // arrange
            var language        = Language.Default;
            var semanticNetwork = new TestSemanticNetwork(language);

            IList <IConcept> subjectAreas = new IConcept[]
            {
                semanticNetwork.SubjectArea_Transport,
                semanticNetwork.SubjectArea_Numbers,
                semanticNetwork.SubjectArea_Processes,
            };

            var conceptsWithoutSubjectArea = new List <IConcept>(SystemConcepts.GetAll());

            conceptsWithoutSubjectArea.AddRange(subjectAreas);

            foreach (var concept in semanticNetwork.SemanticNetwork.Concepts.Except(conceptsWithoutSubjectArea))
            {
                // act
                var answer = semanticNetwork.SemanticNetwork.Ask().ToWhichSubjectAreasBelongs(concept);

                // assert
                Assert.IsFalse(answer.IsEmpty);

                var groupStatement = (GroupStatement)answer.Explanation.Statements.Single();
                Assert.IsTrue(subjectAreas.Contains(groupStatement.Area));
                Assert.AreSame(concept, groupStatement.Concept);

                var conceptsAnswer = (ConceptsAnswer)answer;
                Assert.AreSame(groupStatement.Area, conceptsAnswer.Result.Single());
            }
        }
Esempio n. 21
0
        public static ComparisonStatement IsEqualTo(this StatementBuilder builder, IConcept other)
        {
            var statement = new ComparisonStatement(null, builder.Subject, other, ComparisonSigns.IsEqualTo);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
Esempio n. 22
0
        public bool IsDescendantOf([NotNull] IConcept ancestor)
        {
            var      cache     = new HashSet <IConcept>();
            var      stack     = new Stack <IConcept>();
            IConcept candidate = this;
            var      result    = false;

            while (candidate != null)
            {
                if (!cache.Contains(candidate))
                {
                    if (candidate == ancestor)
                    {
                        result = true;
                        break;
                    }
                    cache.Add(candidate);

                    foreach (var target in candidate.Relations.Where(r => r.Relationship == Relationship.Parent).Select(r => r.To))
                    {
                        stack.Push(target);
                    }
                }

                candidate = stack.Count == 0? null: stack.Pop();
            }
            return(result);
        }
Esempio n. 23
0
        public void Update(String id, IConcept processA, IConcept processB, IConcept sequenceSign)
        {
            if (processA == null)
            {
                throw new ArgumentNullException(nameof(processA));
            }
            if (processB == null)
            {
                throw new ArgumentNullException(nameof(processB));
            }
            if (sequenceSign == null)
            {
                throw new ArgumentNullException(nameof(sequenceSign));
            }
            if (!processA.HasAttribute <IsProcessAttribute>())
            {
                throw new ArgumentException("Process A concept has to be marked as IsProcess Attribute.", nameof(processA));
            }
            if (!processB.HasAttribute <IsProcessAttribute>())
            {
                throw new ArgumentException("Process B concept has to be marked as IsProcess Attribute.", nameof(processB));
            }
            if (!sequenceSign.HasAttribute <IsSequenceSignAttribute>())
            {
                throw new ArgumentException("Sequence Sign concept has to be marked as IsSequenceSign Attribute.", nameof(sequenceSign));
            }

            Update(id);
            ProcessA     = processA;
            ProcessB     = processB;
            SequenceSign = sequenceSign;
        }
        public static ProcessesStatement IsCausedBy(this StatementBuilder builder, IConcept other)
        {
            var statement = new ProcessesStatement(null, builder.Subject, other, SequenceSigns.IsCausedBy);

            builder.SemanticNetwork.Statements.Add(statement);
            return(statement);
        }
Esempio n. 25
0
        public static IConcept Revert(this IConcept sign)
        {
            ensureSuits(sign);

            if (sign == IsGreaterThanOrEqualTo)
            {
                return(IsLessThanOrEqualTo);
            }
            else if (sign == IsGreaterThan)
            {
                return(IsLessThan);
            }
            else if (sign == IsLessThanOrEqualTo)
            {
                return(IsGreaterThanOrEqualTo);
            }
            else if (sign == IsLessThan)
            {
                return(IsGreaterThan);
            }
            else
            {
                return(sign);
            }
        }
Esempio n. 26
0
 private static void ensureSuits(this IConcept sign)
 {
     if (!All.Contains(sign))
     {
         throw new InvalidOperationException("This method can work only with comparison signs.");
     }
 }
Esempio n. 27
0
 public IsStatement(String id, IConcept ancestor, IConcept descendant)
     : base(
         id,
         new Func <ILanguage, String>(language => language.GetExtension <ILanguageClassificationModule>().Statements.Names.Clasification),
         new Func <ILanguage, String>(language => language.GetExtension <ILanguageClassificationModule>().Statements.Hints.Clasification))
 {
     Update(id, ancestor, descendant);
 }
Esempio n. 28
0
 public ComparisonStatement(String id, IConcept leftValue, IConcept rightValue, IConcept comparisonSign)
     : base(
         id,
         new Func <ILanguage, String>(language => language.GetExtension <ILanguageMathematicsModule>().Statements.Names.Comparison),
         new Func <ILanguage, String>(language => language.GetExtension <ILanguageMathematicsModule>().Statements.Hints.Comparison))
 {
     Update(id, leftValue, rightValue, comparisonSign);
 }
Esempio n. 29
0
 public static IConcept WithAttributes(this IConcept concept, IEnumerable <IAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         concept.Attributes.Add(attribute);
     }
     return(concept);
 }
Esempio n. 30
0
        public FormMovie35(IConcept Concept)
        {
            InitializeComponent();
            this.concept = Concept;

            lbxMovie.DataSource = concept.getAllMovies();
            lbxActor.DataSource = concept.getAllActors();
        }
Esempio n. 31
0
 public CustomStatement(string id, IConcept concept1, IConcept concept2)
     : base(
         id,
         new Func <ILanguage, string>(language => language.GetExtension <ILanguageCustomModule>().Statements.Names.Custom),
         new Func <ILanguage, string>(language => language.GetExtension <ILanguageCustomModule>().Statements.Hints.Custom))
 {
     Update(id, concept1, concept2);
 }
 public virtual bool AreEqual(IConceptModel model, IConcept entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // Concept Properties
         && model.StartYear == entity.StartYear
         // Related Objects
         && model.PrimaryImageFileId == entity.PrimaryImageFileId
         && model.FirstIssueAppearanceId == entity.FirstIssueAppearanceId
         ;
 }
 public virtual void MapToEntity(IConceptModel model, ref IConcept entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Concept Properties
     entity.StartYear = model.StartYear;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     entity.FirstIssueAppearanceId = model.FirstIssueAppearanceId;
     entity.FirstIssueAppearance = (Issue)model.FirstIssueAppearance?.MapToEntity();
     // Associated Objects
     entity.ConceptAliases = model.ConceptAliases?.Where(i => i.Active).Select(ConceptAliasMapperExtensions.MapToEntity).ToList();
     entity.ConceptIssuesAppearedIn = model.ConceptIssuesAppearedIn?.Where(i => i.Active).Select(ConceptAppearedInIssueMapperExtensions.MapToEntity).ToList();
     entity.ConceptIssues = model.ConceptIssues?.Where(i => i.Active).Select(ConceptIssueMapperExtensions.MapToEntity).ToList();
     entity.ConceptMovies = model.ConceptMovies?.Where(i => i.Active).Select(ConceptMovieMapperExtensions.MapToEntity).ToList();
     entity.ConceptVolumes = model.ConceptVolumes?.Where(i => i.Active).Select(ConceptVolumeMapperExtensions.MapToEntity).ToList();
 }
 public virtual IConceptModel MapToModel(IConcept entity, int currentDepth = 1)
 {
     currentDepth++;
     var model = NameableEntityMapper.MapToModel<IConcept, ConceptModel>(entity);
     // Concept Properties
     model.StartYear = entity.StartYear;
     // Related Objects
     model.PrimaryImageFileId = entity.PrimaryImageFileId;
     model.PrimaryImageFile = entity.PrimaryImageFile?.MapToModel();
     model.FirstIssueAppearanceId = entity.FirstIssueAppearanceId;
     model.FirstIssueAppearance = entity.FirstIssueAppearance?.MapToModel();
     // Associated Objects
     model.ConceptAliases = entity.ConceptAliases?.Where(i => i.Active).Select(ConceptAliasMapperExtensions.MapToModelLite).ToList();
     model.ConceptIssuesAppearedIn = entity.ConceptIssuesAppearedIn?.Where(i => i.Active).Select(ConceptAppearedInIssueMapperExtensions.MapToModelLite).ToList();
     model.ConceptIssues = entity.ConceptIssues?.Where(i => i.Active).Select(ConceptIssueMapperExtensions.MapToModelLite).ToList();
     model.ConceptMovies = entity.ConceptMovies?.Where(i => i.Active).Select(ConceptMovieMapperExtensions.MapToModelLite).ToList();
     model.ConceptVolumes = entity.ConceptVolumes?.Where(i => i.Active).Select(ConceptVolumeMapperExtensions.MapToModelLite).ToList();
     // Return Entity
     return model;
 }
 public static void MapToEntity(this IConceptModel model, ref IConcept entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
 public static bool AreEqual(this IConceptModel model, IConcept entity)
 {
     return Mapper.AreEqual(model, entity);
 }
 public virtual IConceptModel MapToModelLite(IConcept entity, int currentDepth = 1)
 {
     currentDepth++;
     var model = NameableEntityMapper.MapToModelLite<IConcept, ConceptModel>(entity);
     // Concept Properties
     model.StartYear = entity.StartYear;
     // Related Objects
     model.PrimaryImageFileId = entity.PrimaryImageFileId;
     model.FirstIssueAppearanceId = entity.FirstIssueAppearanceId;
     // Return Entity
     return model;
 }
 public void Update(IConcept entity)
 {
     Context.SetModified(entity);
 }
 protected bool Remove(IConcept entity)
 {
     if (entity == null) { return true; } // No entity found to remove, consider it passed
     // Remove it
     ConceptsRepository.Remove(entity);
     // Try to Save Changes
     ConceptsRepository.SaveChanges();
     // Finished!
     return true;
 }
 public void Deactivate(IConcept entity)
 {
     entity.Active = false;
     Update(entity);
 }
 public void Remove(IConcept entity)
 {
     Context.Concepts.Remove((Concept)entity);
 }
 protected bool Deactivate(IConcept entity)
 {
     // Deactivate it
     ConceptsRepository.Deactivate(entity);
     // Try to Save Changes
     ConceptsRepository.SaveChanges();
     // Finished!
     return true;
 }
 public void Add(IConcept entity)
 {
     Context.Concepts.Add((Concept)entity);
 }