Exemplo n.º 1
0
        private void LoadSimpleList(string path)
        {
            using (TextReader r = File.OpenText(path))
            {
                do
                {
                    string s = r.ReadLine();
                    if (s == null)
                    {
                        break;
                    }
                    s = s.Trim();

                    if (!string.IsNullOrEmpty(s))                    //skip blank lines
                    {
                        var entry = new LexEntry();
                        entry.LexicalForm.SetAlternative(_preferredPromptingWritingSystemId, s);
                        var sense = new LexSense(entry);
                        if (_glossMeaningField)
                        {
                            sense.Gloss.SetAlternative(_preferredPromptingWritingSystemId, s);
                        }
                        else
                        {
                            sense.Definition.SetAlternative(_preferredPromptingWritingSystemId, s);
                        }
                        entry.Senses.Add(sense);
                        _words.Add(entry);
                    }
                }while (true);
            }
        }
Exemplo n.º 2
0
        //TODO: (JDH) fix this so that only an exception *on the last line* will produce a PASS

        // Validity checking in DEBUG mode has been turned off.  It complicates performance testing too much.
        //        [ExpectedException(typeof(ArgumentException))]
        //#if !DEBUG
        //        [Ignore("This test doesn't get an exception in release mode due to CmObject c'tor")]
        //#endif

        //TODO (Steve Miller): The above test fails if the followeng lines are remarked
        // out in CmObject.cs, like below. I have frequently remarked out lines there
        // like this, because they foul up SQL performance tests:
        //
        // (InitExisting method)
        //  //#if DEBUG
        //  //	if (!fcCache.IsDummyObject(hvo))
        //  //		fCheckValidity = true;
        //  //#endif
        //
        // (CreateFromDBObject method)
        // //#if DEBUG
        // //     true/*validity check*/,
        // //#else
        //		false,
        // //#endif

        public void DeleteUnderlyingObject()
        {
            CheckDisposed();

            LexEntry se = new LexEntry();

            m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(se);
            LexSense ls = new LexSense();

            se.SensesOS.Append(ls);
            int khvoLexSense = ls.Hvo;

            ls.DeleteUnderlyingObject();

            Assert.IsTrue(m_fdoCache.VwOleDbDaAccessor.get_ObjOwner(khvoLexSense) <= 0);             // khvoLexSense not removed from cache.

            // See if FDO object is valid. It should not be.
            Assert.IsFalse(ls.IsValidObject());

            // Test to see if it is really gone from DB.
            // An exception should be thrown by CmObject.InitExisting,
            // since khvoLexSense isn't in DB now.
            ls = new LexSense(m_fdoCache, khvoLexSense, true, true);
            Assert.IsFalse(ls.IsValidObject());
        }
Exemplo n.º 3
0
        public void ChangedEntryFound()
        {
#if merging
            Guid       g = Guid.NewGuid();
            Extensible extensibleInfo = CreateFullextensibleInfo(g);

            LexEntry e      = _repository.CreateItem();
            LexSense sense1 = new LexSense();
            LexSense sense2 = new LexSense();
            e.Senses.Add(sense1);
            e.Senses.Add(sense2);
            e.CreationTime     = extensibleInfo.CreationTime;
            e.ModificationTime = new DateTime(e.CreationTime.Ticks + 100, DateTimeKind.Utc);

            LexEntry found = _merger.GetOrMakeEntry(extensibleInfo, 0);
            _merger.FinishEntry(found);
            Assert.AreSame(found, e);
            Assert.AreEqual(2, found.Senses.Count);

            //this is a temp side track
            Assert.AreEqual(1, _repository.CountAllItems());
            Extensible xInfo = CreateFullextensibleInfo(Guid.NewGuid());
            LexEntry   x     = _merger.GetOrMakeEntry(xInfo, 1);
            _merger.FinishEntry(x);
            Assert.AreEqual(2, _repository.CountAllItems());
#endif
        }
Exemplo n.º 4
0
        public void Init(Mediator mediator, XmlNode configurationNode, ICmObject sourceObject)
        {
            CheckDisposed();

            m_cache = sourceObject.Cache;

            // Find the sense owning our LexExampleSentence
            if (sourceObject is LexExampleSentence)
            {
                m_les         = sourceObject as LexExampleSentence;
                m_owningSense = LexSense.CreateFromDBObject(m_cache, m_les.OwnerHVO);
            }
            else if (sourceObject is LexSense)
            {
                m_owningSense = sourceObject as ILexSense;
            }
            else
            {
                throw new ArgumentException("Invalid object type for sourceObject.");
            }

            m_mediator          = mediator;
            m_configurationNode = configurationNode;
            AddConfigurableControls();

            m_virtFlidReference = BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "CmBaseAnnotation", "Reference");
        }
