Exemplo n.º 1
0
        /// <summary>
        /// Get the values we want for the occurrences of the specified LexSE HVO.
        /// </summary>
        /// <param name="hvo"></param>
        /// <returns></returns>
        int[] GetSenseOccurrences(int hvo)
        {
            int[] values;
            if (m_values.TryGetValue(hvo, out values))
            {
                return(values);
            }
            var sense      = m_services.GetInstance <ILexSenseRepository>().GetObject(hvo);
            var bundles    = m_services.GetInstance <IWfiMorphBundleRepository>().InstancesWithSense(sense);
            var valuesList = new List <int>();

            foreach (IWfiAnalysis wa in (from bundle in bundles select bundle.Owner).Distinct())
            {
                var bag = ((IWfiWordform)wa.Owner).OccurrencesBag;
                foreach (var seg in from item in bag.Items where BelongsToInterestingText(item) select item)
                {
                    foreach (var occurrence in seg.GetOccurrencesOfAnalysis(wa, bag.Occurrences(seg), true))
                    {
                        int hvoOcc = m_nextId--;
                        valuesList.Add(hvoOcc);
                        m_occurrences[hvoOcc] = occurrence;
                    }
                }
            }
            values        = valuesList.ToArray();
            m_values[hvo] = values;
            return(values);
        }
Exemplo n.º 2
0
        public void AddTo_RefColToRefCol()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexDb             lexDb   = lp.LexDbOA;
            ILexAppendix       app1    = servLoc.GetInstance <ILexAppendixFactory>().Create();

            lexDb.AppendixesOC.Add(app1);
            ILexAppendix app2 = servLoc.GetInstance <ILexAppendixFactory>().Create();

            lexDb.AppendixesOC.Add(app2);
            ILexEntry le1    = servLoc.GetInstance <ILexEntryFactory>().Create();
            ILexSense sense1 = servLoc.GetInstance <ILexSenseFactory>().Create();

            le1.SensesOS.Add(sense1);
            ILexSense sense2 = servLoc.GetInstance <ILexSenseFactory>().Create();

            le1.SensesOS.Add(sense2);

            sense1.AppendixesRC.Add(app1);
            sense1.AppendixesRC.Add(app2);

            sense1.AppendixesRC.AddTo(sense2.AppendixesRC);

            Assert.AreEqual(2, sense2.AppendixesRC.Count);
            Assert.IsTrue(sense2.AppendixesRC.Contains(app1));
            Assert.IsTrue(sense2.AppendixesRC.Contains(app2));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Make an individual spelling dictionary conform as closely as possible to the spelling status
        /// recorded in Wordforms.
        /// </summary>
        /// <param name="ws"></param>
        /// <param name="cache"></param>
        public static void ConformOneSpellingDictToWordforms(int ws, LcmCache cache)
        {
            ILcmServiceLocator servloc = cache.ServiceLocator;
            var lgwsFactory            = servloc.GetInstance <ILgWritingSystemFactory>();
            var dict = SpellingHelper.GetSpellChecker(ws, lgwsFactory);

            if (dict == null)
            {
                return;
            }
            // we only force one to exist for the default, others might not have one.
            var words = new List <string>();

            foreach (IWfiWordform wf in servloc.GetInstance <IWfiWordformRepository>().AllInstances())
            {
                if (wf.SpellingStatus != (int)SpellingStatusStates.correct)
                {
                    continue;                     // don't put it in the list of correct words
                }
                string wordform = wf.Form.get_String(ws).Text;
                if (!string.IsNullOrEmpty(wordform))
                {
                    words.Add(wordform);
                }
            }
            SpellingHelper.ResetDictionary(SpellingHelper.DictionaryId(ws, lgwsFactory), words);
        }
