Exemplo n.º 1
0
 protected override void Attach(ISemanticNetwork semanticNetwork)
 {
     foreach (var sign in SequenceSigns.All)
     {
         semanticNetwork.Concepts.Add(sign);
     }
 }
Exemplo n.º 2
0
 protected override void Attach(ISemanticNetwork semanticNetwork)
 {
     foreach (var boolean in LogicalValues.All)
     {
         semanticNetwork.Concepts.Add(boolean);
     }
 }
Exemplo n.º 3
0
        public static ISemanticNetwork WithModules(this ISemanticNetwork semanticNetwork, ICollection <IExtensionModule> modules)
        {
            var modulesToApply = new List <IExtensionModule>(modules);

            while (modulesToApply.Count > 0)
            {
                var applied = new List <IExtensionModule>();
                foreach (var module in modulesToApply)
                {
                    if (semanticNetwork.GetMissingDependencies(module).Count == 0)
                    {
                        module.AttachTo(semanticNetwork);
                        applied.Add(module);
                    }
                }

                if (applied.Count > 0)
                {
                    modulesToApply.RemoveAll(applied.Contains);
                }
                else
                {
                    throw new ModuleException(String.Join("; ", modulesToApply.Select(m => m.Name)), $"Impossible to apply {modulesToApply.Count} modules because they have unresolved dependencies.");
                }
            }

            return(semanticNetwork);
        }
Exemplo n.º 4
0
        public object ApplyCreate(ISemanticNetwork semanticNetwork)
        {
            var statement = CreateStatement();

            semanticNetwork.Statements.Add(statement);
            return(statement);
        }
Exemplo n.º 5
0
        private static void checkMultiValues(
            ICollection <SignValueStatement> statements,
            ITextContainer result,
            ISemanticNetwork semanticNetwork)
        {
            var clasifications = semanticNetwork.Statements.OfType <IsStatement>().ToList();

            foreach (var concept in semanticNetwork.Concepts)
            {
                var parents = clasifications.GetParentsOneLevel(concept);
                foreach (var sign in HasSignStatement.GetSigns(semanticNetwork.Statements, concept, true))
                {
                    if (statements.FirstOrDefault(sv => sv.Concept == concept && sv.Sign == sign.Sign) == null &&
                        parents.Select(p => SignValueStatement.GetSignValue(semanticNetwork.Statements, p, sign.Sign)).Count(r => r != null) > 1)
                    {
                        result.Append(
                            language => language.GetExtension <ILanguageSetModule>().Statements.Consistency.ErrorMultipleSignValue,
                            new Dictionary <String, IKnowledge>
                        {
                            { Semantics.Localization.Strings.ParamConcept, concept },
                            { Strings.ParamSign, sign.Sign },
                        });
                    }
                }
            }
        }
Exemplo n.º 6
0
        public QuestionDialog(ISemanticNetwork semanticNetwork, ILanguage language, IViewModelFactory viewModelFactory)
        {
            _language         = language;
            _viewModelFactory = viewModelFactory;

            InitializeComponent();

            var localizationProvider = (ObjectDataProvider)Resources["language"];

            localizationProvider.ConstructorParameters.Add(_language);
            ((NamedConverter)Resources["namedConverter"]).Language = _language;

            Title = _language.GetExtension <IWpfUiModule>().Ui.QuestionDialog.Title;

            panelSelectQuestion.DataContext = Question = null;
            panelSelectQuestion.Visibility  = Visibility.Visible;
            panelQuestionParams.Visibility  = Visibility.Hidden;

            _semanticNetwork = semanticNetwork;
            foreach (var questionDefinition in Repositories.Questions.Definitions.Values)
            {
                var genericType   = typeof(QuestionViewModel <>).MakeGenericType(questionDefinition.Type);
                var viewModelType = Assembly.GetExecutingAssembly().GetTypes().First(t => !t.IsAbstract && genericType.IsAssignableFrom(t));
                _questions[questionDefinition.GetName(_language)] = () => Activator.CreateInstance(viewModelType) as IQuestionViewModel;
            }
            comboBoxQuestion.ItemsSource = _questions.Keys.OrderBy(q => q);

            _propertySelectorCreators = new Dictionary <Type, CreatePropertySelectorDelegate>
            {
                { typeof(IConcept), createConceptSelector },
                { typeof(bool), createCheckBox },
                { typeof(StatementViewModel), createStatementEditor },
                { typeof(ICollection <StatementViewModel>), createStatementsList },
            };
        }
