Ejemplo n.º 1
0
        private void InitializeRelationControl(LexRelation relation)
        {
            //TODO: refactor this (sortHelper, pairStringLexEntryIdList, _keyIdMap, GetKeyIdPairFromLexEntry)
            //      to use ApproximateFinder. Eventually refactor the automcompletetextbox to just take one

            IWritingSystemDefinition writingSystem   = GetWritingSystemFromField();
            ResultSet <LexEntry>     recordTokenList =
                _lexEntryRepository.GetAllEntriesSortedByLexicalFormOrAlternative(writingSystem);

            _resultSet = recordTokenList;

            AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker =
                CreatePicker <RecordToken <LexEntry> >(relation);

            picker.GetKeyValueFromValue = GetRecordTokenFromTargetId;
            picker.GetValueFromKeyValue = GetTargetIdFromRecordToken;

            picker.Box.ItemDisplayStringAdaptor = new PairStringLexEntryIdDisplayProvider();
            picker.Box.FormToObjectFinder       = FindRecordTokenFromForm;
            picker.Box.ItemFilterer             = FindClosestAndNextClosestAndPrefixedPairStringLexEntryForms;

            picker.Box.Items = recordTokenList;
            if (!String.IsNullOrEmpty(relation.TargetId))
            {
                picker.Box.SelectedItem = GetRecordTokenFromLexEntry(_lexEntryRepository.GetLexEntryWithMatchingId(relation.TargetId));
            }

            picker.CreateNewClicked += OnCreateNewPairStringLexEntryId;
            _control = picker;
        }
        public void MergeInRelation(PalasoDataObject extensible,
                                    string relationFieldId,
                                    string targetId,
                                    string rawXml)
        {
            if (String.IsNullOrEmpty(relationFieldId))
            {
                return;                 //"log skipping..."
            }

            //the "field name" of a relation equals the name of the relation type
            LexRelationCollection collection =
                extensible.GetOrCreateProperty <LexRelationCollection>(relationFieldId);
            LexRelation relation = new LexRelation(relationFieldId, targetId, extensible);

            if (!string.IsNullOrEmpty(rawXml))
            {
                var dom = new XmlDocument();
                dom.LoadXml(rawXml);
                foreach (XmlNode child in dom.FirstChild.ChildNodes)
                {
                    relation.EmbeddedXmlElements.Add(child.OuterXml);
                }
            }
            collection.Relations.Add(relation);
        }
		private void AddRelation()
		{
			LexRelationCollection synonyms =
					_source.GetOrCreateProperty<LexRelationCollection>("synonyms");
			LexRelation r = new LexRelation("synonyms", _target.GetOrCreateId(true), _source);
			r.SetTarget(_target);
			synonyms.Relations.Add(r);
		}
        private void AddRelation()
        {
            LexRelationCollection synonyms =
                _source.GetOrCreateProperty <LexRelationCollection>("synonyms");
            LexRelation r = new LexRelation("synonyms", _target.GetOrCreateId(true), _source);

            synonyms.Relations.Add(r);
        }
Ejemplo n.º 5
0
        protected override string GetOutputRelationName(LexRelation relation)
        {
            //Enhance: add "printed-dictionary-label" to fielddefns, so that people have control over this from wesay config.
            var s = relation.FieldId.Replace("confer", "see");

            s = s.Replace("BaseForm", "from");
            return(s);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        private static LexRelation AddRelation(PalasoDataObject source,
                                               string fieldName,
                                               string targetId)
        {
            LexRelationCollection relationColection =
                source.GetOrCreateProperty <LexRelationCollection>(fieldName);

            LexRelation relation = new LexRelation(fieldName, targetId, source);

            relationColection.Relations.Add(relation);
            return(relation);
        }
Ejemplo n.º 8
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);
		}
Ejemplo n.º 9
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(string.Empty, relation.Key);
        }
Ejemplo n.º 10
0
        public void ChangeBoundRelation_Single_ToNonExistant_NoRelation()
        {
            LexRelation relation = AddRelation(_source, _singleSynonymRelationField.FieldName, _target.Id);

            Control c = RelationController.CreateWidget(_source,
                                                        _singleSynonymRelationType,
                                                        _singleSynonymRelationField,
                                                        _lexEntryRepository,
                                                        delegate { });

            c.Text = "NonExistantId";

            Assert.AreEqual(string.Empty, relation.Key);
        }
Ejemplo n.º 11
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);
		}
Ejemplo n.º 12
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(string.Empty, relation.Key);
        }
Ejemplo n.º 13
0
        public void ChangeBoundRelation_Single_Existing()
        {
            LexRelation relation = AddRelation(_source, _singleSynonymRelationField.FieldName, "something");

            Control c = RelationController.CreateWidget(_source,
                                                        _singleSynonymRelationType,
                                                        _singleSynonymRelationField,
                                                        _lexEntryRepository,
                                                        delegate { });

            c.Text = _target.LexicalForm[WritingSystemsIdsForTests.OtherIdForTest];

            Assert.AreEqual(_target.Id, relation.Key);
        }
Ejemplo n.º 14
0
        protected override void WriteRelationTarget(LexRelation relation)
        {
            if (0 == (ExportOptions & Options.DereferenceRelations))
            {
                return;
            }

            string key = relation.Key;

            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            LexEntry target = _lexEntryRepository.GetLexEntryWithMatchingId(key);

            if (target != null)
            {
                WriteHeadWordFieldForRelation(target, "headword-of-target");
            }
        }
