You are on page 1of 10

Biểu diễn tri thức bằng

Prolog
Thien Khai Tran
Cài đặt Swi-Prolog

https://www.swi-prolog.org/download/stable?show=all
Nên chọn version 5.x.x
Chương trình Swi-Prolog

query(query(Hotel, Place)) --> n_hotel, n_hotel(Hotel), v_at, n_place(Place), w_how.


n_hotel --> [khách, sạn].
n_hotel(hotel(Hotel)) --> n_hotels(Hotel).
n_hotels(novotel) --> [novotel].
v_at --> [ở].
n_place(place(Place)) --> n_places(Place).
n_places(hanoi) --> [hà, nội].
w_how --> [như, thế, nào].

Xử lý (biểu diễn) được dạng câu: khách sạn xyz ở abc như thế nào?
query(hotel(xyz),place(abc))

Chuyển thành câu SQL truy vấn CSDL/CSTrithuc


query(hotel(xyz),place(abc)) 
select * from tbl_hotel where tên_ks = ‘xyz’ & tên_tỉnhthành = ‘abc’
Biểu diễn ngữ nghĩa

ID Semantic presentation
1 query(hotel, place, aspect)
2 query(hotel, place)
3 query(hotel,)
4 query(hotel, place, attribute)
5 query(hotel, attribute)
Chương trình Swi-Prolog

Vd2:

query(query(Aspect,Faculty)) --> w_letme, n_aspect(Aspect), n_faculty(Faculty),


w_how.

w_letme --> [cho,tooi,hori].


n_aspect(aspect(Aspect)) --> n_aspects(Aspect).
n_aspects(score) --> [ddieerm,chuaarn].
n_faculty(faculty(Faculty)) --> n_facultys(Faculty).
n_facultys(cntt) --> [ngafnh,cntt].
w_how --> [nhuw, thees, nafo].
Chương trình Swi-Prolog

Vd2:

query(query(Aspect,Faculty, Year)) --> w_letme, n_aspect(Aspect), n_faculty(Faculty),


n_year(Year), w_how.

w_letme --> [cho,tooi,hori].

n_aspect(aspect(Aspect)) --> n_aspects(Aspect).


n_aspects(score) --> [ddieerm,chuaarn].
n_faculty(faculty(Faculty)) --> n_facultys(Faculty).
n_facultys(cntt) --> [cntt].
n_year(year(Year)) --> n_years(Year).
n_years(2017) --> [2017].
w_how --> [nhuw, thees, nafo].
Chương trình Swi-Prolog

Vd3:

query(nganh_khoi_thi_Query(Khoithi)) -->
t_nhungcac,n_nganh,p_at,n_truong(Truong),v_xettuyen,n_khoithi(Khoithi).

t_nhungcac-->[các].
n_nganh-->[ngành,nào].
p_at-->[của].
n_truong(truong(Truong))-->n_truongs(Truong).
n_truongs(huflit)-->[trường,đại,học,huflit].
v_xettuyen-->[thi].
n_khoithi(khoithi(Khoi))-->n_khoi(Khoi).
n_khoi(d1)-->[khối, d1].
Viết luật DCG trên Prolog thực hiện biểu diễn các dạng câu sau:

1. Cho tôi hỏi chỉ tiêu ngành CNTT năm 2017 bao nhiêu?

2. Xin cho tôi biết chỉ tiêu ngành Ngôn ngữ Anh năm 2018 là bao nhiêu?

3. Cho tôi hỏi điểm chuẩn ngành CNTT năm 2015 là bao nhiêu?

4. Tôi muốn biết các ngành nào ở huflit thi khối a vậy?
Ứng dụng

Truy vấn thông tin thời tiết

Truy vấn thông tin học vụ


Ứng dụng

Truy vấn thông tin thời tiết

Truy vấn thông tin học vụ

You might also like