Sunday, January 25, 2026

Knowledge Representation Problem 10.2 Part II

Part II

Make the necessary additions or changes to your knowledge base from the previous exercise so that the questions that follow can be answered. Include in your report a discussion of your changes, explaining why they were needed, whether they were minor or major, and what kinds of questions would necessitate further changes.

a. Are there other people in Safeway while John is there? [Yes—staff!]

b. Is John a vegetarian? [No]

c. Who owns the deodorant in Safeway? [Safeway Corporation]

d. Did John have an ounce of ground beef? [Yes]

e. Does the Shell station next door have any gas? [Yes]

f. Do the tomatoes fit in John’s car trunk? [Yes] 


အထက်ပါမေးခွန်းတွေကို ဖြေဆိုနိုင်ဖို့အတွက် ယခင် Knowledge Base ကို ပြုပြင်ပြောင်းလဲမှုများ၊ ထပ်ဖြည့်စွက်ချက်များနှင့် ဆွေးနွေးချက်များကို အောက်ပါအတိုင်း လုပ်ဆောင်ကြည့်ပါမယ်။

၁။ ပြုပြင်ပြောင်းလဲမှုများနှင့် ဆွေးနွေးချက် (Discussion of Changes)

ယခင် Knowledge Base (KB) သည် "John စျေးဝယ်ထွက်ခြင်း" ဆိုသည့် အဓိက ဖြစ်စဉ်နှင့် ပတ်သက်သော ရိုးရှင်းသည့် ဆက်နွယ်မှုများ (Relations) ကိုသာ အာရုံစိုက်ခဲ့ပါသည်။ ယခု မေးခွန်းအသစ်များကို ဖြေဆိုရန်အတွက်မူ အောက်ပါ ကဏ္ဍသစ်များကို KB တွင် ထပ်ဖြည့်ရန် လိုအပ်ခဲ့ပါသည်။

  1. လူမှုရေးရာနှင့် စီးပွားရေးရာ အခန်းကဏ္ဍများ (Social & Commercial Roles):

    • မေးခွန်း (a) အတွက် "ဆိုင်ဝန်ထမ်း" (Staff) ဆိုသည့် Concept ကို ထည့်သွင်းရသည်။ ဆိုင်ဖွင့်ထားလျှင် ဝန်ထမ်းရှိစမြဲဖြစ်ကြောင်း Rule ထည့်ရသည်။

    • မေးခွန်း (c) အတွက် "ကုန်ပစ္စည်း ပိုင်ဆိုင်မှု" (Inventory Ownership) သဘောတရား လိုအပ်လာသည်။ ဝယ်သူ မဝယ်ရသေးသော ပစ္စည်းသည် ဆိုင်ရှင် (Corporation) ပိုင်ကြောင်း သတ်မှတ်ရသည်။

  2. အစားအသောက် စည်းမျဉ်းများ (Dietary Constraints):

    • မေးခွန်း (b) အတွက် "သက်သတ်လွတ်" (Vegetarian) ဟူသည် အသားမစားသူ ဖြစ်ကြောင်းနှင့်၊ John အမဲသားဝယ်လိုက်သည့်အတွက် သက်သတ်လွတ်သမား မဟုတ်နိုင်ကြောင်း ဆင်ခြင်နိုင်စွမ်း (Reasoning) ထည့်သွင်းရသည်။

  3. အရေအတွက်နှင့် ယူနစ် တွက်ချက်ခြင်း (Quantities & Units):

    • မေးခွန်း (d) အတွက် "၁ ပေါင်တွင် ၁၆ အောင်စ ရှိသည်" ဆိုသော သင်္ချာအသိနှင့်၊ "အများကြီး ပိုင်ဆိုင်လျှင် အနည်းငယ်ကိုလည်း ပိုင်ဆိုင်သည်" (Part-Whole Reasoning) ဆိုသော Logic လိုအပ်လာသည်။

  4. ရူပဗေဒဆိုင်ရာ ခန့်မှန်းချက်များ (Physical & Spatial Constraints):

    • မေးခွန်း (f) အတွက် ခရမ်းချဉ်သီးအိတ်၏ အရွယ်အစားနှင့် ကားနောက်ဖုံး (Trunk) ၏ အရွယ်အစားကို နှိုင်းယှဉ်နိုင်စွမ်း (Size Comparison) လိုအပ်သည်။ "သေးငယ်သော အရာသည် ကြီးမားသော နေရာလွတ်ထဲသို့ ဝင်ဆံ့သည်" ဟူသော Rule ထည့်ရသည်။

  5. စီးပွားရေးဆိုင်ရာ ပုံသေယူဆချက်များ (Default Business Logic):

    • မေးခွန်း (e) အတွက် ဓာတ်ဆီဆိုင် (Shell) သည် ဓာတ်ဆီ ရောင်းသည်ဟု အလိုအလျောက် သိရှိနိုင်မည့် Knowledge လိုအပ်သည်။

