Exemplo n.º 1
0
        /// <summary>
        /// Removes a <see cref="NaturalLanguageRowViewModel"/>
        /// </summary>
        /// <param name="naturalLanguage">The associated <see cref="NaturalLanguage"/></param>
        private void RemoveNaturalLanguageRowViewModel(NaturalLanguage naturalLanguage)
        {
            var row = this.NaturalLanguageRowViewModels.SingleOrDefault(x => x.Thing == naturalLanguage);

            if (row != null)
            {
                this.NaturalLanguageRowViewModels.RemoveAndDispose(row);
            }
        }
        public void VerifyThatConvertProvidesTheExpectedIcon()
        {
            const string NaturalLanguageIcon  = "pack://application:,,,/CDP4Composition;component/Resources/Images/Thing/naturallanguage.png";
            var          naturalLanguage      = new NaturalLanguage();
            var          firstConverterResult = (BitmapImage)this.converter.Convert(new object[] { naturalLanguage }, null, null, null);

            Assert.AreEqual(NaturalLanguageIcon, firstConverterResult.UriSource.ToString());

            var secondConverterResult = (BitmapImage)this.converter.Convert(new object[] { naturalLanguage }, null, null, null);

            Assert.AreSame(firstConverterResult, secondConverterResult);
        }
Exemplo n.º 3
0
        public void VerifyThatConvertingNonParameterOrOverrideBaseReturnsNull()
        {
            var naturalLanguage = new NaturalLanguage();
            var converterResult = (BitmapImage)this.converter.Convert(new object[] { naturalLanguage }, null, null, null);

            Assert.IsNull(converterResult);

            var naturalLanguageRow = new NaturalLanguageRowViewModel(naturalLanguage, this.session.Object, null);
            var converterResult2   = (BitmapImage)this.converter.Convert(new object[] { naturalLanguageRow }, null, null, null);

            Assert.IsNull(converterResult2);
        }
