/// <summary> /// Constructor. /// </summary> public LiftField(string type, LiftMultiText contents) { Annotations = new List<LiftAnnotation>(); Traits = new List<LiftTrait>(); Type = type; Content = contents; }
private static LiftMultiText MakeBasicLiftMultiText() { LiftMultiText forms = new LiftMultiText(); forms.Add("ws-one", "uno"); forms.Add("ws-two", "dos"); return forms; }
public void Create_LiftMultiTextWithOutSpansInForms_ReturnsMultiTextWithOutSpansInForms() { LiftString liftStringToConvert = new LiftString("No spans here!"); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("No spans here!", multiText["de"]); }
public PalasoDataObject MergeInEtymology(LexEntry entry, string source, string type, LiftMultiText form, LiftMultiText gloss, string rawXml) { entry.GetOrCreateProperty <EmbeddedXmlCollection>("etymology").Values.Add(rawXml); return(null); }
/// <summary> Adds in media for audio pronunciation </summary> public void MergeInMedia(LiftObject pronunciation, string href, LiftMultiText caption) { var entry = (LiftEntry)pronunciation; var phonetic = new LiftPhonetic(); var url = new LiftUrlRef { Url = href }; phonetic.Media.Add(url); entry.Pronunciations.Add(phonetic); }
/// <summary> Adds in note, if there is one to add </summary> public void MergeInNote(LiftObject extensible, string type, LiftMultiText contents, string rawXml) { if (extensible is LiftEntry entry) { var note = new LiftNote( // This application only uses "basic" notes, which have no type null, new LiftMultiText(contents.FirstValue.Key, contents.FirstValue.Value.Text)); entry.Notes.Add(note); } }
public void MergeInPicture(LexSense sense, string href, LiftMultiText caption) { //nb 1: we're limiting ourselves to one picture per sense, here: //nb 2: the name and case must match the fieldName PictureRef pict = sense.GetOrCreateProperty <PictureRef>("Picture"); pict.Value = href; if (caption != null) { pict.Caption = MultiText.Create(caption.AsSimpleStrings); } }
public void GetFormWithSpans_WritingSystemLinkedToFormWithSpans_ReturnsFormWithSpans() { LiftString liftStringToConvert = new LiftString("Text to Mark Up!"); LiftSpan span1 = new LiftSpan(0, 4, "", "", ""); liftStringToConvert.Spans.Add(span1); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("<span>Text</span> to Mark Up!", multiText["de"]); }
public void GetFormWithSpans_WritingSystemLinkedToFormWithOutSpans_ReturnsFormWithOutSpans() { LiftString liftStringToConvert = new LiftString("No spans here!"); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("No spans here!", multiText["de"]); }
public void Create_LiftMultiTextWithOutSpansInForms_ReturnsMultiTextWithOutSpansInForms() { LiftString liftStringToConvert = new LiftString("No spans here!"); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("No spans here!", multiText["de"]); }
public void UnexpectedCustomFieldRetained() { LexEntry e = MakeSimpleEntry(); LiftMultiText t = new LiftMultiText(); t["z"] = new LiftString("dub"); _builder.MergeInField(e, "flub", default(DateTime), default(DateTime), t, null); Assert.AreEqual(1, e.Properties.Count); Assert.AreEqual("flub", e.Properties[0].Key); MultiText mt = e.GetProperty <MultiText>("flub"); Assert.AreEqual("dub", mt["z"]); }
private static void AddOrAppendMultiTextProperty(PalasoDataObject dataObject, LiftMultiText contents, string propertyName, string noticeToPrependIfNotEmpty) { MultiText mt = dataObject.GetOrCreateProperty <MultiText>(propertyName); mt.MergeInWithAppend(MultiText.Create(contents), string.IsNullOrEmpty(noticeToPrependIfNotEmpty) ? "; " : noticeToPrependIfNotEmpty); AddAnnotationsToMultiText(contents, mt); //dataObject.GetOrCreateProperty<string>(propertyName) mt)); }
private static void AddAnnotationsToMultiText(LiftMultiText forms, MultiTextBase text) { foreach (Annotation annotation in forms.Annotations) { if (annotation.Name == "flag") { text.SetAnnotationOfAlternativeIsStarred(annotation.LanguageHint, int.Parse(annotation.Value) > 0); } else { //log dropped } } }
public void Create_LiftMultiTextWithSpansInForms_ReturnsMultiTextWithSpansInForms() { LiftString liftStringToConvert = new LiftString("Text to Mark Up!"); LiftSpan span1 = new LiftSpan(0, 4, "", "", ""); liftStringToConvert.Spans.Add(span1); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("<span>Text</span> to Mark Up!", multiText["de"]); }
public void NewEntry_OldLiteralMeaning_GetsMoved() { // _builder.AfterEntryRead += _builder.ApplyWeSayPolicyToParsedEntry; Extensible extensibleInfo = new Extensible(); LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0); LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty); LiftMultiText t = new LiftMultiText("en", "test"); _builder.MergeInField(s, "LiteralMeaning", default(DateTime), default(DateTime), t, null); _builder.FinishEntry(e); Assert.IsNull(e.Senses[0].GetProperty <MultiText>("LiteralMeaning")); Assert.IsNotNull(e.GetProperty <MultiText>(LexEntry.WellKnownProperties.LiteralMeaning)); Assert.AreEqual("test", e.GetProperty <MultiText>(LexEntry.WellKnownProperties.LiteralMeaning).GetExactAlternative("en")); }
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 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"]); }
public void EntryWithCitation() { LexEntry entry = MakeSimpleEntry(); LiftMultiText forms = new LiftMultiText(); forms.Add("x", "hello"); forms.Add("y", "bye"); _builder.MergeInCitationForm(entry, forms); MultiText citation = entry.GetProperty <MultiText>(LexEntry.WellKnownProperties.Citation); Assert.AreEqual(2, citation.Forms.Length); Assert.AreEqual("hello", citation["x"]); Assert.AreEqual("bye", citation["y"]); }
public void SenseGetsPictureWithCaption() { Extensible extensibleInfo = new Extensible(); LexEntry e = MakeSimpleEntry(); LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty); LiftMultiText caption = new LiftMultiText(); caption["aa"] = new LiftString("acaption"); _builder.MergeInPicture(s, "testPicture.png", caption); PictureRef pict = s.GetProperty <PictureRef>("Picture"); Assert.AreEqual("testPicture.png", pict.Value); Assert.AreEqual("acaption", pict.Caption["aa"]); }
public void ExampleTranslation_OneWithNoType() { 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", "aaaa"); _builder.MergeInTranslationForm(ex, "", translation, "bogus raw xml"); _builder.FinishEntry(e); _liftWriter.Add(e); _liftWriter.End(); AssertHasAtLeastOneMatch("//entry/sense/example/translation[not(@type)]/form[@lang='aa']"); }
public static MultiText Create(LiftMultiText liftMultiText) { if (liftMultiText == null) { throw new ArgumentNullException("liftMultiText"); } MultiText m = new MultiText(); Dictionary <string, string> forms = new Dictionary <string, string>(); foreach (KeyValuePair <string, LiftString> pair in liftMultiText) { if (pair.Value != null) { forms.Add(pair.Key, ConvertLiftStringToSimpleStringWithMarkers(pair.Value)); } } CopyForms(forms, m); return(m); }
/// <summary> Adds pronunciation audio of a word to be written out to lift </summary> private static void AddAudio(LexEntry entry, Word wordEntry, string path, string projectId) { foreach (var audioFile in wordEntry.Audio) { var lexPhonetic = new LexPhonetic(); var src = FileStorage.GenerateAudioFilePath(projectId, audioFile); var dest = Path.Combine(path, audioFile); if (File.Exists(src)) { File.Copy(src, dest, true); var proMultiText = new LiftMultiText { { "href", dest } }; lexPhonetic.MergeIn(MultiText.Create(proMultiText)); entry.Pronunciations.Add(lexPhonetic); } } }
public override bool Matches(object o) { LiftMultiText m = (LiftMultiText)o; if (m.Annotations.Count != _expectedCount) { return(false); } Annotation t = m.Annotations[0]; if (!string.IsNullOrEmpty(_expectedLanguageOfFirstAnnotation)) { // if (t.LanguageHint != _expectedLanguageOfFirstAnnotation) // { // return false; // } } return(t.Name == _expectedNameOfFirstAnnotation && t.Value == _expectedValueOfFirstAnnotation && t.Who == _expectedWhoOfFirstAnnotation && t.When == _expectedWhenOfFirstAnnotation); }
/* * private static void AddMultiTextProperty(PalasoDataObject dataObject, LiftMultiText contents, string propertyName) * { * dataObject.Properties.Add( * new KeyValuePair<string, object>(propertyName, * MultiText.Create(contents))); * } */ /// <summary> /// Handle LIFT's "field" entity which can be found on any subclass of "extensible" /// </summary> public void MergeInField(PalasoDataObject extensible, string typeAttribute, DateTime dateCreated, DateTime dateModified, LiftMultiText contents, List <Trait> traits) { MultiText t = MultiText.Create(contents.AsSimpleStrings); //enchance: instead of KeyValuePair, make a LiftField class, so we can either keep the // other field stuff as xml (in order to round-trip it) or model it. extensible.Properties.Add(new KeyValuePair <string, IPalasoDataObjectProperty>(typeAttribute, t)); if (traits != null) { foreach (var trait in traits) { t.EmbeddedXmlElements.Add(string.Format(@"<trait name='{0}' value='{1}'/>", trait.Name, trait.Value)); } } }
public void MergeInTranslationForm(LexExampleSentence example, string type, LiftMultiText forms, string rawXml) { bool alreadyHaveAPrimaryTranslation = example.Translation != null && !string.IsNullOrEmpty( example.Translation.GetFirstAlternative()); /* bool typeIsCompatibleWithWeSayPrimaryTranslation = string.IsNullOrEmpty(type) || * type.ToLower() == "free translation"; //this is the default style in FLEx * */ //WeSay's model only allows for one translation just grab the first translation if (!alreadyHaveAPrimaryTranslation /*&& typeIsCompatibleWithWeSayPrimaryTranslation*/) { MergeIn(example.Translation, forms); example.TranslationType = type; } else { example.GetOrCreateProperty <EmbeddedXmlCollection>(PalasoDataObject.GetEmbeddedXmlNameForProperty(LexExampleSentence.WellKnownProperties.Translation)).Values.Add(rawXml); } }
public void ExampleTranslation_OneWithNoType() { 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", "aaaa"); _builder.MergeInTranslationForm(ex, "", translation, "bogus raw xml"); _builder.FinishEntry(e); _exporter.Add(e); _exporter.End(); AssertXPathNotNull("//entry/sense/example/translation[not(@type)]/form[@lang='aa']"); }
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); _exporter.Add(e); _exporter.End(); AssertXPathNotNull( "//entry/sense/example/translation[not(@type)]/form[@lang='aa']/text[text()='unmarked translation']"); AssertXPathNotNull("//entry/sense/example/translation[@type='type2']/bogus"); }
public void ExampleTranslations_FreeThenUnmarked() { 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", 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); _exporter.Add(e); _exporter.End(); AssertXPathNotNull("//entry/sense/example/translation[not(@type)]/bogusUnmarked"); AssertXPathNotNull( "//entry/sense/example/translation[@type='free']/form/text[text()='freestuff']"); }
///<summary> /// Constructor. ///</summary> public LiftNote(string type, LiftMultiText contents) { Type = type; Content = contents; }
public void MergeInTranslationForm_NoType_GetContents() { LexExampleSentence ex = new LexExampleSentence(); LiftMultiText translation = new LiftMultiText(); translation.Add("aa", "aaaa"); _builder.MergeInTranslationForm(ex, "", translation, "bogus raw xml"); Assert.AreEqual("aaaa", ex.Translation["aa"]); Assert.IsTrue(string.IsNullOrEmpty(ex.TranslationType)); }
private static LiftMultiText MakeBasicLiftMultiText(string text) { LiftMultiText forms = new LiftMultiText(); forms.Add("ws-one", text); forms.Add("ws-two", text+"-in-two"); return forms; }
private static void AddAnnotationToLiftMultiText(LiftMultiText text, string languageHint, string name, string value) { Annotation annotation = new Annotation(name, value, default(DateTime), null); annotation.LanguageHint = languageHint; text.Annotations.Add(annotation); }
public void MergeInTranslationForm(LiftExample example, string type, LiftMultiText multiText, string rawXml) { }
public void MergeInPicture(LiftSense sense, string href, LiftMultiText caption) { }
public void MergeInNote(LiftObject extensible, string type, LiftMultiText contents, string rawXml) { }
public void MergeInExampleForm(LiftExample example, LiftMultiText multiText) { }
public void MergeInDefinition(LiftSense sense, LiftMultiText liftMultiText) { }
public void MultipleNotesCombined() { LexSense sense = new LexSense(); _builder.MergeInNote(sense, null, MakeBasicLiftMultiText()); LiftMultiText secondNote = new LiftMultiText(); secondNote.Add("ws-one", "UNO"); secondNote.Add("ws-three", "tres"); _builder.MergeInNote(sense, null, secondNote); MultiText mt = sense.GetProperty<MultiText>(WeSayDataObject.WellKnownProperties.Note); Assert.AreEqual(3, mt.Forms.Length); Assert.AreEqual("uno || UNO", mt["ws-one"]); }
public void SenseGetsPictureWithCaption() { Extensible extensibleInfo = new Extensible(); LexEntry e = MakeSimpleEntry(); LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty); LiftMultiText caption = new LiftMultiText(); caption["aa"] = new LiftString("acaption"); _builder.MergeInPicture(s, "testPicture.png", caption); PictureRef pict = s.GetProperty<PictureRef>("Picture"); Assert.AreEqual("testPicture.png", pict.Value); Assert.AreEqual("acaption", pict.Caption["aa"]); }
public void GetFormWithSpans_WritingSystemLinkedToFormWithOutSpans_ReturnsFormWithOutSpans() { LiftString liftStringToConvert = new LiftString("No spans here!"); LiftMultiText liftMultiTextWithSpansInForms = new LiftMultiText(); liftMultiTextWithSpansInForms.Add("de", liftStringToConvert); MultiText multiText = MultiText.Create(liftMultiTextWithSpansInForms); Assert.AreEqual("No spans here!", multiText["de"]); }
public void NewEntry_OldLiteralMeaning_GetsMoved() { // _builder.AfterEntryRead += _builder.ApplyWeSayPolicyToParsedEntry; Extensible extensibleInfo = new Extensible(); LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0); LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty); LiftMultiText t = new LiftMultiText("en", "test"); _builder.MergeInField(s, "LiteralMeaning", default(DateTime), default(DateTime), t, null); _builder.FinishEntry(e); Assert.IsNull(e.Senses[0].GetProperty<MultiText>("LiteralMeaning")); Assert.IsNotNull(e.GetProperty<MultiText>(LexEntry.WellKnownProperties.LiteralMeaning)); Assert.AreEqual("test", e.GetProperty<MultiText>(LexEntry.WellKnownProperties.LiteralMeaning).GetExactAlternative("en")); }
public void ProcessFieldDefinition(string tag, LiftMultiText description) { }
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"]); }
public void NewEntryGetsLexemeForm() { LexEntry e = MakeSimpleEntry(); LiftMultiText forms = new LiftMultiText(); forms.Add("x", "hello"); forms.Add("y", "bye"); _builder.MergeInLexemeForm(e, forms); Assert.AreEqual(2, e.LexicalForm.Count); }
public void EntryGetsLexemeFormWithUnheardOfLanguage() { LexEntry e = MakeSimpleEntry(); LiftMultiText forms = new LiftMultiText(); forms.Add("x99", "hello"); _builder.MergeInLexemeForm(e, forms); Assert.AreEqual("hello", e.LexicalForm["x99"]); }
public void MergeInTranslationForm_TypeFree_GetContentsAndSavesType() { LexExampleSentence ex = new LexExampleSentence(); LiftMultiText translation = new LiftMultiText(); translation.Add("aa", "aaaa"); _builder.MergeInTranslationForm(ex, "Free translation", translation, "bogus raw xml"); Assert.AreEqual("aaaa", ex.Translation["aa"]); Assert.AreEqual("Free translation", ex.TranslationType); }
public void EntryWithCitation() { LexEntry entry = MakeSimpleEntry(); LiftMultiText forms = new LiftMultiText(); forms.Add("x", "hello"); forms.Add("y", "bye"); _builder.MergeInCitationForm(entry, forms); MultiText citation = entry.GetProperty<MultiText>(LexEntry.WellKnownProperties.Citation); Assert.AreEqual(2, citation.Forms.Length); Assert.AreEqual("hello", citation["x"]); Assert.AreEqual("bye", citation["y"]); }
public LiftObject MergeInEtymology(LiftEntry entry, string source, string type, LiftMultiText form, LiftMultiText gloss, string rawXml) { return(new LiftEtymology()); }
public void MergeInTranslationForm_UnheardOfType_StillBecomesTranslation() { LexExampleSentence ex = new LexExampleSentence(); LiftMultiText translation = new LiftMultiText(); translation.Add("aa", "aaaa"); _builder.MergeInTranslationForm(ex, "madeUpType", translation, "bogus raw xml"); Assert.AreEqual("aaaa", ex.Translation["aa"]); Assert.AreEqual("madeUpType",ex.TranslationType); }
public LiftObject MergeInReversal(LiftSense sense, LiftObject parent, LiftMultiText contents, string type, string rawXml) { return(new LiftReversal()); }
public void UnexpectedCustomFieldRetained() { LexEntry e = MakeSimpleEntry(); LiftMultiText t = new LiftMultiText(); t["z"] = new LiftString("dub"); _builder.MergeInField(e, "flub", default(DateTime), default(DateTime), t, null); Assert.AreEqual(1, e.Properties.Count); Assert.AreEqual("flub", e.Properties[0].Key); MultiText mt = e.GetProperty<MultiText>("flub"); Assert.AreEqual("dub", mt["z"]); }
public LiftObject MergeInVariant(LiftEntry entry, LiftMultiText contents, string rawXml) { return(new LiftVariant()); }
public void FirstValueOfSimpleMultiText() { LiftMultiText t = new LiftMultiText(); LiftString s1 = new LiftString(); s1.Text = "1"; t.Add("x", s1); LiftString s2 = new LiftString(); s2.Text = "2"; t.Add("y", s2); Assert.AreEqual("x", t.FirstValue.Key); Assert.AreEqual("1", t.FirstValue.Value.Text); }
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']"); }