% Make a simple knowledge base. Represent some of your favorite books and authors. % Solution author('Dune', 'Frank Herbert'). author('Dune Messiah', 'Frank Herbert'). author('Brave New World', 'Aldous Huxley'). author('Lord of the Flies', 'William Golding'). author('Of Mice and Men', 'John Steinbeck'). % Searching for 'Frank Herbert' results in two books. % Find all books in your knowledge base written by one author. % Call: % author(What, 'Frank Herbert'). % Out: % What = 'Dune' ? a % What = 'Dune Messiah' % Make a knowledge base representing musicians and instruments. % Also represent musicians and their genre of music. plays('Wolfgang Amadeus Mozart', piano). plays('Wolfgang Amadeus Mozart', violin). plays('Ludwig van Beethoven', piano). plays('Erik Satie', piano). plays('David Bowie', guitar). plays('Dire Straits', guitar). genre('Ludwig van Beethoven', classic). genre('Wolfgang Amadeus Mozart', classic). genre('Erik Satie', classic). genre('David Bowie', rock). genre('Dire Straits', pubrock). % Find all musicians who play the guitar. % Call: % plays(What, guitar). % Out: % What = 'David Bowie' ? a % What = 'Dire Straits' % (extra) find all genres a specified instrument occurs in allgenres(X, Instrument) :- plays(Y, Instrument), genre(Y, X). % Call: % allgenres(What, guitar). % Out: % What = rock ? a % What = pubrock