public void ShoudBeInSyncWhenAddingWords()
 {
     sentence.Words.Remove(Word);
     var wrapper = new SentenceWrapper(sentence);
     wrapper.Words.Add(new WordWrapper(Word));
     CheckModelWordsCollectionIsInSync(wrapper);
 }
Example #2
0
        private void AddComparableEdges(SentenceWrapper sentence, SentenceGraph sentenceGraph, bool isLeft, bool isRight)
        {
            string to, from;
            var vertices = sentenceGraph.Vertices.ToList();
            foreach (var word in sentence.Words)
            {
                from = word.GetAttributeByName(CurrentDefinition.Edge.SourceVertexAttributeName);

                if (from == "0")
                {
                    continue;
                }

                to = word.GetAttributeByName(CurrentDefinition.Edge.TargetVertexAttributeName);

                var toWordVertex =
                    vertices.FirstOrDefault(
                        v => v.WordWrapper.GetAttributeByName(CurrentDefinition.Edge.TargetVertexAttributeName).Equals(to));
                var fromWordVertex =
                    vertices.FirstOrDefault(
                        v => v.WordWrapper.GetAttributeByName(CurrentDefinition.Edge.TargetVertexAttributeName).Equals(from));
                if ((toWordVertex != null) && (fromWordVertex != null))
                {
                    sentenceGraph.AddEdge(
                        new OrderedWordEdge(fromWordVertex, toWordVertex)
                        {
                            Text = word.GetAttributeByName(CurrentDefinition.Edge.LabelAttributeName),
                            SourceConnectionPointId = 1,
                            TargetConnectionPointId = 1,
                            IsLeft = isLeft,
                            IsRight = isRight
                        });
                }
            }
        }
        public void ShoudBeInSyncAfterClearingWords()
        {
            var wrapper = new SentenceWrapper(sentence);
            wrapper.Words.Clear();

            CheckModelWordsCollectionIsInSync(wrapper);
        }
        public void ShoudBeInSyncWhenRemovingWords()
        {
            var wrapper = new SentenceWrapper(sentence);
            var wordToRemove = wrapper.Words.Single(ww => ww.Model == Word);
            wrapper.Words.Remove(wordToRemove);

            CheckModelWordsCollectionIsInSync(wrapper);
        }
        public WordReorderingViewModel(SentenceWrapper sentenceWrapper)
        {
            if (sentenceWrapper == null)
            {
                throw new ArgumentNullException("sentenceWrapper");
            }

            InitializeCommands();
            Sentence = sentenceWrapper;
        }
Example #6
0
        public SentenceGxLogicCore SetupGraphLogic(SentenceWrapper sentence, SentenceWrapper rightSentence)
        {
            var sentenceGraph = BuildSentenceGraph(sentence, rightSentence);

            return new SentenceGxLogicCore
            {
                EdgeCurvingEnabled = false,
                Graph = sentenceGraph,
                EnableParallelEdges = false
            };
        }
        public void ShouldSetIsValidOfRoot()
        {
            var wrapper = new SentenceWrapper(sentence);

            Assert.IsTrue(wrapper.IsValid);

            wrapper.Words.First().Attributes.Single(a => a.DisplayName.Equals("Form")).Value = string.Empty;

            Assert.IsFalse(wrapper.IsValid);

            wrapper.Words.First().Attributes.Single(a => a.DisplayName.Equals("Form")).Value = "new form";

            Assert.IsTrue(wrapper.IsValid);
        }
