Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

CSE3056

KNOWLEDGE REPRESENTATION AND REASONING

FAMILY TREE GENERATOR

Team Members:
Gautam Manoj 20BRS1242
Harish Kumar Saravanan 20BRS1249
Mudit Arukia 20BRS1131
ABSTRACT
The family tree generator program is an innovative application that utilizes natural
language processing (NLP) techniques to create family trees automatically. The
program allows users to input information about their family members using natural
language, such as names, relationships, and dates of birth, without needing to follow
any specific formatting rules or templates. The NLP algorithms analyze the input text
and extract relevant information to create an accurate and complete family tree.

The program also incorporates advanced features, such as the ability to recognize
synonyms, misspellings, and alternative name forms, and to deduce relationships
based on contextual clues. Additionally, the program can handle complex family
structures, including multiple marriages, step-children, and adoptions, and generate
visually appealing and interactive family trees that can be shared and printed.

The family tree generator program is a valuable tool for individuals and genealogists
who want to create a comprehensive and detailed family tree quickly and easily. By
leveraging the power of NLP, the program eliminates the need for tedious data entry
and simplifies the process of building a family tree, making it accessible to a broader
audience.

SCENARIO 1

Social Media and Personalised Ads:


There are several ways that a family tree generator could be useful in the social
media industry. For example:

Family Connections: Social media platforms can use a family tree generator to help
individuals find and connect with family members they may have lost touch with or
didn't know existed. By inputting family member names and basic information, the
program can generate a family tree and suggest potential connections for the user to
reach out to.

Ancestry Testing: Social media platforms can offer users a more personalized
experience by using a family tree generator to integrate ancestry testing results into
a user's family tree. This can help individuals better understand their family
background and potentially connect with distant relatives they didn't know existed.

User Profile Customization: Social media platforms can use a family tree generator to
customize user profiles based on their family history. For example, if a user's family
has a history of military service, the platform could suggest groups or pages related
to the military. This would make the user's experience more personalized and
relevant to their interests.
Ad Targeting: Social media platforms could use this information to provide
personalized ads for products and services that are relevant to a user's family
history.
We can classify the scenario according to the environment states, action parameters,
and input values in the following way:
Environment States: The environment states in the social media and personalized
ads scenario would include the current user data for the social media platform, such
as user profiles, posts, likes, shares, comments, and other interactions with the
platform. It would also include the current ad inventory available to the platform,
including ad content, targeting parameters, and other relevant ad data.

Different States: The different states in the social media and personalized ads
scenario would represent different scenarios or situations that the system could
reason about based on the available user and ad data. For example, the system
could reason about which ads are most likely to be relevant or interesting to a
particular user, or it could reason about which ad targeting parameters are most
effective for a particular type of product or service.

Input Values: The input values for the social media and personalized ads scenario
would include the user data for each individual user, including demographic
information, interests, preferences, and other relevant data. It would also include
the ad data for each individual ad, including ad content, targeting parameters, and
other relevant data.

Action Parameters: The action parameters in the social media and personalized ads
scenario would depend on the specific actions or decisions being made by the
system. For example, if the system is selecting ads to show to a particular user, the
action parameters might include the specific ad content and targeting parameters
that are most likely to be effective for that user. If the system is optimizing ad
targeting parameters for a particular type of product or service, the action
parameters might include specific recommendations for targeting parameters based
on user data and ad performance metrics.

In summary, a family tree generator could be a valuable tool in the social media
industry for connecting individuals with family members, integrating ancestry testing
results, customizing user profiles, and potentially providing more personalized ads.
However, it's important to approach the use of personal information with care and
ethical considerations to maintain trust and transparency with users.

SCENARIO 2:

Medical History:
The medical history scenario involves using a family tree generator system to help
individuals track their medical history and identify patterns of health issues within
their family. This can be especially useful for individuals with a family history of
certain diseases or conditions, as it can help them make informed decisions about
their health and potentially take steps to prevent or manage these conditions.

In this scenario, the family tree generator system represents the relationships
between family members and their medical history, including any diagnoses,
treatments, medications, and other relevant information. The system can use
knowledge representation techniques to model this information in a structured
format, such as a graph or database, that can be easily queried and analyzed.

Using reasoning techniques, the system can then analyze the medical history data to
identify patterns and trends within the family, such as a higher prevalence of certain
diseases or conditions among certain branches or generations. This information can
then be used to inform medical decision-making, such as screening for certain
conditions or taking preventative measures to reduce the risk of developing a
particular disease.

For example, if a family tree generator system identifies that several members of a
family have a history of heart disease, the system can use reasoning techniques to
suggest that other family members may be at increased risk for heart disease and
should consider lifestyle changes, such as diet and exercise, to reduce their risk.

In addition to individual health management, the medical history scenario can also
be useful for medical research and public health initiatives. By analyzing patterns and
trends within families, researchers can gain insights into the genetic and
environmental factors that contribute to certain diseases and develop targeted
interventions and treatments. Public health initiatives can also use family history
information to identify at-risk populations and develop targeted education and
prevention programs.

Overall, the medical history scenario demonstrates the potential for family tree
generator systems to contribute to personalized medicine and public health by using
knowledge representation and reasoning techniques to identify patterns and trends
within family medical histories.

Environment States: The environment states in the medical history scenario would
include the current medical history data for the family members being represented.
This data would include information such as diagnoses, treatments, medications, and
other relevant medical information for each family member.

Different States: The different states in the medical history scenario would represent
different scenarios or situations that the system could reason about based on the
available medical history data. For example, the system could reason about the risk
of developing certain diseases or conditions based on family history data, or it could
reason about the effectiveness of different treatments or medications based on the
medical history data.
Input Values: The input values for the medical history scenario would include the
medical history data for each family member, as well as any additional information
or data that could be relevant for the system to reason about. This could include
demographic information, lifestyle factors, and other medical data beyond the
immediate family.

Action Parameters: The action parameters in the medical history scenario would
depend on the specific actions or decisions being made by the system. For example,
if the system is recommending lifestyle changes to reduce the risk of a certain
disease, the action parameters might include specific recommendations for diet and
exercise. If the system is identifying potential genetic risk factors, the action
parameters might include recommendations for genetic testing or counseling.

Overall, the medical history scenario involves using knowledge representation and
reasoning techniques to analyze medical history data and make informed decisions
about health management and treatment. The different components of the scenario
can be classified in terms of environment states, different states, input values, and
action parameters to help organize and conceptualize the problem.

SCENARIO 3:

Legal Matters:
The legal matters scenario involves using a family tree generator system to establish
family relationships and identify relevant family members in legal proceedings. This
can be particularly useful in cases involving inheritance disputes, custody battles, or
other situations where family relationships are important.

In this scenario, the family tree generator system represents the relationships
between family members, including parents, siblings, grandparents, aunts, uncles,
cousins, and other relatives. The system can use knowledge representation
techniques to model this information in a structured format, such as a graph or
database, that can be easily queried and analyzed.

Using reasoning techniques, the system can then analyze the family relationship data
to identify relevant family members in legal proceedings. For example, if a will is
being contested and the validity of the deceased person's relationship with a
particular family member is in question, the family tree generator system can
provide evidence to establish or refute that relationship.

Similarly, in a custody battle, the family tree generator system can be used to
identify the relevant family members, including parents, siblings, and other close
relatives, and provide evidence of their relationships to the child in question. This
can help the court make informed decisions about custody and visitation
arrangements.

In addition to legal proceedings, the family tree generator system can also be useful
for estate planning and inheritance management. By identifying relevant family
members and their relationships, the system can help ensure that all relevant parties
are included in the estate planning process and that inheritance is distributed
according to the deceased person's wishes.

Overall, the legal matters scenario demonstrates the potential for family tree
generator systems to contribute to legal proceedings and estate planning by using
knowledge representation and reasoning techniques to establish family relationships
and identify relevant family members.