Exemplo n.º 4
0
        public void CountPropertyTests()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexDb             lexDb   = lp.LexDbOA;
            ILexEntry          le      = servLoc.GetInstance <ILexEntryFactory>().Create();
            ILexSense          sense   = servLoc.GetInstance <ILexSenseFactory>().Create();

            le.SensesOS.Add(sense);

            // LcmReferenceCollection
            int originalCount = lexDb.LexicalFormIndexRC.Count;

            lexDb.LexicalFormIndexRC.Add(le);
            Assert.AreEqual(originalCount + 1, lexDb.LexicalFormIndexRC.Count);
            lexDb.LexicalFormIndexRC.Remove(le);
            Assert.AreEqual(originalCount, lexDb.LexicalFormIndexRC.Count);

            // LcmReferenceSequence
            originalCount = le.MainEntriesOrSensesRS.Count;
            le.MainEntriesOrSensesRS.Add(sense);
            Assert.AreEqual(originalCount + 1, le.MainEntriesOrSensesRS.Count);
            le.MainEntriesOrSensesRS.RemoveAt(le.MainEntriesOrSensesRS.Count - 1);
            Assert.AreEqual(originalCount, le.MainEntriesOrSensesRS.Count);
        }
Exemplo n.º 5
0
        public void IndexedSetter_EmptyList()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            Cache.LangProject.CheckListsOC.Add(servLoc.GetInstance <ICmPossibilityListFactory>().Create());
            Cache.LangProject.CheckListsOC.First().PossibilitiesOS[0] =
                servLoc.GetInstance <ICmPossibilityFactory>().Create();
        }
Exemplo n.º 6
0
        public void IndexedSetter_EmptyList()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            Cache.LangProject.CheckListsOC.Add(servLoc.GetInstance <ICmPossibilityListFactory>().Create());
            Assert.That(() => Cache.LangProject.CheckListsOC.First().PossibilitiesOS[0] =
                            servLoc.GetInstance <ICmPossibilityFactory>().Create(),
                        Throws.TypeOf <ArgumentOutOfRangeException>());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create test data for ReferenceAdjusterService tests.
        /// </summary>
        protected override void CreateTestData()
        {
            base.CreateTestData();
            m_servLoc   = Cache.ServiceLocator;
            m_raService = m_servLoc.GetInstance <IReferenceAdjuster>();
            m_tagFact   = m_servLoc.GetInstance <ITextTagFactory>();

            CreateTestText();
        }
 /// <summary>
 /// set up member variables and test data.
 /// </summary>
 protected override void CreateTestData()
 {
     base.CreateTestData();
     m_servLoc = Cache.ServiceLocator;
     m_servLoc.GetInstance <IVirtualOrderingFactory>();
     m_voRepo   = m_servLoc.GetInstance <IVirtualOrderingRepository>();
     m_possFact = m_servLoc.GetInstance <ICmPossibilityFactory>();
     CreateKnownPossibilityList();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Make and parse a new paragraph and append it to the current text.
        /// In this version the test specifies the text (so it can know how many
        /// words it has.
        /// </summary>
        /// <returns></returns>
        internal IStTxtPara MakeParagraphSpecificContent(string content)
        {
            var para0 = m_servLoc.GetInstance <IStTxtParaFactory>().Create();

            m_stText.ParagraphsOS.Add(para0);
            var tsstring = TsStringUtils.MakeString(content, Cache.DefaultVernWs);

            para0.Contents = tsstring;
            ParseTestParagraphWithSpecificContent(para0);
            return(para0);
        }
Exemplo n.º 10
0
        private void CreateFakeGenreList()
        {
            // this list is null in the LcmTestBase.
            Cache.LangProject.GenreListOA = m_servLoc.GetInstance <ICmPossibilityListFactory>().Create();
            Assert.AreEqual(0, Cache.LangProject.GenreListOA.PossibilitiesOS.Count);

            AppendGenreItemToFakeGenreList("First");
            AppendGenreItemToFakeGenreList("Second");
            AppendGenreItemToFakeGenreList("Third");
            AppendGenreItemToFakeGenreList("Fourth");
        }
Exemplo n.º 11
0
        private IWfiWordform FindOrCreateWordform(string form)
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            IWfiWordform       wf      = servLoc.GetInstance <IWfiWordformRepository>().GetMatchingWordform(m_vernacularWS.Handle, form);

            if (wf == null)
            {
                UndoableUnitOfWorkHelper.Do("Undo create", "Redo create", m_actionHandler,
                                            () => wf = servLoc.GetInstance <IWfiWordformFactory>().Create(TsStringUtils.MakeString(form, m_vernacularWS.Handle)));
            }
            return(wf);
        }
