Fact appears only once in the Knowledge Base <p>I have this KB (Knowledge Base):</p> <pre><code>%artist(ArtistId, ArtistName, YearofDebut). %album(AlbumId, AlbumName, YearOfRelease, Artists). %song(AlbumId, Songname, Duration). %artist/3 artist(1, 'MIEIC', 2006). artist(2, 'John Williams', 1951). artist(3, 'LEIC', 1995). artist(4, 'One Hit Wonder', 2013). %album/4 album(a1, 'MIEIC Reloaded', 2006,[1]). album(a2, 'Best Of', 2015, [2]). album(a3, 'Legacy', 2014, [1,3]). album(a4, 'Release', 2013, [4]). %song/3 song(a1, 'Rap do MIEIC', 4.14). song(a2, 'Indiana Jones', 5.25). song(a1, 'Pop do MIEIC', 4.13). song(a2, 'Harry Potter', 5.13). song(a1, 'Rock do MIEIC', 3.14). song(a2, 'Jaws', 3.04). song(a2, 'Jurassic Park', 5.53). song(a2, 'Back to the Future', 3.24). song(a2, 'Star Wars', 5.20). song(a2, 'E.T. the Extra-Terrestrial', 3.42). song(a3, 'Legacy', 3.14). song(a3, 'Inheritance', 4.13). song(a4, 'How did I do it?', 4.05). </code></pre> <p>And I want a query that asks if an album is a single (Got only one song).</p> <blockquote> <p>recentSingle(+AlbumId).</p> </blockquote> <pre><code>recentSingle(a1) ? No recentSingle(a4) ? Yes </code></pre> <p>How do I search in the whole KB and check if it only appears once?</p> <p><strong>ANSWER:</strong></p> <pre><code>recentSingle(AlbumId) :- album(AlbumId, _, Year, _), Year &gt; 2010, \+ isNotSingle(AlbumId). isNotSingle(AlbumId) :- song(AlbumId, Name1, _), song(AlbumId, Name2, _), Name1 \= Name2. </code></pre> <p>Regards</p>