Exemplo n.º 5
0
        private static void AddExample(LexSense sense)
        {
            LexExampleSentence example = new LexExampleSentence();

            sense.ExampleSentences.Add(example);
            example.Sentence[WritingSystemsIdsForTests.VernacularIdForTest] = "sentence";
        }
Exemplo n.º 6
0
        private static void RenderSense(LexEntry entry, LexSense sense, int senseNumber, CurrentItemEventArgs currentItem, StringBuilder html)
        {
            Field glossField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Gloss);

            if (entry.Senses.Count > 1 ||
                (currentItem != null &&
                 ((glossField.IsMeaningField && currentItem.PropertyName == LexSense.WellKnownProperties.Gloss) ||
                  (!glossField.IsMeaningField && currentItem.PropertyName == LexSense.WellKnownProperties.Definition))
                ))
            {
                html.Append(" " + senseNumber);
            }

            RenderPartOfSpeech(sense, currentItem, html);

            // Render the Gloss/Definition (meaning) field
            if (glossField.IsMeaningField)
            {
                html.Append(" " + RenderField(sense.Gloss, currentItem, 0, glossField));
            }
            else
            {
                Field dfnField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Definition);
                html.Append(" " + RenderField(sense.Definition, currentItem, 0, dfnField));
            }

            RenderExampleSentences(currentItem, html, sense);

            html.Append(RenderGhostedField(sense, "Sentence", currentItem, null));
            html.Append(RenderGhostedField(sense, "Translation", currentItem, null));
        }
Exemplo n.º 7
0
        /// <summary> Adds each sense of a word to be written out to lift </summary>
        private void AddSenses(LexEntry entry, Word wordEntry)
        {
            for (var i = 0; i < wordEntry.Senses.Count; i++)
            {
                // Merge in senses
                var dict = new Dictionary <string, string>();
                foreach (var gloss in wordEntry.Senses[i].Glosses)
                {
                    dict.Add(gloss.Language, gloss.Def);
                }

                var lexSense = new LexSense();
                lexSense.Gloss.MergeIn(MultiTextBase.Create(dict));
                entry.Senses.Add(lexSense);

                // Merge in semantic domains
                foreach (var semdom in wordEntry.Senses[i].SemanticDomains)
                {
                    var orc = new OptionRefCollection();
                    orc.Add(semdom.Id + " " + semdom.Name);

                    entry.Senses[i].Properties.Add(
                        new KeyValuePair <string, IPalasoDataObjectProperty>("semantic-domain-ddp4", orc));
                }
            }
        }
Exemplo n.º 8
0
        private Guid AddEntry(string lexemeForm,
                              string meaningWritingSystemId,
                              string meaning,
                              bool includeExample)
        {
            LexEntry entry = _lexEntryRepository.CreateItem();

            entry.LexicalForm.SetAlternative("th", lexemeForm);

            LexSense sense = new LexSense();

            entry.Senses.Add(sense);
#if GlossMeaning
            sense.Gloss[
                WeSayWordsProject.Project.DefaultViewTemplate.GetField("SenseGloss").WritingSystemIds[0]] =
                meaning;
#else
            sense.Definition.SetAlternative(meaningWritingSystemId, meaning);
#endif
            if (includeExample)
            {
                LexExampleSentence ex = new LexExampleSentence();
                sense.ExampleSentences.Add(ex);
                ex.Sentence.SetAlternative("th", "hello");
            }
            _lexEntryRepository.SaveItem(entry);
            return(entry.Guid);
        }
Exemplo n.º 9
0
        private static void RenderSense(LexEntry entry, LexSense sense, int senseNumber, CurrentItemEventArgs currentItem, StringBuilder rtf)
        {
//rtf.Append(SwitchToWritingSystem(WritingSystems.AnalysisWritingSystemDefault.Id));
#if GlossMeaning
            if (entry.Senses.Count > 1 || (currentItem != null && currentItem.PropertyName == "Gloss"))
#else
            if (entry.Senses.Count > 1 ||
                (currentItem != null &&
                 currentItem.PropertyName == LexSense.WellKnownProperties.Definition))
#endif
            {
                rtf.Append(" " + senseNumber);
            }

            RenderPartOfSpeech(sense, currentItem, rtf);
#if GlossMeaning
            rtf.Append(" " + RenderField(sense.Gloss, currentItem));
#else
            // Render the Definition (meaning) field
            Field dfnField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(
                LexSense.WellKnownProperties.Definition);
            rtf.Append(" " + RenderField(sense.Definition, currentItem, 0, dfnField));
#endif
            //                rtf.Append(@"\i0 ");

            RenderExampleSentences(currentItem, rtf, sense);

            rtf.Append(RenderGhostedField(sense, "Sentence", currentItem, null));
            rtf.Append(RenderGhostedField(sense, "Translation", currentItem, null));
        }
