Cameron Potvin, Shubham Jakhete, Jaiveer Kapadia California State University, Fullerton
A used car recommendation system that uses knowledge representation to help users find reliable, safe vehicles within budget. We focus on two main KR approaches:
- Prolog Logic Programming - Expert rules for vehicle classification
- RDF/OWL Ontology with SPARQL - Semantic knowledge graph
Plus supporting components for constraint filtering and reliability estimation.
pip3 install pandas numpy rdflib matplotlib streamlitFor Prolog reasoning (recommended):
brew install swi-prolog # Mac
# or apt-get install swi-prolog on LinuxWeb interface (easiest):
./run_app.sh
# then go to http://localhost:8501Command line:
python3 cli.pyExpert rules are defined in prolog/car_rules.pl. Python generates the facts from data, but the actual reasoning happens in Prolog at runtime.
Categories defined:
excellent_choice- High reliability + safety + recent + low milesgood_value- Reliable and safe but affordablefamily_car- Prioritizes safetyreliable_commuter- Good for daily drivingbudget_pick- Cheapest decent options
Example rule:
good_value(Car) :-
high_reliability(Car),
high_safety(Car),
affordable(Car).Vehicles are represented as RDF triples in a knowledge graph. SPARQL queries handle the semantic reasoning at runtime.
The ontology includes:
- Vehicle class with properties (price, safety, reliability, mileage)
- Manufacturer relationships
- Body type subclasses
Example SPARQL query:
SELECT ?model ?make ?year ?price
WHERE {
?vehicle a car:Vehicle .
?vehicle car:safetyRating ?safety .
?vehicle car:reliabilityScore ?rel .
FILTER(?safety >= 4.0 && ?rel >= 0.8)
}- Propositional Logic - Simple AND of constraints to filter dataset
- Probabilistic Methods - Reliability estimation from age and complaint data
We integrated three datasets:
- Used Car Prices from Kaggle (4,009 vehicles)
- NHTSA Safety Ratings (11,028 crash test ratings)
- NHTSA Complaints Database (~100k complaints)
Final integrated dataset: 5,181 vehicles
├── app.py # Streamlit web interface
├── cli.py # Command line interface
├── src/
│ ├── recommendation_engine.py # Main orchestration
│ ├── prolog_reasoning.py # Prolog interface
│ ├── ontology_builder.py # RDF/OWL + SPARQL
│ ├── propositional_logic.py # Constraint filtering
│ └── probabilistic_reasoning.py # Reliability estimation
├── prolog/
│ ├── car_rules.pl # Expert rules (hand-written)
│ └── car_facts.pl # Generated from data at runtime
├── ontology/
│ └── cars.ttl # Generated RDF graph
└── data/
└── integrated_cars.csv
- User sets preferences (price, year, safety requirements)
- Propositional logic filters dataset to matching vehicles
- Prolog evaluates expert rules to classify vehicles into categories
- RDF ontology built and queried with SPARQL for semantic matching
- Results combined with weighted scoring
- Explanations show which categories each vehicle belongs to
- ~36% of vehicles have actual NHTSA safety ratings (rest default to 3.0)
- ~22% have complaint data for reliability scoring
- Prolog requires SWI-Prolog installation (system works without it, just loses rule-based classification)
python3 src/prolog_reasoning.py # Test Prolog rules
python3 src/ontology_builder.py # Test SPARQL queries
python3 src/recommendation_engine.py # Test full pipeline