Environment States: The environment states in the legal matters scenario would
include the available legal data for the case, including legal documents, court orders,
evidence, and other relevant information. It would also include the family
relationship data available in the family tree generator system, including family
members, their relationships, and other relevant information.

Different States: The different states in the legal matters scenario would represent
different scenarios or situations that the system could reason about based on the
available legal and family relationship data. For example, the system could reason
about the validity of a family relationship in a will dispute, or it could reason about
the relevant family members in a custody battle.

Input Values: The input values for the legal matters scenario would include the legal
data for each individual case, including legal documents, court orders, evidence, and
other relevant information. It would also include the family relationship data for
each individual case, including family members, their relationships, and other
relevant information.

Action Parameters: The action parameters in the legal matters scenario would
depend on the specific actions or decisions being made by the system. For example,
if the system is identifying relevant family members in a legal case, the action
parameters might include the specific family members and their relationships to the
case. If the system is analyzing the validity of a family relationship in a will dispute,
the action parameters might include recommendations for further investigation or
legal action.
SCENARIO 4

Genealogy Research
Genealogy research is the process of tracing an individual's family history and
identifying their ancestors, descendants, and familial relationships. This process can
involve collecting and analyzing historical records and documents, as well as using
various tools and techniques to build out a graphical representation of the family
tree. A family tree generator system using knowledge representation and reasoning
could help support the genealogy research process by automating some of the more
time-consuming and complex tasks.

In the genealogy research scenario, the system would first need to collect data from
various historical records and genealogy resources. This could involve searching
through census data, birth and death certificates, marriage licenses, wills, and other
legal and historical documents to gather information about individuals and their
familial relationships. The system would need to organize this data in a meaningful
way, identifying relevant individuals and relationships and storing the information in
a database or other data structure.

Next, the system would use knowledge representation and reasoning techniques to
analyze the data and identify potential familial relationships. This could involve using
logical inference to make deductions about the relationships between individuals
based on the available data. For example, the system could use information about an
individual's birth and death dates to infer the birth and death dates of their parents
or children. The system could also use information about familial surnames or
geographic locations to identify potential relatives or ancestors.

Once the system has identified potential familial relationships, it would construct a
graphical representation of the family tree based on the available data. The system
could use different visualization techniques to display the family tree in a meaningful
and easy-to-understand way. For example, the system could display the family tree
as a hierarchical tree structure or as a timeline.

Throughout the genealogy research process, the system could also provide users
with suggestions for further research based on the available data. For example, if the
system identified a gap in the family tree data, it could suggest searching for
additional records or conducting further research to fill in the missing information.
The system could also help users understand any inconsistencies or conflicts in the
data and provide suggestions for resolving them.

Overall, a family tree generator system using knowledge representation and


reasoning could help make the genealogy research process more efficient and
accurate, allowing users to easily trace their family history and identify familial
relationships.

Environment States: The environment states in this scenario would include historical
records and documents, such as census data, birth and death certificates, marriage
licenses, and wills.
Different States: The different states in this scenario would represent different
stages of the research process, such as data collection, data analysis, and building
out the family tree.

Input Values: The input values for this scenario would include data from historical
records and documents, as well as user input and preferences such as research goals
and the level of detail desired in the family tree.

Action Parameters: The action parameters for this scenario would include the
specific operations the system can perform to support the research process, such as
searching historical records, building out the family tree, and suggesting potential
familial relationships based on the available data.

SCENARIO 5

Inheritance Planning
Inheritance planning is the process of preparing for the transfer of an individual's
assets to their beneficiaries after their death. The goal of inheritance planning is to
ensure that an individual's assets are distributed according to their wishes, while
minimizing the impact of taxes and other expenses on their estate. A knowledge
representation and reasoning system can be used to assist with the inheritance
planning process.

The inheritance planning scenario typically involves three main stages: asset
identification, estate planning, and estate administration.

In the asset identification stage, the system would collect information about an
individual's assets, including real estate, investments, bank accounts, retirement
accounts, and personal property. The system could use various sources to collect this
information, such as tax records, financial statements, and legal documents.

In the estate planning stage, the system would use knowledge representation and
reasoning techniques to help the individual determine how they would like their
assets distributed after their death. The system could assist with the creation of a
will or trust, providing guidance on the tax implications of various inheritance
planning strategies. For example, the system could help the individual determine
whether to make charitable donations, create a trust for their children, or take
advantage of various tax exemptions.

In the estate administration stage, the system would help the executor of the estate
manage the distribution of the assets according to the individual's wishes. The
system could help with the valuation of the assets, tracking the status of the
distribution, and ensuring that any necessary legal requirements are met.

Throughout the inheritance planning process, the knowledge representation and


reasoning system could also help ensure that the individual's wishes are carried out
accurately. For example, the system could help identify potential conflicts in the
inheritance plan, such as multiple beneficiaries claiming the same asset, and provide
guidance on how to resolve these conflicts.
In summary, a knowledge representation and reasoning system can be used to assist
with the inheritance planning process, helping individuals to identify their assets,
plan their estate, and administer their assets after their death. The system can
provide guidance on inheritance planning strategies, identify potential conflicts, and
ensure that the individual's wishes are carried out accurately.

Environment states: The environment states for inheritance planning include an


individual's assets, their beneficiaries, and any legal or tax requirements related to
the transfer of those assets.

Different states: The different states in the inheritance planning scenario include the
asset identification stage, the estate planning stage, and the estate administration
stage.

Various input values: The input values for inheritance planning include information
about an individual's assets, their beneficiaries, and any legal or tax requirements.
This information can be obtained from various sources, such as financial statements,
tax records, and legal documents.

Action parameters: The action parameters for the inheritance planning scenario
include creating a will or trust, determining inheritance planning strategies, valuing
assets, and tracking the status of the distribution. The system can also provide
guidance on how to resolve potential conflicts in the inheritance plan.

SCENARIO 6

Adopted Children
The scenario of adopted children involves representing and reasoning about family
relationships and legal statuses of children who have been legally adopted by
parents who are not their biological parents. A knowledge representation and
reasoning system can be used to assist with this scenario by helping to organize and
manage information related to the adoption process.

In this scenario, the environment states include the legal status of the adopted child,
the biological parents of the child, the adoptive parents of the child, and any other
relevant family members or legal entities involved in the adoption process.

The different states in the adopted children scenario include the initial adoption
process, ongoing legal and familial relationships, and any updates or changes to the
legal status of the adopted child.

Various input values for the adopted children scenario include information about the
biological parents of the child, the adoptive parents of the child, and any legal
documents related to the adoption process, such as adoption certificates or court
orders.
Action parameters in the adopted children scenario can include tasks such as
updating legal documents related to the adoption, managing ongoing relationships
between the adopted child and their biological and adoptive families, and ensuring
that the adopted child's legal rights and status are properly represented and
protected.

A knowledge representation and reasoning system can assist with the adopted
children scenario by organizing and managing information related to the adoption
process and providing guidance on legal and familial relationships. For example, the
system can help to identify potential conflicts between the biological and adoptive
families and provide guidance on how to resolve these conflicts. The system can also
help to ensure that the adopted child's legal status and rights are properly
represented and protected over time.

SCENARIO 7

Ancestry Testing
The scenario of ancestry testing involves representing and reasoning about the
genetic heritage and genealogy of an individual or group of individuals using DNA
testing. A knowledge representation and reasoning system can be used to assist with
this scenario by helping to organize and manage information related to genetic
ancestry and genealogy.

In this scenario, the environment states include the DNA sequence of the individual
or group of individuals being tested, the genetic heritage and genealogy of the
individual or group of individuals, and any relevant genetic databases or other
resources that can be used to analyze the DNA sequence.

The different states in the ancestry testing scenario include the initial DNA testing
process, ongoing analysis and interpretation of the DNA results, and any updates or
changes to the genetic heritage and genealogy of the individual or group of
individuals.

Various input values for the ancestry testing scenario include the DNA sequence of
the individual or group of individuals being tested, relevant demographic information
such as age, gender, and geographic location, and any historical or genealogical
information that can be used to interpret the DNA results.