Exemplo n.º 7
0
        private void initializeSemanticNetwork()
        {
#if DEBUG
            SemanticNetwork = new Semantics.Test.Sample.TestSemanticNetwork(CurrentLanguage).SemanticNetwork;
#else
            SemanticNetwork = new SemanticNetwork(CurrentLanguage);
#endif
        }
Exemplo n.º 8
0
 private static void checkSignValues(
     ICollection <SignValueStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     checkMultiValues(statements, result, semanticNetwork);
     checkValuesWithoutSign(statements, result, semanticNetwork);
 }
Exemplo n.º 9
0
        public static ISemanticNetwork WithModule <ModuleT>(this ISemanticNetwork semanticNetwork)
            where ModuleT : IExtensionModule, new()
        {
            var module = new ModuleT();

            module.AttachTo(semanticNetwork);
            return(semanticNetwork);
        }
Exemplo n.º 10
0
        private void setModel(ISemanticNetwork semanticNetwork, string fileName)
        {
            _application.SemanticNetwork = semanticNetwork;
            treeViewSemanticNetwork.Reload();

            _fileName = fileName;

            _changeController.ClearHistory();
        }
Exemplo n.º 11
0
        public ISemanticNetworkContext Instantiate(ISemanticNetwork semanticNetwork)
        {
            if (Children.Count > 0)
            {
                throw new InvalidOperationException("Impossible to instantiate system context more than once.");
            }

            return(new SemanticNetworkContext(Language, this, semanticNetwork));
        }
Exemplo n.º 12
0
        public QuestionBuilder(ISemanticNetwork semanticNetwork, IEnumerable <IStatement> preconditions)
        {
            if (semanticNetwork == null)
            {
                throw new ArgumentNullException(nameof(semanticNetwork));
            }

            SemanticNetwork = semanticNetwork;
            Preconditions   = preconditions;
        }
Exemplo n.º 13
0
        public static IText DescribeRules(this ISemanticNetwork semanticNetwork)
        {
            var result = new UnstructuredContainer();

            foreach (var statement in semanticNetwork.Statements)
            {
                result.Append(statement.DescribeTrue());
            }
            return(result);
        }
Exemplo n.º 14
0
 public static void DisplayRulesDescription(this ISemanticNetwork semanticNetwork, Window ownerWindow, ILanguage language, Action <IKnowledge> knowledgeObjectPicked)
 {
     new FormattedTextDialog(
         language,
         semanticNetwork.DescribeRules(),
         knowledgeObjectPicked)
     {
         Owner = ownerWindow,
         Title = language.GetExtension <IWpfUiModule>().Misc.Rules,
     }.Show();
 }
Exemplo n.º 15
0
 public static void DisplayConsistencyCheckResult(this ISemanticNetwork semanticNetwork, Window ownerWindow, ILanguage language, Action <IKnowledge> knowledgeObjectPicked)
 {
     new FormattedTextDialog(
         language,
         semanticNetwork.CheckConsistency(),
         knowledgeObjectPicked)
     {
         Owner = ownerWindow,
         Title = language.Statements.Consistency.CheckResult,
     }.Show();
 }
Exemplo n.º 16
0
        public void Initialize(ISemanticNetwork semanticNetwork, ILanguage language)
        {
            var languageEditing = language.GetExtension <IWpfUiModule>().Ui.Editing;

            _groupID.Header         = languageEditing.PropertyID;
            _groupName.Header       = languageEditing.PropertyName;
            _groupHint.Header       = languageEditing.PropertyHint;
            _groupAttributes.Header = languageEditing.PropertyAttributes;

            _nameControl.Localize(language);
            _hintControl.Localize(language);
        }