Exemplo n.º 10
0
        public void SenseGetsDef()
        {
            LexSense sense = new LexSense();

            _builder.MergeInDefinition(sense, MakeBasicLiftMultiText());
            AssertPropertyHasExpectedMultiText(sense, LexSense.WellKnownProperties.Definition);
        }
Exemplo n.º 11
0
        public void SenseGetsNote()
        {
            LexSense sense = new LexSense();

            _builder.MergeInNote(sense, null, MakeBasicLiftMultiText(), string.Empty);
            AssertPropertyHasExpectedMultiText(sense, PalasoDataObject.WellKnownProperties.Note);
        }
Exemplo n.º 12
0
        public void ExampleTranslations_FreeFollowedByUnmarked()
        {
            LexEntry e     = MakeSimpleEntry();
            LexSense sense = new LexSense();

            e.Senses.Add(sense);
            LexExampleSentence ex = new LexExampleSentence();

            sense.ExampleSentences.Add(ex);

            LiftMultiText t2 = new LiftMultiText();

            t2.Add("aa", "freestuff");
            _builder.MergeInTranslationForm(ex,
                                            "Free translation",
                                            t2,
                                            "<translation type='free'><bogus/></translation>");
            LiftMultiText translation = new LiftMultiText();

            translation.Add("aa", "unmarked translation");
            _builder.MergeInTranslationForm(ex,
                                            "",
                                            translation,
                                            "<translation><bogusUnmarked/></translation>");
            _builder.FinishEntry(e);

            _liftWriter.Add(e);
            _liftWriter.End();
            AssertHasAtLeastOneMatch("//entry/sense/example/translation[not(@type)]/bogusUnmarked");
            AssertHasAtLeastOneMatch(
                "//entry/sense/example/translation[@type='Free translation']/form/text[text()='freestuff']");
        }
Exemplo n.º 13
0
        public void ExampleTranslations_MultipleTypes()
        {
            LexEntry e     = MakeSimpleEntry();
            LexSense sense = new LexSense();

            e.Senses.Add(sense);
            LexExampleSentence ex = new LexExampleSentence();

            sense.ExampleSentences.Add(ex);
            LiftMultiText translation = new LiftMultiText();

            translation.Add("aa", "unmarked translation");
            _builder.MergeInTranslationForm(ex, "", translation, "bogus raw xml");
            LiftMultiText t2 = new LiftMultiText();

            t2.Add("aa", "type2translation");
            _builder.MergeInTranslationForm(ex,
                                            "type2",
                                            t2,
                                            "<translation type='type2'><bogus/></translation>");
            _builder.FinishEntry(e);

            _liftWriter.Add(e);
            _liftWriter.End();
            AssertHasAtLeastOneMatch(
                "//entry/sense/example/translation[not(@type)]/form[@lang='aa']/text[text()='unmarked translation']");
            AssertHasAtLeastOneMatch("//entry/sense/example/translation[@type='type2']/bogus");
        }
Exemplo n.º 14
0
        public void Reversal_Complex()
        {
            LexEntry e   = MakeSimpleEntry();
            string   xml =
                @"  <entry id='utan'>
				<sense id='utan_'>
				  <grammatical-info value='n'/>
				  <reversal type='eng'>
					<form lang='en'>
					  <text>mushroom</text>
					</form>
					<main>
					  <form lang='en'>
						<text>vegetable</text>
					  </form>
					</main>
				  </reversal>
				</sense>
			  </entry>"            ;

            LexSense sense = new LexSense();

            e.Senses.Add(sense);
            _builder.MergeInReversal(sense, null, null, null, xml);
            _builder.FinishEntry(e);

            _liftWriter.Add(e);
            _liftWriter.End();
            AssertHasAtLeastOneMatch("//entry/sense/reversal/main/form/text[text()='vegetable']");
            AssertHasAtLeastOneMatch("//entry/sense/reversal/form/text[text()='mushroom']");
        }
Exemplo n.º 15
0
        public void WordCollected_LiftWithExtraLangs_OnlyThoseFormsFromLangsInThisProjectAreCopiedOver()
        {
            LexSense firstSense = AddWordAndGetFirstSense();

            Assert.IsFalse(firstSense.Definition.ContainsAlternative("es"), "should not have received spanish definition because it wasn't in the viewtemplate");
            Assert.IsFalse(firstSense.Gloss.ContainsAlternative("es"), "should not have received spanish gloss because it wasn't in the viewtemplate");
        }
Exemplo n.º 16
0
        private static void AddTranslationToEntry(LexEntry entry, string translation)
        {
            LexSense           sense   = entry.Senses[0];
            LexExampleSentence example = sense.ExampleSentences[0];

            example.Translation[WritingSystemsIdsForTests.AnalysisIdForTest] = translation;
        }