Exemplo n.º 4
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);

            this.session = new Mock <ISession>();
            this.uri     = new Uri("http://www.reahroup.com");

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri)
            {
                Name = "site dir"
            };
            this.person = new Person(Guid.NewGuid(), null, this.uri)
            {
                GivenName = "John", Surname = "Doe"
            };

            var language = new NaturalLanguage(Guid.NewGuid(), null, this.uri)
            {
                Name         = "test",
                LanguageCode = "te",
                NativeName   = "test"
            };

            this.siteDir.NaturalLanguage.Add(language);

            this.serviceLocator = new Mock <IServiceLocator>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.navigationService            = new Mock <IPanelNavigationService>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.pluginSettingsService        = new Mock <IPluginSettingsService>();
            this.session        = new Mock <ISession>();
            this.panelViewModel = new Mock <IPanelViewModel>();

            this.serviceLocator.Setup(x => x.GetInstance <IPanelNavigationService>())
            .Returns(this.navigationService.Object);

            this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.ActivePerson).Returns(this.person);

            ServiceLocator.SetLocatorProvider(new ServiceLocatorProvider(() => this.serviceLocator.Object));

            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);

            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();

            this.naturalLanguage = new NaturalLanguage(Guid.NewGuid(), null, null)
            {
                LanguageCode = this.languageCode, NativeName = this.nativeName, Name = this.name
            };
            this.viewModel = new NaturalLanguageRowViewModel(this.naturalLanguage, this.session.Object, null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Serialize the <see cref="NaturalLanguage"/>
        /// </summary>
        /// <param name="naturalLanguage">The <see cref="NaturalLanguage"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(NaturalLanguage naturalLanguage)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), naturalLanguage.ClassKind)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](naturalLanguage.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](naturalLanguage.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](naturalLanguage.Iid));
            jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](naturalLanguage.LanguageCode));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](naturalLanguage.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](naturalLanguage.Name));
            jsonObject.Add("nativeName", this.PropertySerializerMap["nativeName"](naturalLanguage.NativeName));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](naturalLanguage.RevisionNumber));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](naturalLanguage.ThingPreference));
            return(jsonObject);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Take a block of text containing words, separate anything with spaces in between to make separate words and build
        /// a count of unique words against number of occurances.
        /// Filters out words 3 characters or less and converts everything to lowercase.
        /// I'm using floats rather than ints for the count as everything ends up as weights in the end.
        /// </summary>
        /// <param name="Text">The block of text to process</param>
        /// <returns>A dictionary of word counts where all the words are lowercase and >3 characters</returns>
        public Dictionary <string, float> TextToHistogram(string Text)
        {
            Dictionary <string, float> hist = new Dictionary <string, float>();

            string[] words = NaturalLanguage.SplitWords(Text);
            foreach (string word in words)
            {
                if (hist.ContainsKey(word))
                {
                    hist[word] += 1;
                }
                else
                {
                    hist.Add(word, 1);
                }
            }
            return(hist);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Apply the stem words algorithm to all the words in a histogram and return a new one with correct counts.
        /// I'm using floats rather than ints for the counts as everything ends up as weights in the end.
        /// </summary>
        /// <param name="Hist"></param>
        /// <returns></returns>
        public Dictionary <string, float> StemHistogram(Dictionary <string, float> Hist)
        {
            NaturalLanguage            nlp      = new NaturalLanguage();
            Dictionary <string, float> StemHist = new Dictionary <string, float>();

            foreach (KeyValuePair <string, float> KVP in Hist)
            {
                string StemWord = nlp.StemWord(KVP.Key);
                if (StemHist.ContainsKey(StemWord))
                {
                    StemHist[StemWord] += KVP.Value;
                }
                else
                {
                    StemHist.Add(StemWord, KVP.Value);
                }
            }
            return(StemHist);
        }
Exemplo n.º 9
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.session   = new Mock <ISession>();
            this.uri       = new Uri("http://test.com");
            this.assembler = new Assembler(this.uri);
            this.person    = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                GivenName = "John", Surname = "Doe"
            };
            this.siteDir      = new SiteDirectory(Guid.NewGuid(), this.assembler.Cache, this.uri);
            this.siteDir.Name = "site dir";

            var language = new NaturalLanguage(Guid.NewGuid(), null, this.uri)
            {
                Name         = "test",
                LanguageCode = "te",
                NativeName   = "test"
            };

            this.siteDir.NaturalLanguage.Add(language);
            this.serviceLocator    = new Mock <IServiceLocator>();
            this.navigationService = new Mock <IThingDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>())
            .Returns(this.navigationService.Object);

            this.session.Setup(x => x.ActivePerson).Returns(this.person);
            this.session.Setup(x => x.Assembler).Returns(this.assembler);

            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <ClassKind>(), It.IsAny <Thing>())).Returns(true);

            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
        }
        public void VerifyThatPropertiesAreSet()
        {
            var language = new NaturalLanguage(Guid.NewGuid(), null, new Uri("http://test.com"));

            language.Name         = "Test";
            language.LanguageCode = "t";
            language.NativeName   = "Testa";

            var row = new NaturalLanguageRowViewModel(language, this.session.Object, null);

            Assert.AreEqual(language.Name, row.Name);
            Assert.AreEqual(language.LanguageCode, row.LanguageCode);
            Assert.AreEqual(language.NativeName, row.NativeName);

            language.Name = "update";
            // workaround to modify a read-only field
            var type = language.GetType();

            type.GetProperty("RevisionNumber").SetValue(language, 50);
            CDPMessageBus.Current.SendObjectChangeEvent(language, EventKind.Updated);

            Assert.AreEqual(language.Name, row.Name);
        }
        public void Verify_that_CheckWheterTheLanguageCodeExistsInTheSiteDirectory_yields_correct_result_for_SiteDirectory_Contained_Alias()
        {
            var alias = new Alias();

            alias.LanguageCode = "en-GB";

            this.engineeringModelSetup.Alias.Add(alias);

            var result = this.annotationRuleChecker.CheckWheterTheLanguageCodeExistsInTheSiteDirectory(alias).SingleOrDefault();

            Assert.That(result.Id, Is.EqualTo("MA-0100"));
            Assert.That(result.Severity, Is.EqualTo(SeverityKind.Warning));
            Assert.That(result.Thing, Is.EqualTo(alias));

            var naturalLanguage = new NaturalLanguage();

            naturalLanguage.LanguageCode = "en-GB";
            this.siteDirectory.NaturalLanguage.Add(naturalLanguage);

            var results = this.annotationRuleChecker.CheckWheterTheLanguageCodeExistsInTheSiteDirectory(alias);

            Assert.That(results, Is.Empty);
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.cache           = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            this.session         = new Mock <ISession>();
            this.siteDir         = new SiteDirectory(Guid.NewGuid(), this.cache, null);
            this.naturalLanguage = new NaturalLanguage();

            this.clone = this.siteDir.Clone(false);
            this.cache.TryAdd(new CacheKey(this.siteDir.Iid, null), new Lazy <Thing>(() => this.siteDir));

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
Exemplo n.º 13
0
        public void VerifyThatPropertiesAreSet()
        {
            var viewmodel = new NaturalLanguageBrowserViewModel(this.session.Object, this.siteDir, null, null, null, null);

            Assert.AreEqual(1, viewmodel.NaturalLanguageRowViewModels.Count);
            Assert.IsTrue(viewmodel.Caption.Contains(viewmodel.Thing.Name));
            Assert.IsTrue(viewmodel.ToolTip.Contains(viewmodel.Thing.IDalUri.ToString()));

            this.siteDir.Name = "hoho";
            // workaround to modify a read-only field
            var type = this.siteDir.GetType();

            type.GetProperty("RevisionNumber").SetValue(this.siteDir, 50);

            var language = new NaturalLanguage(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                Name         = "test",
                LanguageCode = "te2",
                NativeName   = "test"
            };

            this.siteDir.NaturalLanguage.Add(language);
            this.revField.SetValue(this.siteDir, 10);
            CDPMessageBus.Current.SendObjectChangeEvent(this.siteDir, EventKind.Updated);

            Assert.IsTrue(viewmodel.Caption.Contains(viewmodel.Thing.Name));

            // Verify that the add doesnt do anything as there is already a language with the same languagecode
            Assert.AreEqual(2, viewmodel.NaturalLanguageRowViewModels.Count);


            this.siteDir.NaturalLanguage.Remove(language);
            this.revField.SetValue(this.siteDir, 20);
            CDPMessageBus.Current.SendObjectChangeEvent(this.siteDir, EventKind.Updated);
            Assert.AreEqual(1, viewmodel.NaturalLanguageRowViewModels.Count);
        }
        public void Verify_that_CheckWheterTheLanguageCodeExistsInTheSiteDirectory_yields_correct_result_for_EngineeringModel_Contained_Alias()
        {
            var engineeringModel = new EngineeringModel();

            engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;

            var iteration = new Iteration();

            engineeringModel.Iteration.Add(iteration);

            var elementDefinition = new ElementDefinition();

            iteration.Element.Add(elementDefinition);

            var alias = new Alias {
                LanguageCode = "en-GB"
            };

            elementDefinition.Alias.Add(alias);

            var result = this.annotationRuleChecker.CheckWheterTheLanguageCodeExistsInTheSiteDirectory(alias).SingleOrDefault();

            Assert.That(result.Id, Is.EqualTo("MA-0100"));
            Assert.That(result.Description, Is.EqualTo($"The Annotation.LanguageCode: {alias.LanguageCode} for Idd: {alias.Iid} does not exist in the SiteDirectory { siteDirectory.Iid}"));
            Assert.That(result.Severity, Is.EqualTo(SeverityKind.Warning));
            Assert.That(result.Thing, Is.EqualTo(alias));

            var naturalLanguage = new NaturalLanguage();

            naturalLanguage.LanguageCode = "en-GB";
            this.siteDirectory.NaturalLanguage.Add(naturalLanguage);

            var results = this.annotationRuleChecker.CheckWheterTheLanguageCodeExistsInTheSiteDirectory(alias);

            Assert.That(results, Is.Empty);
        }
Exemplo n.º 15
0
        public void SetUp()
        {
            this.siteDirectory = new SiteDirectory(Guid.NewGuid(), null, null);

            var domain1 = new DomainOfExpertise(Guid.NewGuid(), null, null);

            this.siteDirectory.Domain.Add(domain1);
            var domain2 = new DomainOfExpertise(Guid.NewGuid(), null, null);

            this.siteDirectory.Domain.Add(domain2);

            var alias = new Alias(Guid.NewGuid(), null, null);

            domain1.Alias.Add(alias);

            var domainGroup1 = new DomainOfExpertiseGroup(Guid.NewGuid(), null, null);

            this.siteDirectory.DomainGroup.Add(domainGroup1);
            var domainGroup2 = new DomainOfExpertiseGroup(Guid.NewGuid(), null, null);

            this.siteDirectory.DomainGroup.Add(domainGroup2);

            var engineeringModelSetup = new EngineeringModelSetup(Guid.NewGuid(), null, null);

            this.siteDirectory.Model.Add(engineeringModelSetup);
            var iterationSetup = new IterationSetup(Guid.NewGuid(), null, null);

            engineeringModelSetup.IterationSetup.Add(iterationSetup);

            var naturalLanguage1 = new NaturalLanguage(Guid.NewGuid(), null, null);

            this.siteDirectory.NaturalLanguage.Add(naturalLanguage1);
            var naturalLanguage2 = new NaturalLanguage(Guid.NewGuid(), null, null);

            this.siteDirectory.NaturalLanguage.Add(naturalLanguage2);

            var organization1 = new Organization(Guid.NewGuid(), null, null);

            this.siteDirectory.Organization.Add(organization1);
            var organization2 = new Organization(Guid.NewGuid(), null, null);

            this.siteDirectory.Organization.Add(organization2);

            var participantRole1 = new ParticipantRole(Guid.NewGuid(), null, null);

            this.siteDirectory.ParticipantRole.Add(participantRole1);
            var participantRole2 = new ParticipantRole(Guid.NewGuid(), null, null);

            this.siteDirectory.ParticipantRole.Add(participantRole2);

            this.person1 = new Person(Guid.NewGuid(), null, null);
            this.siteDirectory.Person.Add(this.person1);
            this.person2 = new Person(Guid.NewGuid(), null, null);
            this.siteDirectory.Person.Add(this.person2);

            var personRole1 = new PersonRole(Guid.NewGuid(), null, null);

            this.siteDirectory.PersonRole.Add(personRole1);
            var personRole2 = new PersonRole(Guid.NewGuid(), null, null);

            this.siteDirectory.PersonRole.Add(personRole2);

            var siteReferenceDataLibrary1 = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null);

            this.siteDirectory.SiteReferenceDataLibrary.Add(siteReferenceDataLibrary1);
            var siteReferenceDataLibrary2 = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null);

            this.siteDirectory.SiteReferenceDataLibrary.Add(siteReferenceDataLibrary2);

            this.engineeringModel = new EngineeringModel(Guid.NewGuid(), null, null);
            this.engineeringModel.EngineeringModelSetup = engineeringModelSetup;
            engineeringModelSetup.EngineeringModelIid   = this.engineeringModel.Iid;

            this.iteration = new Iteration(Guid.NewGuid(), null, null);
            this.iteration.IterationSetup = iterationSetup;
            iterationSetup.IterationIid   = this.iteration.Iid;

            this.engineeringModel.Iteration.Add(this.iteration);

            var modelReferenceDataLibrary = new ModelReferenceDataLibrary(Guid.NewGuid(), null, null);

            modelReferenceDataLibrary.RequiredRdl = siteReferenceDataLibrary1;

            engineeringModelSetup.RequiredRdl.Add(modelReferenceDataLibrary);

            var participant = new Participant(Guid.NewGuid(), null, null);

            participant.Person = this.person1;
            participant.Domain.Add(domain1);
            participant.Role = participantRole1;

            engineeringModelSetup.Participant.Add(participant);

            var elementDefinition1 = new ElementDefinition(Guid.NewGuid(), null, null);

            this.iteration.Element.Add(elementDefinition1);
            var elementDefinition2 = new ElementDefinition(Guid.NewGuid(), null, null);

            this.iteration.Element.Add(elementDefinition2);

            var elementUsage = new ElementUsage(Guid.NewGuid(), null, null);

            elementDefinition1.ContainedElement.Add(elementUsage);
            elementUsage.ElementDefinition = elementDefinition2;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Adds a <see cref="NaturalLanguageRowViewModel"/>
        /// </summary>
        /// <param name="naturalLanguage">The associated <see cref="NaturalLanguage"/></param>
        private void AddNaturalLanguageRowViewModel(NaturalLanguage naturalLanguage)
        {
            var row = new NaturalLanguageRowViewModel(naturalLanguage, this.Session, this);

            this.NaturalLanguageRowViewModels.Add(row);
        }
