topics:  main-page   everything   99things   things-to-do   software   space   future   exercise & health   faith  
  thought   web   movies+TV   music   mymusic   food   curiosity   tidbits   I remember   wishlist   misc   links


This section lists all blog posts, regardless of topic.

has_a: Properties VS possessions
July 29, 2008

As I was working on an implementation for exercise 3 tonight, I realized that there is a difference between has_a in the sense of a property VS has_a in terms of a "possession".

Example of a property:

Daniel has_a nose

Example of a possession:

Daniel has_a dog

Where this difference comes into play is in the implementation of the HasA function, and can be highlighted by the following:

Test case 1:

Daniel has_a human_body
human_body has_a human_head
human_head has_a nose

The property Daniel.nose makes sense because each of the above has_a relationships describe properties, or parts.

Test case 2:

Daniel has_a dog
dog has_a tail

The property Daniel.tail doesn't make sense because the relationship Daniel has_a dog is describing dog as a possession of Daniel, rather than as a property.


Exercise 3: is_a and has_a
July 29, 2008

Summary

Implement an IsA function for the Entity class which will perform a depth-first search on is_a relationships to determine whether an entity has a direct or indirect is_a relationship with another entity.
Implement a HasA function for the Entity class which will perform a depth-first search on the is_a relationship followed by a depth of one search of has_a.
Throw an exception from Entity.Get as well as Entity.Set if the requested property does not exist.

Test case:

Click here

Solution

Click here


Exercise 2: Entities, Relationships, and Values
July 27, 2008

Summary

Design an Entity class
An entity can have an id
Implement Set method which allows a property of an entity to be given a value. For the time being, implement words as entities whos IDs are surrounded by single quotes. ex. 'Daniel'
Implement a Get method which returns the value of a entity's property
Implement an AddRelationship method
Design a Relationship class as a subclass of Entity
Design a Brain class which allows entities to be created via CreateEntity and relationships to be created using CreateEntity. Make the Entity and Relationship classes internal to this class and expose their functionality with the interfaces IEntity and IRelationship.
Enforce entity IDs, if specified, to be unique.
Pass the following test case:
[Test]
public void Test1()
{
   IEntity is_a = Brain.CreateEntity("is_a");
   IEntity has_a = Brain.CreateEntity("has_a");

   IEntity Daniel = Brain.CreateEntity("Daniel");
   IEntity person = Brain.CreateEntity("person");
   Brain.CreateRelationship(Daniel, is_a, person);
   IEntity first_name = Brain.CreateEntity("first_name");
   Brain.CreateRelationship(person, has_a, first_name);
   IEntity wDaniel = Brain.CreateEntity("'Daniel'");
   Daniel.Set(first_name, wDaniel);

   Assert.AreEqual("'Daniel'", Daniel.Get(first_name).Id);
}}

Solution

Click here

older >>