Exemplo n.º 17
0
        public void SenseDefinitionWritingSystemNoAnalysis()
        {
            LexEntry entry = CreateEmptyEntryWithOneSense();
            LexSense sense = entry.Senses[0];

            sense.Definition["vernacular"] = "filler";
            Assert.AreEqual(true, _missingMeaningFilter.FilteringPredicate(entry));
        }
Exemplo n.º 18
0
        public void WordCollected_LiftWithCustomField_CopiedOver()
        {
            LexSense firstSense = AddWordAndGetFirstSense();
            var      custom     = firstSense.GetProperty <MultiText>("custom1");

            Assert.IsNotNull(custom);
            Assert.AreEqual("EnglishCustomValue", custom.GetExactAlternative("en"));
        }
Exemplo n.º 19
0
        private static LexEntry CreateEmptyEntryWithOneSense()
        {
            LexEntry entry = new LexEntry();
            LexSense sense = new LexSense();

            entry.Senses.Add(sense);
            return(entry);
        }
Exemplo n.º 20
0
        public void LexSensePropertiesInUse_HasPropertyProp1_ReturnsProp1()
        {
            var lexSense = new LexSense();

            lexSense.GetOrCreateProperty <MultiText>("Prop1");
            Assert.That(lexSense.PropertiesInUse, Contains.Item("Prop1"));
            Assert.That(lexSense.PropertiesInUse.Count(), Is.EqualTo(1));
        }
Exemplo n.º 21
0
        private void AddEntryAndSense(string gloss)
        {
            LexEntry e     = _lexEntryRepository.CreateItem();
            LexSense sense = new LexSense();

            e.Senses.Add(sense);
            sense.Definition[_glossingLanguageWSId] = gloss;
            _lexEntryRepository.SaveItem(e);
        }
Exemplo n.º 22
0
        public void SenseGetsId()
        {
            Extensible extensibleInfo = new Extensible();

            extensibleInfo.Id = "foo";
            LexSense s = _builder.GetOrMakeSense(new LexEntry(), extensibleInfo, string.Empty);

            Assert.AreEqual(extensibleInfo.Id, s.Id);
        }
Exemplo n.º 23
0
        private void AddSenseWithDefinition()
        {
            var sense = new LexSense(_entry);

            _entry.Senses.Add(sense);
            sense.Definition.SetAlternative("en", "fruit");
            sense.Definition.SetAlternative("fr", "pomme");
            sense.GetOrCreateProperty <OptionRef>(LexSense.WellKnownProperties.PartOfSpeech).Key = "Noun";
        }
Exemplo n.º 24
0
        public void WordCollected_LiftWithPartOfSpeech_CopiedOver()
        {
            LexSense  firstSense = AddWordAndGetFirstSense();
            OptionRef pos        =
                firstSense.GetProperty <OptionRef>(
                    LexSense.WellKnownProperties.PartOfSpeech);

            Assert.AreEqual("noun", pos.Key);
        }
Exemplo n.º 25
0
        public void SenseDefinitionHasAnalysisWritingSystem()
        {
            LexEntry entry = CreateEmptyEntryWithOneSense();
            LexSense sense = entry.Senses[0];

            sense.Definition["analysis"] = "filler";

            Assert.AreEqual(false, _missingMeaningFilter.FilteringPredicate(entry));
        }
Exemplo n.º 26
0
        public void OneSenseDefinitionWithOneWithoutWritingSystems()
        {
            LexEntry entry = CreateEmptyEntryWithOneSense();
            LexSense sense = entry.Senses[0];

            sense.Definition["analysis"] = "filler";
            entry.Senses.Add(new LexSense());
            Assert.AreEqual(true, _missingMeaningFilter.FilteringPredicate(entry));
        }
Exemplo n.º 27
0
        private static LexEntry CreateEmptyLexEntryWithOneEmptySentence()
        {
            var entry = new LexEntry();
            var sense = new LexSense();

            entry.Senses.Add(sense);
            sense.ExampleSentences.Add(new LexExampleSentence());
            return(entry);
        }
Exemplo n.º 28
0
		public void ModifiedDateAfterLexSenseGlossChange()
		{
			LexSense sense = new LexSense();
			_entry.Senses.Add(sense);
			long start = _entry.ModificationTime.Ticks;
			Thread.Sleep(1000); //else modtime doesn't change
			sense.Gloss["foo"] = "hello";
			Assert.Greater((decimal) _entry.ModificationTime.Ticks, start);
			Assert.IsTrue(_didNotify);
		}
Exemplo n.º 29
0
 private void CopyOverGlossesIfDefinitionsMissing(LexSense sense)
 {
     foreach (LanguageForm form in sense.Gloss.Forms)
     {
         if (!sense.Definition.ContainsAlternative(form.WritingSystemId))
         {
             sense.Definition.SetAlternative(form.WritingSystemId, form.Form);
         }
     }
 }
