-
Data: 2014-05-29 01:36:21
Temat: Re: Prolog i hierarchiczna baza faktów
Od: A.L. <a...@a...com> szukaj wiadomości tego autora
[ pokaż wszystkie nagłówki ]On Wed, 28 May 2014 20:35:23 +0200, Sebastian Bia?y
<h...@p...onet.pl> wrote:
>On 2014-05-27 23:52, Edek wrote:
>> Nie ty pierwszy - poczytaj zanim się zabierzesz do tematu.
>> Oprogramowanie potrafiące "przeczytać" książkę w miarę techniczną
>
>Nie analizuje języka naturalnego.
>
>> Hierarchiczną? Czy punkt a jest b czy b nad a i dlaczego?
>
>Ponieważ niezygle czesto wystepują tam zalezności "coś jest wewnątrz
>czegoś". Z programowania to oznacza częste relacje parent<->child
>wyrażone z relacji między obiektami w pamięci. Myślę że to dość istotna
>obsewacja.
Moze cie natchnie co prolog moze. To kalsyczny przykald bazy wiedzy, a
pytanie brzmi: kto jest wlascicielem zebry?
1. The Englishman lives in the red house.
2. The Spaniard owns the dog.
3. Coffee is drunk in the green house.
4. The Ukrainian drinks tea.
5. The green house is immediately to the right of the ivory house.
6. The Porsche driver owns snails.
7. The Masserati is driven by the man who lives in the yellow house.
8. Milk is drunk in the middle house.
9. The Norwegian lives in the first house on the left.
10. The man who drives a Saab lives in the house next to the man
with the fox.
11. The Masserati is driven by the man in the house next to the
house where the horse is kept.
12. The Honda driver drinks orange juice.
13. The Japanese drives a Jaguar.
14. The Norwegian lives next to the blue house.
To, jak mie sie wydaje, troche podobne do teojej bazy faktow. A to
ejst program w Prologu. Uzywa prologu zwanego SICStus
Daje taka odpowiedz:
Q: zebra(S).
A: S = [[yellow,norwegian,masserati,water,fox],
[blue,ukranian,saab,tea,horse],
[red,english,porsche,milk,snails],
[ivory,spanish,honda,orange,dog],
[green,japanese,jaguar,coffee,zebra]].
Mzoe jednak warto sprobowac z Prologiem?...
A tu caly program
/*
zebra.pl: Based on the classic zebra puzzle
(C) Pieter Valcke, 2003-2004
(C) Tom.Schrijvers at cs.kuleuven.be, 2003-2004
This program is distributed under the terms of the GNU General Public
License:
http://www.gnu.org/licenses/gpl.html
%% DESCRIPTION
Solves the classic "zebra puzzle" a.k.a. "Einstein's Riddle"
(cf. http://en.wikipedia.org/wiki/Zebra_Puzzle):
1. The Englishman lives in the red house.
2. The Spaniard owns the dog.
3. Coffee is drunk in the green house.
4. The Ukrainian drinks tea.
5. The green house is immediately to the right of the ivory house.
6. The Porsche driver owns snails.
7. The Masserati is driven by the man who lives in the yellow house.
8. Milk is drunk in the middle house.
9. The Norwegian lives in the first house on the left.
10. The man who drives a Saab lives in the house next to the man
with the fox.
11. The Masserati is driven by the man in the house next to the
house where the horse is kept.
12. The Honda driver drinks orange juice.
13. The Japanese drives a Jaguar.
14. The Norwegian lives next to the blue house.
%% HOW TO USE
zebra(S) returns the solution in a 5x5-matrix, one row for each
person:
S = [ [HouseColor1, Nationality1, Car1, Drink1, Pet1],
[ ... ], ... ]
%% SAMPLE QUERIES
Q: zebra(S).
A: S = [[yellow,norwegian,masserati,water,fox],
[blue,ukranian,saab,tea,horse],
[red,english,porsche,milk,snails],
[ivory,spanish,honda,orange,dog],
[green,japanese,jaguar,coffee,zebra]].
*/
:- module(zebra,[zebra/1]).
:- use_module(library(chr)).
:- use_module(library(lists)).
%% Deprecated syntax used for SICStus 3.x
%handler zebra.
%constraints domain/2, diff/2.
%% Syntax for SWI / SICStus 4.x
:- chr_constraint domain/2, diff/2.
domain(_,[]) <=> fail.
domain(X,[V]) <=> X = V.
domain(X,L) <=> nonvar(X) | member(X,L).
diff(X,Y) <=> nonvar(X), nonvar(Y) | X \== Y.
diff(Y,X) \ domain(X,L) <=> nonvar(Y), select(Y,L,NL) | domain(X,NL).
diff(X,Y) \ domain(X,L) <=> nonvar(Y), select(Y,L,NL) | domain(X,NL).
% all_different(L,E) enforces that each element of L is different to E
all_different([],_).
all_different([H|T],E) :-
diff(H,E),
all_different(T,E).
% make_domain(L,D) enforces for each element E of L:
% E is from domain D and different to each other element from L
make_domain([],_).
make_domain([X|L],D) :- all_different(L,X), domain(X,D),
make_domain(L,D).
% left_right(L, R, X) is true when L is to the immediate left of R in
list X
left_right(L, R, List) :- append(_, [L,R|_], List).
% next_to(X, Y, L) is true when X and Y are next to each other in list
L
next_to(X, Y, L) :- left_right(X, Y, L).
next_to(X, Y, L) :- left_right(Y, X, L).
% solves the zebra puzzle and returns solution in S
zebra(S) :-
[ [ ACo, AN, ACa, AD, AP ],
[ BCo, BN, BCa, BD, BP ],
[ CCo, CN, CCa, CD, CP ],
[ DCo, DN, DCa, DD, DP ],
[ ECo, EN, ECa, ED, EP ] ] = S,
make_domain([ACo,BCo,CCo,DCo,ECo], [red,green,ivory,yellow,blue]),
make_domain([AN, BN, CN, DN, EN ],
[english,spanish,ukranian,norwegian,japanese]),
make_domain([ACa,BCa,CCa,DCa,ECa],
[porsche,masserati,saab,honda,jaguar]),
make_domain([AD, BD, CD, DD, ED ],
[coffee,tea,milk,orange,water]),
make_domain([AP, BP, CP, DP, EP ], [dog,snails,fox,horse,zebra]),
[_,_,[_,_,_,milk,_],_,_] = S, % clue 8
[[_,norwegian,_,_,_],_,_,_,_] = S, % clue 9
member( [green,_,_,coffee,_], S), % clue 3
member( [red,english,_,_,_], S), % clue 1
member( [_,ukranian,_,tea,_], S), % clue 4
member( [yellow,_,masserati,_,_], S), % clue 7
member( [_,_,honda,orange,_], S), % clue 12
member( [_,japanese,jaguar,_,_], S), % clue 13
member( [_,spanish,_,_,dog], S), % clue 2
member( [_,_,porsche,_,snails], S), % clue 6
left_right( [ivory,_,_,_,_], [green,_,_,_,_], S), % clue 5
next_to( [_,norwegian,_,_,_],[blue,_,_,_,_], S), % clue 14
next_to( [_,_,masserati,_,_],[_,_,_,_,horse], S), % clue 11
next_to( [_,_,saab,_,_], [_,_,_,_,fox], S). % clue 10
Następne wpisy z tego wątku
Najnowsze wątki z tej grupy
- TCL - problem z escape ostatniego \ w nawiasach {}
- Nauka i Praca Programisty C++ w III Rzeczy (pospolitej)
- testy-wyd-sort - Podsumowanie
- Tworzenie Programów Nieuprzywilejowanych Opartych Na Wtyczkach
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
- Ada 2022 Language Reference Manual to be Published by Springer
Najnowsze wątki
- 2024-11-04 GNSS Motorola G85 vs Redmi Note 9 pro
- 2024-11-04 Katowice => SAP BTP Consultant (mid/senior) <=
- 2024-11-04 Katowice => Spedytor międzynarodowy <=
- 2024-11-04 Warszawa => Specjalista/tka ds. Zamówień publicznych <=
- 2024-11-04 Poznań => QA Engineer <=
- 2024-11-04 Poznań => QA Inżynier <=
- 2024-11-04 Polskie sądy są bardzo wyrozumiałe...
- 2024-11-04 Wrocław => SAP Project System/EPPM Consultant <=
- 2024-11-04 Gliwice => Team Lead / Tribe Lead FrontEnd <=
- 2024-11-04 Kraków => Programista Full Stack (.Net Core) <=
- 2024-11-04 Kraków => Software .Net Developer <=
- 2024-11-04 Kraków => Programista Full Stack .Net <=
- 2024-11-04 Warszawa => Key Account Manager <=
- 2024-11-04 Warszawa => Spedytor Międzynarodowy <=
- 2024-11-04 Warszawa => E-COMMERCE specialist <=