أخر الاخبار

حل اسئلة انظمة ذكية قسم الحاسوب الجامعة المستنصرية نموذج رقم1

 حل اسئلة انظمة ذكية قسم الحاسوب الجامعة المستنصرية نموذج رقم 1

حل اسئلة انظمة ذكية قسم الحاسوب الجامعة المستنصرية نموذج رقم 1


Q1: Choose the correct answer. Note that a multiple-choice question can have more than one correct
answer. (16 marks)

1- The set of approaches proposed to model and find solutions to those real-world problems that

are not modeled or too difficult to model mathematically, is called:

(A) Artificial Immune System (B) Soft Computing (C) Expert Systems

(D) Natural Language Processing (E) None of the above

2- All of the following are shortcomings of an expert system, except:

(A) Separation of knowledge from its processing (B) Opaque relations between rules

(C) Ineffective search strategy (D) Inability to learn (E) All of the above

3- In the backward chaining version of the animal classification system, the subordinate rule that

divides the animals into classes is:

(A) confirm (B) it_is (C) remember (D) identify (E) guess_animal

4- Which of the following is false about Expert System?

(A) Able to show its knowledge in a form that is easy to read and understand

(B) Unable to integrate new knowledge (C) Explain how it reaches a particular conclusion

(D) Act as an intelligent assistant in some specific domain of expertise (E) None of the above

5- All of the following are components of an expert system, except:

(A) Database (B) Knowledge base (C) Knowledge acquisition

(D) Interface engine (E) User interface

6- Natural Language Processing includes anything a computer needs to:

(A) Understand natural language (B) Produce and percept speech

(C) Identify sound patterns of language (D) Generate natural language

(E) Classify acoustic signals into phones

7- Which of the following intelligent systems is often used to understand handwriting in

applications like PDAs?

(A) Fuzzy Logic (B) Artificial Immune System (C) Neural Networks

(D) Genetic Algorithms (E) Natural Language Understanding

8- Who formulates the domain expertise into an expert system?

(A) Domain expert (B) Knowledge engineer (C) Programmer (D) User

(E) Project manager


Q2: Consider the following pattern recognition system:

 (7 marks)

User Machine

... friend ... what about your friends?

... lie or cry ... please do not use words like that.

... I am happy ... what things make you happy?

Write makeans and recognize predicates that correspond to the above system. Make sure to return to the third question or write "Tell me more" when no matching is found.

Sol//

# Define patterns and corresponding responses
patterns = [
    ("friend", "what about your friends?"),
    ("lie", "please do not use words like that."),
    ("cry", "please do not use words like that."),
    ("happy", "what things make you happy?")
]

# Define function to recognize patterns
def recognize(input_text):
    for pattern, response in patterns:
        if pattern in input_text:
            return response
    return "Tell me more"

# Test the function
print(recognize("I have a friend"))  # Output: "what about your friends?"
print(recognize("Please don't lie"))  # Output: "please do not use words like that."
print(recognize("I am happy today"))  # Output: "what things make you happy?"
print(recognize("I am feeling sad"))  # Output: "Tell me more"


Q3: Design a minimized CFG grammar then write a Visual Prolog program that describes commands related to moving a car. The grammar should accept queries of these forms:
(7 marks)

1- "move", followed by a direction (up, down, right, or left), optionally followed by an adverb

describing speed (quickly, rapidly, or slowly).

2- "enter", followed by the, followed by a noun (park or garage).

3- "exit", followed by the, followed by a noun (park or garage).

Sol//

Command -> Move | Enter | Exit Move -> "move" Direction Adverb? Direction -> "up" | "down" | "right" | "left" Adverb -> "quickly" | "rapidly" | "slowly" Enter -> "enter" "the" Noun Exit -> "exit" "the" Noun Noun -> "park" | "garage"

domains
    direction = up; down; right; left.
    adverb = quickly; rapidly; slowly.
    noun = park; garage.

predicates
    command(string).
    move(string, direction).
    enter(string, noun).
    exit(string, noun).

clauses
    command(Input) :-
        tokenize(Input, Tokens),
        (parse_command(Tokens, Rest, Command) ->
            format("Command: ~s~n", [Command]),
            format("Remaining tokens: ~s~n", [Rest])
        ;
            format("Invalid command.~n")
        ).

    parse_command(["move" | Tokens], Rest, Command) :-
        parse_move(Tokens, Rest, Command).
    parse_command(["enter" | Tokens], Rest, Command) :-
        parse_enter(Tokens, Rest, Command).
    parse_command(["exit" | Tokens], Rest, Command) :-
        parse_exit(Tokens, Rest, Command).

    parse_move([Dir | Rest], Rest1, move(Dir, Adverb)) :-
        member(Dir, [up, down, right, left]),
        parse_adverb(Rest, Rest1, Adverb).
    parse_move([Dir | Rest], Rest, move(Dir, none)) :-
        member(Dir, [up, down, right, left]).

    parse_adverb([Adv | Rest], Rest, Adv) :-
        member(Adv, [quickly, rapidly, slowly]).
    parse_adverb(Rest, Rest, none).

    parse_enter(["the" | Rest], Rest1, enter(Noun)) :-
        parse_noun(Rest, Rest1, Noun).
    parse_exit(["the" | Rest], Rest1, exit(Noun)) :-
        parse_noun(Rest, Rest1, Noun).

    parse_noun([N | Rest], Rest, N) :-
        member(N, [park, garage]).