ပြောင်းလဲမှု ပမာဏ (Minor vs. Major): ၎င်းပြောင်းလဲမှုများကို Major (အဓိကကျသော) ပြောင်းလဲမှုများဟု ဆိုနိုင်ပါသည်။ အဘယ်ကြောင့်ဆိုသော် ယခင်က Semantic Network (အမည်နာမ ဆက်နွယ်မှု) အဆင့်သာ ရှိရာမှ၊ ယခုအခါ Physical Reasoning (အရွယ်အစား နှိုင်းယှဉ်ခြင်း) နှင့် Mathematical Reasoning (ယူနစ်ပြောင်းလဲခြင်း) ကဲ့သို့သော နယ်ပယ်သစ် Logic များကိုပါ ထပ်ဖြည့်သွင်းလိုက်ရသောကြောင့် ဖြစ်ပါသည်။


၂။ Python Implementation (Updated AI Agent)

အောက်ပါ Python ကုဒ်သည် မေးခွန်းအသစ်များအတွက် လိုအပ်သော Logic များကို ဖြည့်စွက်ရေးသားထားသော ပရိုဂရမ် ဖြစ်ပါသည်။

Python
class AdvancedKnowledgeBase:
    def __init__(self):
        # 1. Ontology (အမျိုးအစားများ - တိုးချဲ့ထားသည်)
        self.taxonomy = {
            "Ground Beef": ["Meat", "Food", "Perishable"],
            "Tomatoes": ["Vegetable", "Food", "Produce", "SmallObject"],
            "Deodorant": ["Toiletry", "Personal Care", "SmallObject"],
            "Safeway": ["Supermarket", "Store", "Place", "Corporation"],
            "Shell": ["Gas Station", "Store", "Place"],
            "John": ["Person", "Agent", "Shopper", "CarOwner"],
            "Staff": ["Person", "Employee"],
            "Car Trunk": ["Container", "LargeSpace"],
            "Gas": ["Fuel", "Liquid"]
        }
        
        # 2. Facts Database (အဖြစ်အပျက်များ)
        self.facts = {
            "John": {
                "action": ["went", "bought"],
                "bought": {"Tomatoes": 2.0, "Ground Beef": 1.0}, # Amounts in lbs
                "location": "Safeway",
                "has_property": ["CarOwner"] # John owns a car
            },
            "Safeway": {
                "inventory": ["Deodorant", "Tomatoes", "Ground Beef"],
                "staff_present": True # Stores have staff
            },
            "Shell": {
                "primary_product": "Gas",
                "location_context": "Next door"
            }
        }
        
        # 3. Unit Conversions (ယူနစ် အချိုးအဆများ)
        self.units = {
            "lb_to_oz": 16.0 # 1 lb = 16 oz
        }

    # Helper: Check Is-A relationship
    def is_a(self, entity, category):
        if entity in self.taxonomy:
            return category in self.taxonomy[entity]
        return False

    # --- New Reasoning Functions for Updated Questions ---

    def query_a_others_in_store(self, store):
        # Logic: If Store is open/operational -> Staff must be there
        if self.facts[store].get("staff_present"):
            return "Yes (Staff/Employees are required to run the store)"
        return "Unknown"

    def query_b_is_vegetarian(self, person):
        # Logic: Check purchases. If Meat bought -> Not Vegetarian
        purchases = self.facts[person].get("bought", {})
        for item in purchases:
            if self.is_a(item, "Meat"):
                return f"No (He bought {item}, vegetarians do not eat meat)"
        return "Yes (Unknown, but no meat purchased)"

    def query_c_deodorant_owner(self, item, store):
        # Logic: Unsold items in a store belong to the store/corporation
        # Note: John did NOT buy deodorant in our facts
        return f"{store} Corporation (Unsold inventory belongs to the business)"

    def query_d_has_ounce_beef(self, person):
        # Logic: Bought 1 lb. 1 lb = 16 oz. Since 16 > 1, he has 1 oz.
        purchases = self.facts[person].get("bought", {})
        if "Ground Beef" in purchases:
            amount_lbs = purchases["Ground Beef"]
            amount_oz = amount_lbs * self.units["lb_to_oz"]
            if amount_oz >= 1.0:
                return f"Yes (He has {amount_oz} oz, which includes 1 oz)"
        return "No"

    def query_e_shell_has_gas(self, store):
        # Logic: Business type implies inventory of primary product
        if self.facts[store].get("primary_product") == "Gas":
            return "Yes (Gas stations by definition stock gas)"
        return "Unknown"

    def query_f_tomatoes_fit_trunk(self, item, container_owner):
        # Logic: Size(SmallObject) < Size(LargeSpace/CarTrunk)
        # 1. Check if item is small
        is_small = self.is_a(item, "SmallObject") or self.is_a(item, "Produce")
        # 2. Check if owner has a car/trunk
        has_car = "CarOwner" in self.facts[container_owner]["has_property"]
        
        if is_small and has_car:
            return "Yes (2 lbs of tomatoes is small enough to fit in a standard car trunk)"
        return "Unknown"