Exemplo n.º 17
0
        public void Initialize(ISemanticNetwork semanticNetwork, ILanguage language)
        {
            var wrappedConcepts = semanticNetwork.Concepts.Select(c => new ConceptItem(c, language)).ToList();

            _comboBoxConcept.ItemsSource = wrappedConcepts;
            _comboBoxSign.ItemsSource    = wrappedConcepts.Where(c => c.Concept.HasAttribute <IsSignAttribute>()).ToList();

            var languageEditing = language.GetExtension <IWpfUiModule>().Ui.Editing;

            _groupID.Header      = languageEditing.PropertyID;
            _groupConcept.Header = languageEditing.PropertyConcept;
            _groupSign.Header    = languageEditing.PropertySign;
        }
Exemplo n.º 18
0
        public void Initialize(ISemanticNetwork semanticNetwork, ILanguage language)
        {
            var wrappedConcepts = semanticNetwork.Concepts.Select(c => new ConceptItem(c, language)).ToList();

            _comboBoxAncestor.ItemsSource   = wrappedConcepts;
            _comboBoxDescendant.ItemsSource = wrappedConcepts;

            var languageEditing = language.GetExtension <IWpfUiModule>().Ui.Editing;

            _groupID.Header         = languageEditing.PropertyID;
            _groupAncestor.Header   = languageEditing.PropertyAncestor;
            _groupDescendant.Header = languageEditing.PropertyDescendant;
        }
Exemplo n.º 19
0
        public SemanticNetwork(ISemanticNetwork semanticNetwork)
        {
            Name = new LocalizedString(semanticNetwork.Name);

            Modules = semanticNetwork.Modules.Keys.ToList();

            Concepts = semanticNetwork.Concepts
                       .Where(concept => !ConceptIdResolver.SystemConceptsById.ContainsKey(concept.ID))
                       .Select(concept => new Concept(concept))
                       .ToList();

            Statements = semanticNetwork.Statements.Select(statement => Statement.Load(statement)).ToList();
        }
