/// <summary> /// Returns an ImmutableSentenceFormModel with the same contents as the given SentenceFormModel. /// May not actually create a copy if the input is immutable. /// </summary> /// <param name="other"></param> /// <returns></returns> public static ImmutableSentenceFormModel CopyOf(ISentenceFormModel other) { var immutableSentenceDomainModel = other as ImmutableSentenceDomainModel; if (immutableSentenceDomainModel != null) return CopyOf(immutableSentenceDomainModel.FormModel); var immutableSentenceFormModel = other as ImmutableSentenceFormModel; if (immutableSentenceFormModel != null) return immutableSentenceFormModel; var rulesByForm = new MultiDictionary<ISentenceForm, Implication>(false); var trueSentencesByForm = new MultiDictionary<ISentenceForm, Fact>(false); foreach (ISentenceForm form in other.SentenceForms) { rulesByForm[form] = other.GetRules(form); trueSentencesByForm[form] = other.GetSentencesListedAsTrue(form); } var dependencyGraph = new MultiDictionary<ISentenceForm, ISentenceForm>(true); foreach (KeyValuePair<ISentenceForm, ICollection<ISentenceForm>> kv in other.DependencyGraph) dependencyGraph[kv.Key] = kv.Value; return new ImmutableSentenceFormModel(ImmutableList.CreateRange(other.Description), ImmutableHashSet.CreateRange(other.SentenceForms), ImmutableHashSet.CreateRange(other.ConstantSentenceForms), ImmutableHashSet.CreateRange(other.IndependentSentenceForms), dependencyGraph, rulesByForm, trueSentencesByForm); }