# --- AI Agent Interface ---

class UpdatedSmartAgent:
    def __init__(self):
        self.kb = AdvancedKnowledgeBase()
        print("--- Updated AI Agent Initialized ---\n")

    def answer_new_questions(self):
        kb = self.kb
        
        print("Q(a): Are there other people in Safeway while John is there?")
        print(f"Ans: {kb.query_a_others_in_store('Safeway')}\n")

        print("Q(b): Is John a vegetarian?")
        print(f"Ans: {kb.query_b_is_vegetarian('John')}\n")

        print("Q(c): Who owns the deodorant in Safeway?")
        print(f"Ans: {kb.query_c_deodorant_owner('Deodorant', 'Safeway')}\n")

        print("Q(d): Did John have an ounce of ground beef?")
        print(f"Ans: {kb.query_d_has_ounce_beef('John')}\n")

        print("Q(e): Does the Shell station next door have any gas?")
        print(f"Ans: {kb.query_e_shell_has_gas('Shell')}\n")

        print("Q(f): Do the tomatoes fit in John’s car trunk?")
        print(f"Ans: {kb.query_f_tomatoes_fit_trunk('Tomatoes', 'John')}\n")

# --- Execution ---
if __name__ == "__main__":
    agent = UpdatedSmartAgent()
    agent.answer_new_questions()

ပရိုဂရမ်၏ အလုပ်လုပ်ပုံ သုံးသပ်ချက်

  1. ဝန်ထမ်းရှိကြောင်း ဆင်ခြင်ခြင်း (Q-a): Safeway ၏ Facts ထဲတွင် staff_present: True ဟု သတ်မှတ်ထားခြင်းအားဖြင့်၊ လူမရှိပါက ဆိုင်ဖွင့်၍ မရနိုင်ကြောင်း AI က နားလည်စေသည်။

  2. သက်သတ်လွတ် (Q-b): John ဝယ်သော Ground Beef သည် Meat ဖြစ်ကြောင်း Taxonomy တွင် ကြည့်ပြီး၊ အသားဝယ်သူသည် သက်သတ်လွတ်မဟုတ်ကြောင်း ကောက်ချက်ချသည်။

  3. ပိုင်ဆိုင်မှု (Q-c): John ၏ bought စာရင်းတွင် Deodorant မပါပါ။ ထို့ကြောင့် စတိုးဆိုင်ထဲရှိ ပစ္စည်းသည် Safeway ပိုင်ဆိုင်ကြောင်း AI က ဖြေဆိုသည်။

  4. ယူနစ်တွက်ချက်ခြင်း (Q-d): bought စာရင်းတွင် 1 lb ရှိသည်ကို 16 oz ဟု ပြောင်းလဲတွက်ချက်ပြီး၊ ၁ အောင်စထက်များသည့်အတွက် "Yes" ဟု ဖြေဆိုသည်။

  5. အရွယ်အစား နှိုင်းယှဉ်ခြင်း (Q-f): ခရမ်းချဉ်သီး ၂ ပေါင်သည် SmallObject ဖြစ်ပြီး၊ ကားနောက်ဖုံး (Trunk) သည် LargeSpace ဖြစ်သည်ဟု Taxonomy တွင် သတ်မှတ်ထားသဖြင့် ဝင်ဆံ့ကြောင်း (Fit) ဆုံးဖြတ်နိုင်သည်။

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.