Action parameters in the ancestry testing scenario can include tasks such as
analyzing and interpreting the DNA results, identifying potential genetic matches and
genetic relationships with other individuals or groups, and updating the genetic
heritage and genealogy of the individual or group of individuals based on the DNA
results.

A knowledge representation and reasoning system can assist with the ancestry
testing scenario by organizing and managing information related to genetic ancestry
and genealogy, and by providing guidance on the interpretation and analysis of DNA
results.
For example, the system can help to identify potential genetic matches and
relationships with other individuals or groups, and provide information on the
historical and cultural contexts that may have influenced the genetic heritage of the
individual or group of individuals being tested. The system can also help to ensure
that the genetic heritage and genealogy of the individual or group of individuals is
properly represented and updated over time as new information becomes available.

SCENARIO 8

Genetic Counseling
The scenario of genetic counseling involves representing and reasoning about the
genetic makeup and potential genetic risks of an individual or group of individuals, as
well as providing counseling and guidance on how to manage these risks. A
knowledge representation and reasoning system can be used to assist with this
scenario by helping to organize and manage information related to genetic testing,
genetic risks, and potential treatments or interventions.

In this scenario, the environment states include the genetic makeup of the individual
or group of individuals being tested, any relevant family medical history or genetic
testing results, and any known genetic risks or potential health conditions that may
be associated with the individual or group.

The different states in the genetic counseling scenario include the initial genetic
testing process, ongoing analysis and interpretation of the genetic test results, and
any updates or changes to the genetic risks or potential health conditions associated
with the individual or group.

Various input values for the genetic counseling scenario include the genetic testing
results of the individual or group, relevant demographic and medical information
such as age, gender, and family medical history, and any relevant environmental
factors that may influence the development of genetic risks or health conditions.

Action parameters in the genetic counseling scenario can include tasks such as
analyzing and interpreting the genetic test results, identifying potential genetic risks
and associated health conditions, providing counseling and guidance on how to
manage these risks, and developing treatment or intervention plans to address any
identified health conditions.

A knowledge representation and reasoning system can assist with the genetic
counseling scenario by organizing and managing information related to genetic
testing and health risks, and by providing guidance on how to interpret and manage
these risks. For example, the system can help to identify potential genetic risks and
health conditions, and provide information on treatment options and potential
outcomes. The system can also help to ensure that the genetic risks and health
conditions of the individual or group are properly represented and updated over
time as new information becomes available.
SCENARIO 9

Immigration and Citizenship


The scenario of immigration and citizenship involves representing and reasoning
about the legal status, immigration history, and eligibility for citizenship of an
individual or group of individuals. A knowledge representation and reasoning system
can be used to assist with this scenario by organizing and managing information
related to immigration laws, policies, and regulations, as well as the specific
circumstances of each individual or group.

In this scenario, the environment states include the legal status and immigration
history of the individual or group, any relevant legal documents such as visas or
passports, and any applicable immigration laws and regulations.

The different states in the immigration and citizenship scenario include the initial
application process for legal entry into a country, any subsequent applications for
permanent residency or citizenship, and ongoing monitoring of legal status and
compliance with immigration laws and regulations.

Various input values for the immigration and citizenship scenario include personal and
demographic information such as age, nationality, and employment history, as well as
documentation related to legal status and immigration history.

Action parameters in the immigration and citizenship scenario can include tasks such
as processing and evaluating visa applications, conducting background checks and
security screenings, and determining eligibility for permanent residency or citizenship.

A knowledge representation and reasoning system can assist with the immigration
and citizenship scenario by organizing and managing information related to
immigration laws and regulations, as well as the specific circumstances of each
individual or group. The system can help to ensure that legal documentation and
information is accurate and up-to-date, and can provide guidance on eligibility
requirements and application processes. Additionally, the system can help to identify
potential legal issues or obstacles and provide recommendations for addressing these
challenges.
PROJECT REVIEW 2
Task:
Represent your system with any of the following three representations

 Knowledge graph using Neo4J (Or any other tool) (mandatory)


 FOL
 Prolog
 Production rule

Deliverables:

 Knowledge representation using any three methods


 New inferences
Targeted Marketing
1. Knowledge Graph using Neo4J:
a. Code:
CREATE (john:Person {name: 'John'})
CREATE (mary:Person {name: 'Mary'})
CREATE (peter:Person {name: 'Peter'})
CREATE (jane:Person {name: 'Jane'})
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (parent_child:RelationshipType {name: 'parent-child'})
CREATE (spouse:RelationshipType {name: 'spouse'})
CREATE (sibling:RelationshipType {name: 'sibling'})
CREATE (friend:RelationshipType {name: 'friend'})
CREATE (customer:MarketingTarget {name: 'customer'})
CREATE (parent_target:MarketingTarget {name: 'parent'})

CREATE (john)-[:HAS_CHILD]->(mary)
CREATE (john)-[:HAS_SPOUSE]->(jane)
CREATE (mary)-[:HAS_SIBLING]->(peter)
CREATE (alice)-[:HAS_FRIEND]->(bob)
CREATE (mary)-[:IS_CUSTOMER]->(customer)
CREATE (john)-[:IS_PARENT_OF]->(mary)
CREATE (john)-[:HAS_RELATIONSHIP]->(spouse)
CREATE (mary)-[:HAS_RELATIONSHIP]->(parent_child)
CREATE (peter)-[:HAS_RELATIONSHIP]->(sibling)
CREATE (alice)-[:HAS_RELATIONSHIP]->(friend)
CREATE (mary)-[:IS_TARGET_OF]->(parent_target)
MATCH (n)-[r]->(m)
RETURN n, r, m

b. Graph:
2. FOL
 If John is the parent of Mary, then parent(John, Mary).
 If John is married to Jane, then spouse(John, Jane).
 If Mary and Peter are siblings, then sibling(Mary, Peter).
 If Alice and Bob are friends, then friend(Alice, Bob).
 If Mary is a customer, then customer(Mary).
 If we want to target parents, then target(X, parent-child) for any person X who is a
parent.

3. Prolog
person(john).
person(mary).
person(peter).
person(jane).
person(alice).
person(bob).

parent(john, mary).
spouse(john, jane).
sibling(mary, peter).
friend(alice, bob).

customer(mary).

target(X, parent-child) :- parent(X, Y).

4. Production Rule
 IF John is the parent of Mary THEN add parent(John, Mary) to the database.
 IF John is married to Jane THEN add spouse(John, Jane) to the database.
 IF Mary and Peter are siblings THEN add sibling(Mary, Peter) to the database.
 IF Alice and Bob are friends THEN add friend(Alice, Bob) to the database.
 IF Mary is a customer THEN add customer(Mary) to the database.
 IF X is a parent of Y THEN add target(X, parent-child) to the database.
 IF we want to target parents, THEN for each customer who has a parent-child
relationship, add that customer to the target list.

5. New Inferences:
 If Mary is a customer and a parent, we can add target(Mary, parent-child) to the
database.
 If we want to target parents, we can generate a list of customers who have a parent-child
relationship, such as Mary.
 If we want to target friends of parents, we can use the friend predicate to identify
customers who are friends with parents and add them to the target list.
 We can also use the sibling predicate to target customers who have siblings, and the
spouse predicate to target customers who are married.
Medical History
1. Knowledge Graph using Neo4J:
a. Code:
CREATE (john:Person {name: 'John'})
CREATE (mary:Person {name: 'Mary'})
CREATE (peter:Person {name: 'Peter'})
CREATE (jane:Person {name: 'Jane'})
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (flu:Disease {name: 'Flu'})
CREATE (cancer:Disease {name: 'Cancer'})
CREATE (diabetes:Disease {name: 'Diabetes'})
CREATE (arthritis:Disease {name: 'Arthritis'})
CREATE (fever:Symptom {name: 'Fever'})
CREATE (fatigue:Symptom {name: 'Fatigue'})
CREATE (pain:Symptom {name: 'Pain'})
CREATE (hunger:Symptom {name: 'Hunger'})
CREATE (parent_child:RelationshipType {name: 'parent-child'})
CREATE (spouse:RelationshipType {name: 'spouse'})
CREATE (sibling:RelationshipType {name: 'sibling'})
CREATE (doctor:Role {name: 'Doctor'})
CREATE (patient:Role {name: 'Patient'})