Exemplo n.º 30
0
        public void NewEntry_NoGlossNoDef_GetNeitherInTheSense()
        {
            Extensible extensibleInfo = new Extensible();
            LexEntry   e = _builder.GetOrMakeEntry(extensibleInfo, 0);
            LexSense   s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty);

            _builder.FinishEntry(e);
            Assert.AreEqual(0, e.Senses[0].Gloss.Count);
            Assert.AreEqual(0, e.Senses[0].Definition.Count);
        }
Exemplo n.º 31
0
 public int AddGhost(LexSense sense, IList <LexExampleSentence> list, int insertAtRow)
 {
     return(MakeGhostWidget(sense, list,
                            Field.FieldNames.ExampleSentence.ToString(),
                            StringCatalog.Get("~Example",
                                              "This is the field containing an example sentence of a sense of a word."),
                            "Sentence",
                            false,
                            insertAtRow));
 }
Exemplo n.º 32
0
		public void ModifiedDateAfterAddingExampleSentence()
		{
			LexSense sense = new LexSense();
			_entry.Senses.Add(sense);
			long start = _entry.ModificationTime.Ticks;
			Thread.Sleep(1000); //else modtime doesn't change
			sense.ExampleSentences.Add(new LexExampleSentence());
			;
			Assert.Greater((decimal) _entry.ModificationTime.Ticks, start);
			Assert.IsTrue(_didNotify);
		}
Exemplo n.º 33
0
		/// <summary>
		/// Note, this isn't very ambitious. The only thing the new entry will have is the lexeme form and the new sense, not any other traits/fields
		/// </summary>
		/// <param name="repo"> </param>
		/// <param name="sense"></param>
		private static void SpinSenseOffToItsOwnEntry(LiftLexEntryRepository repo, LexSense sense, IProgress progress)
		{
			var existingEntry = (LexEntry) sense.Parent;
			progress.WriteMessage("Splitting off {0} ({1}) into its own entry", existingEntry.LexicalForm.GetFirstAlternative(), sense.Definition.GetFirstAlternative());
			LexEntry newEntry = repo.CreateItem();
			newEntry.LexicalForm.MergeIn(existingEntry.LexicalForm);
			existingEntry.Senses.Remove(sense);
			newEntry.Senses.Add(sense);
			sense.Parent = newEntry;
			repo.SaveItem(existingEntry);
			repo.SaveItem(newEntry);
		}
Exemplo n.º 34
0
		/// <summary>
		/// Create a new sense and add it to the given entry.
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="sandboxMSA"></param>
		/// <param name="gloss"></param>
		/// <returns></returns>
		public ILexSense Create(ILexEntry entry, SandboxGenericMSA sandboxMSA, ITsString gloss)
		{
			var sense = new LexSense();
			entry.SensesOS.Add(sense);
			sense.SandboxMSA = sandboxMSA;

			if (gloss != null)
			{
				sense.Gloss.set_String(gloss.get_WritingSystemAt(0), gloss);
			}
			return sense;
		}
Exemplo n.º 35
0
		public void Construct_TargetIdNull_TargetIdIsEmptyString()
		{
			LexSense sense = new LexSense();
			LexRelationType synonymRelationType = new LexRelationType("synonym",
																	  LexRelationType.Multiplicities
																			  .Many,
																	  LexRelationType.TargetTypes.
																			  Sense);

			LexRelation relation = new LexRelation(synonymRelationType.ID, null, sense);
			Assert.AreEqual(null, relation.GetTarget(_lexEntryRepository));
			Assert.AreEqual(string.Empty, relation.Key);
		}
Exemplo n.º 36
0
		public void TargetId_SetNull_GetStringEmpty()
		{
			LexSense sense = new LexSense();
			LexRelationType synonymRelationType = new LexRelationType("synonym",
																	  LexRelationType.Multiplicities
																			  .Many,
																	  LexRelationType.TargetTypes.
																			  Sense);

			LexRelation relation = new LexRelation(synonymRelationType.ID, "something", sense);
			relation.Key = null;
			Assert.AreEqual(null, relation.GetTarget(_lexEntryRepository));
			Assert.AreEqual(string.Empty, relation.Key);
		}
Exemplo n.º 37
0
		public void HelperGetsActivationCall()
		{
			LexEntry entry = _db4oRepository.CreateItem();
			entry.LexicalForm.SetAlternative("en", "test");

			LexSense sense = new LexSense();
			entry.Senses.Add(sense);
			_db4oRepository.SaveItem(entry);

			Assert.AreEqual(entry, sense.Parent);

			int activations = _db4oRepository.ActivationCount;
			CycleDatabase();
			entry = GetFirstEntry();
			Assert.AreEqual(1, _db4oRepository.CountAllItems());
			Assert.AreEqual(1, entry.Senses.Count);
			Assert.AreEqual(activations + 1 /*entry*/+ 1 /*sense*/, _db4oRepository.ActivationCount);
		}
