190 likes | 360 Views
Topic 4 – Knowledge Representation. St Kentigern’s Academy Unit 3 – Artificial Intelligence. Semantic Net. A semantic net is a design methodology that is used when representing knowledge.
E N D
Topic 4 – Knowledge Representation St Kentigern’s Academy Unit 3 – Artificial Intelligence
Semantic Net • A semantic net is a design methodology that is used when representing knowledge. • Psuedocode would not work because the programs think differently. So instead of pseudocode or structured diagrams we draw a semantic net.
Semantic Net • Here is expert information that has been collated about farm animals: • A pig has four legs, eats slurry, lives on a farm. Cows have four legs, live on a farm, eat grass. Chickens have two legs, live on a farm, eat corn.
Semantic Net four legs two corn pig eats slurry eats legs is_a chicken is_a farm animal is_a cow eats legs grass four
Prolog • These facts can now be turned into prolog. • is_a(pig,farm_animal). • is_a(cow, farm_animal). • is_a(chicken, farm_animal). • legs(pig, four). • legs(cow, four). • legs(chicken, two). • eats(pig, slurry). • eats(cow, grass). • eats(chicken, corn).
Prolog • Rules for writing Prolog facts and rules: • There are no spaces; • There are no capitals unless a variable; • There must be a full stop at the end of each statement.
Simple Facts • Prolog facts which have simple facts only have either one or two arguments. • male(peter). Means peter is male • female(susan). Means susan is female • manager(susan, peter).
Simple Rules • Prolog rules allow us to create more relationships in the knowledge base. • Example: lives_in_sea(X) :- means that X lives in the is_a(X, fish). sea if X is a fish • The :- part means if in prolog. Rules are made up of a head which is the conclusion and a body which is made up of one or more sub-goals. • In order for the condition to be true all of the sub-goals must be true.
Simple Queries • In order to get information from the knowledge base we need to query it. • There are two types of answers that we can get from a query: • If the query we enter does not have a variable (capital letter) then the answer is either yes/true or no/false. • If we enter the following query into our animals knowledge base: • ?legs(pig, four). • The answer would be YES
Simple Queries • If we enter the following query into our animals knowledge base: • ?legs(pig, two). • The answer would be NO • If the query we enter has a variable in it, the answer we are looking for is X=… • If we enter the following query into our animals knowledge base: • ?legs(X, four). • The answer would be : X=pig, X=cow, No
Operators • In our knowledge base we can also use basic arithmetic operators: • And – to connect two subgoals • > - is greater than; • < - is less than; & • = - equal to.
Goals and Subgoals • The goal is what we are looking for when we query our knowledge base. • In order for a rule to be successful, each sub-goal of the rule must be successful.
Trace Tables • A manual trace is when we write out the answer to a query the way that the program works through the query.
Trace Tables • voice(kabira, excellent). • voice(sharon, excellent). • voice(ryan, fair). • voice(jumoke, excellent). • dance(kabira, fair). • dance(sharon, good). • dance(ryan, excellent). • dance(jumoke, excellent). • is_selected(X) if voice(X, excellent) and dance(X, excellent). • is_reserve(X) if voice(X, excellent) and dance(X, good).
Trace Tables • Using the numbering system above to help you, trace how the system will evaluate the query: • is_reserve(X). • to the first solution.
Trace Tables • 1. write out the query and the number of the first match: • ?is_reserve(X). Matches at 10 • 2. write out the rule at the first match: • is_reserve(X) IF voice(X, excellent) and dance(X, good). • 3. Take the first subgoal and try to find a match. • First subgoal voice(X, excellent). Matches at 1, X = kabira • 4. Take the second subgoal and try to find a match. • Second subgoal dance(kabira, good) No Match
Trace Tables • 5. Go back to the first subgoal and carry on. • 1st subgoal voice(X, excellent) matches at 2, X = sharon • 6. Take the second subgoal and try to find a match. • 2nd subgoal sharon, good) matches at 6. • Subgoal returns Yes • Goal returns X = sharon
Trace Tables • Your full answer would be: • ?is_reserve(X). Matches at 10 • is_reserve(X) IF voice(X, excellent) and dance(X, good). • 1st subgoal voice(X, excellent). • Matches at 1, X = kabira • 2nd subgoal dance(kabira, good) • No Match • 1st subgoal voice(X, excellent) matches at 2, • X = sharon • 2nd subgoal sharon, good) matches at 6. • Subgoal returns Yes • Goal returns X = sharon