CREATE (john)-[:diagnosed_by {disease: 'Flu'}]->(mary)


CREATE (jane)-[:diagnosed_by {disease: 'Cancer'}]->(peter)
CREATE (alice)-[:diagnosed_by {disease: 'Arthritis'}]->(bob)
CREATE (flu)-[:has_symptom {symptom: 'Fever'}]->(fever)
CREATE (flu)-[:has_symptom {symptom: 'Fatigue'}]->(fatigue)
CREATE (cancer)-[:has_symptom {symptom: 'Pain'}]->(pain)
CREATE (diabetes)-[:has_symptom {symptom: 'Hunger'}]->(hunger)
CREATE (arthritis)-[:has_symptom {symptom: 'Pain'}]->(pain)
CREATE (john)-[:has_symptom {symptom: 'Fever'}]->(fever)
CREATE (john)-[:has_symptom {symptom: 'Fatigue'}]->(fatigue)
CREATE (jane)-[:has_symptom {symptom: 'Pain'}]->(pain)
CREATE (alice)-[:has_symptom {symptom: 'Pain'}]->(pain)
MATCH (n)-[r]->(m)
RETURN n, r, m
b. Graph:
2. FOL:
Person(x) // x is a person
Disease(y) // y is a disease
DiagnosedBy(z, x, y) // z diagnosed x with ySymptom(s,
y) // s is a symptom of y

// Rules
∀x,y,z (DiagnosedBy(z,x,y) → Person(x) � Disease(y) � Doctor(z))
∀s,y (Symptom(s,y) → Disease(y) � Symptom(s) )

// Queries
∃x,y (DiagnosedBy(z,x,y) � Symptom(s,y))

3. Prolog:
person(john).
person(mary).
person(peter).
person(jane).
person(alice).
person(bob).

disease(flu).
disease(cancer).
disease(diabetes).
disease(arthritis).

symptom(fever, flu).
symptom(fatigue, flu).
symptom(pain, cancer).
symptom(hunger, diabetes).
symptom(pain, arthritis).

diagnosed_by(john, mary, flu).


diagnosed_by(jane, peter, cancer).
diagnosed_by(alice, bob, arthritis).

// Rules
has_symptom(X, Y) :- diagnosed_by(_, X, D), symptom(Y, D).

// Queries
has_symptom(X, Y).

4. Production Rules:
IF patient_diagnosed_with(X, Y)
AND Y has symptom Z
THEN recommend_treatment(Z)

IF patient_diagnosed_with(X, Y)
AND Y is chronic
THEN recommend_specialist()

IF patient_diagnosed_with(X, Y)
AND patient has family history of Y
THEN recommend_screening()

IF patient_has_symptom(X, Y)
AND Y is severe
THEN recommend_emergency_care()

// Example data
patient_diagnosed_with(john, flu).
patient_diagnosed_with(jane, cancer).
patient_diagnosed_with(alice, arthritis).
patient_has_symptom(john, fever).
patient_has_symptom(john, fatigue).
patient_has_symptom(jane, pain).
patient_has_symptom(alice, pain).

5. New Inferences:
 John has flu and has symptoms of fever and fatigue.
 Jane has cancer and has symptoms of pain.
 Alice has arthritis and has symptoms of pain.
 Peter has been diagnosed with cancer.
 Bob has been diagnosed with arthritis.
 Fever and fatigue are symptoms of flu.
 Pain is a symptom of both cancer and arthritis.
 Hunger is a symptom of diabetes.
 Mary diagnosed John with flu.
 Peter was diagnosed by Jane with cancer.
 Bob was diagnosed by Alice with arthritis.
Legal Matters
1. Knowledge Graph using Neo4J
a. Code:
CREATE (:Person {name:"John"})
CREATE (:Person {name:"Jane"})
CREATE (:Person {name:"Tom"})
CREATE (:Person {name:"Sue"})
CREATE (:Person {name:"Joe"})
CREATE (:Person {name:"Liz"})
CREATE (:Person {name:"Matt"})
CREATE (:Person {name:"Amy"})
CREATE (:Person {name:"Bob"})

CREATE (john)-[:parent_of]->(tom)
CREATE (tom)-[:parent_of]->(joe)
CREATE (joe)-[:parent_of]->(liz)
CREATE (tom)-[:parent_of]->(sue)
CREATE (joe)-[:married_to]->(sue)
CREATE (john)-[:married_to]->(jane)
CREATE (matt)-[:parent_of]->(amy)
CREATE (tom)-[:sibling_of]->(joe)
CREATE (joe)-[:sibling_of]->(tom)
CREATE (john)-[:ancestor_of]->(tom)
CREATE (john)-[:ancestor_of]->(joe)
CREATE (john)-[:ancestor_of]->(liz)
CREATE (john)-[:ancestor_of]->(sue)
CREATE (john)-[:ancestor_of]->(amy)
b. Graph:
2. FOL:
Parent(x,y) - x is a parent of y
Married(x,y) - x is married to y
Sibling(x,y) - x is a sibling of y
Grandparent(x,y) - x is a grandparent of y
Ancestor(x,y) - x is an ancestor of y
Descendant(x,y) - x is a descendant of y

3. Prolog:
parent(x,y).
married(x,y).
sibling(x,y).
grandparent(x,y).
ancestor(x,y).
descendant(x,y).

Rules:
1. grandparent(x,z) :- parent(x,y), parent(y,z).
2. \+grandparent(x,z) :- parent(x,y), \+parent(y,z).
3. married(x,y) :- married(y,x).
4. parent(x,z) :- married(x,y), parent(y,z).
5. descendant(x,y) :- parent(x,y).
6. descendant(x,y) :- ancestor(y,x).

4. Production Rules:

Rule 1: If x is a parent of y and y is a parent of z, then x is a grandparent of z.

Rule 2: If x is a parent of y and y is not a parent of z, then x is not a grandparent of z.

Rule 3: If x is married to y, then y is married to x.

Rule 4: If x is married to y and y is a parent of z, then x is a parent of z.

Rule 5: If x is a parent of y, then y is a descendant of x.

Rule 6: If x is an ancestor of y, then y is a descendant of x.


5. New Inferences:
 John and Jane are married to each other.
 Tom is the child of John and Jane.
 Sue is the child of John and Jane.
 Joe is married to Sue.
 Liz is the child of Joe and Sue.
 Matt is the parent of Amy.
 Tom is the brother of Sue.
 Joe is the father of Liz.
 Liz is the granddaughter of John.
 Tom is the uncle of Liz.
 Jane is the wife of John.
 Joe is the son-in-law of John and Jane.
 Sue is the daughter-in-law of John and Jane.
 Liz is the great-granddaughter of John.
Genealogy Research
1. Knowledge graph using Neo4J
A. Code:
// Create person nodes
CREATE (Alice:Person { name: 'Alice', birthdate: '1980-01-01', birthplace: 'New York'})
CREATE (Bob:Person { name: 'Bob', birthdate: '1985-05-05', birthplace: 'Los Angeles'})
CREATE (Charlie:Person { name: 'Charlie', birthdate: '1990-10-10', birthplace: 'Chicago'})
CREATE (Dave:Person { name: 'Dave', birthdate: '1950-12-25', birthplace: 'Boston'})

// Create relationships between people


CREATE (Alice)-[:PARENT_OF]->(Bob)
CREATE (Alice)-[:PARENT_OF]->(Charlie)
CREATE (Bob)-[:PARENT_OF]->(Dave)

// Query for Alice's children


MATCH (Alice:Person { name: 'Alice' })-[:PARENT_OF]->(child)
RETURN Alice.name, child.name, child.birthdate, child.birthplace