Exemplo n.º 12
0
        public void AddNullItem2ToVectorTest()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexEntry          le      = servLoc.GetInstance <ILexEntryFactory>().Create();
            ILexSense          sense   = servLoc.GetInstance <ILexSenseFactory>().Create();

            le.SensesOS.Add(sense);

            le.MainEntriesOrSensesRS.Add(sense);
            le.MainEntriesOrSensesRS[0] = null;             // Should throw the exception.
        }
Exemplo n.º 13
0
        public void AddNullItem2ToVectorTest()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexEntry          le      = servLoc.GetInstance <ILexEntryFactory>().Create();
            ILexSense          sense   = servLoc.GetInstance <ILexSenseFactory>().Create();

            le.SensesOS.Add(sense);

            le.MainEntriesOrSensesRS.Add(sense);
            Assert.That(() => le.MainEntriesOrSensesRS[0] = null,
                        Throws.TypeOf <NotSupportedException>());
        }
Exemplo n.º 14
0
        public void Insert_UnownableObject()
        {
            ILcmServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            IStText text;

            bookFact.Create(1, out text);
            IStTxtPara    para        = text.AddNewTextPara(ScrStyleNames.MainBookTitle);
            IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton;

            para.AnalyzedTextObjectsOS.Insert(0, systemToAdd);
        }
Exemplo n.º 15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds an interlinear text to the language projectin the mocked LcmCache
        /// </summary>
        /// <param name="name">The name (in English).</param>
        /// <param name="fCreateContents">if set to <c>true</c> also creates an StText for the
        /// Contents.</param>
        /// <returns>The new text</returns>
        /// ------------------------------------------------------------------------------------
        public IText AddInterlinearTextToLangProj(string name, bool fCreateContents)
        {
            ILcmServiceLocator servloc = Cache.ServiceLocator;
            IText text = servloc.GetInstance <ITextFactory>().Create();
            //Cache.LangProject.TextsOC.Add(text);
            int wsEn = servloc.GetInstance <ILgWritingSystemFactory>().GetWsFromStr("en");

            text.Name.set_String(wsEn, name);

            if (fCreateContents)
            {
                text.ContentsOA = servloc.GetInstance <IStTextFactory>().Create();
            }
            return(text);
        }
Exemplo n.º 16
0
        public void Insert_UnownableObject()
        {
            ILcmServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            IStText text;

            bookFact.Create(1, out text);
            IStTxtPara    para        = text.AddNewTextPara(ScrStyleNames.MainBookTitle);
            IScrRefSystem systemToAdd = servLoc.GetInstance <IScrRefSystemRepository>().Singleton;

            Assert.That(() => para.AnalyzedTextObjectsOS.Insert(0, systemToAdd),
                        Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("ScrRefSystem can not be owned!"));
        }
Exemplo n.º 17
0
        internal GhostParentHelper(ILcmServiceLocator services, int parentClsid, int flidOwning)
        {
            m_services    = services;
            m_parentClsid = parentClsid;
            m_flidOwning  = flidOwning;
            var mdc = m_services.GetInstance <IFwMetaDataCacheManaged>();

            TargetClass = mdc.GetDstClsId(flidOwning);
            switch ((CellarPropertyType)mdc.GetFieldType(flidOwning))
            {
            case CellarPropertyType.OwningAtomic:
                m_indexToCreate = -2;
                break;

            case CellarPropertyType.OwningCollection:
                m_indexToCreate = -1;
                break;

            case CellarPropertyType.OwningSequence:
                m_indexToCreate = 0;
                break;

            default:
                throw new InvalidOperationException("can only create objects in owning properties");
            }
        }
Exemplo n.º 18
0
        public void Insert_Null()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            servLoc.GetInstance <IScrBookFactory>().Create(1);
            m_scr.ScriptureBooksOS.Insert(0, null);
        }
Exemplo n.º 19
0
        public void Insert_Null()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            servLoc.GetInstance <IScrBookFactory>().Create(1);
            Assert.That(() => m_scr.ScriptureBooksOS.Insert(0, null),
                        Throws.TypeOf <ArgumentNullException>());
        }
