public static ImmutableSentenceDomainModel CopyUsingCartesianDomains(ISentenceDomainModel otherModel)
        {
            var immutableSentenceDomainModel = otherModel as ImmutableSentenceDomainModel;
            if (immutableSentenceDomainModel != null)
                return immutableSentenceDomainModel;

            var domains = ImmutableDictionary.CreateBuilder<ISentenceForm, ISentenceFormDomain>();
            foreach (ISentenceForm form in otherModel.SentenceForms)
            {
                ISentenceFormDomain otherDomain = otherModel.GetDomain(form);
                var domainsForSlots = new List<ISet<TermObject>>();
                for (int i = 0; i < form.TupleSize; i++)
                    domainsForSlots.Add(otherDomain.GetDomainForSlot(i));
                domains[form] = new CartesianSentenceFormDomain(form, domainsForSlots);
            }
            return new ImmutableSentenceDomainModel(ImmutableSentenceFormModel.CopyOf(otherModel), domains.ToImmutable());
        }
示例#2
0
 private Dictionary<ISentenceForm, ISentenceFormDomain> GetCartesianDomainsFromModel()
 {
     var results = new Dictionary<ISentenceForm, ISentenceFormDomain>();
     foreach (NameAndArity sentenceEntry in _sentencesModel.SentencesModel.Keys)
     {
         List<TermModel> bodyModels = _sentencesModel.SentencesModel[sentenceEntry];
         // We'll end up taking the Cartesian product of the different types of terms we have available
         if (sentenceEntry.Arity == 0)
         {
             Fact sentence = new GroundFact(sentenceEntry.Name);
             var form = new SimpleSentenceForm(sentence);
             results[form] = new CartesianSentenceFormDomain(form, new MultiDictionary<int, TermObject>(false));
         }
         else
         {
             IEnumerable<HashSet<Term>> sampleTerms = ToSampleTerms(bodyModels);
             foreach (IEnumerable<Term> terms in sampleTerms.CartesianProduct())
             {
                 Fact sentence = new VariableFact(true, sentenceEntry.Name, terms.ToArray());
                 var form = new SimpleSentenceForm(sentence);
                 results[form] = GetDomain(form, sentence);
             }
         }
     }
     return results;
 }