// Query for Bob's parents


MATCH (Bob:Person { name: 'Bob' })<-[:PARENT_OF]-(parent)
RETURN Bob.name, parent.name, parent.birthdate, parent.birthplace

B. Graph
2. FOL
isPerson(x) //x is a person
isParentOf(x, y) //x is a parent of y
isChildOf(x, y) //x is a child of y
isMarriedTo(x, y) //x is married to y
isSiblingOf(x, y) //x is a sibling of y
isGrandparentOf(x, y) //x is a grandparent of y
isGrandchildOf(x, y) //x is a grandchild of y

isParentOf(John, Mary)
isParentOf(John, Paul)
isParentOf(Paul, George)
isParentOf(Paul, Ringo)
isMarriedTo(John, Jane)
isMarriedTo(Paul, Linda)
∀x,y,z ((isParentOf(x, y) ∧ isParentOf(y, z)) -> isGrandparentOf(x, z))
3. Prolog
% Define individuals
person(john).
person(jane).
person(paul).
person(linda).
person(george).
person(ringo).
person(mary).

% Define relationships between individuals


parent(john, mary).
parent(john, paul).
parent(paul, george).
parent(paul, ringo).
married(john, jane).
married(paul, linda).

% Define rules for inferring relationships


grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

% Query the database


?- grandparent(john, george).
4. Production Rules

IF person_has_child(X, Y)
THEN child_parent(Y, X)

IF person_married_to(X, Y)
THEN person_married_to(Y, X)

IF person_has_sibling(X, Y)
THEN person_has_parent(Z, X) AND person_has_parent(Z, Y)
IF person_has_parent(X, Y) AND person_has_parent(X, Z) AND Y != Z
THEN person_has_sibling(Y, Z)

IF person_has_child(X, Y) AND person_has_child(Y, Z)


THEN person_is_grandparent(X, Z)

IF person_has_child(X, Y) AND person_married_to(Y, Z)


THEN person_is_child_in_law(Z, X)

5. New Inferences
 If "parent(X, Y)" is true, then "child(Y, X)" is also true (based on the first clause of the
"child" predicate).
 If "parent(X, Y)" and "parent(Y, Z)" are both true, then "grandparent(X, Z)" is also true
(based on the second clause of the "grandparent" predicate).
 If "parent(X, Y)" and "parent(X, Z)" are both true and Y is not equal to Z, then "sibling(Y,
Z)" is true (based on the first clause of the "sibling" predicate).
 If "parent(X, Y)" is true and "male(X)" is also true, then "father(X, Y)" is true (based on the
second clause of the "father" predicate).
 If "parent(X, Y)" is true and "female(X)" is also true, then "mother(X, Y)" is true (based on
the third clause of the "mother" predicate).
Inheritance Planning
1. Knowledge graph using Neo4J
A. Code:
// Create Persons and their relationships
CREATE (p1:Person {name: "John", age: 60, gender: "Male"})
CREATE (p2:Person {name: "Alice", age: 35, gender: "Female"})
CREATE (p3:Person {name: "Bob", age: 30, gender: "Male"})
CREATE (p4:Person {name: "Charlie", age: 25, gender: "Male"})

CREATE (p1)-[:MARRIED_TO]->(p5:Person {name: "Mary", age: 55, gender: "Female"})


CREATE (p2)-[:MARRIED_TO]->(p3)

// Create Assets
CREATE (a1:Asset {name: "House", value: 500000})
CREATE (a2:Asset {name: "Bank Account", value: 100000})

// Create Inheritance Rules


CREATE (p1)-[:HAS_RULE]->(:InheritanceRule {asset_type: "House", recipient: "Alice",
percentage: 75})
CREATE (p1)-[:HAS_RULE]->(:InheritanceRule {asset_type: "Bank Account", recipient:
"Bob", percentage: 50})
CREATE (p1)-[:HAS_RULE]->(:InheritanceRule {asset_type: "Bank Account", recipient:
"Charlie", percentage: 50})

// Create Inheritance Events


CREATE (p1)-[:HAS_INHERITED]->(i1:Inheritance {asset_type: "House", value: 500000})
CREATE (i1)-[:INHERITED_BY]->(p2)
CREATE (i1)-[:INHERITED_BY]->(p4)

CREATE (p1)-[:HAS_INHERITED]->(i2:Inheritance {asset_type: "Bank Account", value:


100000})
CREATE (i2)-[:INHERITED_BY]->(p3)
CREATE (i2)-[:INHERITED_BY]->(p4)
B. Graph

2. FOL
Person(x) // x is a person
Heir(x,y) // x is an heir of y
Estate(x,y) // x owns estate y
Will(x,y) // x has a will that describes distribution of estate y
Executor(x,y) // x is the executor of the will of y
isEqual(x,y) // x is equal to y

// Rule: A person can have multiple heirs


forall x,y,z (Heir(x,z) ∧ Heir(y,z) → isEqual(x,y))

// Rule: An estate belongs to only one person


forall x,y,z (Estate(x,z) ∧ Estate(y,z) → isEqual(x,y))

// Rule: An executor executes the will of only one person


forall x,y,z (Executor(x,z) ∧ Executor(y,z) → isEqual(x,y))

// Rule: All heirs inherit a share of the estate as defined in the will
forall x,y,z (Will(x,z) ∧ Estate(z,w) ∧ Heir(y,x) → InheritShare(y,z,w))

// Rule: An executor is responsible for distributing the estate according to the will
forall x,y,z (Will(x,z) ∧ Estate(z,w) ∧ Executor(y,x) → DistributeEstate(y,z,w))
3. Prolog
person(john, 60, male).
person(alice, 35, female).
person(bob, 30, male).
person(charlie, 25, male).
person(mary, 55, female).

married(john, mary).
married(alice, bob).

asset(house, 500000).
asset(bank_account, 100000).

inheritance_rule(john, house, alice, 75).


inheritance_rule(john, bank_account, bob, 50).
inheritance_rule(john, bank_account, charlie, 50).

inheritance(john, alice, house, 500000).


inheritance(john, bob, bank_account, 50000).
inheritance(john, charlie, bank_account, 50000).
4. Production Rules

IF a person P has an asset A, and there is an inheritance rule that assigns asset A to person R
with percentage PCT,
THEN create an inheritance event for asset A with value V = A.value * PCT,
AND assign the inheritance event to person R.

IF a person P has an inheritance rule R that assigns asset A to person R with percentage PCT,
AND the sum of all inheritance percentages for asset A exceeds 100%,
THEN mark inheritance rule R as invalid and notify person P of the violation.

IF a person P has an inheritance rule R that assigns asset A to person R with percentage PCT,
AND the sum of all inheritance percentages for asset A exceeds 100%,
THEN mark inheritance rule R as invalid and notify person P of the violation.

IF a person P has an inheritance rule R that assigns asset A to person R,


AND person P's family relationship with person R changes to a non-spouse relationship (e.g.
divorce or disownment),
THEN mark inheritance rule R as invalid and notify person P to update the inheritance plan.

IF a person P wants to create an inheritance plan,


THEN prompt person P to provide a list of assets and their desired recipients and inheritance
percentages,
AND create inheritance rules for each asset based on the provided information.
5. New Inferences
 If a person has an inheritance rule for a specific asset type with a recipient and a
percentage, and they pass away, then the asset is inherited by the recipient with the
specified percentage.

 If a person inherits an asset, then they become the owner of the asset and can use it as
they see fit.

 If a person inherits an asset, then the value of the asset is added to their net worth.

 If a person has a joint account with someone else, and they pass away, then the account
becomes the property of the other person.

 If a person has a joint account with someone else, and they both pass away, then the
account is distributed according to their inheritance rules.

 If a person has no inheritance rules, then their assets are distributed according to the laws
of intestacy.

 If a person has a will, then their assets are distributed according to their will.
