%delivery D456 %--------------------------------------------------------------- delivery('D456'). %contact (sender) contact('I3321'). %name, street, city, country for contact contactName('I3321', 'JT Brewery'). street('I3321', 'West Av. 345'). city('I3321', 'El Paso'). country('I3321', 'USA'). %sender of this deliver (has a contact) sender('D456','I3321'). %contact (recipient) contact('I7712'). contactName('I7712', 'J. Boldman'). street('I7712', 'West Av. 345'). city('I7712', 'Sydney'). country('I7712', 'Australia'). % recipient of this delivery (has a contact) recipient('D456', 'I7712'). %parcel parcel('P219'). % parcel card parcelCard('C256'). % parcel id in parcel card hasParcelId('C256','219'). % category number in parcel card categoryNumberOfItemsInParcel('C256', 'P12'). % the parcel has one parcel card hasParcelCard('P219','C256'). % item It1002 in parcel item('It1002'). % item description description('It1002', 'fragile'). % category number of the item categoryNumberOfItem('It1002', 'P12'). % item It3002 item('It3002'). % item description description('It3002', 'fragile'). % category number of the item categoryNumberOfItem('It3002', 'P12'). % pallet P341 plasticPallet('P341'). %the parcel contains 2 items + one plastic pallet containsParcelComponent('P219', 'It1002'). containsParcelComponent('P219', 'It3002'). containsParcelComponent('P219', 'P341'). % item It009 item('It009'). % item description description('It009', 'fragile'). % category number of the item categoryNumberOfItem('It009', 'P02345'). % delivery contains one parcel and one item containsDeliveryComponent('D456','P219'). containsDeliveryComponent('D456','It009'). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %delivery D457 %--------------------------------------------------------------- delivery('D457'). %contact (sender) contact('I7122'). %contactName, street, city, country for contact contactName('I7122','R. Bach'). street('I7122', 'Colony St. 15'). city('I7122','San Diego'). country('I7122','USA'). %sender of this deliver (has a contact) sender('D457','I7122'). %contact (recipient) contact('I7129'). contactName('I7129','K. Forest'). street('7712', 'McCartney St. 992'). city('I7129', 'Boston'). country('I7129','USA'). % recipient of this delivery (has a contact) recipient('D457', 'I7129'). %parcel parcel('P009'). % parcel card parcelCard('C267'). % parcel id in parcel card hasParcelId('C267','009'). % category number in parcel card categoryNumberOfItemsInParcel('C267', 'P32'). % the parcel has one parcel card hasParcelCard('P009','C267'). % item It1402 in parcel item('It1402'). % item description (no description for this item) % description('It1402', ). % category number of the item categoryNumberOfItem('It1402', 'P32'). % pallet P461 woodPallet('P461'). %the parcel contains 1 items + one wood pallet containsParcelComponent('P009', 'It1402'). containsParcelComponent('P009', 'P461'). % item It9009 item('It9009'). % item description description('It9009', 'foto albums'). % category number of the item categoryNumberOfItem('It9009', 'P02222'). % delivery contains one parcel and one item containsDeliveryComponent('D457','P009'). containsDeliveryComponent('D457','It9009'). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% domesticDelivery(VDelivery, VCountry) :- delivery(VDelivery), sender(VDelivery, VSender), recipient(VDelivery, VRecipient), country(VSender, VCountry), country(VRecipient, VCountry). neighbours(VRecipient1, VRecipient2) :- recipient(VDelivery, VRecipient1), recipient(VDelivery, VRecipient2), city(VRecipient1, VCity), city(VRecipient2, VCity), VRecipient1 \== VRecipient2. illegalParcelFragileNonFragile(VParcel) :- parcel(VParcel), containsParcelComponent(VParcel, VItem1), containsParcelComponent(VParcel, VItem2), item(VItem1), item(VItem2), description(VItem1, 'fragile'), description(VItem2, VDescription), VDescription \== 'fragile'. illegalParcelAustraliaWithWoodPallet(VParcel) :- parcel(VParcel), containsDeliveryComponent(VDelivery, VParcel), recipient(VDelivery, VRecipient), country(VRecipient, 'Australia'), containsParcelComponent(VParcel, VPallet), woodPallet(VPallet). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % domestic deliveries within USA in database question1(VDelivery, VCountry) :- domesticDelivery(VDelivery, VCountry). :- question1(VDelivery, 'USA'). % what the database says about J.Boldman question2(VDelivery, VName, VStreet, VCity, VCountry) :- contactName(VContact, VName), street(VContact, VStreet), city(VContact, VCity), country(VContact, VCountry), recipient(VDelivery, VContact). :- question2(VDelivery, 'J. Boldman', VStreet, VCity, VCountry). % are there some illegal parcels in the database? question3(VParcel):- illegalParcelFragileNonFragile(VParcel) ; illegalParcelAustraliaWithWoodPallet(VParcel). :- question3(VParcel).