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 WriteRelationCollection(string key, LexRelationCollection collection) { if (!ShouldOutputProperty(key)) { return; } foreach (LexRelation relation in collection.Relations) { if (string.IsNullOrEmpty(relation.Key)) { continue; } if (!EntryDoesExist(relation.TargetId)) { continue; } Writer.WriteStartElement("relation"); Writer.WriteAttributeString("type", GetOutputRelationName(relation)); Writer.WriteAttributeString("ref", relation.Key); WriteRelationTarget(relation); WriteExtensible(relation); foreach (string rawXml in relation.EmbeddedXmlElements) { Writer.WriteRaw(rawXml); } Writer.WriteEndElement(); } }
private bool IsMissingData(object content) { switch (Field.DataTypeName) { case "Option": return(((OptionRef)content).IsEmpty); case "OptionCollection": return(((OptionRefCollection)content).IsEmpty); case "MultiText": return(HasAllRequiredButMissingAtLeastOneWeWantToFillIn((MultiText)content)); case "RelationToOneEntry": LexRelationCollection collection = (LexRelationCollection)content; if (IsSkipped(collection.Parent, Field.FieldName)) { return(false); } foreach (LexRelation r in collection.Relations) { if (!string.IsNullOrEmpty(r.TargetId)) { return(false); // has one non-empty relation } } return(true); //collection is empty or all its members don't really have targets default: Debug.Fail("unknown DataTypeName"); return(false); } }
private void AddRelation() { LexRelationCollection synonyms = _source.GetOrCreateProperty <LexRelationCollection>("synonyms"); LexRelation r = new LexRelation("synonyms", _target.GetOrCreateId(true), _source); synonyms.Relations.Add(r); }
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); }
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); }
public void MergeInRelation_RelationHasEmbeddedTraits_RelationGetsEmbeddedXmlForLaterRoundTrip() { LexEntry e = MakeSimpleEntry(); var xml = @"<relation type='component-lexeme' ref='bodzi_d333f64f-d388-431f-bb2b-7dd9b7f3fe3c'> <trait name='complex-form-type' value='Composto'></trait> <trait name='is-primary' value='true'/> </relation>" ; _builder.MergeInRelation(e, "component-lexeme", "someId", xml); LexRelationCollection collection = e.GetOrCreateProperty <LexRelationCollection>("component-lexeme"); Assert.AreEqual(2, collection.Relations[0].EmbeddedXmlElements.Count); }
public void SenseWithSynonymRelations() { LexSense sense = new LexSense(); LexRelationType synonymRelationType = new LexRelationType("synonym", LexRelationType.Multiplicities .Many, LexRelationType.TargetTypes. Sense); LexRelationType antonymRelationType = new LexRelationType("antonym", LexRelationType.Multiplicities .Many, LexRelationType.TargetTypes. Sense); LexRelationCollection relations = new LexRelationCollection(); sense.Properties.Add(new KeyValuePair<string, object>("relations", relations)); relations.Relations.Add(new LexRelation(synonymRelationType.ID, "one", sense)); relations.Relations.Add(new LexRelation(synonymRelationType.ID, "two", sense)); relations.Relations.Add(new LexRelation(antonymRelationType.ID, "bee", sense)); _exporter.Add(sense); CheckAnswer(GetSenseElement(sense) + "<relation type=\"synonym\" ref=\"one\" /><relation type=\"synonym\" ref=\"two\" /><relation type=\"antonym\" ref=\"bee\" /></sense>"); }
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); } }
public void SenseWithSynonymRelations() { using (var session = new LiftExportAsFragmentTestSession()) { var sense = new LexSense(); var synonymRelationType = new LexRelationType( "synonym", LexRelationType.Multiplicities.Many, LexRelationType.TargetTypes.Sense ); var antonymRelationType = new LexRelationType( "antonym", LexRelationType.Multiplicities.Many, LexRelationType.TargetTypes.Sense ); var relations = new LexRelationCollection(); sense.Properties.Add(new KeyValuePair<string, IPalasoDataObjectProperty>("relations", relations)); relations.Relations.Add(new LexRelation(synonymRelationType.ID, "one", sense)); relations.Relations.Add(new LexRelation(synonymRelationType.ID, "two", sense)); relations.Relations.Add(new LexRelation(antonymRelationType.ID, "bee", sense)); session.LiftWriter.Add(sense); string result = session.OutputString(); AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath( "/sense/relation[@type='synonym' and @ref='one']" ); AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath( "/sense/relation[@type='synonym' and @ref='two']" ); AssertThatXmlIn.String(result).HasAtLeastOneMatchForXpath( "/sense/relation[@type='antonym' and @ref='bee']" ); } }
private void WriteRelationCollection(string key, LexRelationCollection collection) { if (!ShouldOutputProperty(key)) { return; } foreach (LexRelation relation in collection.Relations) { Writer.WriteStartElement("relation"); Writer.WriteAttributeString("type", relation.FieldId); Writer.WriteAttributeString("ref", relation.Key); WriteRelationTarget(relation); Writer.WriteEndElement(); } }