Adopted Children
1. Knowledge Graph using Neo4J
A. Code
// Create Persons
CREATE (p1:Person {name: "John", gender: "Male"})
CREATE (p2:Person {name: "Mary", gender: "Female"})
CREATE (p3:Person {name: "Alice", gender: "Female"})
CREATE (p4:Person {name: "Bob", gender: "Male"})
CREATE (p5:Person {name: "Charlie", gender: "Male"})

// Create Adoption Relationships


CREATE (p1)-[:ADOPTED]->(p3)
CREATE (p2)-[:ADOPTED]->(p4)
CREATE (p2)-[:ADOPTED]->(p5)

// Create Biological Relationships


CREATE (p1)-[:PARENT_OF]->(p4)
CREATE (p1)-[:PARENT_OF]->(p5)
CREATE (p2)-[:PARENT_OF]->(p3)

B. Graph
2. FOL
Person(John)
Person(Mary)
Person(Alice)
Person(Bob)
Person(Charlie)
Adopted(John, Alice)
Adopted(Mary, Bob)
Adopted(Mary, Charlie)
Parent_of(John, Bob)
Parent_of(John, Charlie)
Parent_of(Mary, Alice)
3. Prolog
% Define predicates for persons, adopted relationships and biological relationships
person(X) :- male(X) ; female(X).
male(X) :- parent_of(_, X, male).
female(X) :- parent_of(_, X, female).
adopted(X, Y) :- parent_of(X, Y, _), not((parent_of(X, Z, _), Z \= Y)).
parent_of(X, Y, Z) :- (X)-[:PARENT_OF]->(Y), person(Y), member(Z, [male, female]).
parent_of(X, Y, Z) :- (X)-[:ADOPTED]->(Y), person(Y), member(Z, [male, female]).

4. Production rules

parent(X, Y) :- parent_of(X, Y).

parent(X, Y) :- adopted(X, Y).

grandparent(X, Z) :- parent(X, Y), parent(Y, Z).

parent(X, Z) :- parent(X, Y), sibling(Y, Z).

parent(X, Z) :- parent(X, Y), sibling(Y, Z).

adopted(X, Z) :- adopted(X, Y), sibling(Y, Z), not parent(X, Z).

5. New Inferences

p1 is the biological parent of p4 and p5.


p2 is the biological parent of p3.
p3 is the adopted child of p1.
p4 and p5 are the adopted children of p2.
p1 is the adoptive parent of p3.
p2 is the adoptive parent of p4 and p5.

Therefore, p1 has two children: p4 and p5, and one adopted child: p3. Similarly, p2 has
two adopted children: p4 and p5, and one biological child: p3.
Ancestry Testing
1. Knowledge Graph using Neo4J
A. Code
// Create Persons and their Ancestry
CREATE (p1:Person {name: "John", ancestry: "Irish"})
CREATE (p2:Person {name: "Mary", ancestry: "Italian"})
CREATE (p3:Person {name: "Alice", ancestry: "Irish"})
CREATE (p4:Person {name: "Bob", ancestry: "Irish"})
CREATE (p5:Person {name: "Charlie", ancestry: "Italian"})
CREATE (p6:Person {name: "David", ancestry: "Italian"})
CREATE (p7:Person {name: "Emma", ancestry: "Irish"})
CREATE (p8:Person {name: "Frank", ancestry: "Italian"})

// Create Relationships
CREATE (p1)-[:PARENT_OF]->(p3)
CREATE (p1)-[:PARENT_OF]->(p4)
CREATE (p2)-[:PARENT_OF]->(p5)
CREATE (p2)-[:PARENT_OF]->(p6)
CREATE (p3)-[:PARENT_OF]->(p7)
CREATE (p4)-[:PARENT_OF]->(p8)

// Create Ancestry Testing Results


CREATE (p9:Person {name: "Test Subject", ancestry: "Unknown"})
CREATE (p9)-[:HAS_TEST_RESULT]->(:AncestryTestResult {ancestry: "Italian",
confidence: 0.8})
B. Graph
2. FOL
Person(x): x is a person
AncestryTest(y): y is an ancestry test
hasTakenTest(x, y): Person x has taken ancestry test y
Parent(x, y): x is the parent of y
BiologicalParent(x, y): x is the biological parent of y
Ancestor(x, y): x is an ancestor of y

3. Prolog
person(X).
ancestryTest(Y).
hasTakenTest(X, Y).
parent(X, Y).
biologicalParent(X, Y).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

4. Production Rules
If there is a DNA match between two individuals, then they are likely to be related.

If two individuals are known to be related, and one of them has a specific ancestry,
then the other is likely to share that ancestry.

If an individual has a specific ancestry, and a group of individuals share DNA with that
individual, then it is likely that the group also has that ancestry.

If an individual has multiple ancestors with a specific ancestry, then it is more likely
that the individual has that ancestry.

If an individual has no known ancestry, but shares DNA with a group of individuals who
all have a specific ancestry, then it is likely that the individual also has that ancestry.

If an individual has a specific set of genetic markers, and those markers are commonly
found in a specific population, then it is likely that the individual has ancestry from that
population.
5. New Inferences
If DNA_match(X,Y), then related(X,Y).
If related(X,Y) and ancestry(Y,A), then ancestry(X,A).
If ancestry(X,A) and DNA_match(X,Y) for all Y in group G, then ancestry(G,A).
If ancestry(X,A1) and ancestry(X,A2) and A1 ≠ A2, then less_likely(X,A2).
If DNA_match(X,Y) for all Y in group G and ancestry(G,A), then ancestry(X,A).
If genetic_markers(X,M) and common_markers(M,P), then ancestry(X,P).
Genetic Counseling
1. Knowledge Graph using Neo4J
A. Code
// Create genetic counselors
CREATE (:GeneticCounselor {name: "Alice"})
CREATE (:GeneticCounselor {name: "Bob"})

// Create patients and their genetic information


CREATE (p1:Patient {name: "John", gender: "Male"})
CREATE (g1:GeneticInformation {patient_id: "p1", gene: "BRCA1", mutation:
"c.5266dupC"})
CREATE (p1)-[:HAS_GENETIC_INFO]->(g1)

CREATE (p2:Patient {name: "Mary", gender: "Female"})


CREATE (g2:GeneticInformation {patient_id: "p2", gene: "BRCA2", mutation:
"c.68_69delAG"})
CREATE (p2)-[:HAS_GENETIC_INFO]->(g2)

// Create genetic test results


CREATE (p1)-[:TOOK_TEST]->(t1:TestResult {test_date: "2022-02-01", result:
"Positive"})
CREATE (p2)-[:TOOK_TEST]->(t2:TestResult {test_date: "2022-02-01", result:
"Negative"})

// Create genetic counseling sessions


CREATE (c1:CounselingSession {session_date: "2022-02-10"})
CREATE (c2:CounselingSession {session_date: "2022-02-15"})

// Associate patients and genetic counselors with counseling sessions


CREATE (c1)-[:WITH]->(p1)
CREATE (c1)-[:WITH]->(p2)
CREATE (c1)-[:CONDUCTED_BY]->(:GeneticCounselor {name: "Alice"})

CREATE (c2)-[:WITH]->(p1)
CREATE (c2)-[:WITH]->(p2)
CREATE (c2)-[:CONDUCTED_BY]->(:GeneticCounselor {name: "Bob"})
B. Graph

2. FOL
If an individual carries a disease-causing mutation, and they have a child with another
individual who carries the same mutation, then their child is likely to inherit the disease:

∀x,y,z ((hasMutation(x) ∧ hasMutation(y) ∧ carries(x,z) ∧ carries(y,z) ∧ x≠y) →


(inherit(z) → hasDisease(z)))

If two individuals are carriers of a disease-causing mutation, and they have a child
together, then their child has a 25% chance of inheriting the disease:

∀x,y,z ((hasMutation(x) ∧ hasMutation(y) ∧ carries(x,z) ∧ carries(y,z) ∧ x≠y) →


((inherit(z) ∧ prob(z,25)) → hasDisease(z)))

