Example #1
0
        private void ReadMedia(XmlNode n, TBase parent)
        {
            string        href    = Utilities.GetStringAttribute(n, "href");
            LiftMultiText caption = LocateAndReadMultiText(n, "label");

            if (caption.IsEmpty)
            {
                caption = null;
            }
            _merger.MergeInMedia(parent, href, caption);
        }
Example #2
0
 private void ReadFormNodes(XmlNodeList nodesWithForms, LiftMultiText text)
 {
     foreach (XmlNode formNode in nodesWithForms)
     {
         try
         {
             string  lang     = Utilities.GetStringAttribute(formNode, _wsAttributeLabel);
             XmlNode textNode = formNode.SelectSingleNode("text");
             if (textNode != null)
             {
                 // Add the separator if we need it.
                 if (textNode.InnerText.Length > 0)
                 {
                     text.AddOrAppend(lang, "", "; ");
                 }
                 foreach (XmlNode node in textNode.ChildNodes)
                 {
                     if (node.Name == "span")
                     {
                         var span = text.AddSpan(lang,
                                                 Utilities.GetOptionalAttributeString(node, "lang"),
                                                 Utilities.GetOptionalAttributeString(node, "class"),
                                                 Utilities.GetOptionalAttributeString(node, "href"),
                                                 node.InnerText.Length);
                         ReadSpanContent(text, lang, span, node);
                     }
                     else
                     {
                         text.AddOrAppend(lang, node.InnerText, "");
                     }
                 }
             }
             var nodelist = formNode.SelectNodes("annotation");
             if (nodelist != null)
             {
                 foreach (XmlNode annotationNode in nodelist)
                 {
                     Annotation annotation = GetAnnotation(annotationNode);
                     annotation.LanguageHint = lang;
                     text.Annotations.Add(annotation);
                 }
             }
         }
         catch (Exception e)
         {
             // not a fatal error
             NotifyFormatError(e);
         }
     }
 }
Example #3
0
        private void ReadNotes(XmlNode node, TBase e)
        {
            // REVIEW (SRMc): Should we detect multiple occurrences of the same
            // type of note?  See ReadExtensibleElementDetails() for how field
            // elements are handled in this regard.
            var nodes = node.SelectNodes("note");

            if (nodes != null)
            {
                foreach (XmlNode noteNode in nodes)
                {
                    string        noteType = Utilities.GetOptionalAttributeString(noteNode, "type");
                    LiftMultiText noteText = ReadMultiText(noteNode);
                    _merger.MergeInNote(e, noteType, noteText, noteNode.OuterXml);
                }
            }
        }
Example #4
0
        private void ReadEtymology(XmlNode node, TEntry entry)
        {
//            if (_limitedMerger != null && _limitedMerger.DoesPreferXmlForEtymology)
//            {
//                _limitedMerger.MergeInEtymology(entry, node.OuterXml);
//                return;
//            }

            string        source    = Utilities.GetOptionalAttributeString(node, "source");
            string        type      = Utilities.GetOptionalAttributeString(node, "type");
            LiftMultiText form      = LocateAndReadMultiText(node, null);
            LiftMultiText gloss     = LocateAndReadOneElementPerFormData(node, "gloss");
            TBase         etymology = _merger.MergeInEtymology(entry, source, type, form, gloss, node.OuterXml);

            if (etymology != null)
            {
                ReadExtensibleElementDetails(etymology, node);
            }
        }
Example #5
0
        private void ReadExample(XmlNode node, TSense sense)
        {
            TExample example = _merger.GetOrMakeExample(sense, ReadExtensibleElementBasics(node));

            if (example != null)            //not been pruned
            {
                LiftMultiText exampleSentence = LocateAndReadMultiText(node, null);
                if (!exampleSentence.IsEmpty)
                {
                    _merger.MergeInExampleForm(example, exampleSentence);
                }
                var nodes = node.SelectNodes("translation");
                if (nodes != null)
                {
                    foreach (XmlNode translationNode in nodes)
                    {
                        LiftMultiText translation = ReadMultiText(translationNode);
                        string        type        = Utilities.GetOptionalAttributeString(translationNode, "type");
                        _merger.MergeInTranslationForm(example, type, translation, translationNode.OuterXml);
                    }
                }
                string source = Utilities.GetOptionalAttributeString(node, "source");
                if (source != null)
                {
                    _merger.MergeInSource(example, source);
                }

                // REVIEW(SRMc): If you don't think the note element should be valid
                // inside an example, then remove the next line and the corresponding
                // chunk from the rng file.
                // JH says: LIFT ver 0.13 is going to make notes available to all extensibles
                // todo: remove this when that is true
                ReadNotes(node, example);

                ReadExtensibleElementDetails(example, node);
            }
            return;
        }
Example #6
0
        private TBase ReadParentReversal(string type, XmlNode node)
        {
            XmlNodeList nodelist = node.SelectNodes("main");

            if (nodelist != null && nodelist.Count > 1)
            {
                NotifyFormatError(new LiftFormatException(String.Format("Only one <main> element is allowed inside a <main> element:\r\n{0}", node.OuterXml)));
            }
            TBase parent = null;

            if (nodelist != null && nodelist.Count == 1)
            {
                parent = ReadParentReversal(type, nodelist[0]);
            }
            LiftMultiText text     = ReadMultiText(node);
            TBase         reversal = _merger.GetOrMakeParentReversal(parent, text, type);

            if (reversal != null)
            {
                ReadGrammi(reversal, node);
            }
            return(reversal);
        }