goal
    command("move up quickly").
    command("enter the park").
    command("exit the garage").


Q4: (7 marks)

Consider the following knowledge base. Assume that the conflict resolution strategy is to pick the

rule with the most preconditions that matches Working Memory (WM) and has not already been

used. Break ties by choosing the lowest numbered rule.

(1) A ^ ¬B → ADD(D)

(2) C ^ A ^ ¬D → DELETE(A)^ ADD(B)

(3) D → PRINT("Brilliant!")

(4) B → PRINT("Brilliant!")

(5) C ^ B → DELETE(C)^ DELETE(B) ^ ADD(A)

(6) ¬C ^ ¬A ^ ¬D ^ ¬B → PRINT("Oops!")

Assume that the system terminates when either no unused rules match Working Memory (WM) or the system executes a PRINT action. Illustrate the operation of this production system; assume that the initial contents of WM are: C, A, ¬D, ¬B.

Note: ADD’ing X means that ¬X is removed from WM and X is inserted, while DELETE’ing X

means that X is removed from WM and ¬X is inserted.

Sol//


1. Initial Working Memory (WM): C, A, ¬D, ¬B


2. Matching Rules:

   - Rule (2) matches: C ^ A ^ ¬D, has 3 preconditions

   - Rule (5) matches: C ^ B, has 2 preconditions


3. Conflict Resolution:

   - Rule (2) has more preconditions than Rule (5), so it is chosen.


4. Action:

   - DELETE(A)^ ADD(B) is executed, modifying WM to: C, ¬A, ¬D, B


5. Matching Rules with New WM:

   - Rule (1) matches: A ^ ¬B, has 2 preconditions

   - Rule (3) matches: D, has 1 precondition

   - Rule (4) matches: B, has 1 precondition


6. Conflict Resolution:

   - Rule (1) and Rule (3) have the same number of preconditions. Rule (1) is lower numbered, so it is chosen.


7. Action:

   - ADD(D) is executed, modifying WM to: C, ¬A, ¬D


8. Matching Rules with New WM:

   - Rule (6) matches: ¬C ^ ¬A ^ ¬D ^ ¬B, has 4 preconditions


9. Action:

   - PRINT("Oops!") is executed.


10. Termination: The system executes a PRINT action, so the operation terminates.


العملي Lab

Note: Answer ONE question (12 marks)

Q1: Consider the following sentences:

1- Ali will buy a new car tomorrow.

2- Some persons can own respecting by a nice job.

Build a context free grammar for the above sentences, and then write a complete Visual Prolog program that parses them.

Sol//

S -> NP VP | Aux NP VP NP -> Pronoun | ProperNoun | Det Noun | NP PP VP -> Verb | VP NP | VP Adverb | VP PP | VP Aux VP PP -> Preposition NP Det -> "a" | "the" | "some" Noun -> "car" | "persons" | "job" ProperNoun -> "Ali" Pronoun -> "Some" Verb -> "will" | "buy" | "own" | "respecting" Aux -> "can" Adverb -> "tomorrow" | "nicely" Preposition -> "by"

parse(Sentence) :-
    atom_chars(Sentence, Chars),
    phrase(s, Chars),
    write('Parsing successful!').

s --> np, vp.
s --> aux, np, vp.
np --> pronoun.
np --> proper_noun.
np --> det, noun.
np --> np, pp.
vp --> verb.
vp --> vp, np.
vp --> vp, adverb.
vp --> vp, pp.
vp --> vp, aux, vp.
pp --> preposition, np.
det --> "a" | "the" | "some".
noun --> "car" | "persons" | "job".
proper_noun --> "Ali".
pronoun --> "Some".
verb --> "will" | "buy" | "own" | "respecting".
aux --> "can".
adverb --> "tomorrow" | "nicely".
preposition --> "by".


Q2: Do as required

a- Write a Visual Prolog program that finds the index of an element in a list L:

L= [a,b,c,d,e,f,g] index of c=3

b- Consider the following Visual Prolog program segment:

result(_, []).

result([_, E | L], [E | M]) :- result(L, M).

After having consulted this program, what would Prolog reply when presented with the following

query?

Sol//

a) Here's a Visual Prolog program that finds the index of an element in a list:

domains element = char list = element* predicates index_of(element, list, integer) clauses index_of(Element, List, Index) :- index_of(Element, List, 1, Index). index_of(_, [], _, -1). index_of(Element, [Element|_], Index, Index). index_of(Element, [_|Tail], CurrentIndex, Index) :- NextIndex = CurrentIndex + 1, index_of(Element, Tail, NextIndex, Index).


You can use the `index_of/3` predicate to find the index of an element in a list. For example:

index_of('c', [a,b,c,d,e,f,g], Index).

This will return `Index = 3`.

b) The Prolog program segment you provided defines a predicate `result/2` which succeeds when the second argument is a sublist of the first argument, with elements interspersed with other elements. For example:

result([a,b,c,d,e,f,g], [b,c,e]).

Prolog would reply `true` for this query.



تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-