Пример #1
0
        public FamilyTree()
        {
            //Initialise the DB layer or service to be consumed.
            //In case you want this can be injected by sevice discovery or Dependency injection pattern too.
            _familyDBInstance = new InMemoryFamilyDatabase();

            _relationLookup = new RelationshipLookup();
        }
Пример #2
0
        public void SetRelationshipLookupTest1()
        {
            IEntity entity1 = new ProperSingularNoun("John");
            IVerbal verb    = new PastTenseVerb("walked");
            IEntity entity2 = new NounPhrase(new Determiner("the"), new CommonSingularNoun("store"));

            verb.BindSubject(entity1);
            verb.BindDirectObject(entity2);
            IEnumerable <IVerbal> domain = new[] { verb };
            IRelationshipLookup <IEntity, IVerbal> relationshipLookup = CreateRelationshipLookup(domain);

            // Without calling RelationShipInferenceExtensions.SetRelationshipLookup(entity1, relationshipLookup) beforehand
            Check.ThatCode(() => entity1.IsRelatedTo(entity2)).Throws <InvalidOperationException>();
        }
Пример #3
0
        public void SetRelationshipLookupTest4()
        {
            IEntity entity1 = new ProperSingularNoun("John");
            IVerbal verb    = new PastTenseVerb("walked");
            IEntity entity2 = new NounPhrase(new Determiner("the"), new CommonSingularNoun("store"));

            verb.BindSubject(entity1);
            verb.BindDirectObject(entity2); IEnumerable <IVerbal> domain = new[] { verb };
            IRelationshipLookup <IEntity, IVerbal> relationshipLookup    = CreateRelationshipLookup(domain);

            RelationshipInferenceExtensions.SetRelationshipLookup(entity1, relationshipLookup);
            ActionsRelatedOn?actual;

            actual = entity1.IsRelatedTo(new NounPhrase(new Determiner("the"), new CommonSingularNoun("store")));
            Check.That(actual).IsNull();// After calling RelationShipInferenceExtensions.SetRelationshipLookup(entity1, relationshipLookup);
        }
Пример #4
0
 /// <summary>
 /// Creates a new relationship lookup with the same domain as the first but uses the given comparison function to compare <typeparamref name="TEntity"/>s.
 /// </summary>
 /// <typeparam name="TEntity">The type of the entities in the lookup.</typeparam>
 /// <typeparam name="TVerbal">The type of the verbals in the lookup.</typeparam>
 /// <param name="lookup">The source lookup.</param>
 /// <param name="entityEquator">The comparison function the resulting lookup will use to compare <typeparamref name="TEntity"/>s.</param>
 /// <returns>A new relationship lookup with the same domain as the first but uses the given comparison function to compare <typeparamref name="TEntity"/>s.</returns>
 public static IRelationshipLookup <TEntity, TVerbal> UsingEntityComparer <TEntity, TVerbal>(this IRelationshipLookup <TEntity, TVerbal> lookup, Func <TEntity, TEntity, bool> entityEquator)
     where TEntity : class, IEntity
     where TVerbal : class, IVerbal => new RelationshipLookup <TEntity, TVerbal>(lookup, entityEquator, entityEquator);
Пример #5
0
 /// <summary>
 /// Associates the given IEntity to the given IRelationshipLookup. All future searches involving the provided entity will be done in the context of the provided lookup.
 /// </summary>
 /// <param name="entity">The IEntity to associate to a lookup context.</param>
 /// <param name="relationshipLookup">The IRelationshipLookup instance providing a lookup context for the entity.</param>
 public static void SetRelationshipLookup(this IEntity entity, IRelationshipLookup <IEntity, IVerbal> relationshipLookup)
 {
     entityLookupContexts.AddOrUpdate(entity, relationshipLookup, (k, v) => relationshipLookup);
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the RelationshipLookup class from the domain of an exiting RelationshipLookup;
 /// </summary>
 /// <param name="domain">The RelationshipLookup instance which contains the relevant lexical data set.</param>
 /// <param name="performerComparer">A predicate function which determines how to find matches for action Performer.</param>
 /// <param name="receiverComparer">A predicate function which determines how to find matches for action Receiver.</param>
 public RelationshipLookup(IRelationshipLookup <TEntity, TVerbal> domain, Func <TEntity, TEntity, bool> performerComparer, Func <TEntity, TEntity, bool> receiverComparer)
     : this(domain.VerbalRelationshipDomain, EqualityComparer <TVerbal> .Default.Equals, performerComparer, receiverComparer)
 {
 }