public void Setup() { _ws = WritingSystemDefinition.Parse("qaa-x-qaa"); _ws.DefaultFontName = "Arial"; _ws.DefaultFontSize = (float)55.9; // _createNewClickedFired=false; // _valueChangedFired = false; _sourceChoices = new OptionsList(); _choiceKeys = new List <string>(); AddSourceChoice("one", "1", "Notice, this is not the number two."); //nb: key 'two' in there AddSourceChoice("two", "2", "A description of two which includes the word duo."); AddSourceChoice("three", "3", "A description of this which includes the word trio and is not two."); _displayAdaptor = new OptionDisplayAdaptor(_sourceChoices, _ws.Id); _control = new AutoCompleteWithCreationBox <Option, string>( CommonEnumerations.VisibilitySetting.Visible, null); _control.Name = "autobox"; _control.Box.Items = _sourceChoices.Options; _control.Box.ItemFilterer = _displayAdaptor.GetItemsToOffer; //leave for individual tests _control.CreateNewClicked += new EventHandler<CreateNewArgs>(_control_CreateNewClicked); _control.Box.ItemDisplayStringAdaptor = _displayAdaptor; _control.Box.WritingSystem = _ws; _control.GetKeyValueFromValue = _displayAdaptor.GetOptionFromKey; _control.GetValueFromKeyValue = _displayAdaptor.GetKeyFromOption; _control.ValueChanged += _control_ValueChanged; _dataBeingEditted = new OptionRef(); }
public void MergeInGrammaticalInfo(PalasoDataObject senseOrReversal, string val, List <Trait> traits) { LexSense sense = senseOrReversal as LexSense; if (sense == null) { return; //todo: preserve grammatical info on reversal, when we hand reversals } OptionRef o = sense.GetOrCreateProperty <OptionRef>(LexSense.WellKnownProperties.PartOfSpeech); o.Value = val; if (traits != null) { foreach (Trait trait in traits) { if (trait.Name == "flag" && int.Parse(trait.Value) > 0) { o.IsStarred = true; } else { o.EmbeddedXmlElements.Add(string.Format(@"<trait name='{0}' value='{1}'/>", trait.Name, trait.Value)); } } } }
private void WriteDisplayNameFieldForOption(OptionRef optionRef, string fieldName) { OptionsList list = WeSayWordsProject.Project.GetOptionsList(fieldName); if (list != null) { Option posOption = list.GetOptionFromKey(optionRef.Value); if (posOption == null) { return; } if (posOption.Name == null) { return; } LanguageForm[] labelForms = posOption.Name.GetOrderedAndFilteredForms( _viewTemplate.GetField(fieldName).WritingSystemIds); if (labelForms != null && labelForms.Length > 0) { Writer.WriteStartElement("field"); Writer.WriteAttributeString("type", fieldName == "POS" ? "grammatical-info" : fieldName); Add(labelForms, false); Writer.WriteEndElement(); } } }
public void CompareTo_OtherIsNotOptionRef_Throws() { OptionRef reference = new OptionRef(); string other = ""; Assert.Throws <ArgumentException>(() => reference.CompareTo(other)); }
public void MergeInSource(LexExampleSentence example, string source) { OptionRef o = example.GetOrCreateProperty <OptionRef>( LexExampleSentence.WellKnownProperties.Source); o.Value = source; }
public void CompareTo_OtherHasSameKey_ReturnsLesser() { OptionRef reference = new OptionRef(); reference.Key = "key1"; OptionRef other = new OptionRef(); other.Key = "key1"; Assert.AreEqual(0, reference.CompareTo(other)); }
public void WordCollected_LiftWithPartOfSpeech_CopiedOver() { LexSense firstSense = AddWordAndGetFirstSense(); OptionRef pos = firstSense.GetProperty <OptionRef>( LexSense.WellKnownProperties.PartOfSpeech); Assert.AreEqual("noun", pos.Key); }
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); }
protected override void WritePosCore(OptionRef pos) { if ((0 == (_options & Options.ExportPartOfSpeechAsGrammaticalInfoElement)) && (0 != (_options & Options.DereferenceOptions))) { WriteDisplayNameFieldForOption(pos, LexSense.WellKnownProperties.PartOfSpeech); } else { base.WritePosCore(pos); } }
protected virtual void WritePosCore(OptionRef pos) { Writer.WriteStartElement("grammatical-info"); Writer.WriteAttributeString("value", pos.Value); WriteFlags(pos); foreach (string rawXml in pos.EmbeddedXmlElements) { Writer.WriteRaw(rawXml); } Writer.WriteEndElement(); }
public void ExpectedAtomicTraitOnEntry() { _builder.ExpectedOptionTraits = new[] { "flub" }; LexEntry e = MakeSimpleEntry(); _builder.MergeInTrait(e, new Trait("flub", "dub")); Assert.AreEqual(1, e.Properties.Count); Assert.AreEqual("flub", e.Properties[0].Key); OptionRef option = e.GetProperty <OptionRef>("flub"); Assert.AreEqual("dub", option.Value); }
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 Add(LexExampleSentence example) { if (!ShouldOutputProperty(LexExampleSentence.WellKnownProperties.ExampleSentence)) { return; } List <string> propertiesAlreadyOutput = new List <string>(); Writer.WriteStartElement("example"); OptionRef source = example.GetProperty <OptionRef>(LexExampleSentence.WellKnownProperties.Source); if (source != null && source.Value.Length > 0) { if (ShouldOutputProperty(LexExampleSentence.WellKnownProperties.Source)) { Writer.WriteAttributeString("source", source.Value); propertiesAlreadyOutput.Add("source"); } } WriteMultiTextNoWrapper(LexExampleSentence.WellKnownProperties.ExampleSentence, example.Sentence); propertiesAlreadyOutput.Add(LexExampleSentence.WellKnownProperties.ExampleSentence); // WriteMultiWithWrapperIfNonEmpty(LexExampleSentence.WellKnownProperties.Translation, "translation", example.Translation); if (!MultiTextBase.IsEmpty(example.Translation)) { Writer.WriteStartElement("translation"); if (!string.IsNullOrEmpty(example.TranslationType)) { Writer.WriteAttributeString("type", example.TranslationType); propertiesAlreadyOutput.Add("type"); } AddMultitextForms(LexExampleSentence.WellKnownProperties.Translation, example.Translation); Writer.WriteEndElement(); propertiesAlreadyOutput.Add(LexExampleSentence.WellKnownProperties.Translation); } if (ShouldOutputProperty(LexExampleSentence.WellKnownProperties.ExampleSentence)) { WriteWellKnownCustomMultiText(example, PalasoDataObject.WellKnownProperties.Note, propertiesAlreadyOutput); } WriteCustomProperties(example, propertiesAlreadyOutput); Writer.WriteEndElement(); }
private void WriteGrammi(LexSense sense) { if (!ShouldOutputProperty(LexSense.WellKnownProperties.PartOfSpeech)) { return; } OptionRef pos = sense.GetProperty <OptionRef>(LexSense.WellKnownProperties.PartOfSpeech); if (pos != null && !pos.IsEmpty) { WritePosCore(pos); } }
public void SenseWithOnlyPOS_ReadyForDeletion() { Assert.IsFalse(_sense.IsEmptyForPurposesOfDeletion); ClearSenseMeaning(); ClearSenseExample(); ClearSenseCustom(); Assert.IsTrue(_sense.IsEmpty); OptionRef pos = _sense.GetOrCreateProperty <OptionRef>(LexSense.WellKnownProperties.PartOfSpeech); pos.Value = "noun"; Assert.IsFalse(_sense.IsEmpty); Assert.IsTrue(_sense.IsEmptyForPurposesOfDeletion); }
protected override void WriteOptionRef(string key, OptionRef optionRef) { if (optionRef.Value.Length > 0) { if (0 != (ExportOptions & Options.DereferenceOptions)) { WriteDisplayNameFieldForOption(optionRef, key); } else { base.WriteOptionRef(key, optionRef); } } }
protected Control MakeOptionWidget(PalasoDataObject target, Field field) { OptionRef optionRefTarget = target.GetOrCreateProperty <OptionRef>(field.FieldName); OptionsList list = WeSayWordsProject.Project.GetOptionsList(field, false); IWritingSystemDefinition preferredWritingSystem = _viewTemplate.GetDefaultWritingSystemForField(field.FieldName); SingleOptionControl control = new SingleOptionControl(optionRefTarget, list, field.FieldName, preferredWritingSystem, WeSayWordsProject.Project.ServiceLocator); SimpleBinding <string> binding = new SimpleBinding <string>(optionRefTarget, control); binding.CurrentItemChanged += _detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
protected virtual void WriteOptionRef(string key, OptionRef optionRef) { if (optionRef.Value.Length > 0) { Writer.WriteStartElement("trait"); Writer.WriteAttributeString("name", key); Writer.WriteAttributeString("value", optionRef.Value); foreach (string rawXml in optionRef.EmbeddedXmlElements) { Writer.WriteRaw(rawXml); } Writer.WriteEndElement(); } }
/// <summary> /// Handle LIFT's "trait" entity, /// which can be found on any subclass of "extensible", on any "field", and as /// a subclass of "annotation". /// </summary> public void MergeInTrait(PalasoDataObject extensible, Trait trait) { if (String.IsNullOrEmpty(trait.Name)) { //"log skipping..." return; } if (ExpectedOptionTraits.Contains(trait.Name)) { OptionRef o = extensible.GetOrCreateProperty <OptionRef>(trait.Name); o.Value = trait.Value.Trim(); } else if (trait.Name.StartsWith("flag-")) { extensible.SetFlag(trait.Name); } // if it is unknown assume it is a collection. else //if (ExpectedOptionCollectionTraits.Contains(trait.Name)) { var key = trait.Value.Trim(); OptionRefCollection refs = extensible.GetOrCreateProperty <OptionRefCollection>(trait.Name); if (trait.Name == LexSense.WellKnownProperties.SemanticDomainDdp4) { if (_semanticDomainsList != null && _semanticDomainsList.GetOptionFromKey(key) == null) { var match = _semanticDomainsList.Options.FirstOrDefault(option => option.Key.StartsWith(key)); if (match != null) { refs.Add(match.Key); return; } } } refs.Add(key); } //else //{ // //"log skipping..." //} }
private static void RenderPartOfSpeech(LexSense sense, CurrentItemEventArgs currentItem, StringBuilder rtf) { OptionRef posRef = sense.GetProperty <OptionRef>( LexSense.WellKnownProperties.PartOfSpeech ); if (posRef == null) { return; } OptionsList list = WeSayWordsProject.Project.GetOptionsList( LexSense.WellKnownProperties.PartOfSpeech ); if (list == null) { return; } Option posOption = list.GetOptionFromKey(posRef.Value); if (posOption == null) { return; } Field posField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate( LexSense.WellKnownProperties.PartOfSpeech ); if (posField == null) { return; } rtf.Append(@" \i "); rtf.Append(RenderField(posOption.Name, currentItem, 0, posField)); rtf.Append(@"\i0 "); }
protected override void WritePosCore(OptionRef pos) { if (0 != (_options & Options.DereferenceOptions)) { WriteDisplayNameFieldForOption(pos, LexSense.WellKnownProperties.PartOfSpeech); } else { base.WritePosCore(pos); } }
public void Setup() { _ws = new WritingSystem("xx", new Font("Arial", (float) 55.9)); // _createNewClickedFired=false; // _valueChangedFired = false; _sourceChoices = new OptionsList(); _choiceKeys = new List<string>(); AddSourceChoice("one", "1", "Notice, this is not the number two."); //nb: key 'two' in there AddSourceChoice("two", "2", "A description of two which includes the word duo."); AddSourceChoice("three", "3", "A description of this which includes the word trio and is not two."); _displayAdaptor = new OptionDisplayAdaptor(_sourceChoices, _ws.Id); _control = new AutoCompleteWithCreationBox<Option, string>( CommonEnumerations.VisibilitySetting.Visible); _control.Name = "autobox"; _control.Box.Items = _sourceChoices.Options; _control.Box.ItemFilterer = _displayAdaptor.GetItemsToOffer; //leave for individual tests _control.CreateNewClicked += new EventHandler<CreateNewArgs>(_control_CreateNewClicked); _control.Box.ItemDisplayStringAdaptor = _displayAdaptor; _control.Box.WritingSystem = _ws; _control.GetKeyValueFromValue = _displayAdaptor.GetOptionFromKey; _control.GetValueFromKeyValue = _displayAdaptor.GetKeyFromOption; _control.ValueChanged += _control_ValueChanged; _dataBeingEditted = new OptionRef(); }
public void CompareTo_OtherIsNotOptionRef_Throws() { OptionRef reference = new OptionRef(); string other = ""; Assert.AreEqual(0, reference.CompareTo(other)); }
public void CompareTo_Null_ReturnsGreater() { OptionRef reference = new OptionRef(); Assert.AreEqual(1, reference.CompareTo(null)); }
protected virtual void WriteOptionRef(string key, OptionRef optionRef) { if (optionRef.Value.Length > 0) { Writer.WriteStartElement("trait"); Writer.WriteAttributeString("name", key); Writer.WriteAttributeString("value", optionRef.Value); Writer.WriteEndElement(); } }
protected virtual void WritePosCore(OptionRef pos) { Writer.WriteStartElement("grammatical-info"); Writer.WriteAttributeString("value", pos.Value); WriteFlags(pos); Writer.WriteEndElement(); }