Exemplo n.º 20
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a text for testing.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void CreateTestText()
        {
            m_txt = m_servLoc.GetInstance <ITextFactory>().Create();
            //Cache.LangProject.TextsOC.Add(m_txt);
            m_possTagList    = Cache.LangProject.GetDefaultTextTagList();
            m_stTxt          = m_servLoc.GetInstance <IStTextFactory>().Create();
            m_txt.ContentsOA = m_stTxt;
            m_txtPara        = m_txt.ContentsOA.AddNewTextPara(null);

            // 0    1  2 3    4      5   6                        7    8
            // This is a test string for ReferenceAdjusterService tests.

            var hvoVernWs = Cache.DefaultVernWs;

            m_txtPara.Contents = TsStringUtils.MakeString("This is a test string for ReferenceAdjusterService tests.", hvoVernWs);
            ParseText();
        }
Exemplo n.º 21
0
        static public InterestingTextList GetInterestingTextList(Mediator mediator, PropertyTable propertyTable, ILcmServiceLocator services)
        {
            var interestingTextList = propertyTable.GetValue <InterestingTextList>(InterestingTextKey, null);

            if (interestingTextList == null)
            {
                interestingTextList = new InterestingTextList(mediator, propertyTable, services.GetInstance <ITextRepository>(),
                                                              services.GetInstance <IStTextRepository>(), services.GetInstance <IScrBookRepository>().AllInstances().Any());
                // Make this list available for other tools in this window, but don't try to persist it.
                propertyTable.SetProperty(InterestingTextKey, interestingTextList, false);
                propertyTable.SetPropertyPersistence(InterestingTextKey, false);
                // Since the list hangs around indefinitely, it indefinitely monitors prop changes.
                // I can't find any way to make sure it eventually gets removed from the notification list.
                services.GetInstance <ISilDataAccessManaged>().AddNotification(interestingTextList);
            }
            return(interestingTextList);
        }
Exemplo n.º 22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds an empty chart on the specified text.
        /// </summary>
        /// <param name="name">Chart name.</param>
        /// <param name="stText">Chart is BasedOn this text.</param>
        /// ------------------------------------------------------------------------------------
        private IDsConstChart AddChartToLangProj(string name, IStText stText)
        {
            ILcmServiceLocator servloc = Cache.ServiceLocator;
            IDsConstChart      chart   = servloc.GetInstance <IDsConstChartFactory>().Create();

            if (Cache.LangProject.DiscourseDataOA == null)
            {
                Cache.LangProject.DiscourseDataOA = servloc.GetInstance <IDsDiscourseDataFactory>().Create();
            }

            Cache.LangProject.DiscourseDataOA.ChartsOC.Add(chart);

            // Setup the new chart
            chart.Name.AnalysisDefaultWritingSystem = TsStringUtils.MakeString(name, Cache.DefaultAnalWs);
            chart.BasedOnRA = stText;

            return(chart);            // This chart has no template or rows, so far!!
        }
Exemplo n.º 23
0
        public void Insert_Deleted()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            IScrBook book0 = servLoc.GetInstance <IScrBookFactory>().Create(1);

            m_scr.ScriptureBooksOS.Remove(book0);
            m_scr.ScriptureBooksOS.Insert(0, book0);
        }
Exemplo n.º 24
0
        public void Insert_Deleted()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;

            IScrBook book0 = servLoc.GetInstance <IScrBookFactory>().Create(1);

            m_scr.ScriptureBooksOS.Remove(book0);
            Assert.That(() => m_scr.ScriptureBooksOS.Insert(0, book0),
                        Throws.TypeOf <LcmObjectDeletedException>().With.Message.EqualTo("Owned object has been deleted."));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Restore any appropriate settings which have values in the property table
        /// </summary>
        public static void RestoreSettings(ILcmServiceLocator services, PropertyTable propertyTable)
        {
            var hcSettings = propertyTable.GetStringProperty(khomographconfiguration, null);

            if (hcSettings != null)
            {
                var hc = services.GetInstance <HomographConfiguration>();
                hc.PersistData = hcSettings;
            }
        }
