This repository contains a Python-based application that uses Prolog logic to manage and query family tree relationships. The program allows users to interactively input names and retrieve various relationships within the family, such as parents, grandparents, siblings, uncles, and children.
- Family Tree Representation: The program uses Prolog assertions to represent family relationships, including parents, siblings, grandparents, and uncles.
- Interactive Mode: Users can input a child's name and get information about their family tree.
- Prolog Integration: Prolog rules and facts are asserted in the program, allowing logical queries for relationships.
-
Family Tree Setup:
- Prolog facts are asserted to represent parent-child relationships.
- Logical rules define relationships like grandparents, uncles, and siblings.
-
Interactive Console:
- The program continuously prompts for a child's name and provides the family tree, listing relationships like parents, siblings, grandparents, uncles, and children (if applicable).
-
Prolog Queries:
- Uses Prolog logic to derive relationships by querying the family tree.
- Python (recommended version: 3.10.12)
- Prolog Engine: The program utilizes a Prolog engine integrated into the Python environment to handle logical assertions and queries.
-
Clone the repository:
git clone https://github.com/at-sso/FamilyTree.git cd FamilyTree -
Create a virtual environment:
python3 -m venv ./.venv
-
Install the required dependencies (assuming Prolog engine support is included in your environment):
pip install -r ./config/requirements.txt
-
Ensure that Prolog support is correctly set up in your environment: SWI-Prolog.
To start the application, run the main.py file:
python3 ./main.pyThe program will prompt you to input the name of a child from the family tree.
Valid child names are: Mary, Susan, Paul, James, Alice
> Mary
Output:
Family tree of Mary:
Parent of Mary:
John is the parent of Mary
Grandparent of Mary:
Mary doesn't have any grandparent.
...The family tree is represented using Prolog rules. Here are the key relationships:
-
Parent: Direct parent-child relationship.
parent(john, mary). parent(john, paul). parent(mary, susan). parent(mary, james). parent(paul, alice).
-
Grandparent: A person is a grandparent if they are the parent of someone who is also a parent.
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
-
Sibling: Two people are siblings if they share at least one parent and are not the same person.
sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.
-
Uncle: A person is an uncle if they are a sibling of someone's parent.
uncle(X, Y) :- sibling(X, Z), parent(Z, Y).
.
├── config
│ └── requirements.txt
├── main.py # Main script that runs the family tree logic
└── src
├── env
│ ├── ctypes.py # Defines necessary types for the program
│ ├── globales.py # Global variables and constants
│ ├── logger.py # Logging utilities
│ └── tools.py # Helper functions for formatting and styling output
└── functions.py # Core Prolog engine integration and function handling
To customize the family tree, you can modify the Prolog facts in main.py. For example, to add a new child or define new relationships, modify the following section:
assertz(f"{PARENT}(john, mary)")
assertz(f"{PARENT}(john, paul)")
# Add more family relationships here...This project is partially licensed under the MIT License.