Exemplo n.º 38
0
		public static bool TryMergeSenseWithSomeExistingSense(LexSense targetSense, LexSense incomingSense, string[] traitsWithMultiplicity, IProgress progress)
		{
			//can we unify the properites?
			if (!TryMergeProperties(targetSense, incomingSense, traitsWithMultiplicity, "senses of " + targetSense.Parent.ToString(), progress))
			{
				return false;
			}

			progress.WriteMessageWithColor("blue", "Merged two senses of {0} together: {1} into {2}", targetSense.Parent.ToString(), incomingSense.Id, targetSense.Id);

			//at this point, we're committed);

			foreach (var lexExampleSentence in incomingSense.ExampleSentences)
			{
				targetSense.ExampleSentences.Add(lexExampleSentence);
			}

			return true;
		}
Exemplo n.º 39
0
		private static void MergeOrAddSense(LexEntry targetEntry, LexSense incomingSense, string[] traitsWithMultiplicity, IProgress progress)
		{
			if (targetEntry.Senses.Count == 0)
			{
				targetEntry.Senses.Add(incomingSense);//no problem!
			}
			else
			{
				if (targetEntry.Senses.Count == 1)
				{
					var targetSense = targetEntry.Senses[0];
					if (SenseMerger.TryMergeSenseWithSomeExistingSense(targetSense, incomingSense, traitsWithMultiplicity, progress))
					{
						//it was merged in
						return;
					}
				}
			}
			//it needs to be added
			targetEntry.Senses.Add(incomingSense);
		}
Exemplo n.º 40
0
		public void Setup()
		{
			_entry = new LexEntry();
			_sense = new LexSense();
			_entry.Senses.Add(_sense);
#if GlossMeaning
			this._sense.Gloss["th"] = "sense";
#else
			_sense.Definition["th"] = "sense";
#endif
			MultiText customFieldInSense =
					_sense.GetOrCreateProperty<MultiText>("customFieldInSense");
			customFieldInSense["th"] = "custom";
			_examples = new LexExampleSentence();
			_sense.ExampleSentences.Add(_examples);
			_examples.Sentence["th"] = "example";
			_examples.Translation["en"] = "translation";
			MultiText customFieldInExample =
					_examples.GetOrCreateProperty<MultiText>("customFieldInExample");
			customFieldInExample["th"] = "custom";
			_entry.EmptyObjectsRemoved += _entry_EmptyObjectsRemoved;
			_entry.PropertyChanged += _entry_PropertyChanged;
			_removed = false;
		}
		public void SenseGetsNote()
		{
			LexSense sense = new LexSense();
			_builder.MergeInNote(sense, null, MakeBasicLiftMultiText(), string.Empty);
			AssertPropertyHasExpectedMultiText(sense, PalasoDataObject.WellKnownProperties.Note);
		}
		public void SenseGetsRelation()
		{
			LexSense sense = new LexSense();
			_builder.MergeInRelation(sense, "synonym", "foo", null);
			LexRelationCollection synonyms = sense.GetProperty<LexRelationCollection>("synonym");
			LexRelation relation = synonyms.Relations[0];
			Assert.AreEqual("synonym", relation.FieldId);
			Assert.AreEqual("foo", relation.Key);
		}
		public void SenseGetsDef()
		{
			LexSense sense = new LexSense();
			_builder.MergeInDefinition(sense, MakeBasicLiftMultiText());
			AssertPropertyHasExpectedMultiText(sense, LexSense.WellKnownProperties.Definition);
		}
		public void GrammiGetsFlagTrait()
		{
			LexSense sense = new LexSense();
			_builder.MergeInGrammaticalInfo(sense,
										   "red",
										   new List<Trait>(new Trait[] {new Trait("flag", "1")}));
			OptionRef optionRef =
					sense.GetProperty<OptionRef>(LexSense.WellKnownProperties.PartOfSpeech);
			Assert.IsTrue(optionRef.IsStarred);
		}
		public void SenseGetsExample()
		{
			LexSense sense = new LexSense();
			Extensible x = new Extensible();
			LexExampleSentence ex = _builder.GetOrMakeExample(sense, x);
			Assert.IsNotNull(ex);
			_builder.MergeInExampleForm(ex, MakeBasicLiftMultiText());
			Assert.AreEqual(2, ex.Sentence.Forms.Length);
			Assert.AreEqual("dos", ex.Sentence["ws-two"]);
		}
Exemplo n.º 46
0
		/// <summary>
		/// Create a new sense with the given guid owned by the given entry.
		/// </summary>
		public ILexSense Create(Guid guid, ILexEntry owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			ILexSense ls;
			if (guid == Guid.Empty)
			{
				ls = Create();
			}
			else
			{
				int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();
				ls = new LexSense(m_cache, hvo, guid);
			}
			owner.SensesOS.Add(ls);
			return ls;
		}
		public void SenseGetsGrammi()
		{
			LexSense sense = new LexSense();
			_builder.MergeInGrammaticalInfo(sense, "red", null);
			OptionRef optionRef =
					sense.GetProperty<OptionRef>(LexSense.WellKnownProperties.PartOfSpeech);
			Assert.IsNotNull(optionRef);
			Assert.AreEqual("red", optionRef.Value);
		}
