database( { word( string ) } ). % % Import predicate to split words from C++ % import foreign all_letters( $Word: string, Letter: string, Position: integer) from '/home/natraj/new_ldl++/system/demo/all_letters.o'. export common( Word1, Word2 ). export all_letters( $Word, Letter, Position ). % % Collect all letters of a word into a set % group_letters( Atom, < Letter > ) <- all_letters( Atom, Letter, _ ). % % Find words that are closely related. That is, % over half of the letters that appear in either % word also appear on the other word. % common( Word1, Word2 ) <- word( Word1 ), word( Word2 ), group_letters( Word1, Set1 ), group_letters( Word2, Set2 ), intersection( Set1, Set2, Inter ), union( Set1, Set2, Union ), cardinality( Union, UCard ), cardinality( Inter, ICard ), ICard > 0.5*UCard.