demo completed
This commit is contained in:
@@ -1,158 +1,52 @@
|
||||
Here's a **Prolog program** that represents the logical rules for classifying an animal as either a **cat** or a **dog**, based on the morphological features described in your detailed comparison. The program uses a set of predicates representing visual traits, and applies a decision framework to infer classification.
|
||||
|
||||
This version is designed to work with facts (trait observations) and logical inference using rules.
|
||||
|
||||
---
|
||||
|
||||
### ✅ Prolog Program: Animal Classifier
|
||||
|
||||
```prolog
|
||||
% -------------------------------
|
||||
% TRAIT PREDICATES
|
||||
% These represent observable features from an image.
|
||||
% Each predicate returns true if the trait is present in the animal.
|
||||
% -------------------------------
|
||||
% Observable biological traits for identifying cats and dogs
|
||||
% Based on static image analysis with ranked diagnostic reliability
|
||||
|
||||
% Skull traits
|
||||
is_short_rounded_skull :- true. % Assume this is observed (can be set based on image input)
|
||||
is_flat_face :- true.
|
||||
% Muzzle Structure
|
||||
short_muzzle.
|
||||
rounded_muzzle.
|
||||
distinct_stop.
|
||||
straight_nasal_bridge.
|
||||
narrow_nose.
|
||||
smooth_rounded_tip.
|
||||
nose_pad_below_eyes.
|
||||
pointed_ears.
|
||||
upright_ears.
|
||||
narrow_set_ears.
|
||||
vertical_slit_pupils.
|
||||
eyes_set_high_on_face.
|
||||
whiskers_extend_horizontally.
|
||||
narrow_vertically_aligned_pad.
|
||||
tail_tapers_to_fine_point.
|
||||
base_narrower_than_head_width.
|
||||
head_appears_large.
|
||||
slender_neck.
|
||||
compact_body.
|
||||
|
||||
is_long_elongated_skull :- false.
|
||||
is_prominent_muzzle :- false.
|
||||
% Dog traits (secondary confirmation)
|
||||
long_muzzle.
|
||||
prominent_stop.
|
||||
convex_nasal_bridge.
|
||||
larger_nose.
|
||||
blunt_or_upturned_tip.
|
||||
nose_pad_prominent.
|
||||
variable_ear_shapes.
|
||||
wider_set_ears.
|
||||
round_pupils.
|
||||
eyes_level_with_nose_tip.
|
||||
whiskers_extend_forward_downward.
|
||||
broad_horizontally_oriented_pad.
|
||||
tail_blunt_or_bushy.
|
||||
base_wider_than_head_width.
|
||||
head_proportionally_smaller.
|
||||
thicker_neck.
|
||||
distinct_shoulder_hip_separation.
|
||||
|
||||
% Ear traits
|
||||
is_tall_pointed_ear :- true.
|
||||
is_high_set_ear :- true.
|
||||
% Decision rules for classification
|
||||
dog :- long_muzzle; prominent_stop; convex_nasal_bridge; larger_nose; blunt_or_upturned_tip; nose_pad_prominent; variable_ear_shapes; wider_set_ears; round_pupils; eyes_level_with_nose_tip; whiskers_extend_forward_downward; broad_horizontally_oriented_pad; tail_blunt_or_bushy; base_wider_than_head_width.
|
||||
cat :- short_muzzle; rounded_muzzle; distinct_stop; straight_nasal_bridge; narrow_nose; smooth_rounded_tip; nose_pad_below_eyes; pointed_ears; upright_ears; narrow_set_ears; vertical_slit_pupils; eyes_set_high_on_face; whiskers_extend_horizontally; narrow_vertically_aligned_pad; tail_tapers_to_fine_point; base_narrower_than_head_width.
|
||||
|
||||
is_floppy_or_rounded_ear :- false.
|
||||
is_wide_spaced_ear :- false.
|
||||
|
||||
% Eye traits
|
||||
is_large_round_eye :- true.
|
||||
is_lateral_eye_position :- true.
|
||||
|
||||
is_small_eye :- false.
|
||||
is_forward_facing_eye :- false.
|
||||
|
||||
% Paw traits
|
||||
is_small_paw_with_visible_toes :- true.
|
||||
has_retractable_claws :- true.
|
||||
|
||||
is_large_paw_with_non_retractable_claws :- false.
|
||||
|
||||
% Tail traits
|
||||
is_long_thin_tail :- true.
|
||||
is_tail_held_high_or_curled :- true.
|
||||
|
||||
is_thick_tail :- false.
|
||||
|
||||
% Body posture traits
|
||||
is_low_to_ground_body :- true.
|
||||
is_compact_body :- true.
|
||||
|
||||
is_robust_upright_body :- false.
|
||||
is_long_legs_relative_to_body :- false.
|
||||
|
||||
% Muzzle traits (profile)
|
||||
has_visible_stop_in_profile :- false.
|
||||
has_overbite_or_underbite :- false.
|
||||
|
||||
% -------------------------------
|
||||
% CLASSIFICATION RULES
|
||||
% These are based on the decision framework provided.
|
||||
% -------------------------------
|
||||
|
||||
% Cat classification rules
|
||||
is_cat :-
|
||||
cat_traits_count(CatCount),
|
||||
dog_traits_count(DogCount),
|
||||
CatCount >= 3,
|
||||
DogCount =:= 0.
|
||||
|
||||
% Dog classification rules
|
||||
is_dog :-
|
||||
cat_traits_count(CatCount),
|
||||
dog_traits_count(DogCount),
|
||||
DogCount >= 3,
|
||||
CatCount =:= 0.
|
||||
|
||||
% Counting cat-specific traits
|
||||
cat_traits_count(Count) :-
|
||||
findall(Trait, cat_trait(Trait), Traits),
|
||||
length(Traits, Count).
|
||||
|
||||
% Define which predicates are cat-specific traits
|
||||
cat_trait(is_short_rounded_skull).
|
||||
cat_trait(is_flat_face).
|
||||
cat_trait(is_tall_pointed_ear).
|
||||
cat_trait(is_high_set_ear).
|
||||
cat_trait(is_large_round_eye).
|
||||
cat_trait(is_lateral_eye_position).
|
||||
cat_trait(is_small_paw_with_visible_toes).
|
||||
cat_trait(has_retractable_claws).
|
||||
cat_trait(is_long_thin_tail).
|
||||
cat_trait(is_tail_held_high_or_curled).
|
||||
cat_trait(is_low_to_ground_body).
|
||||
cat_trait(is_compact_body).
|
||||
|
||||
% Counting dog-specific traits
|
||||
dog_traits_count(Count) :-
|
||||
findall(Trait, dog_trait(Trait), Traits),
|
||||
length(Traits, Count).
|
||||
|
||||
% Define which predicates are dog-specific traits
|
||||
dog_trait(is_long_elongated_skull).
|
||||
dog_trait(is_prominent_muzzle).
|
||||
dog_trait(is_floppy_or_rounded_ear).
|
||||
dog_trait(is_wide_spaced_ear).
|
||||
dog_trait(is_small_eye).
|
||||
dog_trait(is_forward_facing_eye).
|
||||
dog_trait(is_large_paw_with_non_retractable_claws).
|
||||
dog_trait(is_thick_tail).
|
||||
dog_trait(is_robust_upright_body).
|
||||
dog_trait(is_long_legs_relative_to_body).
|
||||
dog_trait(has_visible_stop_in_profile).
|
||||
dog_trait(has_overbite_or_underbite).
|
||||
|
||||
% -------------------------------
|
||||
% SAMPLE QUERY
|
||||
% To test, you can run:
|
||||
% ?- is_cat.
|
||||
% ?- is_dog.
|
||||
% You may want to redefine facts like is_short_rounded_skull/0, etc., depending on image input.
|
||||
% -------------------------------
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 🧠 How It Works
|
||||
|
||||
- **Traits** are defined as simple predicates (e.g., `is_short_rounded_skull`, `is_large_round_eye`) that can be set to `true` or `false`.
|
||||
- The program counts how many traits match for cats and dogs.
|
||||
- If **three or more cat-specific traits** are present, and **no dog-specific traits**, it classifies as a **cat**.
|
||||
- Similarly, if three or more **dog-specific traits** are present, it classifies as a **dog**.
|
||||
|
||||
---
|
||||
|
||||
### 🧪 Example Queries
|
||||
|
||||
```prolog
|
||||
?- is_cat. % Returns true if enough cat traits are set to true
|
||||
?- is_dog. % Returns true if enough dog traits are set to true
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 🛠️ Extending for Image Input
|
||||
|
||||
To use this with real image data (e.g., a computer vision pipeline), you would:
|
||||
|
||||
- Set the facts dynamically from image analysis.
|
||||
- Use `assert/1` or `retract/1` to change trait values.
|
||||
- For example:
|
||||
```prolog
|
||||
?- assert(is_short_rounded_skull).
|
||||
?- is_cat.
|
||||
```
|
||||
|
||||
Let me know if you want a version that integrates with actual image recognition libraries or uses probability-based reasoning!
|
||||
% Queries for classification
|
||||
query(dog).
|
||||
query(cat).
|
||||
```
|
||||
Reference in New Issue
Block a user