Exemplo n.º 48
0
		private static string GetSenseElement(LexSense sense)
		{
			return string.Format("<sense id=\"{0}\">", sense.GetOrCreateId());
		}
Exemplo n.º 49
0
		public void Picture_OutputAsPictureURLRef()
		{
			LexSense sense = new LexSense();
			PictureRef p = sense.GetOrCreateProperty<PictureRef>("Picture");
			p.Value = "bird.jpg";
			_exporter.Add(sense);
			_exporter.End();
			CheckAnswer(GetSenseElement(sense) + "<illustration href=\"bird.jpg\" /></sense>");
		}
Exemplo n.º 50
0
		public void Sense_HasId_RemembersId()
		{
			LexSense s = new LexSense();
			s.Id = "my id";
			_exporter.Add(s);
			_exporter.End();
			ShouldContain("id=\"my id\"");
		}
Exemplo n.º 51
0
		public void Picture_OutputAsPictureWithCaption()
		{
			LexSense sense = new LexSense();
			PictureRef p = sense.GetOrCreateProperty<PictureRef>("Picture");
			p.Value = "bird.jpg";
			p.Caption = new MultiText();
			p.Caption["aa"] = "aCaption";
			_exporter.Add(sense);
			_exporter.End();
			CheckAnswer(GetSenseElement(sense) +
						"<illustration href=\"bird.jpg\"><label><form lang=\"aa\"><text>aCaption</text></form></label></illustration></sense>");
		}
Exemplo n.º 52
0
		public void Sense_NoId_GetsId()
		{
			LexSense sense = new LexSense();
			_exporter.Add(sense);
			_exporter.End();
			ShouldContain(string.Format("id=\"{0}\"", sense.Id));
		}
Exemplo n.º 53
0
		public void SensesAreLastObjectsInEntry() // this helps conversions to sfm
		{
			LexEntry entry = _lexEntryRepository.CreateItem();

			entry.LexicalForm["blue"] = "ocean";

			LexSense sense1 = new LexSense();
			sense1.Gloss["a"] = "aaa";
			entry.Senses.Add(sense1);
			LexSense sense2 = new LexSense();
			sense2.Gloss["b"] = "bbb";
			entry.Senses.Add(sense2);

			MultiText citation =
					entry.GetOrCreateProperty<MultiText>(LexEntry.WellKnownProperties.Citation);
			citation["zz"] = "orange";

			MultiText note =
					entry.GetOrCreateProperty<MultiText>(WeSayDataObject.WellKnownProperties.Note);
			note["zz"] = "orange";

			MultiText field = entry.GetOrCreateProperty<MultiText>("custom");
			field["zz"] = "orange";

			_lexEntryRepository.SaveItem(entry);
			_exporter.Add(entry);

			ShouldContain(
					string.Format(GetSenseElement(sense1) +
								  "<gloss lang=\"a\"><text>aaa</text></gloss></sense>" +
								  GetSenseElement(sense2) +
								  "<gloss lang=\"b\"><text>bbb</text></gloss></sense></entry>"));
		}
