--- title: Cars Knowledge Graph emoji: 🚗 colorFrom: blue colorTo: red sdk: docker pinned: false --- # Knowledge Representation Project: Cars Knowledge Graph ## 1. Introduction & Motivation This project transforms a flat CSV dataset of **Car Specifications (2025)** into a semantic **Knowledge Graph (RDF/OWL)**. **Domain**: Automotive Industry (Cars, Manufacturers, Engines, Performance). **Motivation**: To enable complex querying of car data that is not possible with simple tabular lookups, such as inferring "High Performance" vehicles or categorizing cars by complex criteria (e.g., specific engine types + price ranges). ## 2. Ontology Design (Conceptual Model) The Ontology is designed using **RDFLib** and conforms to the project requirements (20+ Classes, 7+ Properties). ### Core Classes - **Car**: The central entity. - **Subclasses**: `SportsCar`, `HyperCar`, `Sedan`, `Coupe`, `ElectricCar`, `PetrolCar`, `LuxuryCar`. - **Manufacturer**: Companies like Ferrari, Tesla, Bugatti. - **Component**: `Engine`, `V8Engine`, `V12Engine`. - **defined Classes**: - `SuperCar`: Cars with Top Speed > 300 km/h. ### Properties - **Object Properties**: `hasManufacturer`, `hasEngine`, `usesFuel`, `manufactures`. - **Datatype Properties**: `hasPriceValue`, `hasHorsePowerValue`, `hasSeatCount`, `hasTopSpeedKMH`. ## 3. Knowledge Graph Construction - **Source**: `Cars Datasets 2025.csv` - **Output**: `cars_knowledge_graph.ttl` (Turtle Syntax) - **Triples Generated**: ~9,842 ## 4. Competency Questions & Validation The following questions guided the design and were validated via SPARQL: 1. **"List all cars manufactured by Ferrari"** - Verified: Returns models like `SF90 STRADALE`, `ROMA`, `812 GTS`. 2. **"Which cars have > 800 HorsePower?"** - Verified: Returns `Bugatti Chiron`, `Tesla Roadster 2`, etc. 3. **"Count of 2-Seater Coupes"** - Result: 147 vehicles. 4. **"What is the average price of all cars?"** - Result: ~$137,193 USD. ## 5. How to Run ### Prerequisites - Python 3.x - Libraries: `rdflib`, `pandas` ### Steps 1. **Install Dependencies**: ```bash pip install rdflib pandas ``` 2. **Generate Knowledge Graph**: ```bash python src/ontology.py # Generates Ontology Schema python src/convert_data.py # Generates Graph from CSV ``` 3. **Run Validation Queries**: ```bash python src/validate.py ```