-
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
- Can you activate BMW 48V 10Ah Li-Ion battery, connecting to CAN-USB laptop interface ?
- We Wrocławiu ruszyła Odra 5, pierwszy w Polsce komputer kwantowy z nadprzewodzącymi kubitami
- Ada-Europe - AEiC 2025 early registration deadline imminent
- John Carmack twierdzi, że gdyby gry były optymalizowane, to wystarczyły by stare kompy
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2025
- Linuks od wer. 6.15 przestanie wspierać procesory 486 i będzie wymagać min. Pentium
- ,,Polski przemysł jest w stanie agonalnym" - podkreślił dobitnie, wskazując na brak zamówień.
- Rewolucja w debugowaniu!!! SI analizuje zrzuty pamięci systemu M$ Windows!!!
- Brednie w wiki - hasło Dehomag
- Perfidne ataki krakerów z KRLD na skrypciarzy JS i Pajton
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- U nas propagują modę na SI, a w Chinach naukowcy SI po kolei umierają w wieku 40-50lat
- C++. Podróż Po Języku - komentarz
Najnowsze wątki
- 2025-07-03 ROG
- 2025-07-03 OZE dały Polsce więcej prądu niż elektrownie węglowe
- 2025-07-03 Dlaczego nikt nie powiadamia służb!
- 2025-07-02 Jaka ładowarka sieciowa do Iphona?
- 2025-07-02 ,,The Plot to Get RFK" (,,Spisek, by pozbyć się RFK")
- 2025-07-02 Rozkaz 17-2025: O Zaprzestaniu Zaciągania Kredytów
- 2025-07-02 Rozkaz 16-2025: 2025-06-19 Apelacja Do Wyroku Sądu Rej. w Sprawie IVRNs 295-23
- 2025-07-02 Rozkaz 17-2025: O Zaprzestaniu Zaciągania Kredytów
- 2025-07-02 Inżynierowie... inżynierzy...
- 2025-07-02 Can you activate BMW 48V 10Ah Li-Ion battery, connecting to CAN-USB laptop interface ?
- 2025-07-02 Kto potrafi sprawdzić aku BMW 48V 10Ah Li-Ion do mini hybrydy, czy sprawny ?
- 2025-07-02 Warszawa => Senior IT Recruitment Consultant <=
- 2025-07-02 Gdańsk => Konsultant wdrożeniowy (systemy controlingowe) <=
- 2025-07-02 Warszawa => IT Hardware Specialist - Wsparcie i Konfiguracja <=
- 2025-07-02 Warszawa => Inżynier oprogramowania .Net <=