Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

St Cloud State University Logic Inferencing Program Python Code Project

St Cloud State University Logic Inferencing Program Python Code Project

St Cloud State University Logic Inferencing Program Python Code Project

Question Description

I’m working on a Python question and need a sample draft to help me understand better.

Please write a logic inferencing program using Python which can handle family relationship. The input files are (t60,t61,t69) given below. Each input file contains lines of facts (each ended with period “.”) of family relationships and lines of questions (each ended with question mark “?”) about family relationships in any order. The questions should be answered based on all “previous” facts in the same file. The facts always have the format “<person1>’s <relation> is <person2>”, e.g., “Martha’s husband is John”. The questions always have the format “Who is <person>’s <relation>?”, e.g., “Who is John’s father?” Since some names can be either female or male, so you cannot infer the gender of a person by her/his name, instead, you need to infer gender by the family relationship. All the possible relationships are mother, father, husband, wife, son, daughter, brother, and sister. Assume each one has at most 1 mother and/or 1 father, and each one has at most one spouse (husband or wife), but one can have any number of siblings.

Here is the pseudocode for the functions. For each test case, call relation(f), and relation() needs to call propagate before answering every query.

genders = {

‘mother’:’F’, ‘father’:’M’, ‘son’:’M’, ‘daughter’:’F’, ‘brother’:’M’,

‘sister’:’F’, ‘husband’:’M’, ‘wife’:’F’

}

reverses = {

‘mother’:’child’, ‘father’:’child’, ‘son’:’parent’, ‘daughter’:’parent’,

‘brother’:’sibling’, ‘sister’:’sibling’, ‘husband’:’spouse’, ‘wife’:’spouse’

}

supers = {

‘mother’:’parent’, ‘father’:’parent’, ‘son’:’child’, ‘daughter’:’child’,

‘brother’:’sibling’, ‘sister’:’sibling’, ‘husband’:’spouse’, ‘wife’:’spouse’

}

def propogate(hash):

for all person, add each person’s child’s siblings as the person’s children

for all person, add each person’s spouse’s children as the person’s children

for all person, add each person’s parent’s spouse as a person’s parent

for all person, add each person’s sibling’s parents as a person’s parent

def relation(f):

hash = {}

hash[“gender”] = {}

hash[“parent”] = {}

hash[“spouse”] = {}

hash[“child”] = {}

hash[“sibling”] = {}

print(f, ‘:’)

for each line from input file f:

if line ends with ‘.’: # handle fact

add ‘super’ relationship (refer supers dict above)

check if conflict genders, if no, set gender, otherwise, return error

handle relationship of wife/husband by checking genders and

set genders for spouse

add ‘reverse’ relationship (refer reverses dict above)

elif line ends with ‘?’: # handle query

call propogate(hash)

if supers[relationship] of the queried person match the gender:

output answers

else:

output ‘Unknown’

else:

return(“ERROR”)

else:

return(“ERROR”)

The t69 is an illegal test data, so you need report error and handle the next file is exists. Both t60.dat and t61.dat is legal tests, and t61.dat also test for whitespace convention. For t60.dat, you should answer the first questions with “Martha” and the second question with “Edward”. For t60.dat, you should answer “Martha” and “Unknown”.

t60

Edward’s son is David.

John’s daughter is Mary.

Martha’s husband is John.

Mary’s sister is Catherine.

Who is Catherine’s mother?

David’s brother is John.

Edward’s wife is Jennifer.

Who is John’s father?


t 61

Edward’s son is David.

John’s daughter is Mary.

Martha’s husband is John .

Mary’s sister is Catherine.

Who is Catherine’s mother ?

Edward’s wife is Jennifer.

Who is John’s father?

t69

123 Edward’s son is David.

John’s daughter is Mary. Martha’s husband is John.

Mary’s uncle Catherine.

Catherine’s mother?

David’s brother is John.

Edward’s wife is Jennifer.

Who is John’s father?

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20