Sei sulla pagina 1di 4

COMSATS University Islamabad Lahore Campus

Assignment II – FALL 2019


Course Title: Artificial Intelligence - LAB Course Code: CSC402 Credit Hours: 3(2,1)
Course
Mahmood Hussain Programme Name: BS Computer Science
Instructor/s:
Semester: 7th Batch: FA16 Section: A, B, E, F Date: 04-11-2019
Due on 19-11-2019 Maximum Marks: 10
Name & Registration no: M.FARAN KHALID & FA16-BCS-178

Question No. 1 Marks: 10


Create an aiml-python based small talk chatbot that require introduction of user with “user_name” and
“password”. Get these attributes in python then match in neo4j social network graph if found then
welcome with his name if not then ask user to enter his name, user_name, email and password and create
node in neo4j with these attributes along with IP address of user. While making a new user node, a
module must check and match IP with existing nodes IPs. If matched three parts of IP with any existing
node your chatbot must ask new user if he knows existing person, if yes then get relationship from his
reply by parsing and identifying relationship using NLP techniques provided by NLTK and create
relationship between new and existing user.
COMSATS University Islamabad Lahore Campus

Assignment II – FALL 2019


Course Title: Artificial Intelligence Course Code: CSC402 Credit Hours: 3(2,1)
Dr. Wajahat Mahmood Qazi
Course Instructor/s: Programme Name: BS Computer Science
Dr. Atifa Athar
Student Name: M.FARAN KHALID Registration # FA16-BCS-178

Section: A

AIML FILE :
<?xml version="1.0" encoding="UTF-8"?>

<aiml>

<category>

<pattern>Hi</pattern>

<template>

<random> <!-- random and list tag -->

<li>hy, What is your name?</li>

<li>hello,What is your name?</li>

<li>good to see you,What is your name?</li>

</random>

</template>

</category>

<category>

<pattern> hello ^</pattern>

<template><srai>hy</srai></template> <!--use of srai to link with same category-->

</category>

<category>

<pattern>My name is *</pattern>


<template> <think><set name = "name"><star></star></set></think> NICE NAME!\n What is
your password? </template> <!--think with set and get tag-->

</category>

<category>

<pattern>My password is *</pattern>

<template> <think><set name = "password"><star></star></set></think> REMEBERED THE


PASSWORD</template> <!--think with set and get tag-->

</category>

</aiml>

PYTHON LOGIN FILE :

import aiml,socket
import nltk as nltk
from py2neo import Graph, Node, Relationship, NodeMatcher
kernel = aiml.Kernel()
kernel.learn('aiml.aiml')
graph = Graph("http://localhost:7474",auth=("neo4j","12345"))
matcher = NodeMatcher(graph)

def sigUp():
name = str(input("kindly Enter Name:"))
u_name = str(input("kindly Enter User_name:"))
Email = str(input("Enter your Email:"))
password = str(input("Enter your password:"))
host_name = socket.gethostname()
ip = socket.gethostbyname(host_name)
node = Node("person",name=name,u_name=u_name,email=Email,passwd=password,ip=ip)
graph.create(node)
ret = matcher.match("person",ip=ip)
for i in list(ret):
print("Do you know this user "+ i['name'])
us_in = str(input())
words = nltk.word_tokenize(us_in)
tagged = nltk.pos_tag(words)
NN = [i[0] for i in tagged if i[1]=='NN']
relation = Relationship(node,NN,i)
graph.create(relation)
def main():
while True:
user = None
robot = None
user = str(input("user: "))
robot = kernel.respond(user)
print("Robot: " + robot)
if 'What is your name?' in robot:
user = 'My name is ' + str(input("user:My name is "))
robot = kernel.respond(user)
print("Robot: " + robot)
if 'What is your password?' in robot:
user = 'My password is ' + str(input("user:My password is "))
robot = kernel.respond(user)
print("Robot: " + robot)
password = kernel.getPredicate("password")
name = kernel.getPredicate("name")
ret = matcher.match("person", u_name=name, passwd=password)
if ret.first() is not None:
print("Login Successfull!")

else:
sigUp()

main()

Potrebbero piacerti anche