internal void MergeInTranslations(SemanticDomainInfo ddp1SemanticDomain) { this.Names = MergeTranslationsInFormCollections(this.Names, ddp1SemanticDomain.Names); this.Descriptions = MergeTranslationsInFormCollections(this.Descriptions, ddp1SemanticDomain.Descriptions); this.Abbreviation = MergeTranslationsInFormCollections(this.Abbreviation, ddp1SemanticDomain.Abbreviation); this.SearchKeys = MergeTranslationsInFormCollections(this.SearchKeys, ddp1SemanticDomain.SearchKeys); }
static private SemanticDomainInfo PopulateSemanticDomainFromXml(XmlReader fileReader) { if (fileReader.Name != "option") { throw new InvalidOperationException(String.Format("Node is {0} but we expected an 'option' node.", fileReader.Name)); } SemanticDomainInfo semanticDomain = null; if (fileReader.IsEmptyElement) { throw new InvalidOperationException("An empty 'option' element was found."); } while (fileReader.Read()) { bool readerHasReachedEndOfOption = fileReader.NodeType == XmlNodeType.EndElement && fileReader.Name == "option"; if (readerHasReachedEndOfOption) { break; } if (fileReader.Name == "key") { string key = PopulateKeyFromXml(fileReader); semanticDomain = new SemanticDomainInfo(key); } else if (fileReader.Name == "name") { semanticDomain.Names = PopulateFormsFromXml(fileReader); } else if (fileReader.Name == "abbreviation") { semanticDomain.Abbreviation = PopulateFormsFromXml(fileReader); } else if (fileReader.Name == "description") { semanticDomain.Descriptions = PopulateFormsFromXml(fileReader); } else if (fileReader.Name.ToLower() == "searchkeys") { semanticDomain.SearchKeys = PopulateFormsFromXml(fileReader); } else { throw new ApplicationException(String.Format("An unhandled Element {0} was found!", fileReader.Name)); } } if (semanticDomain == null) { throw new ApplicationException("An empty option was found!"); } return(semanticDomain); }
private static void WriteSemanticDomainToFile(XmlWriter fileWriter, SemanticDomainInfo semanticDomain) { fileWriter.WriteStartElement("option"); WriteKeyToFile(fileWriter, semanticDomain.Key); WriteFormCollectionToFile(fileWriter, semanticDomain.Names, "name"); WriteFormCollectionToFile(fileWriter, semanticDomain.Abbreviation, "abbreviation"); WriteFormCollectionToFile(fileWriter, semanticDomain.Descriptions, "description"); WriteFormCollectionToFile(fileWriter, semanticDomain.SearchKeys, "searchkeys"); fileWriter.WriteEndElement(); }
static void Main(string[] args) { string filePathToDdp1 = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\Ddp1.xml"; string filePathToDdp4 = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\Ddp4.xml"; string filePathToThaiDdp1Questions = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\Ddp4Questions-th.xml"; string filePathToEnglishDdp4Questions = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\Ddp4Questions-en.xml"; string filePathToMap = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\Semantic Domains v1 to v4 map.txt"; string newDdpFile = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\newDdp.xml"; string newQuestionsFile = @"D:\SoftwareDevelopment\Ddp124Map\DDP4\newQuestion.xml"; SemanticDomainCollection semanticDomainsDdp1 = SemanticDomainReader.ReadFromFile(filePathToDdp1); SemanticDomainCollection semanticDomainsDdp4 = SemanticDomainReader.ReadFromFile(filePathToDdp4); Dictionary <string, string> map = Ddp4to1MapReader.ReadFromFile(filePathToMap); foreach (SemanticDomainInfo ddp1SemanticDomain in semanticDomainsDdp1.AllSemanticDomains) { string correspondingNumberInDdp4 = ddp1SemanticDomain.Number; if (map.ContainsKey(ddp1SemanticDomain.Number)) { correspondingNumberInDdp4 = map[ddp1SemanticDomain.Number]; } SemanticDomainInfo semanticDomainToMergeInto = semanticDomainsDdp4.GetSemanticDomainWithNumber(correspondingNumberInDdp4); semanticDomainToMergeInto.MergeInTranslations(ddp1SemanticDomain); } SemanticDomainWriter.WriteToFile(newDdpFile, semanticDomainsDdp4); SemanticDomainQuestionsCollection thaiDdp1Questions = SemanticDomainQuestionsReader.ReadFromFile(filePathToThaiDdp1Questions); SemanticDomainQuestionsCollection thaiDdp4Questions = new SemanticDomainQuestionsCollection(thaiDdp1Questions.Version, thaiDdp1Questions.WritingSystemId); foreach (SemanticDomainQuestions domainQuestions in thaiDdp1Questions.DomainKeyToQuestionsMap.Values) { string semanticDomainKey = GetMappedSemanticDomainKey(map, semanticDomainsDdp4, domainQuestions); bool questionsForDomainAlreadyExist = thaiDdp4Questions.DomainKeyToQuestionsMap.ContainsKey(semanticDomainKey); if (!questionsForDomainAlreadyExist) { SemanticDomainQuestions newQuestions = new SemanticDomainQuestions(Guid.NewGuid(), semanticDomainKey); thaiDdp4Questions.DomainKeyToQuestionsMap.Add(semanticDomainKey, newQuestions); } thaiDdp4Questions.DomainKeyToQuestionsMap[semanticDomainKey].Questions.AddRange(domainQuestions.Questions); } SemanticDomainQuestionsWriter.WriteToFile(newQuestionsFile, thaiDdp4Questions); Console.ReadLine(); }
public void AddSemanticDomain(SemanticDomainInfo semanticDomain) { _semanticDomains.Add(semanticDomain); }