Example #8
0
        public void ShouldSetValueOfUnderlyingModelProperty()
        {
            var wrapper = new SentenceWrapper(sentence);

            const string newWordId = "2";

            var newWord = DomainMother.Word;
            newWord.Attributes.Single(a => a.Name == "Id").Value = newWordId;

            wrapper.Words = new ChangeTrackingCollection<WordWrapper>(new List<WordWrapper>
            {
                new WordWrapper(newWord)
            });

            Assert.AreEqual(wrapper.Words.First().Attributes.Single(a => a.DisplayName == "Id").Value, newWordId);
        }
        public void ShouldRefreshErrorsAndIsValidWhenRejectingChanges()
        {
            var wrapper = new SentenceWrapper(sentence);

            Assert.IsTrue(wrapper.IsValid);
            Assert.IsFalse(wrapper.HasErrors);

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;
            Assert.IsFalse(wrapper.IsValid);
            Assert.IsTrue(wrapper.HasErrors);

            wrapper.RejectChanges();

            Assert.IsTrue(wrapper.IsValid);
            Assert.IsFalse(wrapper.HasErrors);
        }
        public void ShoudRaisePropertyChangedEventForParserIsChanged()
        {
            var wrapper = new SentenceWrapper(sentence);

            var fired = false;

            wrapper.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "ParserIsChanged")
                {
                    fired = true;
                }
            };

            wrapper.Attributes.Single(a => a.Name == "Parser").Value = "new parser";

            Assert.IsTrue(fired);
        }
        public void ShouldAcceptChanges()
        {
            var wrapper = new SentenceWrapper(sentence);

            wrapper.Attributes.Single(a => a.Name == "Parser").Value = "new value";

            Assert.AreEqual("new value", wrapper.Attributes.Single(a => a.Name == "Parser").Value);
            Assert.AreEqual(parserValue, wrapper.Attributes.Single(a => a.Name == "Parser").ValueOriginalValue);
            Assert.IsTrue(wrapper.Attributes.Single(a => a.Name == "Parser").ValueIsChanged);
            Assert.IsTrue(wrapper.IsChanged);

            wrapper.AcceptChanges();

            Assert.AreEqual("new value", wrapper.Attributes.Single(a => a.Name == "Parser").Value);
            Assert.AreEqual("new value", wrapper.Attributes.Single(a => a.Name == "Parser").ValueOriginalValue);
            Assert.IsFalse(wrapper.Attributes.Single(a => a.Name == "Parser").ValueIsChanged);
            Assert.IsFalse(wrapper.IsChanged);
        }
        public void ShoudNotRaisePropertyChangedEventIfNewValueIsSameAsOldValue()
        {
            var wrapper = new SentenceWrapper(sentence);

            var fired = false;

            wrapper.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Parser")
                {
                    fired = true;
                }
            };

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value =
                sentence.Attributes.Single(a => a.DisplayName == "Parser").Value;

            Assert.IsFalse(fired);
        }
        public void ShouldReturnValidationErrorWhenParserIsSetToEmptyAnd()
        {
            var wrapper = new SentenceWrapper(sentence);

            Assert.IsFalse(wrapper.HasErrors);

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;

            Assert.IsTrue(wrapper.HasErrors);

            var errors = (List<string>) wrapper.GetErrors("Parser");

            Assert.AreEqual(1, errors.Count());
            Assert.AreEqual("Parser is required.", errors.First());

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = "parser value";

            Assert.IsFalse(wrapper.HasErrors);
        }
        public void ShouldRaisePropertyChangedEventForIsValid()
        {
            var wrapper = new SentenceWrapper(sentence);

            var fired = false;

            wrapper.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "IsValid")
                {
                    fired = true;
                }
            };

            wrapper.Words.First().Attributes.Single(a => a.DisplayName.Equals("Form")).Value = string.Empty;
            Assert.IsTrue(fired);

            fired = false;
            wrapper.Words.First().Attributes.Single(a => a.DisplayName.Equals("Form")).Value = "form value";
            Assert.IsTrue(fired);
        }
        public void ShouldRaisePropertyChangedEventForIsValid()
        {
            var wrapper = new SentenceWrapper(sentence);

            var fired = false;

            wrapper.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "IsValid")
                {
                    fired = true;
                }
            };

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;
            Assert.IsTrue(fired);

            fired = false;
            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = "parser values";
            Assert.IsTrue(fired);
        }
        public void ShouldRaiseErrorsChangedEventWhenParserIsSetToEmpty()
        {
            var wrapper = new SentenceWrapper(sentence);

            var fired = false;

            wrapper.ErrorsChanged += (s, e) =>
            {
                if (e.PropertyName == "Parser")
                {
                    fired = true;
                }
            };

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;

            Assert.IsTrue(fired);

            fired = false;
            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = "parser value";

            Assert.IsFalse(wrapper.HasErrors);
        }
Example #17
0
        private SentenceGraph BuildSentenceGraph(SentenceWrapper sentence, SentenceWrapper rightSentence)
        {
            var sentenceGraph = new SentenceGraph();

            sentence.Words.Sort(
                    (l, r) =>
                        int.Parse(l.GetAttributeByName(CurrentDefinition.Edge.TargetVertexAttributeName))
                            .CompareTo(int.Parse(r.GetAttributeByName(CurrentDefinition.Edge.TargetVertexAttributeName))));

            foreach (var word in sentence.Words)
            {
                sentenceGraph.AddVertex(new WordVertex(word, CurrentDefinition.Vertex.LabelAttributeName));
            }

            AddComparableEdges(sentence, sentenceGraph, true, false);
            AddComparableEdges(rightSentence, sentenceGraph, false, true);

            return sentenceGraph;
        }
        public void ShouldSetIsValid()
        {
            var wrapper = new SentenceWrapper(sentence);

            Assert.IsTrue(wrapper.IsValid);

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;
            Assert.IsFalse(wrapper.IsValid);

            wrapper.Attributes.Single(a => a.DisplayName == "Parser").Value = "parser value";
            Assert.IsTrue(wrapper.IsValid);
        }
        public void ShouldSetErrorsAndIsValidAfterInitialization()
        {
            sentence.Attributes.Single(a => a.DisplayName == "Parser").Value = string.Empty;
            var wrapper = new SentenceWrapper(sentence);

            Assert.IsFalse(wrapper.IsValid);
            Assert.IsTrue(wrapper.HasErrors);

            var errors = (List<string>) wrapper.GetErrors("Parser");
            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual("Parser is required.", errors.First());
        }