Example #7
0
        private void ReadReversal(XmlNode node, TSense sense)
        {
            string      type     = Utilities.GetOptionalAttributeString(node, "type");
            XmlNodeList nodelist = node.SelectNodes("main");

            if (nodelist != null && nodelist.Count > 1)
            {
                NotifyFormatError(new LiftFormatException(String.Format("Only one <main> element is allowed inside a <reversal> element:\r\n{0}", node.OuterXml)));
            }
            TBase parent = null;

            if (nodelist != null && nodelist.Count == 1)
            {
                parent = ReadParentReversal(type, nodelist[0]);
            }
            LiftMultiText text     = ReadMultiText(node);
            TBase         reversal = _merger.MergeInReversal(sense, parent, text, type, node.OuterXml);

            if (reversal != null)
            {
                ReadGrammi(reversal, node);
            }
        }
Example #8
0
        private void ReadPronunciation(XmlNode node, TEntry entry)
        {
//            if (_limitedMerger != null && _limitedMerger.DoesPreferXmlForPhonetic)
//            {
//                _limitedMerger.MergeInPronunciation(entry, node.OuterXml);
//                return;
//            }

            LiftMultiText contents      = ReadMultiText(node);
            TBase         pronunciation = _merger.MergeInPronunciation(entry, contents, node.OuterXml);

            if (pronunciation != null)
            {
                var nodes = node.SelectNodes("media");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadMedia(n, pronunciation);
                    }
                }
                ReadExtensibleElementDetails(pronunciation, node);
            }
        }
Example #9
0
        internal TEntry ReadEntry(XmlNode node)
        {
            if (_changeReport != null)
            {
                string id = Utilities.GetOptionalAttributeString(node, "id");
                if (ChangeReport.GetChangeType(id) == LiftChangeReport.ChangeType.None)
                {
                    return(default(TEntry));
                }
            }

            Extensible extensible  = ReadExtensibleElementBasics(node);
            DateTime   dateDeleted = GetOptionalDate(node, "dateDeleted", default(DateTime));

            if (dateDeleted != default(DateTime))
            {
                _merger.EntryWasDeleted(extensible, dateDeleted);
                return(default(TEntry));
            }

            int    homograph = 0;
            string order     = Utilities.GetOptionalAttributeString(node, "order");

            if (!String.IsNullOrEmpty(order))
            {
                if (!Int32.TryParse(order, out homograph))
                {
                    homograph = 0;
                }
            }
            TEntry entry = _merger.GetOrMakeEntry(extensible, homograph);

            if (entry == null)            // pruned
            {
                return(entry);
            }


            LiftMultiText lexemeForm = LocateAndReadMultiText(node, "lexical-unit");

            if (!lexemeForm.IsEmpty)
            {
                _merger.MergeInLexemeForm(entry, lexemeForm);
            }
            LiftMultiText citationForm = LocateAndReadMultiText(node, "citation");

            if (!citationForm.IsEmpty)
            {
                _merger.MergeInCitationForm(entry, citationForm);
            }

            ReadNotes(node, entry);

            var nodes = node.SelectNodes("sense");

            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ReadSense(n, entry);
                }
            }
            nodes = node.SelectNodes("relation");
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ReadRelation(n, entry);
                }
            }
            nodes = node.SelectNodes("variant");
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ReadVariant(n, entry);
                }
            }
            nodes = node.SelectNodes("pronunciation");
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ReadPronunciation(n, entry);
                }
            }
            nodes = node.SelectNodes("etymology");
            if (nodes != null)
            {
                foreach (XmlNode n in nodes)
                {
                    ReadEtymology(n, entry);
                }
            }
            ReadExtensibleElementDetails(entry, node);
            _merger.FinishEntry(entry);
            return(entry);
        }
Example #10
0
        private void FinishReadingSense(XmlNode node, TSense sense)
        {
            if (sense != null)            //not been pruned
            {
                ReadGrammi(sense, node);
                LiftMultiText gloss = LocateAndReadOneElementPerFormData(node, "gloss");
                if (!gloss.IsEmpty)
                {
                    _merger.MergeInGloss(sense, gloss);
                }
                LiftMultiText def = LocateAndReadMultiText(node, "definition");
                if (!def.IsEmpty)
                {
                    _merger.MergeInDefinition(sense, def);
                }

                ReadNotes(node, sense);
                var nodes = node.SelectNodes("example");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadExample(n, sense);
                    }
                }
                nodes = node.SelectNodes("relation");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadRelation(n, sense);
                    }
                }
                nodes = node.SelectNodes("illustration");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadPicture(n, sense);
                    }
                }
                nodes = node.SelectNodes("reversal");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadReversal(n, sense);
                    }
                }
                nodes = node.SelectNodes("subsense");
                if (nodes != null)
                {
                    foreach (XmlNode n in nodes)
                    {
                        ReadSubsense(n, sense);
                    }
                }
                ReadExtensibleElementDetails(sense, node);
            }
            // return sense;
        }
Example #11
0
 /// <summary>
 /// Merge another LiftMultiText with a common ancestor into this LiftMultiText.
 /// </summary>
 public void Merge(LiftMultiText theirs, LiftMultiText ancestor)
 {
     // TODO: implement this?!
 }