If an individual has a family history of a certain disease, then they may be at higher risk
of developing that disease themselves:

∀x,y ((hasDisease(x) ∧ familyHistory(x,y)) → risk(y))

If an individual has a certain genotype or genetic marker associated with a disease,


then they may be at higher risk of developing that disease:
∀x,y ((hasGenotype(x,y) ∨ hasMarker(x,y)) → risk(y))

If an individual is known to be at higher risk of a certain disease, then they may benefit
from increased screening or preventive measures:

∀x,y ((risk(x) ∧ hasDisease(y) ∧ screeningBenefit(x,y)) → shouldScreen(x,y))

3. Prolog
% Patients
patient(p1, john, male).
patient(p2, mary, female).

% Genetic information
genetic_information(g1, p1, brca1, 'c.5266dupC').
genetic_information(g2, p2, brca2, 'c.68_69delAG').

% Test results
test_result(p1, '2022-02-01', positive).
test_result(p2, '2022-02-01', negative).

% Genetic counselors
genetic_counselor(alice).
genetic_counselor(bob).

% Counseling sessions
counseling_session(c1, '2022-02-10', [p1, p2], alice).
counseling_session(c2, '2022-02-15', [p1, p2], bob).
4. Production Rules

If a patient has a positive test result for a genetic mutation, then the genetic counselor should
provide information about the risk of developing a related condition and the available
treatment options.

If a patient has a negative test result for a genetic mutation, then the genetic counselor should
provide information about the limitations of the test and the possibility of false negatives.

If two or more patients have positive test results for the same genetic mutation, then the
genetic counselor should discuss the possibility of a familial inheritance pattern and
recommend testing for other family members.

If a patient has a family history of a genetic condition, then the genetic counselor should
recommend testing for the patient and their family members, and provide information about
the inheritance pattern and the risks and benefits of testing.

If a patient has a positive test result for a genetic mutation, and the mutation is associated
with a high risk of developing a related condition, then the genetic counselor should discuss
the option of prophylactic surgery or other risk-reducing measures.
If a patient has a positive test result for a genetic mutation, and the mutation is associated
with a moderate or low risk of developing a related condition, then the genetic counselor
should discuss the option of increased surveillance or monitoring.

If a patient is considering genetic testing but is uncertain about the potential risks and benefits,
then the genetic counselor should provide information about the test and its implications, and
help the patient make an informed decision.

5. New Inferences

If a patient has a positive genetic test result for a specific gene mutation, and that gene
mutation is associated with an increased risk of a certain condition, then the patient may be at
increased risk for that condition.

If a patient has a negative genetic test result for a specific gene mutation, and that gene
mutation is associated with an increased risk of a certain condition, then the patient may have
a lower risk for that condition.

If a patient has a family history of a certain condition, and that condition has a genetic
component, then the patient may be at increased risk for that condition.

If a patient has a family history of a certain condition, and a genetic test reveals a specific gene
mutation associated with that condition in a family member, then the patient may also be at
increased risk for that condition.

If a patient has a positive genetic test result for a specific gene mutation, and there are
treatment options available for the associated condition, then the patient may be a candidate
for those treatments.

If a patient has a positive genetic test result for a specific gene mutation, and there are no
treatment options available for the associated condition, then the patient may benefit from
genetic counseling and support to manage their risk and cope with the implications of the
result.
Immigration and Citizenship
1. Knowledge graph using Neo4J
A. Code:
// Create countries
CREATE (:Country {name: "United States"})
CREATE (:Country {name: "Canada"})
CREATE (:Country {name: "Mexico"})

// Create individuals
CREATE (p1:Person {name: "John", age: 30, citizenship: "United States"})
CREATE (p2:Person {name: "Mary", age: 28, citizenship: "Canada"})
CREATE (p3:Person {name: "Alice", age: 25, citizenship: "Mexico"})

// Create immigration events


CREATE (p1)-[:IMMIGRATED_TO {date: "2010-01-01"}]->(:Country {name:
"Canada"})
CREATE (p2)-[:IMMIGRATED_TO {date: "2012-02-01"}]->(:Country {name:
"United States"})
CREATE (p3)-[:IMMIGRATED_TO {date: "2015-03-01"}]->(:Country {name:
"United States"})

// Create naturalization events