Example #20
0
        private async Task LoadWordsForSentence(
            SentenceWrapper selectedSentence,
            string documentFilePath,
            string configFilePath)
        {
            var extension = Path.GetExtension(documentFilePath);
            if (extension != null)
            {
                var lowercaseExtension = extension.Substring(1).ToLowerInvariant();

                DocumentMapperClient documentMapper = null;

                if (lowercaseExtension.Equals(ConfigurationStaticData.XmlFormat))
                {
                    documentMapper =
                        new DocumentMapperClient(
                            new LightDocumentMapperWithReader
                            {
                                AppConfigMapper = appConfigMapper,
                                EventAggregator = eventAggregator
                            });
                }
                else if (lowercaseExtension.Equals(ConfigurationStaticData.ConllxFormat)
                         || lowercaseExtension.Equals(ConfigurationStaticData.ConllFormat))
                {
                    documentMapper =
                        new DocumentMapperClient(
                            new LightConllxDocumentMapper
                            {
                                AppConfigMapper = appConfigMapper,
                                EventAggregator = eventAggregator
                            });
                }

                if (documentMapper == null)
                {
                    return;
                }

                var sentenceLoaded =
                    await documentMapper.LoadSentence(selectedSentence.Id.Value, documentFilePath, configFilePath);

                if (sentenceLoaded == null)
                {
                    return;
                }

                var selectedSentenceIndex = SelectedDocument.Sentences.IndexOf(SelectedSentence);

                SelectedDocument.Sentences[selectedSentenceIndex] = new SentenceWrapper(sentenceLoaded);

                SelectedSentence = SelectedDocument.Sentences[selectedSentenceIndex];
            }

            SelectedDocument.AcceptChanges();
        }
Example #21
0
        private void OnCheckIsTreeOnSentence(SentenceWrapper sentenceWrapper)
        {
            if (sentenceWrapper == null)
            {
                return;
            }

            var validationResult = new CheckGraphResult();

            // todo no bueno with the app config
            var appConfig =
                appConfigMapper.Map(SelectedDocument.Model.GetAttributeByName("configurationFilePath"))
                    .GetAwaiter()
                    .GetResult();

            sentenceWrapper.IsTree =
                GraphOperations.GetGraph(sentenceWrapper.Model, appConfig.Definitions.First(), eventAggregator)
                    .IsTree(validationResult);

            if (!sentenceWrapper.IsTree)
            {
                foreach (var disconnectedWordId in validationResult.DisconnectedWordIds)
                {
                    eventAggregator.GetEvent<ValidationExceptionEvent>()
                        .Publish(
                            string.Format(
                                "The word id: {0}, in sentence id: {1}, is not connected to another word.",
                                disconnectedWordId,
                                sentenceWrapper.Id.Value));
                }

                foreach (var cycle in validationResult.Cycles)
                {
                    eventAggregator.GetEvent<ValidationExceptionEvent>()
                        .Publish(
                            string.Format(
                                "The sentence with id {0} has cycle: {1}",
                                sentence.Id.Value,
                                string.Join(",", cycle)));
                }

                if (validationResult.DisconnectedWordIds.Any() || validationResult.Cycles.Any())
                {
                    eventAggregator.GetEvent<StatusNotificationEvent>()
                        .Publish("Please check warnings in the Output panel.");
                }
            }
        }