Ejemplo n.º 15
0
        public void ChangeBoundRelation_Single_ToNonExistantCreate_CreatesRelation()
        {
            LexRelation relation = AddRelation(_source, _singleSynonymRelationField.FieldName, _target.Id);

            Control c = RelationController.CreateWidget(_source,
                                                        _singleSynonymRelationType,
                                                        _singleSynonymRelationField,
                                                        _lexEntryRepository,
                                                        delegate { });

            c.Text = "new";

            AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker =
                (AutoCompleteWithCreationBox <RecordToken <LexEntry>, string>)c;

            picker.CreateNewObjectFromText();

            LexEntry newEntry = _lexEntryRepository.GetLexEntryWithMatchingId(relation.Key);

            Assert.IsNotNull(newEntry);
            Assert.AreEqual("new", newEntry.LexicalForm[WritingSystemsIdsForTests.OtherIdForTest]);
        }
Ejemplo n.º 16
0
        private void MakeControl()
        {
            //relations come to us in collections, even when they are atomic
            // this will get a collection if we already have some for this field, or else
            // it will make one. If unused, it will be cleaned up at the right time by the PalasoDataObject parent.
            var targetRelationCollection =
                _relationParent.GetOrCreateProperty <LexRelationCollection>(_field.FieldName);

            switch (_relationType.Multiplicity)
            {
            case LexRelationType.Multiplicities.One:
                LexRelation relation;
                if (targetRelationCollection.Relations.Count > 0)
                {
                    relation        = targetRelationCollection.Relations[0];
                    relation.Parent = _relationParent;
                }
                else
                {
                    //we have to make one so we can show the control. It will be cleaned up, if not used, by the PalasoDataObject target
                    relation = new LexRelation(_field.FieldName, string.Empty, _relationParent);
                    targetRelationCollection.Relations.Add(relation);
                }

                InitializeRelationControl(relation);

                break;

            //                case LexRelationType.Multiplicities.Many:
            //                    _control = new ReferenceCollectionEditor<LexRelation>
            //                                    (targetRelationCollection.Relations,
            //                                     _field.WritingSystemIds);
            //                    break;
            default:
                break;
            }
        }
Ejemplo n.º 17
0
        private AutoCompleteWithCreationBox <T, string> CreatePicker <T>(LexRelation relation)
            where T : class
        {
            var picker = new AutoCompleteWithCreationBox <T, string> (
                CommonEnumerations.VisibilitySetting.Visible,
                WeSayWordsProject.Project.ServiceLocator
                );

            picker.Box.Tag = relation;
            //                    switch (type.TargetType)
            //                    {
            //                        case LexRelationType.TargetTypes.Entry:
            //                            //picker.Box.Items = Project.WeSayWordsProject.Project
            //                            break;
            //                        case LexRelationType.TargetTypes.Sense:
            //                            break;
            //                        default:
            //                            break;
            //                    }
            picker.Box.WritingSystem = GetWritingSystemFromField();
            picker.Box.PopupWidth    = 200;

            //review:
            picker.Box.MinimumSize = new Size(40, 10);
            if (picker.Box.SelectedItem == null && !string.IsNullOrEmpty(relation.Key))
            {
                picker.Box.Text = relation.Key;
                // picker.Box.ShowRedSquiggle = true;
            }

            _binding = new SimpleBinding <string>(relation, picker);
            //for underlinging the relation in the preview pane
            _binding.CurrentItemChanged += _focusDelegate;

            return(picker);
        }
Ejemplo n.º 18
0
 protected virtual string GetOutputRelationName(LexRelation relation)
 {
     return(relation.FieldId);
 }
Ejemplo n.º 19
0
		public void SenseWithRelationWithEmbeddedXml()
		{
			using (var session = new LiftExportAsFragmentTestSession())
			{
				var sense = new LexSense();

				var synonymRelationType = new LexRelationType(
					"synonym",
					LexRelationType.Multiplicities.Many,
					LexRelationType.TargetTypes.Sense
				);

				var relations = new LexRelationCollection();
				sense.Properties.Add(new KeyValuePair<string, IPalasoDataObjectProperty>("relations", relations));

				var lexRelation = new LexRelation(synonymRelationType.ID, "one", sense);
				lexRelation.EmbeddedXmlElements.Add("<trait name='x' value='X'/>");
				lexRelation.EmbeddedXmlElements.Add("<field id='z'><text>hello</text></field>");
				relations.Relations.Add(lexRelation);


				session.LiftWriter.Add(sense);
				session.LiftWriter.End();
				AssertThatXmlIn.String(session.StringBuilder.ToString()).HasSpecifiedNumberOfMatchesForXpath("//sense/relation/trait",1);
				AssertThatXmlIn.String(session.StringBuilder.ToString()).HasSpecifiedNumberOfMatchesForXpath("//sense/relation/field", 1);
			}
		}
Ejemplo n.º 20
0
 /// <summary>
 /// allows subclass to output a dereferenced target name, e.g., for plift
 /// </summary>
 protected virtual void WriteRelationTarget(LexRelation relation)
 {
 }
Ejemplo n.º 21
0
		protected override void WriteRelationTarget(LexRelation relation)
		{
			if (0 == (ExportOptions & Options.DereferenceRelations))
			{
				return;
			}

			string key = relation.Key;
			if(string.IsNullOrEmpty(key))
			{
				return;
			}

			LexEntry target = this._lexEntryRepository.GetLexEntryWithMatchingId(key);
			if (target != null)
			{
				WriteHeadWordField(target, "headword-of-target");
			}
		}
Ejemplo n.º 22
0
		private static LexRelation AddRelation(WeSayDataObject source,
											   string fieldName,
											   string targetId)
		{
			LexRelationCollection relationColection =
					source.GetOrCreateProperty<LexRelationCollection>(fieldName);

			LexRelation relation = new LexRelation(fieldName, targetId, source);
			relationColection.Relations.Add(relation);
			return relation;
		}
Ejemplo n.º 23
0
		protected virtual void WriteRelationTarget(LexRelation relation) {}