├── README.md └── engine.cpp /README.md: -------------------------------------------------------------------------------- 1 | # Ibn-Taymiyyah-Analogy-Engine 2 | This program is an analogy engine designed to determine if a drink is prohibited based on its attributes and by comparing it to a database of known drinks. The decision is made using analogical reasoning, inspired by Ibn Taymiyyah's critique of Aristotelian logic. 3 | ----------------------------------------------------------------------------------------- 4 | ![T](https://github.com/qalassa/Ibn-Taymiyyah-Analogy-Engine/assets/109701506/769ef3a2-9eb7-4291-904d-b5a4c35a49a0) 5 | 6 | Components: 7 | 8 | 1. DrinkCase Struct: 9 | 10 | Represents a drink with attributes like name, flavor, color, origin, alcohol content, and its intoxicating and prohibited properties. 11 | 12 | 2. AttributeWeights Struct: 13 | 14 | Represents the importance (weight) of each attribute. For instance, alcohol content might be deemed more significant than color in determining if a drink is prohibited. 15 | 16 | 3. AnalogyEngine Class: 17 | 18 | Contains the core logic of the program. 19 | Maintains a database of known drinks. 20 | Uses a similarity measure to compare a new drink to the drinks in the database. The similarity is calculated based on the attributes of the drinks and the weights assigned to each attribute. 21 | Determines if a drink is prohibited by considering multiple similar drinks from the database and making a decision based on a majority. 22 | 23 | 4. Main Function: 24 | 25 | Allows the user to define weights for different attributes, making the analogy engine adaptable to different perspectives. 26 | Collects information about a new drink from the user. 27 | Uses the analogy engine to determine if the new drink is prohibited and then displays the result. 28 | 29 | Working: 30 | 31 | 1. The user is prompted to assign weights to different attributes of a drink. These weights signify the importance of each attribute in determining the prohibition status of a drink. 32 | 2. The user then provides details about a new drink, including its name, flavor, color, origin, and alcohol content. 33 | 3. The program considers a drink intoxicating if its alcohol content is more than 0.5%. 34 | 4. The analogy engine compares the new drink to a database of known drinks. It calculates a similarity score for each known drink based on the attributes and the user-defined weights. 35 | 5. The program considers drinks that have a similarity score within 80% of the highest score. 36 | 6. If more than half of these similar drinks are prohibited, the new drink is deemed prohibited; otherwise, it's not. 37 | 7. The program then displays whether the new drink is prohibited or not. 38 | -------------------------------------------------------------------------------- /engine.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct DrinkCase { 7 | std::string name; 8 | std::string flavor; 9 | std::string color; 10 | std::string origin; 11 | double alcoholContent; 12 | bool isIntoxicating; 13 | bool isProhibited; 14 | }; 15 | 16 | struct AttributeWeights { 17 | double flavorWeight = 1.0; 18 | double colorWeight = 1.0; 19 | double originWeight = 1.0; 20 | double alcoholContentWeight = 2.0; 21 | }; 22 | 23 | class AnalogyEngine { 24 | private: 25 | std::vector database; 26 | AttributeWeights weights; 27 | 28 | // Calculate similarity between two cases 29 | double calculateSimilarity(const DrinkCase& a, const DrinkCase& b) { 30 | double score = 0.0; 31 | 32 | if (a.flavor == b.flavor) score += weights.flavorWeight; 33 | if (a.color == b.color) score += weights.colorWeight; 34 | if (a.origin == b.origin) score += weights.originWeight; 35 | score += weights.alcoholContentWeight * (1.0 - std::abs(a.alcoholContent - b.alcoholContent)); 36 | 37 | return score; 38 | } 39 | 40 | public: 41 | AnalogyEngine(const AttributeWeights& w) : weights(w) { 42 | // Initialize with known cases 43 | database.push_back({"grape wine", "sweet", "red", "Italy", 12.0, true, true}); 44 | database.push_back({"apple cider", "sweet", "golden", "USA", 0.0, false, false}); 45 | // Add more cases as needed 46 | } 47 | 48 | bool isDrinkProhibited(const DrinkCase& newDrink) { 49 | double maxSimilarity = -1.0; 50 | int similarCount = 0; 51 | int prohibitedCount = 0; 52 | 53 | for (const DrinkCase& existingDrink : database) { 54 | double similarity = calculateSimilarity(newDrink, existingDrink); 55 | if (similarity > maxSimilarity * 0.8) { // considering drinks with similarity within 80% of the max 56 | similarCount++; 57 | if (existingDrink.isProhibited) { 58 | prohibitedCount++; 59 | } 60 | } 61 | if (similarity > maxSimilarity) { 62 | maxSimilarity = similarity; 63 | } 64 | } 65 | 66 | // If more than half of the similar drinks are prohibited, then the new drink is prohibited 67 | return prohibitedCount > similarCount / 2; 68 | } 69 | }; 70 | 71 | int main() { 72 | AttributeWeights userWeights; 73 | std::cout << "Enter weight for flavor (default 1.0): "; 74 | std::cin >> userWeights.flavorWeight; 75 | 76 | std::cout << "Enter weight for color (default 1.0): "; 77 | std::cin >> userWeights.colorWeight; 78 | 79 | std::cout << "Enter weight for origin (default 1.0): "; 80 | std::cin >> userWeights.originWeight; 81 | 82 | std::cout << "Enter weight for alcohol content (default 2.0): "; 83 | std::cin >> userWeights.alcoholContentWeight; 84 | 85 | AnalogyEngine engine(userWeights); 86 | 87 | DrinkCase inputDrink; 88 | std::cout << "Enter the name of the drink: "; 89 | std::cin >> inputDrink.name; 90 | 91 | std::cout << "Enter the flavor of the drink: "; 92 | std::cin >> inputDrink.flavor; 93 | 94 | std::cout << "Enter the color of the drink: "; 95 | std::cin >> inputDrink.color; 96 | 97 | std::cout << "Enter the origin of the drink: "; 98 | std::cin >> inputDrink.origin; 99 | 100 | std::cout << "Enter the alcohol content of the drink (in percentage): "; 101 | std::cin >> inputDrink.alcoholContent; 102 | 103 | inputDrink.isIntoxicating = inputDrink.alcoholContent > 0.5; // considering a drink intoxicating if alcohol content is more than 0.5% 104 | 105 | bool isProhibited = engine.isDrinkProhibited(inputDrink); 106 | 107 | if (isProhibited) { 108 | std::cout << inputDrink.name << " is prohibited." << std::endl; 109 | } else { 110 | std::cout << inputDrink.name << " is not prohibited." << std::endl; 111 | } 112 | 113 | return 0; 114 | } 115 | --------------------------------------------------------------------------------