Exemplo n.º 54
0
		/// <summary>
		/// Handle a column that contains a "transduce" specification indicating how to find the
		/// field that should be filled in. Currently we support class.field, where class is
		/// LexEntry, LexSense, LexExampleSentence, or CmTranslation, and field is one of the multilingual
		/// or simple string fields of that class.
		/// LexSense means set a field of the sense passed to the method; entry means its owning entry;
		/// example means its first example, which will be created if it doesn't already have one;
		/// and CmTranslation means the first translation of the first example (both of which will
		/// be created if needed). (Since this is used as part of RDENewSense, the first example field
		/// encountered will always create a new example, and the first translation field a new translation.)
		/// enhance: also handle class.field.field, where the first field indicates an atomic object
		/// property?
		/// </summary>
		/// <param name="ls"></param>
		/// <param name="column"></param>
		/// <param name="ws"></param>
		/// <param name="val"></param>
		/// <returns></returns>
		private bool HandleTransduceColum(LexSense ls, XmlNode column, int ws, ITsString val)
		{
			var transduce = XmlUtils.GetOptionalAttributeValue(column, "transduce");
			if (string.IsNullOrEmpty(transduce))
				return false;
			var mdc = ls.Cache.MetaDataCacheAccessor;
			var parts = transduce.Split('.');
			if (parts.Length == 2)
			{
				var className = parts[0];
				var fieldName = parts[1];
				int flid = mdc.GetFieldId(className, fieldName, true);
				int hvo;
				switch (className)
				{
					case "LexSense":
						hvo = ls.Hvo;
						break;
					case "LexEntry":
						hvo = ls.OwningEntry.Hvo;
						break;
					case "LexExampleSentence":
						hvo = GetOrMakeFirstExample(ls).Hvo;
						break;
					case "CmTranslation":
						var example = GetOrMakeFirstExample(ls);
						hvo = GetOrMakeFirstTranslation(example).Hvo;
						break;
						// Enhance JohnT: handle other cases as needed.
					default:
						throw new ArgumentException(
							string.Format("transduce attribute of column argument specifies an unhandled class ({0})"), className);
				}
				if (mdc.GetFieldType(flid) == (int)CellarPropertyType.String)
					ls.Cache.DomainDataByFlid.SetString(hvo, flid, val);
				else // asssume multistring
					ls.Cache.DomainDataByFlid.SetMultiStringAlt(hvo, flid, ws, val);
				return true;
			}
			throw new ArgumentException("transduce attr for column spec has wrong number of parts " + transduce + " " + column.OuterXml);
		}
		public void GlossGetsFlag()
		{
			LexSense sense = new LexSense();
			LiftMultiText text = MakeBasicLiftMultiText();
			AddAnnotationToLiftMultiText(text, "ws-one", "flag", "1");
			_builder.MergeInGloss(sense, text);
			Assert.IsTrue(sense.Gloss.GetAnnotationOfAlternativeIsStarred("ws-one"));
			Assert.IsFalse(sense.Gloss.GetAnnotationOfAlternativeIsStarred("ws-two"));

			text = MakeBasicLiftMultiText();
			AddAnnotationToLiftMultiText(text, "ws-one", "flag", "0");
			_builder.MergeInGloss(sense, text);
			Assert.IsFalse(sense.Gloss.GetAnnotationOfAlternativeIsStarred("ws-one"));
		}
		public void ChangedEntryFound()
		{
#if merging
			Guid g = Guid.NewGuid();
			Extensible extensibleInfo = CreateFullextensibleInfo(g);

			LexEntry e = _repository.CreateItem();
			LexSense sense1 = new LexSense();
			LexSense sense2 = new LexSense();
			e.Senses.Add(sense1);
			e.Senses.Add(sense2);
			e.CreationTime = extensibleInfo.CreationTime;
			e.ModificationTime = new DateTime(e.CreationTime.Ticks + 100, DateTimeKind.Utc);

			LexEntry found = _merger.GetOrMakeEntry(extensibleInfo, 0);
			_merger.FinishEntry(found);
			Assert.AreSame(found, e);
			Assert.AreEqual(2, found.Senses.Count);

			//this is a temp side track
			Assert.AreEqual(1, _repository.CountAllItems());
			Extensible xInfo = CreateFullextensibleInfo(Guid.NewGuid());
			LexEntry x = _merger.GetOrMakeEntry(xInfo, 1);
			_merger.FinishEntry(x);
			Assert.AreEqual(2, _repository.CountAllItems());
#endif
		}
		public void MultipleGlossesCombined()
		{
			LexSense sense = new LexSense();
			_builder.MergeInGloss(sense, MakeBasicLiftMultiText());
			LiftMultiText secondGloss = new LiftMultiText();
			secondGloss.Add("ws-one", "UNO");
			secondGloss.Add("ws-three", "tres");
			_builder.MergeInGloss(sense, secondGloss);

			//MultiText mt = sense.GetProperty<MultiText>(LexSense.WellKnownProperties.Note);
			Assert.AreEqual(3, sense.Gloss.Forms.Length);
			Assert.AreEqual("uno; UNO", sense.Gloss["ws-one"]);
		}
Exemplo n.º 58
0
		private static ILexExampleSentence GetOrMakeFirstExample(LexSense ls)
		{
			if (ls.ExamplesOS.Count == 0)
				ls.ExamplesOS.Add(ls.Services.GetInstance<ILexExampleSentenceFactory>().Create());
			return ls.ExamplesOS.ToArray()[0];
		}
Exemplo n.º 59
0
		public void LexSense_becomes_sense()
		{
			LexSense sense = new LexSense();
			_exporter.Add(sense);
			_exporter.End();
			Assert.IsTrue(_stringBuilder.ToString().StartsWith("<sense"));
		}
Exemplo n.º 60
0
		public void NoteOnSense_OutputAsNote()
		{
			LexSense sense = new LexSense();
			MultiText m =
					sense.GetOrCreateProperty<MultiText>(WeSayDataObject.WellKnownProperties.Note);
			m["zz"] = "orange";
			_exporter.Add(sense);
			_exporter.End();
			AssertXPathNotNull("sense/note/form[@lang='zz' and text='orange']");
			AssertXPathNotNull("sense[not(field)]");
		}