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).
|
||||
```
|
||||
BIN
.tmp-data/dog.jpg
Normal file
BIN
.tmp-data/dog.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 408 KiB |
14
.tmp-data/grounding_results
Normal file
14
.tmp-data/grounding_results
Normal file
@@ -0,0 +1,14 @@
|
||||
- 0.9:long_muzzle
|
||||
- 0.9:prominent_stop
|
||||
- 0.9:convex_nasal_bridge
|
||||
- 0.9:larger_nose
|
||||
- 0.9:blunt_or_upturned_tip
|
||||
- 0.9:nose_pad_prominent
|
||||
- 0.9:variable_ear_shapes
|
||||
- 0.9:wider_set_ears
|
||||
- 0.9:round_pupils
|
||||
- 0.9:eyes_level_with_nose_tip
|
||||
- 0.9:whiskers_extend_forward_downward
|
||||
- 0.9:broad_horizontally_oriented_pad
|
||||
- 0.9:tail_blunt_or_bushy
|
||||
- 0.9:base_wider_than_head_width
|
||||
35
.tmp-data/reasoning_description
Normal file
35
.tmp-data/reasoning_description
Normal file
@@ -0,0 +1,35 @@
|
||||
### Comparative Analysis: Cat vs. Dog (Image-Based Identification)
|
||||
*Based solely on observable biological traits from a static image. Traits are ranked by diagnostic reliability.*
|
||||
|
||||
1. **Muzzle Structure**
|
||||
- *Cat*: Short, rounded muzzle with a distinct "stop" (forehead indentation), nasal bridge straight/rounded.
|
||||
- *Dog*: Longer muzzle (proportional to head size), prominent stop (dip between eyes/nose) common in breeds; nasal bridge often convex.
|
||||
|
||||
2. **Nose Shape & Position**
|
||||
- *Cat*: Small, narrow nose with a smooth, rounded tip; nose pad positioned directly below eyes.
|
||||
- *Dog*: Larger nose relative to head; tip often blunt or slightly upturned; nose pad may appear more prominent.
|
||||
|
||||
3. **Ear Shape & Placement**
|
||||
- *Cat*: Pointed, upright ears; placed high on head with minimal distance between ears (narrow-set).
|
||||
- *Dog*: Variable ear shapes (floppy, erect, semi-erect); typically wider-set (greater inter-ear distance).
|
||||
|
||||
4. **Eye Morphology**
|
||||
- *Cat*: Vertically slit pupils (even when dilated); eyes set closer to muzzle, higher on face.
|
||||
- *Dog*: Round pupils (except in rare breeds like Huskies); eyes usually level with nose tip.
|
||||
|
||||
5. **Whisker Pad Position**
|
||||
- *Cat*: Whiskers extend horizontally from a narrow, vertically aligned facial pad.
|
||||
- *Dog*: Whiskers often extend forward and downward; facial pad broader, more horizontally oriented.
|
||||
|
||||
6. **Tail Structure**
|
||||
- *Cat*: Tail typically tapers to a fine point; base narrower than head width.
|
||||
- *Dog*: Tail often blunt or bushy at tip; base usually wider than head width (except in breeds like Greyhounds).
|
||||
|
||||
7. **Body Proportions (Head-to-Body)**
|
||||
- *Cat*: Head appears relatively large; neck slender, body compact with less visible separation between shoulders/hips.
|
||||
- *Dog*: Head proportionally smaller; neck often thicker; distinct shoulder/hip separation visible in stance.
|
||||
|
||||
*Decision Logic*:
|
||||
- **Muzzle + nose** (Trait 1 & 2) are the most reliable initial identifiers. A short muzzle with rounded nasal bridge confirms cat; elongated muzzle with prominent stop suggests dog.
|
||||
- **Eyes + ears** (Trait 3 & 4) provide secondary confirmation (e.g., vertical pupils override ambiguous muzzle).
|
||||
- *Note*: Breed variations exist (e.g., Pugs have shortened muzzles), but core traits remain consistent at species level.
|
||||
Reference in New Issue
Block a user