Exemplo n.º 20
0
        public StatementBuilder(ISemanticNetwork semanticNetwork, IConcept subject)
        {
            if (semanticNetwork == null)
            {
                throw new ArgumentNullException(nameof(semanticNetwork));
            }
            if (subject == null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            SemanticNetwork = semanticNetwork;
            Subject         = subject;
        }
Exemplo n.º 21
0
 private static void checkStatementDuplicates(ISemanticNetwork semanticNetwork, ITextContainer result)
 {
     foreach (var statement in semanticNetwork.Statements)
     {
         if (!statement.CheckUnique(semanticNetwork.Statements))
         {
             result.Append(
                 language => language.Statements.Consistency.ErrorDuplicate,
                 new Dictionary <String, IKnowledge> {
                 { Strings.ParamStatement, statement }
             });
         }
     }
 }
Exemplo n.º 22
0
 private static void checkCyclicParents(
     ICollection <IsStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     foreach (var clasification in statements)
     {
         if (!clasification.CheckCyclic(statements))
         {
             result.Append(
                 language => language.GetExtension <ILanguageClassificationModule>().Statements.Consistency.ErrorCyclic,
                 new Dictionary <String, IKnowledge> {
                 { Strings.ParamStatement, clasification }
             });
         }
     }
 }
Exemplo n.º 23
0
 private static void checkValuesWithoutSign(
     ICollection <SignValueStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     foreach (var signValue in statements)
     {
         if (!signValue.CheckHasSign(semanticNetwork.Statements))
         {
             result.Append(
                 language => language.GetExtension <ILanguageSetModule>().Statements.Consistency.ErrorSignWithoutValue,
                 new Dictionary <String, IKnowledge> {
                 { Semantics.Localization.Strings.ParamStatement, signValue }
             });
         }
     }
 }
Exemplo n.º 24
0
 private static void checkSelfRelations(
     ICollection <CustomStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     foreach (var statement in statements)
     {
         if (statement.Concept1 == statement.Concept2)
         {
             result.Append(
                 language => language.GetExtension <ILanguageCustomModule>().Statements.Consistency.SelfReference,
                 new Dictionary <String, IKnowledge> {
                 { CustomStatement.ParamConcept1, statement.Concept1 }
             });
         }
     }
 }
Exemplo n.º 25
0
        public void Initialize(ILanguage language, ISemanticNetwork semanticNetwork)
        {
            _radioGroup.Children.Clear();
            foreach (var statementDefinition in Repositories.Statements.Definitions.Values)
            {
                var radioButton = new RadioButton
                {
                    Margin  = new Thickness(5),
                    Content = statementDefinition.GetName(language),
                    Tag     = statementDefinition.Type,
                };
                _radioGroup.Children.Add(radioButton);
            }

            Title                 = language.GetExtension <IWpfUiModule>().Ui.StatementTypeDialogHeader;
            _buttonOk.Content     = language.GetExtension <IWpfUiModule>().Common.Ok;
            _buttonCancel.Content = language.GetExtension <IWpfUiModule>().Common.Cancel;
        }
Exemplo n.º 26
0
 private static void checkComparisonValueSystems(
     ICollection <ComparisonStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     foreach (var contradiction in statements.CheckForContradictions())
     {
         result
         .Append(
             language => language.GetExtension <ILanguageMathematicsModule>().Statements.Consistency.ErrorComparisonContradiction,
             new Dictionary <String, IKnowledge>
         {
             { Strings.ParamLeftValue, contradiction.Value1 },
             { Strings.ParamRightValue, contradiction.Value2 },
         })
         .Append(contradiction.Signs.EnumerateOneLine());
     }
 }
Exemplo n.º 27
0
 private static void checkProcessSequenceSystems(
     ICollection <ProcessesStatement> statements,
     ITextContainer result,
     ISemanticNetwork semanticNetwork)
 {
     foreach (var contradiction in statements.CheckForContradictions())
     {
         result
         .Append(
             language => language.GetExtension <ILanguageProcessesModule>().Statements.Consistency.ErrorProcessesContradiction,
             new Dictionary <String, IKnowledge>
         {
             { Localization.Strings.ParamProcessA, contradiction.Value1 },
             { Localization.Strings.ParamProcessB, contradiction.Value2 },
         })
         .Append(contradiction.Signs.EnumerateOneLine());
     }
 }
Exemplo n.º 28
0
        private static void checkSignDuplications(
            ICollection <HasSignStatement> statements,
            ITextContainer result,
            ISemanticNetwork semanticNetwork)
        {
            var clasifications = semanticNetwork.Statements.OfType <IsStatement>().ToList();

            foreach (var hasSign in statements)
            {
                if (!hasSign.CheckSignDuplication(statements, clasifications))
                {
                    result.Append(
                        language => language.GetExtension <ILanguageSetModule>().Statements.Consistency.ErrorMultipleSign,
                        new Dictionary <String, IKnowledge> {
                        { Semantics.Localization.Strings.ParamStatement, hasSign }
                    });
                }
            }
        }
Exemplo n.º 29
0
        public static IText CheckConsistency(this ISemanticNetwork semanticNetwork)
        {
            var result = new UnstructuredContainer();

            // 1. check all duplicates
            checkStatementDuplicates(semanticNetwork, result);

            // 2. check specific statements
            foreach (var statementDefinition in Repositories.Statements.Definitions.Values)
            {
                statementDefinition.CheckConsistency(semanticNetwork, result);
            }

            if (result.Items.Count == 0)
            {
                result.Append(language => language.Statements.Consistency.CheckOk);
            }
            return(result);
        }
Exemplo n.º 30
0
        public override Window CreateEditDialog(Window owner, ISemanticNetwork semanticNetwork, ILanguage language)
        {
            var control = new ProcessesStatementControl
            {
                Statement = this,
            };

            control.Initialize(semanticNetwork, language);
            var dialog = new EditDialog
            {
                Owner                 = owner,
                Editor                = control,
                Title                 = language.GetExtension <ILanguageProcessesModule>().Statements.Names.Processes,
                SizeToContent         = SizeToContent.WidthAndHeight,
                MinWidth              = 200,
                MinHeight             = 100,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
            };

            dialog.Localize(language);
            return(dialog);
        }