Example #22
0
        private void AddSentenceCommandExecute(object obj)
        {
            if (SelectedDocument != null)
            {
                var appconfig =
                    appConfigMapper.Map(SelectedDocument.Model.GetAttributeByName("configurationFilePath"))
                        .GetAwaiter()
                        .GetResult();

                var sentencePrototype = DataStructure.Elements.OfType<Sentence>().FirstOrDefault();
                var wordPrototype = DataStructure.Elements.OfType<Word>().FirstOrDefault();
                var configuration = appconfig.Definitions.FirstOrDefault();

                if (configuration == null)
                {
                    eventAggregator.GetEvent<StatusNotificationEvent>()
                        .Publish("Must define a configuration in the configuration file before adding a sentence");
                    return;
                }

                var inputDialog = new InputDialog("Enter sentence");

                if (inputDialog.ShowDialog().GetValueOrDefault())
                {
                    var sentenceContent = inputDialog.Value;

                    if (sentencePrototype != null)
                    {
                        var sentenceClone = ObjectCopier.Clone(sentencePrototype);

                        sentenceClone.SetAttributeByName("date", DateTime.Now.ToString("dd-MM-yyyy"));
                        sentenceClone.SetAttributeByName("id", (SelectedDocument.Sentences.Count + 1).ToString());
                        var newSentence = new SentenceWrapper(sentenceClone)
                        {
                            IsOptional = false,
                            Content =
                                new AttributeWrapper(
                                    new Attribute
                                    {
                                        Name = "content",
                                        DisplayName =
                                            "Content",
                                        Value =
                                            sentenceContent,
                                        IsOptional = true,
                                        IsEditable = false
                                    })
                        };

                        var words = sentenceContent.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

                        for (var i = 0; i < words.Length; i++)
                        {
                            var wordContent = words[i];
                            var newWord = ObjectCopier.Clone(wordPrototype);
                            newWord.Value = wordContent;

                            newWord.SetAttributeByName(configuration.Edge.TargetVertexAttributeName, (i + 1).ToString());
                            newWord.SetAttributeByName(configuration.Edge.SourceVertexAttributeName, "0");

                            newWord.Attributes.Add(
                                new Attribute
                                {
                                    Name = "content",
                                    DisplayName = "Content",
                                    Value = wordContent,
                                    IsOptional = true,
                                    IsEditable = false
                                });

                            if (wordPrototype != null)
                            {
                                var attribute =
                                    newWord.Attributes.FirstOrDefault(
                                        a => a.Name == configuration.Vertex.LabelAttributeName);

                                if (attribute != null)
                                {
                                    attribute.Value = wordContent;
                                }
                            }

                            var newWordWrapper = new WordWrapper(newWord);

                            newSentence.Words.Add(newWordWrapper);
                        }

                        newSentence.Attributes.ForEach(
                            a =>
                            {
                                a.IsOptional = false;
                                a.IsEditable = true;
                            });

                        SelectedDocument.Sentences.Add(newSentence);
                        SelectedSentence = newSentence;
                    }
                }
            }
        }
 public void ShoudInitializeWordsPropery()
 {
     var wrapper = new SentenceWrapper(sentence);
     Assert.IsNotNull(wrapper.Words);
     CheckModelWordsCollectionIsInSync(wrapper);
 }
 private void CheckModelWordsCollectionIsInSync(SentenceWrapper wrapper)
 {
     Assert.AreEqual(sentence.Words.Count, wrapper.Words.Count);
     Assert.IsTrue(
         sentence.Words.All(modelWord => wrapper.Words.Any(wrappedWord => wrappedWord.Model == modelWord)));
 }
        public void ShouldStoreOriginalValue()
        {
            var wrapper = new SentenceWrapper(sentence);

            Assert.AreEqual(parserValue, wrapper.Attributes.Single(a => a.Name == "Parser").ValueOriginalValue);

            wrapper.Attributes.Single(a => a.Name == "Parser").Value = "new value";

            Assert.AreEqual(parserValue, wrapper.Attributes.Single(a => a.Name == "Parser").ValueOriginalValue);
        }
        public void ShouldSetIsChanged()
        {
            var wrapper = new SentenceWrapper(sentence);
            Assert.IsFalse(wrapper.Attributes.Single(a => a.Name == "Parser").ValueIsChanged);
            Assert.IsFalse(wrapper.IsChanged);

            wrapper.Attributes.Single(a => a.Name == "Parser").Value = "new value";
            Assert.IsTrue(wrapper.Attributes.Single(a => a.Name == "Parser").ValueIsChanged);
            Assert.IsTrue(wrapper.IsChanged);

            wrapper.Attributes.Single(a => a.Name == "Parser").Value = parserValue;
            Assert.IsFalse(wrapper.Attributes.Single(a => a.Name == "Parser").ValueIsChanged);
            Assert.IsFalse(wrapper.IsChanged);
        }
Example #27
0
 public void ShouldContainModelInModelProperty()
 {
     var wrapper = new SentenceWrapper(sentence);
     Assert.AreEqual(sentence, wrapper.Model);
 }