CREATE (p1)-[:NATURALIZED {date: "2015-04-01"}]->(:Country {name:
"Canada"})
CREATE (p2)-[:NATURALIZED {date: "2016-05-01"}]->(:Country {name: "United
States"})

// Create family relationships


CREATE (p1)-[:MARRIED_TO]->(p2)
CREATE (p1)-[:PARENT_OF]->(:Person {name: "Sam", age: 5, citizenship:
"Canada"})
CREATE (p2)-[:PARENT_OF]->(:Person {name: "Emily", age: 3, citizenship:
"United States"})
B. Graph

2. Prolog
% Facts
immigrant("John").
immigrant("Mary").
immigrant("Alice").
immigrant("Bob").
immigrant("Charlie").
born_in("John", "Canada").
born_in("Mary", "USA").
born_in("Alice", "Mexico").
born_in("Bob", "Canada").
born_in("Charlie", "USA").
has_residence("John", "Canada").
has_residence("Mary", "USA").
has_residence("Alice", "Mexico").
has_residence("Bob", "Canada").
has_residence("Charlie", "USA").

% Rules
citizen(X) :- immigrant(X), born_in(X, Country), has_residence(X, Country).
% Queries
?- citizen("John"). % true
?- citizen("Mary"). % true
?- citizen("Alice"). % false
?- citizen("Bob"). % true
?- citizen("Charlie"). % true
3. FOL
Let I(x) be "x is an immigrant"
Let C(x) be "x is a citizen"
Let P(x) be "x is a person"
Let P(x, y) be "x is the parent of y"
Let B(x, y) be "x was born in y"
Let R(x, y) be "x has resided in y"
Let N(x) be "x has naturalized"

∀x (I(x) → P(x)) // All immigrants are people.


∀x (C(x) → P(x)) // All citizens are people.
∀x,y (P(x,y) → P(x)) // All parents are people.
∀x,y (B(x,y) → P(x)) // All birthplaces have people.
∀x,y (R(x,y) → P(x)) // All residences have people.
∀x (I(x) → ¬C(x)) // All immigrants are not citizens.
∀x,y (P(x,y) ∧ B(y,"USA") → C(x)) // A person born in the USA to a parent is a citizen.
∀x,y (I(x) ∧ R(x,y) ∧ ¬N(x) → ¬C(x)) // An immigrant who has not naturalized and
resides in the USA is not a citizen.
∀x,y,z (P(x,y) ∧ P(y,z) → P(x,z)) // Transitive property of parenthood.
∀x (N(x) → C(x)) // A naturalized person is a citizen.
4. Production Rules
If a person is born in a country, then they are a citizen of that country.

If a person has at least one parent who is a citizen of a country, then they are also a
citizen of that country.

If a person is married to a citizen of a country, then they may be eligible for citizenship
in that country.

If a person has lived in a country for a certain period of time, they may be eligible for
permanent residency in that country.

If a person has committed a serious crime or poses a threat to national security, they
may be deported from a country.
5. New Inferences
If a person is a citizen of a country, then they have the right to reside in that country.

If a person is not a citizen of a country, but has a valid visa, then they have the right to
reside in that country for the duration of the visa.

If a person is not a citizen of a country, and does not have a valid visa, then they do not
have the right to reside in that country.

If a person has lived in a country for a certain number of years and meets other
residency requirements, then they may be eligible to apply for citizenship.

If a person is granted citizenship in a country, then they have the right to reside in that
country indefinitely and enjoy the same rights as other citizens.

If a person is convicted of a serious crime or deemed a threat to national security, then


they may be subject to deportation, regardless of their citizenship status.

If a person renounces their citizenship in a country, then they lose their right to reside
in that country and may be subject to deportation.

If a person marries a citizen of a country, they may be eligible for citizenship or


residency in that country, depending on the country's laws and regulations.
CSE3056

KNOWLEDGE REPRESENTATION AND


REASONING

FAMILY TREE GENERATOR

REVIEW 3

TEAM MEMBERS-
Gautam Manoj 20BRS1242
Harish Kumar Saravanan 20BRS1249
Mudit Arukia 20BRS1131
ABSTRACT:

The family tree generator program is an innovative application that utilizes


natural language processing (NLP) techniques to create family trees
automatically. The program allows users to input information about their
family members using natural language, such as names, relationships, and
dates of birth, without needing to follow any specific formatting rules or
templates. The NLP algorithms analyze the input text and extract relevant
information to create an accurate and complete family tree. The program also
incorporates advanced features, such as the ability to recognize synonyms,
misspellings, and alternative name forms, and to deduce relationships based
on contextual clues.

Additionally, the program can handle complex family structures, including


multiple marriages, step-children, and adoptions, and generate visually
appealing and interactive family trees that can be shared and printed. The
family tree generator program is a valuable tool for individuals and
genealogists who want to create a comprehensive and detailed family tree
quickly and easily. By leveraging the power of NLP, the program eliminates
the need for tedious data entry and simplifies the process of building a family
tree, making it accessible to a broader audience.
CODE AND SCREENSHOTS:

Necessary packages:
import pandas as pd
import spacy
from spacy import displacy
from IPython.display import display, HTML
import csv
import networkx as nx
import matplotlib.pyplot as plt

Dataset:
relationships = [
'Father', 'Mother', 'Son', 'Daughter', 'Brother',
'Sister', 'Sibling',
'Grandfather', 'Grandmother', 'Grandson',
'Granddaughter',
'Uncle', 'Aunt', 'Nephew', 'Niece', 'Cousin',
'Husband', 'Wife',
'Partner', 'Fiance', 'Married', 'Parent'
]
NLP Model:
# Load the English language model in spaCy
nlp = spacy.load("en_core_web_sm")

# Define the function to extract the names


def extract_names(text):
global superdf
# Parse the text with spaCy
doc = nlp(text)
# Loop through each sentence in the text
for sent in doc.sents:
sentence = sent.text.strip()
sent_names = []
sent_positions = []
names_and = []
df = pd.DataFrame(columns=['Member1', 'Member2',
'Relationship'])
member1 = []
member2 = []
relation = []
a = 0
flag = 0

# Loop through each token in the sentence


for i, token in enumerate(sent):
# Check if the token is a proper noun and its
title is capitalized
for rel in relationships:
if rel.lower() in token.text.lower():
relation.append(rel)
flag = 1
if token.pos_ == "PROPN" and token.text.istitle():
# Add the name to the list of names and its
position to the list of positions
sent_names.append(token.text)
a = a+1
sent_positions.append(str(i+1))
if flag == 0:
member1.append(token.text)
else:
member2.append(token.text)

# Find the names that are separated by "and"


if a > 1 and (sent_names[a-2]+" and " +
sent_names[a-1] in sentence):
names_and.append(sent_names[a-2])
names_and.append(sent_names[a-1])
for mem1 in member1:
for mem2 in member2:
temp = [mem1, mem2, relation[-1]]
df.loc[len(df.index)] = temp
# Merge all the dataframes:
frames = [superdf, df]
superdf = pd.concat(frames, ignore_index=True)

# If names were found in the sentence, print them


along with the sentence and their positions
if sent_names:
print(f"Sentence: {sentence}")
print(f"Names: {', '.join(sent_names)}")
print(f"Names separated by and: {',
'.join(names_and)}")
print(f"Relations: {', '.join(relation)}")
print(f"Position: {', '.join(sent_positions)}\n")
display(df)

Test Case:
text = "John and Jerry are cousins with Jacob and
Jack. Jack is the brother of Jacob. John is
married to Jane. Jane is the mother of Emily"
superdf = pd.DataFrame(columns=['Member1',
'Member2', 'Relationship'])
extract_names(text)
Saving the dataframe as a CSV file:
display(superdf)
# saving the dataframe
superdf.to_csv('family_tree.csv', index = False)

Visualization model:
def generate_family_tree(csv_file):
# Create an empty graph using networkx
G = nx.Graph()
# Read the CSV file and add nodes and edges to
the graph
with open(csv_file, 'r') as file:
reader = csv.reader(file)
next(reader) # skip header
for row in reader:
member1, member2, relation = row
G.add_node(member1)
G.add_node(member2)
G.add_edge(member1, member2, relation=relation)
# Draw the graph
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True)
edge_labels = {(u, v): d['relation'] for u, v, d
in G.edges(data=True)}
nx.draw_networkx_edge_labels(G, pos,
edge_labels=edge_labels)
plt.show()

Output:
generate_family_tree('/content/family_tree.csv')

Using a custom named entity recognition model on Spacy:


import spacy

# Load the English language model


nlp = spacy.load('en_core_web_sm')

# Split the string into different sentences


doc = nlp(text)
sentences = list(doc.sents)
print("NER output: ")
displacy.render(doc, style="ent", jupyter=True)

# Extract the Names of persons present in each


sentence
for sentence in sentences:
print("\n\t", sentence)
persons = []
for ent in sentence.ents:
if ent.label_ == 'PERSON':
persons.append(ent.text)
if persons:
print("\t>>> Persons in the sentence: ", persons)

Training custom relationship data:


import spacy
from spacy.training import Example
from spacy.util import minibatch, compounding

# Load an existing Spacy NER model


nlp = spacy.load("en_core_web_sm")

# Add a new label to the NER model


ner = nlp.get_pipe('ner')
ner.add_label('Relationship')

# Annotate training data with the custom label


train_data = [
('John is the father of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('Mary is the mother of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('John is the son of Sarah.', {'entities': [(12,
15, 'Relationship')]}),
('Mary is the daughter of Sarah.', {'entities':
[(12, 20, 'Relationship')]}),
('John is the brother of Sarah.', {'entities':
[(12, 19, 'Relationship')]}),
('Mary is the sister of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('John is the sibling of Sarah.', {'entities':
[(12, 19, 'Relationship')]}),
('John is the grandfather of Sarah.', {'entities':
[(12, 23, 'Relationship')]}),
('Anna is the grandmother of Sarah.', {'entities':
[(12, 23, 'Relationship')]}),
('John is the grandson of Sarah.', {'entities':
[(12, 20, 'Relationship')]}),
('Katy is the granddaughter of Sarah.',
{'entities': [(12, 25, 'Relationship')]}),
('John is the uncle of Sarah.', {'entities': [(12,
17, 'Relationship')]}),
('Mary is the aunt of Sarah.', {'entities': [(12,
16, 'Relationship')]}),
('John is the nephew of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('Mary is the niece of Sarah.', {'entities': [(12,
17, 'Relationship')]}),
('John is the cousin of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('John is the husband of Sarah.', {'entities':
[(12, 19, 'Relationship')]}),
('Mary is the wife of John.', {'entities': [(12,
16, 'Relationship')]}),
('John is the Sarah\'s partner.', {'entities':
[(20, 27, 'Relationship')]}),
('John is the fiance of Sarah.', {'entities':
[(12, 18, 'Relationship')]}),
('John is married to Sarah.', {'entities': [(8,
15, 'Relationship')]}),
('John is the parent of Sarah.', {'entities':
[(12, 18, 'Relationship')]})
]

optimizer = nlp.resume_training()
n_iter = 10
batch_size = 4

# Train the model


for i in range(n_iter):
losses = {}
batches = minibatch(train_data,
size=compounding(batch_size, 32, 1.001))
for batch in batches:
texts, annotations = zip(*batch)
examples = [Example.from_dict(nlp.make_doc(text),
annotation) for text, annotation in zip(texts,
annotations)]
nlp.update(examples, sgd=optimizer, losses=losses)
print(f'Iteration {i}: Losses: {losses}')

Checking if the class is added to the labels of entitites:

Using the same example:

You might also like