Exemplo n.º 17
0
 public void Setup()
 {
     result = NaturalLanguage.AnalyzeEverything(inputText);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NaturalLanguageDialogViewModel"/> class
 /// </summary>
 /// <param name="naturalLanguage">The <see cref="NaturalLanguage"/> represented</param>
 /// <param name="transaction">
 /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
 /// </param>
 /// <param name="session">
 /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="DomainOfExpertiseDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="DomainOfExpertiseDialogViewModel"/> performs
 /// </param>
 /// <param name="thingDialogNavigationService">
 /// The <see cref="IThingDialogNavigationService"/> that allows to navigate to <see cref="Thing"/> dialog view models
 /// </param>
 /// <param name="container">The container <see cref="Thing"/> for the created <see cref="Thing"/></param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 public NaturalLanguageDialogViewModel(NaturalLanguage naturalLanguage, ThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(naturalLanguage, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
 }
Exemplo n.º 19
0
 public KeywordProcessor(string StopWordsFilename)
 {
     //load the stop words into a hash
     StopWordsList = NaturalLanguage.LoadStopWords(StopWordsFilename);
 }
Exemplo n.º 20
0
        public Claim GetAnnotatedText(string text)
        {
            var claim = new ClaimPopulator();

            return(claim.PopulateClaim(NaturalLanguage.AnalyzeEverything(text)));
        }
 /// <summary>
 /// Add an Natural Language row view model to the list of <see cref="NaturalLanguage"/>
 /// </summary>
 /// <param name="naturalLanguage">
 /// The <see cref="NaturalLanguage"/> that is to be added
 /// </param>
 private NaturalLanguageRowViewModel AddNaturalLanguageRowViewModel(NaturalLanguage naturalLanguage)
 {
     return(new NaturalLanguageRowViewModel(naturalLanguage, this.Session, this));
 }