Exemplo n.º 26
0
        public void MoveTo_EmptyListTest()
        {
            ILcmServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            bookFact.Create(1);
            IScrBook book1 = bookFact.Create(2);
            IScrBook book2 = bookFact.Create(3);

            // Setup the target sequence so it's able to have items moved to it.
            IScrDraft targetSeq = servLoc.GetInstance <IScrDraftFactory>().Create("MoveTo_EmptyListTest");

            m_scr.ScriptureBooksOS.MoveTo(1, 2, targetSeq.BooksOS, 0);

            Assert.AreEqual(2, targetSeq.BooksOS.Count);
            Assert.AreEqual(1, m_scr.ScriptureBooksOS.Count);
            Assert.AreEqual(book1, targetSeq.BooksOS[0]);
            Assert.AreEqual(book2, targetSeq.BooksOS[1]);
        }
Exemplo n.º 27
0
        public void InsertIntoRefSequence_Uninitialized()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexEntry          le      = servLoc.GetInstance <ILexEntryFactory>().Create();

            var senseUninitialized = MockRepository.GenerateStub <ILexSense>();

            senseUninitialized.Stub(x => x.Hvo).Return((int)SpecialHVOValues.kHvoUninitializedObject);
            le.MainEntriesOrSensesRS.Insert(0, senseUninitialized);
        }
Exemplo n.º 28
0
        public void InsertIntoRefSequence_Uninitialized()
        {
            ILcmServiceLocator servLoc = Cache.ServiceLocator;
            ILangProject       lp      = Cache.LanguageProject;
            ILexEntry          le      = servLoc.GetInstance <ILexEntryFactory>().Create();

            var senseUninitialized = MockRepository.GenerateStub <ILexSense>();

            senseUninitialized.Stub(x => x.Hvo).Return((int)SpecialHVOValues.kHvoUninitializedObject);
            Assert.That(() => le.MainEntriesOrSensesRS.Insert(0, senseUninitialized),
                        Throws.TypeOf <LcmObjectUninitializedException>().With.Message.EqualTo("Object has not been initialized."));
        }
Exemplo n.º 29
0
        public void MoveTo_DestListLargerThenSrcTest()
        {
            ILcmServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            IScrBook book0 = bookFact.Create(1);

            // Setup the target sequence so it's able to have items moved to it.
            IScrDraft targetSeq = servLoc.GetInstance <IScrDraftFactory>().Create("MoveTo_DestListLargerThenSrcTest");
            IScrBook  bookD0    = bookFact.Create(targetSeq.BooksOS, 1);
            IScrBook  bookD1    = bookFact.Create(targetSeq.BooksOS, 2);

            m_scr.ScriptureBooksOS.MoveTo(0, 0, targetSeq.BooksOS, 2);

            Assert.AreEqual(3, targetSeq.BooksOS.Count);
            Assert.AreEqual(0, m_scr.ScriptureBooksOS.Count);
            Assert.AreEqual(bookD0, targetSeq.BooksOS[0]);
            Assert.AreEqual(bookD1, targetSeq.BooksOS[1]);
            Assert.AreEqual(book0, targetSeq.BooksOS[2]);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParseFiler"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="taskUpdateHandler">The task update handler.</param>
        /// <param name="idleQueue">The idle queue.</param>
        /// <param name="parserAgent">The parser agent.</param>
        public ParseFiler(LcmCache cache, Action <TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent parserAgent)
        {
            Debug.Assert(cache != null);
            Debug.Assert(taskUpdateHandler != null);
            Debug.Assert(idleQueue != null);
            Debug.Assert(parserAgent != null);

            m_cache             = cache;
            m_taskUpdateHandler = taskUpdateHandler;
            m_idleQueue         = idleQueue;
            m_parserAgent       = parserAgent;
            m_workQueue         = new Queue <WordformUpdateWork>();
            m_syncRoot          = new object();

            ILcmServiceLocator servLoc = cache.ServiceLocator;

            m_analysisFactory          = servLoc.GetInstance <IWfiAnalysisFactory>();
            m_mbFactory                = servLoc.GetInstance <IWfiMorphBundleFactory>();
            m_baseAnnotationRepository = servLoc.GetInstance <ICmBaseAnnotationRepository>();
            m_baseAnnotationFactory    = servLoc.GetInstance <ICmBaseAnnotationFactory>();
            m_userAgent                = m_cache.LanguageProject.DefaultUserAgent;
        }