├── Medical Expert System ├── requirements.txt ├── Disease symptoms │ ├── Asthma.txt │ ├── Epilepsy.txt │ ├── Alzheimers.txt │ ├── Arthritis.txt │ ├── Diabetes.txt │ ├── Glaucoma.txt │ ├── Hypothermia.txt │ ├── Jaundice.txt │ ├── Sinusitis.txt │ ├── Heart Disease.txt │ ├── Heat Stroke.txt │ ├── Hyperthyroidism.txt │ ├── Tuberculosis.txt │ └── Coronavirus.txt ├── .ipynb_checkpoints │ └── Untitled-checkpoint.ipynb ├── __pycache__ │ ├── greetings.cpython-311.pyc │ └── greetings.cpython-312.pyc ├── diseases.txt ├── Disease descriptions │ ├── Epilepsy.txt │ ├── Coronavirus.txt │ ├── Alzheimers.txt │ ├── Sinusitis.txt │ ├── Asthma.txt │ ├── Arthritis.txt │ ├── Jaundice.txt │ ├── Glaucoma.txt │ ├── Diabetes.txt │ ├── Heat Stroke.txt │ ├── Hypothermia.txt │ ├── Hyperthyroidism.txt │ ├── Heart Disease.txt │ └── Tuberculosis.txt ├── Disease treatments │ ├── Alzheimers.txt │ ├── Heart Disease.txt │ ├── Jaundice.txt │ ├── Coronavirus.txt │ ├── Epilepsy.txt │ ├── Asthma.txt │ ├── Sinusitis.txt │ ├── Hypothermia.txt │ ├── Glaucoma.txt │ ├── Tuberculosis.txt │ ├── Hyperthyroidism.txt │ ├── Diabetes.txt │ ├── Arthritis.txt │ └── Heat Stroke.txt ├── main.py └── greetings.py ├── README.md ├── Uninformed Search ├── dfs.py └── BFS.py ├── N_Queens.py ├── Hangman game ├── hangman_art.py ├── hangman_man.py └── hangman_words.py ├── Water jug problem ├── wjugauto.py └── jugmanual.py ├── MLP Classifier.py ├── A star algorithm.ipynb └── NLP.ipynb /Medical Expert System/requirements.txt: -------------------------------------------------------------------------------- 1 | experta 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI-Programs 2 | Common Artificial Intelligence programs manual and automated can be found here.... 3 | -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Asthma.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | high 5 | no 6 | no 7 | no 8 | low 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | low 8 | no 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | high 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Arthritis.txt: -------------------------------------------------------------------------------- 1 | no 2 | high 3 | no 4 | no 5 | no 6 | no 7 | low 8 | no 9 | no 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Diabetes.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | no 11 | no 12 | low 13 | low -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | low 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | no 11 | no 12 | high 13 | low -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | yes 6 | no 7 | no 8 | no 9 | high 10 | no 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Jaundice.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | low 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | low 2 | no 3 | no 4 | high 5 | no 6 | high 7 | no 8 | no 9 | no 10 | low 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/.ipynb_checkpoints/Untitled-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 5 6 | } 7 | -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | no 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | high 2 | no 3 | no 4 | no 5 | no 6 | no 7 | no 8 | no 9 | no 10 | high 11 | no 12 | high 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | no 4 | no 5 | no 6 | no 7 | high 8 | no 9 | no 10 | no 11 | no 12 | low 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | no 2 | no 3 | high 4 | low 5 | no 6 | no 7 | no 8 | no 9 | no 10 | high 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/Disease symptoms/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | high 2 | no 3 | high 4 | high 5 | no 6 | high 7 | high 8 | no 9 | no 10 | high 11 | no 12 | no 13 | no -------------------------------------------------------------------------------- /Medical Expert System/__pycache__/greetings.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sainathch45/Artificial-Intelligence/HEAD/Medical Expert System/__pycache__/greetings.cpython-311.pyc -------------------------------------------------------------------------------- /Medical Expert System/__pycache__/greetings.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sainathch45/Artificial-Intelligence/HEAD/Medical Expert System/__pycache__/greetings.cpython-312.pyc -------------------------------------------------------------------------------- /Medical Expert System/diseases.txt: -------------------------------------------------------------------------------- 1 | Jaundice 2 | Alzheimers 3 | Arthritis 4 | Tuberculosis 5 | Asthma 6 | Sinusitis 7 | Epilepsy 8 | Heart Disease 9 | Diabetes 10 | Glaucoma 11 | Hyperthyroidism 12 | Heat Stroke 13 | Hypothermia 14 | Coronavirus -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | Epilepsy is defined as a brain disorder characterized by an enduring predisposition to generate epileptic seizures and by the neurobiologic, cognitive, psychological, and social consequences of this condition. 2 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | No treatments stop or reverse its progression, though some may temporarily improve symptoms but medication and management strategies may temporarily improve symptoms. 2 | 3 | Medication: 4 | 5 | Cognition-enhancing medication 6 | Improves mental function, lowers blood pressure and may balance mood. -------------------------------------------------------------------------------- /Uninformed Search/dfs.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 3 | 'A':['B','C'], 4 | 'B':['D','E'], 5 | 'C':['F'], 6 | 'D':[], 7 | 'E':['F'], 8 | 'F':[],} 9 | 10 | visited=set() 11 | def dfs(visited,graph,node): 12 | if node not in visited: 13 | print(node) 14 | visited.add(node) 15 | for neighbour in graph[node]: 16 | dfs(visited,graph,neighbour) 17 | print("Following is the Depth-First Search") 18 | dfs(visited,graph,'A') 19 | -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | Coronavirus disease (COVID-19) is an infectious disease caused by a newly discovered coronavirus. 2 | 3 | Most people infected with the COVID-19 virus will experience mild to moderate respiratory illness and recover without requiring special treatment. Older people, and those with underlying medical problems like cardiovascular disease, diabetes, chronic respiratory disease, and cancer are more likely to develop serious illness. -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Alzheimers.txt: -------------------------------------------------------------------------------- 1 | Alzheimer’s disease is an irreversible, progressive brain disorder that slowly destroys memory and thinking skills and, eventually, the ability to carry out the simplest tasks. 2 | 3 | In most people with the disease—those with the late-onset type—symptoms first appear in their mid-60s. 4 | 5 | Early-onset Alzheimer’s occurs between a person’s 30s and mid-60s and is very rare. 6 | 7 | Alzheimer’s disease is the most common cause of dementia among older adults. 8 | -------------------------------------------------------------------------------- /Uninformed Search/BFS.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 'P':['S','R','Q'], 3 | 'Q':{'P','R'}, 4 | 'R':['P','Q','T'], 5 | 'T':['R'], 6 | 'S':['P'] 7 | } 8 | visited=[] 9 | queqe=[] 10 | def bfs(visited,graph,node): 11 | visited.append(node) 12 | queqe.append(node) 13 | while queqe: 14 | m=queqe.pop(0) 15 | print(m,end=" ") 16 | for i in graph[m]: 17 | if i not in visited: 18 | visited.append(i) 19 | queqe.append(i) 20 | print("Following is the breadth first search:") 21 | bfs(visited,graph,'P') 22 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Certain types of heart disease, such as heart defects, can't be prevented. However, you can help prevent many other types of heart disease by making the same lifestyle changes that can improve your heart disease, such as: 4 | 5 | Quit smoking 6 | Control other health conditions, such as high blood pressure, high cholesterol and diabetes 7 | Exercise at least 30 minutes a day on most days of the week 8 | Eat a diet that's low in salt and saturated fat 9 | Maintain a healthy weight 10 | Reduce and manage stress 11 | Practice good hygiene 12 | 13 | Medications: 14 | 15 | ACE Inhibitors 16 | Antiarrhythmics 17 | Beta-Blocker Therapy 18 | Digoxin 19 | Diuretics -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | Sinusitis is generally triggered by a viral upper respiratory tract infection, with only 2% of cases being complicated by bacterial sinusitis.2 About 90% of patients in the United States are estimated to receive an antibiotic from their general practitioner, yet in most cases the condition resolves without antibiotics, even if it is bacterial in origin.3 Most general practitioners rely on clinical findings to make the diagnosis. Signs and symptoms of acute bacterial sinusitis and those of a prolonged viral upper respiratory tract infection are closely similar, resulting in frequent misclassification of viral cases as bacterial sinusitis. Boxes 1 and 2 list common and rarer causes of rhinosinusitis. 2 | -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Asthma.txt: -------------------------------------------------------------------------------- 1 | Asthma is a major noncommunicable disease characterized by recurrent attacks of breathlessness and wheezing, which vary in severity and frequency from person to person. 2 | 3 | Symptoms may occur several times in a day or week in affected individuals, and for some people become worse during physical activity or at night. 4 | 5 | During an asthma attack, the lining of the bronchial tubes swell, causing the airways to narrow and reducing the flow of air into and out of the lungs. 6 | 7 | Recurrent asthma symptoms frequently cause sleeplessness, daytime fatigue, reduced activity levels and school and work absenteeism. 8 | 9 | Asthma has a relatively low fatality rate compared to other chronic diseases. 10 | -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Arthritis.txt: -------------------------------------------------------------------------------- 1 | Arthritis is inflammation of one or more of your joints. Pain, swelling, and stiffness are the primary symptoms of arthritis. Any joint in the body may be affected by the disease, but it is particularly common in the knee. 2 | 3 | Knee arthritis can make it hard to do many everyday activities, such as walking or climbing stairs. It is a major cause of lost work time and a serious disability for many people. 4 | 5 | The most common types of arthritis are osteoarthritis and rheumatoid arthritis, but there are more than 100 different forms. While arthritis is mainly an adult disease, some forms affect children. 6 | 7 | Although there is no cure for arthritis, there are many treatment options available to help manage pain and keep people staying active. 8 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Jaundice.txt: -------------------------------------------------------------------------------- 1 | Jaundice is treated by managing the underlying cause. 2 | 3 | Medication: 4 | 5 | Medication or supplements can help jaundice depending on the cause. 6 | Treatment will depend on the underlying cause. 7 | 8 | Jaundice treatment targets the cause rather than the jaundice symptoms. 9 | 10 | The following treatments are used: 11 | 12 | Anemia-induced jaundice may be treated by boosting the amount of iron in the blood by either taking iron supplements or eating more iron-rich foods. 13 | Hepatitis-induced jaundice requires antiviral or steroid medications. 14 | Doctors can treat obstruction-induced jaundice by surgically removing the obstruction. 15 | 16 | If the jaundice has been caused by use of a medication, treatment for involves changing to an alternative medication. -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Jaundice.txt: -------------------------------------------------------------------------------- 1 | Jaundice causes your skin and the whites of your eyes to turn yellow. 2 | Too much bilirubin causes jaundice. 3 | Bilirubin is a yellow chemical in hemoglobin, the substance that carries oxygen in your red blood cells. 4 | As red blood cells break down, your body builds new cells to replace them. The old ones are processed by the liver. If the liver cannot handle the blood cells as they break down, bilirubin builds up in the body and your skin may look yellow. 5 | 6 | Many healthy babies have some jaundice during the first week of life. It usually goes away. However, jaundice can happen at any age and may be a sign of a problem. Jaundice can happen for many reasons, such as 7 | 8 | Blood diseases 9 | Genetic syndromes 10 | Liver diseases, such as hepatitis or cirrhosis 11 | Blockage of bile ducts 12 | Infections 13 | Medicines 14 | -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | Glaucoma is a group of eye disorders that lead to progressive damage to the nerve that connects the eye to the brain called the optic nerve. People with glaucoma can lose nerve tissue, resulting in vision loss. 2 | 3 | The optic nerve is a bundle of about 1 million individual nerve fibers that transmits the visual signals from the eye to the brain. In the most common form of glaucoma, primary open-angle glaucoma, the fluid pressure inside the eye increases. This increase in pressure may cause progressive damage to the optic nerve and loss of nerve fibers. Advanced glaucoma may even lead to blindness. 4 | 5 | Not everyone with high eye pressure will develop glaucoma, and some people with normal eye pressure will develop glaucoma. When the pressure inside a person's eye is too high for a particular optic nerve, whatever that pressure measurement may be, glaucoma will develop. 6 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Coronavirus.txt: -------------------------------------------------------------------------------- 1 | The disease will last around 14 days during which you must quarantine yourself to prevent others from being infected. 2 | 3 | Prevention: 4 | The best way to prevent and slow down transmission is to be well informed about the COVID-19 virus, the disease it causes and how it spreads. Protect yourself and others from infection by washing your hands or using an alcohol based rub frequently and not touching your face. 5 | 6 | Vaccines have also been produced which protects you from few common variants of the disease. Getting yourself vaccinated also prevents the infection. 7 | 8 | Treatments for this disease include: 9 | 10 | Medicines: 11 | Remdesvir 12 | Bamlanivimab 13 | Etesevimab 14 | Casirivimab 15 | Imdevimab 16 | 17 | This disease affects your lungs and might give you trouble breathing. Hence, supplemental oxygen and mechanical ventilatory support will also help in case you have difficulties in breathing. -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Epilepsy.txt: -------------------------------------------------------------------------------- 1 | Treatment with medications or sometimes surgery can control seizures for the majority of people with epilepsy. 2 | 3 | Some people require lifelong treatment to control seizures, but for others, the seizures eventually go away. Some children with epilepsy may outgrow the condition with age. 4 | 5 | Medication: 6 | 7 | Epilepsy medications, sometimes called anti-seizure or anticonvulsant medications, change the way your brain cells work and send messages to each other. 8 | 9 | The kind of medication depends on: 10 | 11 | The type of seizures 12 | Frequency of seizures 13 | Age 14 | Sex 15 | Other medical conditions 16 | 17 | General Medications are: 18 | 19 | Carbamazepine (Tegretol or Carbatrol) 20 | Divalproex (depakote, Depakote ER) 21 | Diazepam (Valium and similar tranquilizers) 22 | Ethosuximide (Zarontin) 23 | Phenytoin (Dilantin or Phenytek) 24 | Phenobarbital 25 | Primidone (Mysoline) 26 | Valproic acid (Depakene) -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Diabetes.txt: -------------------------------------------------------------------------------- 1 | Diabetes is a disease in which your blood glucose, or blood sugar, levels are too high. 2 | 3 | Glucose comes from the foods you eat. 4 | 5 | Insulin is a hormone that helps the glucose get into your cells to give them energy. 6 | 7 | With type 1 diabetes, your body does not make insulin. 8 | 9 | With type 2 diabetes, the more common type, your body does not make or use insulin well. 10 | 11 | Without enough insulin, the glucose stays in your blood. 12 | 13 | You can also have prediabetes. This means that your blood sugar is higher than normal but not high enough to be called diabetes. Having prediabetes puts you at a higher risk of getting type 2 diabetes. 14 | 15 | Over time, having too much glucose in your blood can cause serious problems. It can damage your eyes, kidneys, and nerves. Diabetes can also cause heart disease, stroke and even the need to remove a limb. Pregnant women can also get diabetes, called gestational diabetes. 16 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Asthma.txt: -------------------------------------------------------------------------------- 1 | There is no cure for asthma. 2 | 3 | Symptoms can be prevented by avoiding triggers, such as allergens and irritants, and by the use of inhaled corticosteroids. 4 | 5 | Anti-inflammatory drugs, particularly inhaled steroids, are the most important treatment for most people with asthma. 6 | 7 | Bronchodilators relieve the symptoms of asthma by relaxing the muscles that can tighten around the airways. This helps to open up the airways. 8 | 9 | Short-acting bronchodilator inhalers are often referred to as rescue inhalers and are used to quickly relieve the cough, wheeze, chest tightness, and shortness of breath caused by asthma 10 | 11 | Long-acting beta agonists (LABA) or antileukotriene agents may be used in addition to inhaled corticosteroids if asthma symptoms remain uncontrolled. 12 | 13 | Treatment of rapidly worsening symptoms is usually with an inhaled short-acting beta-2 agonist such as salbutamol and corticosteroids taken by mouth. In very severe cases, intravenous corticosteroids, magnesium sulfate, and hospitalization may be required. -------------------------------------------------------------------------------- /N_Queens.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def _init_(self): 3 | self.MAX=20 4 | self.A=[0]*self.MAX 5 | def placement(self,i,j): 6 | for k in range(1,i): 7 | if(self.A[k]==j) or abs(self.A[k]-j)==abs(k-i): 8 | return False 9 | print(self.A) 10 | return True 11 | def printplacedqueen(self,N): 12 | print('Arrangement--->') 13 | print() 14 | for i in range(1,N+1): 15 | for j in range(1,N+1): 16 | if self.A[i] != j: 17 | print('\t_',end=' ') 18 | else: 19 | print('\tQ',end=' ') 20 | print() 21 | print() 22 | def N_Queens(self,i,j): 23 | for k in range(1,N+1): 24 | if self.placement(i,k): 25 | self.A[i]=k 26 | if i == N: 27 | self.printplacedqueen(N) 28 | else: 29 | self.N_Queens(i+1,N) 30 | N=int(input("Enter the queens value:")) 31 | obj=solution() 32 | obj.N_Queens(1,N) 33 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Sinusitis.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Take these steps to help reduce your risk of getting acute sinusitis: 4 | 5 | Avoid upper respiratory infections. Minimize contact with people who have colds. Wash your hands frequently with soap and water, especially before your meals. 6 | 7 | Manage your allergies. 8 | 9 | Avoid cigarette smoke and polluted air. Tobacco smoke and other pollutants can irritate and inflame your lungs and nasal passages. 10 | 11 | Use a humidifier. If the air in your home is dry, such as it is if you have forced-air heat, adding moisture to the air may help prevent sinusitis. Be sure the humidifier stays clean and free of mold with regular, thorough cleaning. 12 | 13 | Treatment: 14 | 15 | Using a nasal decongestant spray, such as oxymetazoline, can help relieve sinus infection symptoms short-term. 16 | 17 | Other over-the-counter medicines that contain antihistamines and decongestants can help with sinus infections, particularly if you also suffer from allergies. 18 | 19 | Medications: 20 | 21 | Sudafed 22 | Zyrtec 23 | Allegra 24 | Claritin 25 | 26 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | Depending on the severity of hypothermia, emergency medical care for hypothermia may include one of the following interventions to raise the body temperature: 2 | 3 | Passive rewarming: For someone with mild hypothermia, it is enough to cover them with heated blankets and offer warm fluids to drink. 4 | 5 | Blood rewarming : Blood may be drawn, warmed and recirculated in the body. A common method of warming blood is the use of a hemodialysis machine, which is normally used to filter blood in people with poor kidney function. Heart bypass machines also may need to be used. 6 | 7 | Warm intravenous fluids: A warmed intravenous solution of salt water may be put into a vein to help warm the blood. 8 | 9 | Airway rewarming: The use of humidified oxygen administered with a mask or nasal tube can warm the airways and help raise the temperature of the body. 10 | 11 | Irrigation: A warm saltwater solution may be used to warm certain areas of the body, such as the area around the lungs (pleura) or the abdominal cavity (peritoneal cavity). The warm liquid is introduced into the affected area with catheters. 12 | 13 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Glaucoma.txt: -------------------------------------------------------------------------------- 1 | Vision loss due to glaucoma can't be recovered. 2 | 3 | Prevention: 4 | Get regular eye exams that include measurements of your eye pressure. 5 | If glaucoma is recognized early, vision loss can be slowed or prevented. life. 6 | 7 | Treatments for Glaucoma include: 8 | 9 | Medicines: 10 | 11 | Medicines, in the form of eyedrops or pills, are the most common early treatment for glaucoma. 12 | 13 | Taken regularly, these eyedrops lower eye pressure. Some medicines cause the eye to make less fluid. Others lower pressure by helping fluid drain from the eye. 14 | 15 | Laser trabeculoplasty: 16 | 17 | Laser trabeculoplasty helps fluid drain out of the eye. Your doctor may suggest this step at any time. In many cases, medicines still need to be taken after the procedure. 18 | 19 | If glaucoma is present in both eyes, usually only one eye will be treated at a time. Laser treatments for each eye will be scheduled several days to several weeks apart. 20 | 21 | Conventional surgery: 22 | Conventional surgery makes a new opening for the fluid to leave the eye. Conventional surgery often is done after medicines and laser surgery have failed to control pressure -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | Medications are the cornerstone of tuberculosis treatment. 2 | 3 | Medications are the cornerstone of tuberculosis treatment. But treating TB takes much longer than treating other types of bacterial infections. 4 | 5 | With tuberculosis, you must take antibiotics for at least six to nine months. The exact drugs and length of treatment depend on your age, overall health, possible drug resistance, the form of TB (latent or active) and the infection's location in the body. 6 | 7 | Four months instead of nine — with combined medication may be effective in keeping latent TB from becoming active TB. With the shorter course of treatment, people are more likely to take all their medication, and the risk of side effects is lessened. 8 | 9 | The most common medications used to treat tuberculosis include: 10 | Isoniazid 11 | Rifampin (Rifadin, Rimactane) 12 | Ethambutol (Myambutol) 13 | Pyrazinamide 14 | 15 | If you have drug-resistant TB, a combination of antibiotics called fluoroquinolones and injectable medications, such as amikacin, kanamycin or capreomycin, are generally used for 20 to 30 months. Some types of TB are developing resistance to these medications as well. -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | Treatment 2 | 3 | Several treatments for hyperthyroidism exist. The best approach depends on age, physical condition, the underlying cause of the hyperthyroidism, personal preference and the severity of disorder: 4 | 5 | Radioactive iodine. Taken by mouth, radioactive iodine is absorbed by thyroid gland, where it causes the gland to shrink and symptoms to subside, usually within three to six months. Because this treatment causes thyroid activity to slow considerably, causing the thyroid gland to be underactive (hypothyroidism), you may eventually need to take medication every day to replace thyroxine. 6 | 7 | Anti-thyroid medications. These medications gradually reduce symptoms of hyperthyroidism by preventing thyroid gland from producing excess amounts of hormones. They include propylthiouracil and methimazole (Tapazole). Both drugs can cause serious liver damage, sometimes leading to death. 8 | 9 | Beta blockers. These drugs are commonly used to treat high blood pressure. They won't reduce thyroid levels, but they can reduce a rapid heart rate and help prevent palpitations. 10 | 11 | Surgery (thyroidectomy). If patients can't tolerate anti-thyroid drugs and don't want to or can't have radioactive iodine therapy, they may be a candidate for thyroid surgery. 12 | -------------------------------------------------------------------------------- /Hangman game/hangman_art.py: -------------------------------------------------------------------------------- 1 | stages = [''' 2 | +---+ 3 | | | 4 | O | 5 | /|\ | 6 | / \ | 7 | | 8 | ========= 9 | ''', ''' 10 | +---+ 11 | | | 12 | O | 13 | /|\ | 14 | / | 15 | | 16 | ========= 17 | ''', ''' 18 | +---+ 19 | | | 20 | O | 21 | /|\ | 22 | | 23 | | 24 | ========= 25 | ''', ''' 26 | +---+ 27 | | | 28 | O | 29 | /| | 30 | | 31 | | 32 | =========''', ''' 33 | +---+ 34 | | | 35 | O | 36 | | | 37 | | 38 | | 39 | ========= 40 | ''', ''' 41 | +---+ 42 | | | 43 | O | 44 | | 45 | | 46 | | 47 | ========= 48 | ''', ''' 49 | +---+ 50 | | | 51 | | 52 | | 53 | | 54 | | 55 | ========= 56 | '''] 57 | 58 | logo = ''' 59 | _ 60 | | | 61 | | |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ 62 | | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ 63 | | | | | (_| | | | | (_| | | | | | | (_| | | | | 64 | |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| 65 | __/ | 66 | |___/ ''' 67 | 68 | 69 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Diabetes.txt: -------------------------------------------------------------------------------- 1 | Patients with type 1 diabetes will need to take insulin injections for the rest of their life. They must also ensure proper blood-glucose levels by carrying out regular blood tests and following a special diet. 2 | 3 | Type 2 patients need to eat healthily, be physically active, and test their blood glucose. They may also need to take oral medication, and/or insulin to control blood glucose levels. 4 | 5 | Treatment for type 1 diabetes includes: 6 | 7 | Taking insulin 8 | Carbohydrate, fat and protein counting 9 | Frequent blood sugar monitoring 10 | Eating healthy foods 11 | Exercising regularly and maintaining a healthy weight 12 | 13 | Types of insulin are many and include: 14 | 15 | Short-acting (regular) insulin 16 | Rapid-acting insulin 17 | Intermediate-acting (NPH) insulin 18 | Long-acting insulin 19 | 20 | Other Medications: 21 | 22 | High blood pressure medications 23 | Aspirin 24 | Cholesterol-lowering drugs 25 | 26 | Treatment for type 2 diabetes includes: 27 | 28 | Healthy eating 29 | Regular exercise 30 | Possibly, diabetes medication or insulin therapy 31 | Blood sugar monitoring 32 | 33 | Examples of possible treatments for type 2 diabetes include: 34 | 35 | Metformin (Glucophage, Glumetza, others) 36 | Sulfonylureas 37 | Meglitinides 38 | Thiazolidinediones 39 | Insulin therapy -------------------------------------------------------------------------------- /Hangman game/hangman_man.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | from hangman_words import word_list 4 | from hangman_art import stages,logo 5 | chosen_word=random.choice(word_list) 6 | 7 | lives=6 8 | #print(f"Pssst, the solution is {chosen_word}.") 9 | print(logo) 10 | print(len(stages)) 11 | display=[] 12 | guessed=[] 13 | for i in range(len(chosen_word)): 14 | 15 | display.append("_") 16 | 17 | while "_" in display and lives>0: 18 | guess=input("Guess a letter:").lower() 19 | if len(guess)==1 and guess.isalpha(): 20 | if guess in guessed: 21 | print("letter already present") 22 | continue 23 | guessed.append(guess) 24 | for i in range(len(chosen_word)): 25 | letter=chosen_word[i] 26 | 27 | if letter==guess: 28 | display[i]=letter 29 | if guess not in chosen_word: 30 | if lives>0: 31 | lives=lives-1 32 | if lives==0: 33 | print(stages[lives]) 34 | print(f"The solution is {chosen_word}.") 35 | print("You loose") 36 | exit(1) 37 | print(f"{''.join(display)}") 38 | print(lives) 39 | print(stages[lives]) 40 | else: 41 | print("guess hsould be a character rather than a word") 42 | else: 43 | print("You have won") 44 | -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | Heatstroke generally occurs when an individual has been too hot for too long, whether working, exercising, or simply sitting in a hot environment. 2 | 3 | Also known as sunstroke, heatstroke is a serious condition and must be considered an emergency. 4 | 5 | If the body temperature rises above 40° Celsius, and the body loses the ability to cool down, it is considered to be heatstroke. 6 | 7 | If left untreated, damage to internal organs can occur. The longer it is left, the more serious heatstroke can become. In some cases, heatstroke can be fatal. 8 | 9 | Heatstroke can be brought on by physical exertion in hot conditions, or simply by being in a hot environment 10 | 11 | Treating heatstroke centers around bringing body temperature down. 12 | 13 | Heatstroke can occur as a result of: 14 | 15 | Exposure to a hot environment. 16 | 17 | In a type of heatstroke, called nonexertional (classic) heatstroke, being in a hot environment leads to a rise in core body temperature. This type of heatstroke typically occurs after exposure to hot, humid weather, especially for prolonged periods. 18 | 19 | It occurs most often in older adults and in people with chronic illness. 20 | 21 | Strenuous activity. Exertional heatstroke is caused by an increase in core body temperature brought on by intense physical activity in hot weather. 22 | 23 | Anyone exercising or working in hot weather can get exertional heatstroke, but it's most likely to occur if you're not used to high temperatures. -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Hypothermia.txt: -------------------------------------------------------------------------------- 1 | Hypothermia is a medical emergency that occurs when your body loses heat faster than it can produce heat, causing a dangerously low body temperature. Normal body temperature is around 98.6 F (37 C). Hypothermia (hi-poe-THUR-me-uh) occurs as your body temperature falls below 95 F (35 C). 2 | 3 | When your body temperature drops, your heart, nervous system and other organs can't work normally. Left untreated, hypothermia can eventually lead to complete failure of your heart and respiratory system and eventually to death. 4 | 5 | Hypothermia is often caused by exposure to cold weather or immersion in cold water. Primary treatments for hypothermia are methods to warm the body back to a normal temperature. 6 | 7 | Hypothermia has two main types of causes. It classically occurs from exposure to extreme cold. 8 | 9 | It may also occur from any condition that decreases heat production or increases heat loss. 10 | Commonly this includes alcohol intoxication but may also include low blood sugar, anorexia, and advanced age. 11 | 12 | Body temperature is usually maintained near a constant level of 36.5–37.5 °C (97.7–99.5 °F) through thermoregulation. 13 | 14 | Efforts to increase body temperature involve shivering, increased voluntary activity, and putting on warmer clothing. 15 | 16 | Diagnosis: 17 | 18 | The diagnosis of hypothermia is usually apparent based on a person's physical signs and the conditions in which the person with hypothermia became ill or was found. Blood tests also can help confirm hypothermia and its severity. 19 | 20 | A diagnosis may not be readily apparent, however, if the symptoms are mild, as when an older person who is indoors has symptoms of confusion, lack of coordination and speech problems. -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Hyperthyroidism.txt: -------------------------------------------------------------------------------- 1 | Hyperthyroidism is a condition of the thyroid. The thyroid is a small, butterfly-shaped gland located at the front of your neck. It produces tetraiodothyronine (T4) and triiodothyronine (T3), which are two primary hormones that control how your cells use energy. Your thyroid gland regulates your metabolism through the release of these hormones. 2 | 3 | Hyperthyroidism occurs when the thyroid makes too much T4, T3, or both. Diagnosis of overactive thyroid and treatment of the underlying cause can relieve symptoms and prevent complications. 4 | 5 | A variety of conditions can cause hyperthyroidism. Graves' disease, an autoimmune disorder, is the most common cause of hyperthyroidism. It causes antibodies to stimulate the thyroid to secrete too much hormone. Graves’ disease occurs more often in women than in men. It tends to run in families, which suggests a genetic link. You should tell your doctor if your relatives have had the condition. 6 | 7 | Other causes of hyperthyroidism include: 8 | 9 | Excess iodine, a key ingredient in T4 and T3 10 | 11 | Thyroiditis, or inflammation of the thyroid, which causes T4 and T3 to leak out of the gland 12 | 13 | Tumors of the ovaries or testes 14 | 15 | Benign tumors of the thyroid or pituitary gland 16 | 17 | Large amounts of tetraiodothyronine taken through dietary supplements or medication 18 | 19 | Diagnosis: 20 | 21 | Cholesterol test 22 | T4, free T4, T3 tests 23 | Thyroid stimulating hormone level test 24 | Triglyceride test 25 | Thyroid scan and uptake 26 | Ultrasound 27 | CT or MRI scans 28 | Radio Iodine Uptake test 29 | 30 | Physical Exam 31 | Blood Tests 32 | Checking for weight loss 33 | Checking for protruding eyes 34 | Checking for enlarged thyroid gland 35 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Arthritis.txt: -------------------------------------------------------------------------------- 1 | Arthritis treatment focuses on relieving symptoms and improving joint function. You may need to try several different treatments, or combinations of treatments, before you determine what works best for you. 2 | 3 | Medications 4 | The medications used to treat arthritis vary depending on the type of arthritis. Commonly used arthritis medications include: 5 | 6 | Analgesics. These medications help reduce pain, but have no effect on inflammation. 7 | 8 | Nonsteroidal anti-inflammatory drugs (NSAIDs). NSAIDs reduce both pain and inflammation. Over-the-counter NSAIDs include ibuprofen and naproxen sodium. Oral NSAIDs can cause stomach irritation, and some may increase your risk of heart attack or stroke. 9 | 10 | Disease-modifying antirheumatic drugs (DMARDs). Often used to treat rheumatoid arthritis, DMARDs slow or stop your immune system from attacking your joints. 11 | 12 | Therapy 13 | Physical therapy can be helpful for some types of arthritis. Exercises can improve range of motion and strengthen the muscles surrounding joints. In some cases, splints or braces may be warranted. 14 | 15 | Surgery 16 | 17 | If conservative measures don't help, your doctor may suggest surgery, such as: 18 | 19 | Joint repair. In some instances, joint surfaces can be smoothed or realigned to reduce pain and improve function. These types of procedures can often be performed arthroscopically — through small incisions over the joint. 20 | 21 | Joint replacement. This procedure removes your damaged joint and replaces it with an artificial one. Joints most commonly replaced are hips and knees. 22 | 23 | Joint fusion. This procedure is more often used for smaller joints, such as those in the wrist, ankle and fingers. It removes the ends of the two bones in the joint and then locks those ends together until they heal into one rigid unit. -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Heart Disease.txt: -------------------------------------------------------------------------------- 1 | Heart disease describes a range of conditions that affect your heart. Diseases under the heart disease umbrella include blood vessel diseases, such as coronary artery disease; heart rhythm problems (arrhythmias); and heart defects you're born with (congenital heart defects), among others. 2 | 3 | The term "heart disease" is often used interchangeably with the term "cardiovascular disease." Cardiovascular disease generally refers to conditions that involve narrowed or blocked blood vessels that can lead to a heart attack, chest pain (angina) or stroke. Other heart conditions, such as those that affect your heart's muscle, valves or rhythm, also are considered forms of heart disease. 4 | 5 | Many forms of heart disease can be prevented or treated with healthy lifestyle choices. 6 | 7 | Cardiovascular disease symptoms may be different for men and women. 8 | 9 | Causes: 10 | 11 | While cardiovascular disease can refer to different heart or blood vessel problems, the term is often used to mean damage to your heart or blood vessels by atherosclerosis, a buildup of fatty plaques in your arteries. 12 | 13 | Plaque buildup thickens and stiffens artery walls, which can inhibit blood flow through your arteries to your organs and tissues. 14 | 15 | Atherosclerosis is also the most common cause of cardiovascular disease. It can be caused by correctable problems, such as an unhealthy diet, lack of exercise, being overweight and smoking 16 | 17 | Common causes of abnormal heart rhythms (arrhythmias) or conditions that can lead to arrhythmias include: 18 | 19 | Heart defects since birth 20 | Coronary artery disease 21 | High blood pressure 22 | Diabetes 23 | Smoking 24 | Excessive use of alcohol or caffeine 25 | Drug abuse 26 | Stress 27 | Some over-the-counter medications, prescription medications, dietary supplements and herbal remedies 28 | Valvular heart disease -------------------------------------------------------------------------------- /Water jug problem/wjugauto.py: -------------------------------------------------------------------------------- 1 | import math 2 | from collections import deque 3 | a=int(input("Jug A capacity:")) 4 | b=int(input("Jug B capacity:")) 5 | ai=int(input("Initial water in jug A:")) 6 | bi=int(input("Initial water in jug B:")) 7 | af=int(input("Final in A:")) 8 | bf=int(input("Final in B:")) 9 | 10 | if a<=0 or b<=0: 11 | print("Jug capacities must be +ve") 12 | exit(1) 13 | if ai<0 or bi<0 or af<0 or bf<0: 14 | print("-ve Values not allowed") 15 | exit(1) 16 | if ai==af and bi==bf: 17 | print(f"Initial state is already the final stae: jug a = {ai} and jug b= {bi}") 18 | exit() 19 | 20 | def bfs_wjug(a,b,ai,bi,af,bf): 21 | visited=set() 22 | queue=deque([(ai,bi,[])]) 23 | 24 | while queue: 25 | curr_ai,curr_bi,ops=queue.popleft() 26 | 27 | if(curr_ai,curr_bi) in visited: 28 | continue 29 | visited.add((curr_ai,curr_bi)) 30 | 31 | if curr_ai == af and curr_bi == bf: 32 | for i,op in enumerate(ops): 33 | print(f"Step {i+1}: {op}") 34 | print(f"final state reached: jug a = {curr_ai} and jug b= {curr_bi}") 35 | return 36 | 37 | possible_ops=[ 38 | (a,curr_bi,"Fill Jug A"), 39 | (curr_ai,b,"Fill Jug B"), 40 | (0,curr_bi,"Empty Jug A"), 41 | (curr_ai,0,"Empty Jug B"), 42 | (curr_ai - min(curr_ai,b-curr_bi),curr_bi + min(curr_ai, b- curr_bi),"Pour from Jug A to B"), 43 | (curr_ai + min(curr_bi,a-curr_ai),curr_bi - min(curr_bi, a- curr_ai),"Pour from Jug B to A"),] 44 | 45 | 46 | for next_ai,next_bi,op in possible_ops: 47 | if(next_ai,next_bi) not in visited: 48 | queue.append((next_ai, next_bi,ops+[op])) 49 | print("No solution found.") 50 | return 51 | 52 | gcd= math.gcd(a,b) 53 | if(af<=a and bf<=b) and (af%gcd==bf%gcd==0): 54 | bfs_wjug(a,b,ai,bi,af,bf) 55 | else: 56 | print("The final state is not achievable with the given capacities.") 57 | exit() 58 | 59 | 60 | -------------------------------------------------------------------------------- /Medical Expert System/Disease treatments/Heat Stroke.txt: -------------------------------------------------------------------------------- 1 | Prevention: 2 | 3 | Heatstroke is predictable and preventable. 4 | 5 | Wearing excess clothing or clothing that fits tightly won't allow your body to cool properly. 6 | 7 | Protect against sunburn. Sunburn affects the body's ability to cool itself, so protect yourself outdoors with a wide-brimmed hat and sunglasses and use a broad-spectrum sunscreen with an SPF of at least 15. 8 | 9 | Drink plenty of fluids. Staying hydrated will help your body sweat and maintain a normal body temperature.. 10 | 11 | Treatments: 12 | 13 | The underlying cause must be removed. Mild hyperthemia caused by exertion on a hot day may be adequately treated through self-care measures, such as increased water consumption and resting in a cool place. 14 | 15 | Heat stroke that results from drug exposure requires prompt cessation of that drug, and occasionally the use of other drugs as counter measures. Antipyretics (e.g., acetaminophen, aspirin, other nonsteroidal anti-inflammatory drugs) have no role in the treatment of heatstroke because antipyretics interrupt the change in the hypothalamic set point caused by pyrogens; they are not expected to work on a healthy hypothalamus that has been overloaded, as in the case of heatstroke. 16 | 17 | In this situation, antipyretics actually may be harmful in patients who develop hepatic, hematologic, and renal complications because they may aggravate bleeding tendencies. 18 | 19 | When body temperature is significantly elevated, mechanical cooling methods are used to remove heat and to restore the body's ability to regulate its own temperatures. 20 | 21 | Passive cooling techniques, such as resting in a cool, shady area and removing clothing can be applied immediately. Active cooling methods, such as sponging the head, neck, and trunk with cool water, remove heat from the body and thereby speed the body's return to normal temperatures. Drinking water and turning a fan or dehumidifying air conditioning unit on the affected person may improve the effectiveness of the body's evaporative cooling mechanisms (sweating). -------------------------------------------------------------------------------- /Medical Expert System/Disease descriptions/Tuberculosis.txt: -------------------------------------------------------------------------------- 1 | Tuberculosis (TB) is a potentially serious infectious disease that mainly affects your lungs. The bacteria that cause tuberculosis are spread from one person to another through tiny droplets released into the air via coughs and sneezes. 2 | 3 | Many strains of tuberculosis resist the drugs most used to treat the disease. People with active tuberculosis must take several types of medications for many months to eradicate the infection and prevent development of antibiotic resistance. 4 | 5 | Although your body may harbor the bacteria that cause tuberculosis, your immune system usually can prevent you from becoming sick. For this reason, doctors make a distinction between: 6 | 7 | Latent TB. In this condition, you have a TB infection, but the bacteria remain in your body in an inactive state and cause no symptoms. Latent TB, also called inactive TB or TB infection, isn't contagious. It can turn into active TB, so treatment is important for the person with latent TB and to help control the spread of TB. An estimated 2 billion people have latent TB. 8 | 9 | Active TB. This condition makes you sick and can spread to others. It can occur in the first few weeks after infection with the TB bacteria, or it might occur years later. 10 | 11 | Although tuberculosis is contagious, it's not easy to catch. You're much more likely to get tuberculosis from someone you live with or work with than from a stranger. Most people with active TB who've had appropriate drug treatment for at least two weeks are no longer contagious. 12 | 13 | The most commonly used diagnostic tool for tuberculosis is a simple skin test, though blood tests are becoming more commonplace. A small amount of a substance called PPD tuberculin is injected just below the skin of your inside forearm. You should feel only a slight needle prick. 14 | 15 | Within 48 to 72 hours, a health care professional will check your arm for swelling at the injection site. A hard, raised red bump means you're likely to have TB infection. The size of the bump determines whether the test results are significant. -------------------------------------------------------------------------------- /Water jug problem/jugmanual.py: -------------------------------------------------------------------------------- 1 | import math 2 | a=int(input("Enter jug A cap: ")) 3 | b=int(input("Enter jug B cap: ")) 4 | ai=int(input("Initial water in jug A: ")) 5 | bi=int(input("Initial water in jug B: ")) 6 | af=int(input("Final state of jug A: ")) 7 | bf=int(input("Final state of jug B: ")) 8 | 9 | if a<=0 or b<=0: 10 | printf("Jug caps must be +ve") 11 | exit(1) 12 | if ai<0 or bi<0 or af<0 or bf<0: 13 | print("-ve values are not allowed") 14 | exit(1) 15 | 16 | def wjug(a,b,ai,bi,af,bf): 17 | print("List of ops: ") 18 | print("1. Fill jug A completely") 19 | print("2. Fill jug B completely") 20 | print("3. Empty jug A") 21 | print("4. Empty jug B") 22 | print("5. Pour from A to B until B is full or A is empty") 23 | print("6. Pour from B to A until A is full or B is empty") 24 | print("7. Pour from B to A") 25 | print("8. Pour from A to B") 26 | 27 | while ai!=af or bi!=bf: 28 | op=int(input("Enter operation(1-8):")) 29 | if op==1: 30 | ai=a 31 | elif op==2: 32 | bi=b 33 | elif op==3: 34 | ai=0 35 | elif op==4: 36 | bi=0 37 | elif op==5: 38 | pour_amt=min(a,b-bi) 39 | ai-=pour_amt 40 | bi+=pour_amt 41 | elif op==6: 42 | pour_amt=min(b,a-ai) 43 | bi-=pour_amt 44 | ai+=pour_amt 45 | elif op==7: 46 | pour_amt=min(b,a-ai) 47 | ai+=pour_amt 48 | bi-=pour_amt 49 | elif op==8: 50 | pour_amt=min(a,b-bi) 51 | bi+=pour_amt 52 | ai-=pour_amt 53 | else: 54 | print("Invalid operation. Please choose a number between 1 & 8") 55 | continue 56 | print(f"jug A: {ai} , Jug B: {bi}") 57 | if ai==af and bi==bf: 58 | print("Final state reached: Jug A= ",ai,", Jug B= ",bi) 59 | return 60 | print("Final state reached: Jug A= ",ai,", Jug B= ",bi) 61 | gcd=math.gcd(a,b) 62 | if(af<=a and bf<=b) and (af%gcd==bf%gcd==0): 63 | wjug(a,b,ai,bi,af,bf) 64 | else: 65 | print("Final state not achieavable") 66 | exit(1) 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /MLP Classifier.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # In[6]: 5 | 6 | 7 | import numpy as np 8 | import pandas as pd 9 | data=pd.read_csv("HR_comma_sep.csv") 10 | 11 | 12 | # In[7]: 13 | 14 | 15 | data.head() 16 | 17 | 18 | # In[8]: 19 | 20 | 21 | data.info 22 | 23 | 24 | # In[9]: 25 | 26 | 27 | data['Departments'].value_counts() 28 | 29 | 30 | # In[10]: 31 | 32 | 33 | data["Departments"].unique() 34 | 35 | 36 | # In[11]: 37 | 38 | 39 | data['salary'].unique() 40 | 41 | 42 | # In[12]: 43 | 44 | 45 | from sklearn import preprocessing 46 | le=preprocessing.LabelEncoder() 47 | print(le) 48 | data['salary']=le.fit_transform(data['salary']) 49 | data['Departments']=le.fit_transform(data['Departments']) 50 | 51 | 52 | # In[13]: 53 | 54 | 55 | data['salary'].unique() 56 | 57 | 58 | # In[14]: 59 | 60 | 61 | print(pd.__version__) 62 | 63 | 64 | # In[15]: 65 | 66 | 67 | X=data[['satisfaction_level','last_evaluation','number_project','average_montly_hours','time_spend_company','Work_accident','promotion_last_5years','Departments','salary']] 68 | y=data['left'] 69 | from sklearn.model_selection import train_test_split 70 | X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42) 71 | 72 | 73 | # In[20]: 74 | 75 | 76 | X_train 77 | 78 | 79 | # In[16]: 80 | 81 | 82 | y_train 83 | 84 | 85 | # In[17]: 86 | 87 | 88 | from sklearn.neural_network import MLPClassifier 89 | clf=MLPClassifier(hidden_layer_sizes=(6,5),random_state=5,verbose=True,learning_rate_init=0.01) 90 | clf.fit(X_train,y_train) 91 | 92 | 93 | # In[18]: 94 | 95 | 96 | ypred=clf.predict(X_test) 97 | from sklearn.metrics import accuracy_score 98 | accuracy_score(y_test,ypred) 99 | 100 | 101 | # In[20]: 102 | 103 | 104 | X_test.shape 105 | 106 | 107 | # In[25]: 108 | 109 | 110 | n=pd.DataFrame({'satisfaction_level':[0.23],'last_evaluation':[0.53],'number_project':[1],'average_montly_hours':[25],'time_spend_company':[3],'Work_accident':[0],'promotion_last_5years':[0],'Departments':[1],'salary':[1]}) 111 | new_data=clf.predict(n) 112 | print(new_data) 113 | 114 | 115 | # In[28]: 116 | 117 | 118 | from sklearn.metrics import classification_report 119 | print(classification_report(y_test,ypred)) 120 | 121 | 122 | # In[30]: 123 | 124 | 125 | from sklearn.metrics import confusion_matrix 126 | y_pred=clf.predict(X_test) 127 | print(confusion_matrix(y_test,ypred)) 128 | 129 | 130 | # In[31]: 131 | 132 | 133 | print(y_train.value_counts()) 134 | print(y_test.value_counts()) 135 | 136 | -------------------------------------------------------------------------------- /Medical Expert System/main.py: -------------------------------------------------------------------------------- 1 | from greetings import Greetings 2 | diseases_list = [] 3 | diseases_symptoms = [] 4 | symptom_map = {} 5 | d_desc_map = {} 6 | d_treatment_map = {} 7 | 8 | #loads the knowledge from .txt files into variables to allow the code to use it 9 | def preprocess(): 10 | #global diseases_list, diseases_symptoms, symptom_map, d_desc_map, d_treatment_map 11 | diseases = open("diseases.txt") 12 | diseases_t = diseases.read() 13 | diseases_list = diseases_t.split("\n") 14 | diseases.close() 15 | 16 | for disease in diseases_list: 17 | disease_s_file = open("Disease symptoms/" + disease + ".txt") 18 | disease_s_data = disease_s_file.read() 19 | s_list = disease_s_data.split("\n") 20 | diseases_symptoms.append(s_list) 21 | symptom_map[str(s_list)] = disease 22 | disease_s_file.close() 23 | 24 | disease_s_file = open("Disease descriptions/" + disease + ".txt") 25 | disease_s_data = disease_s_file.read() 26 | d_desc_map[disease] = disease_s_data 27 | disease_s_file.close() 28 | 29 | disease_s_file = open("Disease treatments/" + disease + ".txt") 30 | disease_s_data = disease_s_file.read() 31 | d_treatment_map[disease] = disease_s_data 32 | disease_s_file.close() 33 | 34 | 35 | def identify_disease(*arguments): 36 | symptom_list = [] 37 | for symptom in arguments: 38 | symptom_list.append(symptom) 39 | 40 | return symptom_map[str(symptom_list)] 41 | 42 | 43 | def get_details(disease): 44 | return d_desc_map[disease] 45 | 46 | 47 | def get_treatments(disease): 48 | return d_treatment_map[disease] 49 | 50 | 51 | def if_not_matched(disease): 52 | print("") 53 | id_disease = disease 54 | disease_details = get_details(id_disease) 55 | treatments = get_treatments(id_disease) 56 | print("") 57 | print("The most probable disease that you have is %s\n" % (id_disease)) 58 | print("A short description of the disease is given below :\n") 59 | print(disease_details + "\n") 60 | print( 61 | "The common medications and procedures suggested by other real doctors are: \n" 62 | ) 63 | print(treatments + "\n") 64 | 65 | 66 | if __name__ == "__main__": 67 | preprocess() 68 | #creating class object 69 | engine = Greetings(symptom_map, if_not_matched, get_treatments, get_details) 70 | #loop to keep running the code until user says no when asked for another diagnosis 71 | while 1: 72 | engine.reset() 73 | engine.run() 74 | print("Would you like to diagnose some other symptoms?\n Reply yes or no") 75 | if input() == "no": 76 | exit() 77 | -------------------------------------------------------------------------------- /Hangman game/hangman_words.py: -------------------------------------------------------------------------------- 1 | word_list = [ 2 | 'abruptly', 3 | 'absurd', 4 | 'abyss', 5 | 'affix', 6 | 'askew', 7 | 'avenue', 8 | 'awkward', 9 | 'axiom', 10 | 'azure', 11 | 'bagpipes', 12 | 'bandwagon', 13 | 'banjo', 14 | 'bayou', 15 | 'beekeeper', 16 | 'blitz', 17 | 'blizzard', 18 | 'boggle', 19 | 'bookworm', 20 | 'boxcar', 21 | 'boxful', 22 | 'buckaroo', 23 | 'buffalo', 24 | 'buffoon', 25 | 'buxom', 26 | 'buzzard', 27 | 'buzzing', 28 | 'buzzwords', 29 | 'caliph', 30 | 'cobweb', 31 | 'cockiness', 32 | 'croquet', 33 | 'crypt', 34 | 'curacao', 35 | 'cycle', 36 | 'daiquiri', 37 | 'dirndl', 38 | 'disavow', 39 | 'dizzying', 40 | 'duplex', 41 | 'dwarves', 42 | 'embezzle', 43 | 'equip', 44 | 'espionage', 45 | 'euouae', 46 | 'exodus', 47 | 'faking', 48 | 'fishhook', 49 | 'fixable', 50 | 'fjord', 51 | 'flapjack', 52 | 'flopping', 53 | 'fluffiness', 54 | 'flyby', 55 | 'foxglove', 56 | 'frazzled', 57 | 'frizzled', 58 | 'fuchsia', 59 | 'funny', 60 | 'gabby', 61 | 'galaxy', 62 | 'galvanize', 63 | 'gazebo', 64 | 'giaour', 65 | 'gizmo', 66 | 'glowworm', 67 | 'glyph', 68 | 'gnarly', 69 | 'gnostic', 70 | 'gossip', 71 | 'grogginess', 72 | 'haiku', 73 | 'haphazard', 74 | 'hyphen', 75 | 'iatrogenic', 76 | 'icebox', 77 | 'injury', 78 | 'ivory', 79 | 'ivy', 80 | 'jackpot', 81 | 'jaundice', 82 | 'jawbreaker', 83 | 'jaywalk', 84 | 'jazziest', 85 | 'jazzy', 86 | 'jelly', 87 | 'jigsaw', 88 | 'jinx', 89 | 'jiujitsu', 90 | 'jockey', 91 | 'jogging', 92 | 'joking', 93 | 'jovial', 94 | 'joyful', 95 | 'juicy', 96 | 'jukebox', 97 | 'jumbo', 98 | 'kayak', 99 | 'kazoo', 100 | 'keyhole', 101 | 'khaki', 102 | 'kilobyte', 103 | 'kiosk', 104 | 'kitsch', 105 | 'kiwifruit', 106 | 'klutz', 107 | 'knapsack', 108 | 'larynx', 109 | 'lengths', 110 | 'lucky', 111 | 'luxury', 112 | 'lymph', 113 | 'marquis', 114 | 'matrix', 115 | 'megahertz', 116 | 'microwave', 117 | 'mnemonic', 118 | 'mystify', 119 | 'naphtha', 120 | 'nightclub', 121 | 'nowadays', 122 | 'numbskull', 123 | 'nymph', 124 | 'onyx', 125 | 'ovary', 126 | 'oxidize', 127 | 'oxygen', 128 | 'pajama', 129 | 'peekaboo', 130 | 'phlegm', 131 | 'pixel', 132 | 'pizazz', 133 | 'pneumonia', 134 | 'polka', 135 | 'pshaw', 136 | 'psyche', 137 | 'puppy', 138 | 'puzzling', 139 | 'quartz', 140 | 'queue', 141 | 'quips', 142 | 'quixotic', 143 | 'quiz', 144 | 'quizzes', 145 | 'quorum', 146 | 'razzmatazz', 147 | 'rhubarb', 148 | 'rhythm', 149 | 'rickshaw', 150 | 'schnapps', 151 | 'scratch', 152 | 'shiv', 153 | 'snazzy', 154 | 'sphinx', 155 | 'spritz', 156 | 'squawk', 157 | 'staff', 158 | 'strength', 159 | 'strengths', 160 | 'stretch', 161 | 'stronghold', 162 | 'stymied', 163 | 'subway', 164 | 'swivel', 165 | 'syndrome', 166 | 'thriftless', 167 | 'thumbscrew', 168 | 'topaz', 169 | 'transcript', 170 | 'transgress', 171 | 'transplant', 172 | 'triphthong', 173 | 'twelfth', 174 | 'twelfths', 175 | 'unknown', 176 | 'unworthy', 177 | 'unzip', 178 | 'uptown', 179 | 'vaporize', 180 | 'vixen', 181 | 'vodka', 182 | 'voodoo', 183 | 'vortex', 184 | 'voyeurism', 185 | 'walkway', 186 | 'waltz', 187 | 'wave', 188 | 'wavy', 189 | 'waxy', 190 | 'wellspring', 191 | 'wheezy', 192 | 'whiskey', 193 | 'whizzing', 194 | 'whomever', 195 | 'wimpy', 196 | 'witchcraft', 197 | 'wizard', 198 | 'woozy', 199 | 'wristwatch', 200 | 'wyvern', 201 | 'xylophone', 202 | 'yachtsman', 203 | 'yippee', 204 | 'yoked', 205 | 'youthful', 206 | 'yummy', 207 | 'zephyr', 208 | 'zigzag', 209 | 'zigzagging', 210 | 'zilch', 211 | 'zipper', 212 | 'zodiac', 213 | 'zombie', 214 | ] 215 | -------------------------------------------------------------------------------- /A star algorithm.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 11, 20 | "metadata": { 21 | "id": "DiQW0hJGeKQJ" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "graph=[['A','B',1,3],\n", 26 | " ['A','C',2,4],\n", 27 | " ['A','H',7,0],\n", 28 | " ['B','D',4,2],\n", 29 | " ['B','E',6,6],\n", 30 | " ['C','F',3,3],\n", 31 | " ['C','G',2,1],\n", 32 | " ['D','E',7,6],\n", 33 | " ['D','H',5,0],\n", 34 | " ['F','H',1,0],\n", 35 | " ['G','H',2,0]]" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "source": [ 41 | "temp=[]\n", 42 | "temp1=[]\n", 43 | "for i in graph:\n", 44 | " temp.append(i[0])\n", 45 | " temp1.append(i[1])\n", 46 | "print(temp)\n", 47 | "print(temp1)" 48 | ], 49 | "metadata": { 50 | "colab": { 51 | "base_uri": "https://localhost:8080/" 52 | }, 53 | "id": "y--FWldCiIp3", 54 | "outputId": "74bad633-fe9f-479d-be0e-dbcb5758106f" 55 | }, 56 | "execution_count": 15, 57 | "outputs": [ 58 | { 59 | "output_type": "stream", 60 | "name": "stdout", 61 | "text": [ 62 | "['A', 'A', 'A', 'B', 'B', 'C', 'C', 'D', 'D', 'F', 'G']\n", 63 | "['B', 'C', 'H', 'D', 'E', 'F', 'G', 'E', 'H', 'H', 'H']\n" 64 | ] 65 | } 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "source": [ 71 | "nodes=set(temp+temp1)\n", 72 | "print(nodes)\n", 73 | "def A_star(graph,costs,open,closed,cur_node):\n", 74 | " if cur_node in open:\n", 75 | " open.remove(cur_node)\n", 76 | " closed.add(cur_node)\n", 77 | " for i in graph:\n", 78 | " if(i[0]==cur_node and costs[i[0]]+i[2]+i[3] < costs[i[1]]):\n", 79 | " open.add(i[1])\n", 80 | " costs[i[1]]=costs[i[0]]+i[2]+i[3]\n", 81 | " path[i[1]]=path[i[0]]+ '-->' + i[1]\n", 82 | " costs[cur_node]=999999\n", 83 | " small=min(costs, key=costs.get)\n", 84 | " if small not in closed:\n", 85 | " A_star(graph,costs,open,closed,small)\n", 86 | "costs=dict()\n", 87 | "path=dict()\n", 88 | "for i in nodes:\n", 89 | " costs[i]=9999999\n", 90 | " path[i]=' '\n" 91 | ], 92 | "metadata": { 93 | "id": "ctqtAToIilHJ", 94 | "colab": { 95 | "base_uri": "https://localhost:8080/" 96 | }, 97 | "outputId": "e51c14e1-f75a-436a-eaa4-fd32d1179bf6" 98 | }, 99 | "execution_count": 16, 100 | "outputs": [ 101 | { 102 | "output_type": "stream", 103 | "name": "stdout", 104 | "text": [ 105 | "{'H', 'F', 'B', 'D', 'E', 'G', 'A', 'C'}\n" 106 | ] 107 | } 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "source": [ 113 | "open=set()\n", 114 | "closed=set()\n", 115 | "start_node=input(\"Enter the start node:\")\n", 116 | "open.add(start_node)" 117 | ], 118 | "metadata": { 119 | "colab": { 120 | "base_uri": "https://localhost:8080/" 121 | }, 122 | "id": "Lmm1_Hdvmssc", 123 | "outputId": "8f408bfc-2a0c-44ba-bbc4-48a09a304e06" 124 | }, 125 | "execution_count": 25, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "Enter the start node:A\n" 132 | ] 133 | } 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "source": [ 139 | "path[start_node]=start_node\n", 140 | "costs[start_node]=0\n" 141 | ], 142 | "metadata": { 143 | "id": "giG-yy-JnZfH" 144 | }, 145 | "execution_count": 27, 146 | "outputs": [] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "source": [ 151 | "A_star(graph,costs,open,closed,start_node)\n", 152 | "goal_node=input(\"Enter the Goal node:\")\n", 153 | "print(\"Path with least cost is: \",path[goal_node])" 154 | ], 155 | "metadata": { 156 | "colab": { 157 | "base_uri": "https://localhost:8080/" 158 | }, 159 | "id": "bkX1xdwEnhfF", 160 | "outputId": "16a79dfc-5440-4bd2-bf1d-700dae3d88d1" 161 | }, 162 | "execution_count": 29, 163 | "outputs": [ 164 | { 165 | "output_type": "stream", 166 | "name": "stdout", 167 | "text": [ 168 | "Enter the Goal node:H\n", 169 | "Path with least cost is: A-->C-->G-->H\n" 170 | ] 171 | } 172 | ] 173 | } 174 | ] 175 | } -------------------------------------------------------------------------------- /NLP.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "source": [ 20 | "pip install nltk" 21 | ], 22 | "metadata": { 23 | "colab": { 24 | "base_uri": "https://localhost:8080/" 25 | }, 26 | "id": "O5qfIsU4okPy", 27 | "outputId": "507613ea-960c-427e-df05-4578564699d0" 28 | }, 29 | "execution_count": 22, 30 | "outputs": [ 31 | { 32 | "output_type": "stream", 33 | "name": "stdout", 34 | "text": [ 35 | "Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (3.9.1)\n", 36 | "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk) (8.1.7)\n", 37 | "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk) (1.4.2)\n", 38 | "Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk) (2024.9.11)\n", 39 | "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from nltk) (4.66.6)\n" 40 | ] 41 | } 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 42, 47 | "metadata": { 48 | "colab": { 49 | "base_uri": "https://localhost:8080/" 50 | }, 51 | "id": "sLLlRX3UmAaA", 52 | "outputId": "2b241742-9d88-4b73-c9cf-eb35256b9f6c" 53 | }, 54 | "outputs": [ 55 | { 56 | "output_type": "stream", 57 | "name": "stderr", 58 | "text": [ 59 | "[nltk_data] Downloading package wordnet to /root/nltk_data...\n", 60 | "[nltk_data] Package wordnet is already up-to-date!\n", 61 | "[nltk_data] Downloading package stopwords to /root/nltk_data...\n", 62 | "[nltk_data] Package stopwords is already up-to-date!\n", 63 | "[nltk_data] Downloading package omw-1.4 to /root/nltk_data...\n", 64 | "[nltk_data] Package omw-1.4 is already up-to-date!\n", 65 | "[nltk_data] Downloading package punkt_tab to /root/nltk_data...\n", 66 | "[nltk_data] Package punkt_tab is already up-to-date!\n", 67 | "[nltk_data] Downloading package averaged_perceptron_tagger_eng to\n", 68 | "[nltk_data] /root/nltk_data...\n", 69 | "[nltk_data] Unzipping taggers/averaged_perceptron_tagger_eng.zip.\n" 70 | ] 71 | }, 72 | { 73 | "output_type": "execute_result", 74 | "data": { 75 | "text/plain": [ 76 | "True" 77 | ] 78 | }, 79 | "metadata": {}, 80 | "execution_count": 42 81 | } 82 | ], 83 | "source": [ 84 | "import nltk\n", 85 | "nltk.download('wordnet')\n", 86 | "nltk.download('stopwords')\n", 87 | "nltk.download('omw-1.4')\n", 88 | "nltk.download('punkt_tab')\n", 89 | "nltk.download('averaged_perceptron_tagger_eng')\n" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "source": [ 95 | "text=\"Hello Mr. Seith, how are you doing today? The weather is great, and city is awesome. The sky is pinkish-blue. You shouldn\\'t eat cardboard\"" 96 | ], 97 | "metadata": { 98 | "id": "g7Tl9iMGmKvj" 99 | }, 100 | "execution_count": 19, 101 | "outputs": [] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "source": [ 106 | "sent=nltk.sent_tokenize(text)\n", 107 | "print(sent)" 108 | ], 109 | "metadata": { 110 | "colab": { 111 | "base_uri": "https://localhost:8080/" 112 | }, 113 | "id": "so0JjfQfnPTh", 114 | "outputId": "7a36b99e-dc3d-4c71-b909-d62d6a940b9d" 115 | }, 116 | "execution_count": 20, 117 | "outputs": [ 118 | { 119 | "output_type": "stream", 120 | "name": "stdout", 121 | "text": [ 122 | "['Hello Mr. Seith, how are you doing today?', 'The weather is great, and city is awesome.', 'The sky is pinkish-blue.', \"You shouldn't eat cardboard\"]\n" 123 | ] 124 | } 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "source": [ 130 | "import re\n", 131 | "#text='SaaaaMMM'\n", 132 | "print(text.lower())\n", 133 | "text=re.sub(r\"[^a-z\\'A-Z]\",\" \",text.lower())\n", 134 | "text" 135 | ], 136 | "metadata": { 137 | "colab": { 138 | "base_uri": "https://localhost:8080/", 139 | "height": 52 140 | }, 141 | "id": "32SJHuOdoJQg", 142 | "outputId": "18fd1496-64b5-4cc8-8009-217e3a36c5bb" 143 | }, 144 | "execution_count": 25, 145 | "outputs": [ 146 | { 147 | "output_type": "stream", 148 | "name": "stdout", 149 | "text": [ 150 | "hello mr seith how are you doing today the weather is great and city is awesome the sky is pinkish blue you shouldn't eat cardboard\n" 151 | ] 152 | }, 153 | { 154 | "output_type": "execute_result", 155 | "data": { 156 | "text/plain": [ 157 | "\"hello mr seith how are you doing today the weather is great and city is awesome the sky is pinkish blue you shouldn't eat cardboard\"" 158 | ], 159 | "application/vnd.google.colaboratory.intrinsic+json": { 160 | "type": "string" 161 | } 162 | }, 163 | "metadata": {}, 164 | "execution_count": 25 165 | } 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "source": [ 171 | "words=text.split()\n", 172 | "print(words)" 173 | ], 174 | "metadata": { 175 | "colab": { 176 | "base_uri": "https://localhost:8080/" 177 | }, 178 | "id": "kiROzWDBqF7h", 179 | "outputId": "4517a99a-9417-4793-934f-18501f9f7aae" 180 | }, 181 | "execution_count": 27, 182 | "outputs": [ 183 | { 184 | "output_type": "stream", 185 | "name": "stdout", 186 | "text": [ 187 | "['hello', 'mr', 'seith', 'how', 'are', 'you', 'doing', 'today', 'the', 'weather', 'is', 'great', 'and', 'city', 'is', 'awesome', 'the', 'sky', 'is', 'pinkish', 'blue', 'you', \"shouldn't\", 'eat', 'cardboard']\n" 188 | ] 189 | } 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "source": [ 195 | "from nltk.corpus import stopwords\n", 196 | "print(stopwords.words(\"english\"))" 197 | ], 198 | "metadata": { 199 | "colab": { 200 | "base_uri": "https://localhost:8080/" 201 | }, 202 | "id": "_mdHQaEkqNZY", 203 | "outputId": "299c3bb0-1c4d-4aa2-ac1a-d81c44798e54" 204 | }, 205 | "execution_count": 29, 206 | "outputs": [ 207 | { 208 | "output_type": "stream", 209 | "name": "stdout", 210 | "text": [ 211 | "['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', \"you're\", \"you've\", \"you'll\", \"you'd\", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', \"she's\", 'her', 'hers', 'herself', 'it', \"it's\", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', \"that'll\", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', \"don't\", 'should', \"should've\", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', \"aren't\", 'couldn', \"couldn't\", 'didn', \"didn't\", 'doesn', \"doesn't\", 'hadn', \"hadn't\", 'hasn', \"hasn't\", 'haven', \"haven't\", 'isn', \"isn't\", 'ma', 'mightn', \"mightn't\", 'mustn', \"mustn't\", 'needn', \"needn't\", 'shan', \"shan't\", 'shouldn', \"shouldn't\", 'wasn', \"wasn't\", 'weren', \"weren't\", 'won', \"won't\", 'wouldn', \"wouldn't\"]\n" 212 | ] 213 | } 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "source": [ 219 | "words=[w for w in words if w not in stopwords.words(\"english\")]\n", 220 | "print(words)" 221 | ], 222 | "metadata": { 223 | "colab": { 224 | "base_uri": "https://localhost:8080/" 225 | }, 226 | "id": "8eJS2YGbrPnR", 227 | "outputId": "d634d462-6b9b-47be-ff4e-56101a957f06" 228 | }, 229 | "execution_count": 33, 230 | "outputs": [ 231 | { 232 | "output_type": "stream", 233 | "name": "stdout", 234 | "text": [ 235 | "['hello', 'mr', 'seith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 236 | ] 237 | } 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "source": [ 243 | "#from nltk.stem.porter import PorterStemmer\n", 244 | "#stemmed=[PorterStemmer().stem(w) for w in words]\n", 245 | "#print(stemmed)" 246 | ], 247 | "metadata": { 248 | "id": "A6xFqv9Zuxa5" 249 | }, 250 | "execution_count": 37, 251 | "outputs": [] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "source": [ 256 | "from nltk.stem.wordnet import WordNetLemmatizer\n", 257 | "lemmed=[WordNetLemmatizer().lemmatize(w) for w in words]\n", 258 | "print(lemmed)" 259 | ], 260 | "metadata": { 261 | "colab": { 262 | "base_uri": "https://localhost:8080/" 263 | }, 264 | "id": "fc9hcQmI0KFi", 265 | "outputId": "2921ab85-1cc1-4caf-8062-28067c04b5ee" 266 | }, 267 | "execution_count": 39, 268 | "outputs": [ 269 | { 270 | "output_type": "stream", 271 | "name": "stdout", 272 | "text": [ 273 | "['hello', 'mr', 'seith', 'today', 'weather', 'great', 'city', 'awesome', 'sky', 'pinkish', 'blue', 'eat', 'cardboard']\n" 274 | ] 275 | } 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "source": [ 281 | "from nltk import pos_tag,RegexpParser\n", 282 | "tagged=pos_tag(lemmed)\n", 283 | "print(tagged)\n", 284 | "for i, (word,tag) in enumerate(tagged):\n", 285 | " if word=='weather':\n", 286 | " tagged[i]=(word, \"NN\")\n", 287 | " if word=='eat':\n", 288 | " tagged[i]=(word, 'VB')\n", 289 | "chunker = RegexpParser(\"\"\"\n", 290 | "NP:{}\n", 291 | "P:{}\n", 292 | "V:{}\n", 293 | "PP:{}\n", 294 | "VP:{}\n", 295 | "\"\"\")\n", 296 | "output=chunker.parse(tagged)\n", 297 | "print(\"After extracting\",output)" 298 | ], 299 | "metadata": { 300 | "colab": { 301 | "base_uri": "https://localhost:8080/" 302 | }, 303 | "id": "2jGYAEXL1U-S", 304 | "outputId": "c0fb12ce-be8e-41d3-e70e-b0ab7cc83ad0" 305 | }, 306 | "execution_count": 47, 307 | "outputs": [ 308 | { 309 | "output_type": "stream", 310 | "name": "stdout", 311 | "text": [ 312 | "[('hello', 'NN'), ('mr', 'NN'), ('seith', 'NN'), ('today', 'NN'), ('weather', 'VBP'), ('great', 'JJ'), ('city', 'NN'), ('awesome', 'VBP'), ('sky', 'JJ'), ('pinkish', 'JJ'), ('blue', 'NN'), ('eat', 'NN'), ('cardboard', 'NN')]\n", 313 | "After extracting (S\n", 314 | " hello/NN\n", 315 | " mr/NN\n", 316 | " seith/NN\n", 317 | " today/NN\n", 318 | " weather/NN\n", 319 | " great/JJ\n", 320 | " city/NN\n", 321 | " awesome/VBP\n", 322 | " sky/JJ\n", 323 | " pinkish/JJ\n", 324 | " blue/NN\n", 325 | " eat/VB\n", 326 | " cardboard/NN)\n" 327 | ] 328 | } 329 | ] 330 | } 331 | ] 332 | } -------------------------------------------------------------------------------- /Medical Expert System/greetings.py: -------------------------------------------------------------------------------- 1 | from experta import * 2 | 3 | class Greetings(KnowledgeEngine): 4 | 5 | def __init__(self, symptom_map, if_not_matched, get_treatments, get_details): 6 | self.symptom_map = symptom_map 7 | self.if_not_matched = if_not_matched 8 | self.get_details = get_details 9 | self.get_treatments = get_treatments 10 | KnowledgeEngine.__init__(self) 11 | 12 | #code giving instructions on how to use the Expert System 13 | @DefFacts() 14 | def _initial_action(self): 15 | print("") 16 | print("This is a knowledge based bot to diagnose diseases") 17 | print("") 18 | print("Do you feel any of the following symptoms?") 19 | print("Reply high or low or no") 20 | print("") 21 | yield Fact(action="find_disease") 22 | 23 | #taking various input from user 24 | @Rule(Fact(action="find_disease"), NOT(Fact(headache=W())), salience=4) 25 | def symptom_0(self): 26 | self.declare(Fact(headache=input("headache: "))) 27 | 28 | @Rule(Fact(action="find_disease"), NOT(Fact(back_pain=W())), salience=1) 29 | def symptom_1(self): 30 | self.declare(Fact(back_pain=input("back pain: "))) 31 | 32 | @Rule(Fact(action="find_disease"), NOT(Fact(chest_pain=W())), salience=1) 33 | def symptom_2(self): 34 | self.declare(Fact(chest_pain=input("chest pain: "))) 35 | 36 | @Rule(Fact(action="find_disease"), NOT(Fact(cough=W())), salience=3) 37 | def symptom_3(self): 38 | self.declare(Fact(cough=input("cough: "))) 39 | 40 | @Rule(Fact(action="find_disease"), NOT(Fact(fainting=W())), salience=1) 41 | def symptom_4(self): 42 | self.declare(Fact(fainting=input("fainting: "))) 43 | 44 | @Rule(Fact(action="find_disease"), NOT(Fact(fatigue=W())), salience=1) 45 | def symptom_5(self): 46 | self.declare(Fact(fatigue=input("fatigue: "))) 47 | 48 | @Rule(Fact(action="find_disease"), NOT(Fact(sunken_eyes=W())), salience=1) 49 | def symptom_6(self): 50 | self.declare(Fact(sunken_eyes=input("sunken eyes: "))) 51 | 52 | @Rule(Fact(action="find_disease"), NOT(Fact(low_body_temp=W())), salience=1) 53 | def symptom_7(self): 54 | self.declare(Fact(low_body_temp=input("low body temperature: "))) 55 | 56 | @Rule(Fact(action="find_disease"), NOT(Fact(restlessness=W())), salience=1) 57 | def symptom_8(self): 58 | self.declare(Fact(restlessness=input("restlessness: "))) 59 | 60 | @Rule(Fact(action="find_disease"), NOT(Fact(sore_throat=W())), salience=1) 61 | def symptom_9(self): 62 | self.declare(Fact(sore_throat=input("sore throat: "))) 63 | 64 | @Rule(Fact(action="find_disease"), NOT(Fact(fever=W())), salience=1) 65 | def symptom_10(self): 66 | self.declare(Fact(fever=input("fever: "))) 67 | 68 | @Rule(Fact(action="find_disease"), NOT(Fact(nausea=W())), salience=1) 69 | def symptom_11(self): 70 | self.declare(Fact(nausea=input("nausea: "))) 71 | 72 | @Rule(Fact(action="find_disease"), NOT(Fact(blurred_vision=W())), salience=1) 73 | def symptom_12(self): 74 | self.declare(Fact(blurred_vision=input("blurred_vision: "))) 75 | 76 | #different rules checking for each disease match 77 | @Rule( 78 | Fact(action="find_disease"), 79 | Fact(headache="no"), 80 | Fact(back_pain="no"), 81 | Fact(chest_pain="no"), 82 | Fact(cough="no"), 83 | Fact(fainting="no"), 84 | Fact(sore_throat="no"), 85 | Fact(fatigue="high"), 86 | Fact(restlessness="no"), 87 | Fact(low_body_temp="no"), 88 | Fact(fever="low"), 89 | Fact(sunken_eyes="no"), 90 | Fact(nausea="high"), 91 | Fact(blurred_vision="no"), 92 | ) 93 | def disease_0(self): 94 | self.declare(Fact(disease="Jaundice")) 95 | 96 | @Rule( 97 | Fact(action="find_disease"), 98 | Fact(headache="no"), 99 | Fact(back_pain="no"), 100 | Fact(chest_pain="no"), 101 | Fact(cough="no"), 102 | Fact(fainting="no"), 103 | Fact(sore_throat="no"), 104 | Fact(fatigue="no"), 105 | Fact(restlessness="high"), 106 | Fact(low_body_temp="no"), 107 | Fact(fever="no"), 108 | Fact(sunken_eyes="no"), 109 | Fact(nausea="no"), 110 | Fact(blurred_vision="no"), 111 | ) 112 | def disease_1(self): 113 | self.declare(Fact(disease="Alzheimers")) 114 | 115 | @Rule( 116 | Fact(action="find_disease"), 117 | Fact(headache="no"), 118 | Fact(back_pain="high"), 119 | Fact(chest_pain="no"), 120 | Fact(cough="no"), 121 | Fact(fainting="no"), 122 | Fact(sore_throat="no"), 123 | Fact(fatigue="low"), 124 | Fact(restlessness="no"), 125 | Fact(low_body_temp="no"), 126 | Fact(fever="no"), 127 | Fact(sunken_eyes="no"), 128 | Fact(nausea="no"), 129 | Fact(blurred_vision="no"), 130 | ) 131 | def disease_2(self): 132 | self.declare(Fact(disease="Arthritis")) 133 | 134 | @Rule( 135 | Fact(action="find_disease"), 136 | Fact(headache="no"), 137 | Fact(back_pain="no"), 138 | Fact(chest_pain="high"), 139 | Fact(cough="low"), 140 | Fact(fainting="no"), 141 | Fact(sore_throat="no"), 142 | Fact(fatigue="no"), 143 | Fact(restlessness="no"), 144 | Fact(low_body_temp="no"), 145 | Fact(fever="high"), 146 | Fact(sunken_eyes="no"), 147 | Fact(nausea="no"), 148 | Fact(blurred_vision="no"), 149 | ) 150 | def disease_3(self): 151 | self.declare(Fact(disease="Tuberculosis")) 152 | 153 | @Rule( 154 | Fact(action="find_disease"), 155 | Fact(headache="no"), 156 | Fact(back_pain="no"), 157 | Fact(chest_pain="high"), 158 | Fact(cough="high"), 159 | Fact(fainting="no"), 160 | Fact(sore_throat="no"), 161 | Fact(fatigue="no"), 162 | Fact(restlessness="low"), 163 | Fact(low_body_temp="no"), 164 | Fact(fever="no"), 165 | Fact(sunken_eyes="no"), 166 | Fact(nausea="no"), 167 | Fact(blurred_vision="no"), 168 | ) 169 | def disease_4(self): 170 | self.declare(Fact(disease="Asthma")) 171 | 172 | @Rule( 173 | Fact(action="find_disease"), 174 | Fact(headache="low"), 175 | Fact(back_pain="no"), 176 | Fact(chest_pain="no"), 177 | Fact(cough="high"), 178 | Fact(fainting="no"), 179 | Fact(sore_throat="high"), 180 | Fact(fatigue="no"), 181 | Fact(restlessness="no"), 182 | Fact(low_body_temp="no"), 183 | Fact(fever="low"), 184 | Fact(sunken_eyes="no"), 185 | Fact(nausea="no"), 186 | Fact(blurred_vision="no"), 187 | ) 188 | def disease_5(self): 189 | self.declare(Fact(disease="Sinusitis")) 190 | 191 | @Rule( 192 | Fact(action="find_disease"), 193 | Fact(headache="no"), 194 | Fact(back_pain="no"), 195 | Fact(chest_pain="no"), 196 | Fact(cough="no"), 197 | Fact(fainting="no"), 198 | Fact(sore_throat="no"), 199 | Fact(fatigue="low"), 200 | Fact(restlessness="no"), 201 | Fact(low_body_temp="no"), 202 | Fact(fever="no"), 203 | Fact(sunken_eyes="no"), 204 | Fact(nausea="no"), 205 | Fact(blurred_vision="no"), 206 | ) 207 | def disease_6(self): 208 | self.declare(Fact(disease="Epilepsy")) 209 | 210 | @Rule( 211 | Fact(action="find_disease"), 212 | Fact(headache="no"), 213 | Fact(back_pain="no"), 214 | Fact(chest_pain="high"), 215 | Fact(cough="no"), 216 | Fact(fainting="no"), 217 | Fact(sore_throat="no"), 218 | Fact(fatigue="no"), 219 | Fact(restlessness="no"), 220 | Fact(low_body_temp="no"), 221 | Fact(fever="no"), 222 | Fact(sunken_eyes="no"), 223 | Fact(nausea="high"), 224 | Fact(blurred_vision="no"), 225 | ) 226 | def disease_7(self): 227 | self.declare(Fact(disease="Heart Disease")) 228 | 229 | @Rule( 230 | Fact(action="find_disease"), 231 | Fact(headache="no"), 232 | Fact(back_pain="no"), 233 | Fact(chest_pain="no"), 234 | Fact(cough="no"), 235 | Fact(fainting="no"), 236 | Fact(sore_throat="no"), 237 | Fact(fatigue="high"), 238 | Fact(restlessness="no"), 239 | Fact(low_body_temp="no"), 240 | Fact(fever="no"), 241 | Fact(sunken_eyes="no"), 242 | Fact(nausea="low"), 243 | Fact(blurred_vision="low"), 244 | ) 245 | def disease_8(self): 246 | self.declare(Fact(disease="Diabetes")) 247 | 248 | @Rule( 249 | Fact(action="find_disease"), 250 | Fact(headache="low"), 251 | Fact(back_pain="no"), 252 | Fact(chest_pain="no"), 253 | Fact(cough="no"), 254 | Fact(fainting="no"), 255 | Fact(sore_throat="no"), 256 | Fact(fatigue="no"), 257 | Fact(restlessness="no"), 258 | Fact(low_body_temp="no"), 259 | Fact(fever="no"), 260 | Fact(sunken_eyes="no"), 261 | Fact(nausea="high"), 262 | Fact(blurred_vision="low"), 263 | ) 264 | def disease_9(self): 265 | self.declare(Fact(disease="Glaucoma")) 266 | 267 | @Rule( 268 | Fact(action="find_disease"), 269 | Fact(headache="no"), 270 | Fact(back_pain="no"), 271 | Fact(chest_pain="no"), 272 | Fact(cough="no"), 273 | Fact(fainting="no"), 274 | Fact(sore_throat="no"), 275 | Fact(fatigue="high"), 276 | Fact(restlessness="no"), 277 | Fact(low_body_temp="no"), 278 | Fact(fever="no"), 279 | Fact(sunken_eyes="no"), 280 | Fact(nausea="low"), 281 | Fact(blurred_vision="no"), 282 | ) 283 | def disease_10(self): 284 | self.declare(Fact(disease="Hyperthyroidism")) 285 | 286 | @Rule( 287 | Fact(action="find_disease"), 288 | Fact(headache="high"), 289 | Fact(back_pain="no"), 290 | Fact(chest_pain="no"), 291 | Fact(cough="no"), 292 | Fact(fainting="no"), 293 | Fact(sore_throat="no"), 294 | Fact(fatigue="no"), 295 | Fact(restlessness="no"), 296 | Fact(low_body_temp="no"), 297 | Fact(fever="high"), 298 | Fact(sunken_eyes="no"), 299 | Fact(nausea="high"), 300 | Fact(blurred_vision="no"), 301 | ) 302 | def disease_11(self): 303 | self.declare(Fact(disease="Heat Stroke")) 304 | 305 | @Rule( 306 | Fact(action="find_disease"), 307 | Fact(headache="no"), 308 | Fact(back_pain="no"), 309 | Fact(chest_pain="no"), 310 | Fact(cough="no"), 311 | Fact(fainting="yes"), 312 | Fact(sore_throat="no"), 313 | Fact(fatigue="no"), 314 | Fact(restlessness="no"), 315 | Fact(low_body_temp="high"), 316 | Fact(fever="no"), 317 | Fact(sunken_eyes="no"), 318 | Fact(nausea="no"), 319 | Fact(blurred_vision="no"), 320 | ) 321 | def disease_12(self): 322 | self.declare(Fact(disease="Hypothermia")) 323 | 324 | @Rule( 325 | Fact(action="find_disease"), 326 | Fact(headache="high"), 327 | Fact(back_pain="no"), 328 | Fact(chest_pain="high"), 329 | Fact(cough="high"), 330 | Fact(fainting="no"), 331 | Fact(sore_throat="high"), 332 | Fact(fatigue="high"), 333 | Fact(restlessness="no"), 334 | Fact(low_body_temp="no"), 335 | Fact(fever="high"), 336 | Fact(sunken_eyes="no"), 337 | Fact(nausea="no"), 338 | Fact(blurred_vision="no"), 339 | ) 340 | def disease_13(self): 341 | self.declare(Fact(disease="Coronavirus")) 342 | 343 | #when the user's input doesn't match any disease in the knowledge base 344 | @Rule(Fact(action="find_disease"), Fact(disease=MATCH.disease), salience=-998) 345 | def disease(self, disease): 346 | print("") 347 | id_disease = disease 348 | disease_details = self.get_details(id_disease) 349 | treatments = self.get_treatments(id_disease) 350 | print("") 351 | print("Your symptoms match %s\n" % (id_disease)) 352 | print("A short description of the disease is given below :\n") 353 | print(disease_details + "\n") 354 | print( 355 | "The common medications and procedures suggested by other real doctors are: \n" 356 | ) 357 | print(treatments + "\n") 358 | 359 | @Rule( 360 | Fact(action="find_disease"), 361 | Fact(headache=MATCH.headache), 362 | Fact(back_pain=MATCH.back_pain), 363 | Fact(chest_pain=MATCH.chest_pain), 364 | Fact(cough=MATCH.cough), 365 | Fact(fainting=MATCH.fainting), 366 | Fact(sore_throat=MATCH.sore_throat), 367 | Fact(fatigue=MATCH.fatigue), 368 | Fact(low_body_temp=MATCH.low_body_temp), 369 | Fact(restlessness=MATCH.restlessness), 370 | Fact(fever=MATCH.fever), 371 | Fact(sunken_eyes=MATCH.sunken_eyes), 372 | Fact(nausea=MATCH.nausea), 373 | Fact(blurred_vision=MATCH.blurred_vision), 374 | NOT(Fact(disease=MATCH.disease)), 375 | salience=-999 376 | ) 377 | def not_matched( 378 | self, 379 | headache, 380 | back_pain, 381 | chest_pain, 382 | cough, 383 | fainting, 384 | sore_throat, 385 | fatigue, 386 | restlessness, 387 | low_body_temp, 388 | fever, 389 | sunken_eyes, 390 | nausea, 391 | blurred_vision, 392 | ): 393 | print("\nThe bot did not find any diseases that match your exact symptoms.") 394 | lis = [ 395 | headache, 396 | back_pain, 397 | chest_pain, 398 | cough, 399 | fainting, 400 | sore_throat, 401 | fatigue, 402 | restlessness, 403 | low_body_temp, 404 | fever, 405 | sunken_eyes, 406 | nausea, 407 | blurred_vision, 408 | ] 409 | max_count = 0 410 | max_disease = "" 411 | for key, val in self.symptom_map.items(): 412 | count = 0 413 | temp_list = eval(key) 414 | for j in range(0, len(lis)): 415 | if temp_list[j] == lis[j] and (lis[j] == "high" or lis[j] == "low" or lis[j] == "yes"): 416 | count = count + 1 417 | if count > max_count: 418 | max_count = count 419 | max_disease = val 420 | if max_disease != "": 421 | self.if_not_matched(max_disease) --------------------------------------------------------------------------------