LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it...

25
Fakti Likumi Izveduma mehānisms Jauni fakti Deduktīvās datu bāzes sistēmas sastāvdaļas Deduktīvā datu bāze sastāv no: 1) sākuma dati jeb fakti (facts). To sauc par paplašināmo (extensional) datu bāzi; 2) secinājumu iegūšanas likumi (inference rules), kas glabā zināšanas par to, kā var iegūt no esošajiem faktiem jaunus faktus; 3) jaunos faktus sauc par papildināto (intensional) datu bāzi. Deduktīvām datu bāzēm ir dažādas metodes, kas nosaka, kā paplašināmā datu bāze sadarbosies ar papildināto datu bāzi. Mērķis

Transcript of LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it...

Page 1: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Fakti

Likumi

Izveduma mehānismsJauni fakti

Deduktīvās datu bāzes sistēmas sastāvdaļasDeduktīvā datu bāze sastāv no:

1) sākuma dati jeb fakti (facts). To sauc par paplašināmo (extensional) datu bāzi;2) secinājumu iegūšanas likumi (inference rules), kas glabā zināšanas par to, kā var iegūt no esošajiem faktiem jaunus faktus; 3) jaunos faktus sauc par papildināto (intensional) datu bāzi.

Deduktīvām datu bāzēm ir dažādas metodes, kas nosaka, kā paplašināmā datu bāze sadarbosies ar papildināto datu bāzi.

Mērķis

Page 2: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Deduktīvās datu bāzes realizēšanas varianti1. Loģiskās programmēšanas valodu Prolog un Datalog sistēmu izmantošana.

2. Deduktīvās datu bāzes čaulu izmantošana.

3. Datu bāzes sistēmas iekšējās programmēšanas valodas (PL/SQL, Java) un SQL izmantošana:

a) SQL WITH konstrukcija saliktu vaicājumu veidošanai;

b) SQL WITH konstrukcija rekursīvu vaicājumu veidošanai;

c) dināmiskais dzimtais SQL (EXECUTE IMMEDIATE) saliktu vaicājumu un dināmisku programmu veidošanai;

d) dināmiskais SQL (pakete DBMS_SQL) saliktu vaicājumu un dināmisku programmu veidošanai.

Page 3: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Datu bāzes tehnoloģijas un loģiskās programmēšanas integrēšana1

Datu bāzes tehnoloģijas un loģiskās programmēšanas integrāciju sekmēja arī tas, ka loģiskās programmēšanas valoda Prolog tika izvēlēta par pamatu Japānas projektam “5-paaudzes skaitļotāju izstrāde”, kurā bija paredzēts iekļaut mākslīgā intelekta metodes jaunākajos skaitļotājos (1980. gads).

1. Deduktīvā datu bāze (loģiskās programmēšanas pielietošana datu bāzes datiem, lai veiktu dedukciju).

2. Zināšanu bāzes vadības sistēma (zināšanu (ne datu) apstrādes vadības sistēmas).

3. Ekspertu - sistēma (ekspertu zināšanu izmantošana, lietojot datu bāzes datus).

1 S.Ceri, G.Gottlob, L.Tanka. Logic Programming and Databases. Springer-Verlag, Berlin, 1990, 350 p.

Page 4: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Prolog2 is a logical and a declarative programming language

The name itself, Prolog, is short for PROgramming in LOGic. Prolog's heritage includes the research on theorem provers and other automated deduction systems developed in the 1960s and 1970s. The inference mechanism of Prolog is based upon Robinson's resolution principle (1965) together with mechanisms for extracting answers proposed by Green (1968). These ideas came together forcefully with the advent of linear resolution procedures. Explicit goal-directed linear resolution procedures, such as those of Kowalski and Kuehner (1971) and Kowalski (1974), gave impetus to the development of a general purpose logic programming system. The "first" Prolog was "Marseille Prolog" based on work by Colmerauer (1970). The first detailed description of the Prolog language was the manual for the Marseille Prolog interpreter (Roussel, 1975). The other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. Prolog is the major example of a fourth generation programming language supporting the declarative programming paradigm. The Japanese Fifth-Generation Computer Project, announced in 1981, adopted Prolog as a development language, and thereby focused considerable attention on the language and its capabilities. The programs in this tutorial are written in "standard" (University of) Edinburgh Prolog, as specified in the classic Prolog textbook by authors Clocksin and Mellish (1981,1992). The other major kind of Prolog is the PrologII family of Prologs which are the descendants of Marseille Prolog. The reference to Giannesini, et.al. (1986) uses a version of PrologII. There are differences between these two varieties of Prolog; part of the difference is syntax, and part is semantics. However, students who learn either kind of Prolog can easily adapt to the other kind.

2 https://www.cpp.edu/~jrfisher/www/prolog_tutorial/contents.html

Page 5: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Loģiskās programmēšanas valoda Datu bāzes sistēma

Loģiskās programmēšanas valodas un DBS kopdarbība1. Sasaiste – divu autonomu sistēmu interfeisa izveide, lai apmainītos ar datiem (datu bāze loģiskās programmēšanas valodas izpildes vides operatīvā atmiņa). Ābu autonomo sistēmu apvienojums tiek saukts par CPR sistēmām (Coupling Prolog to Relational databases).

a) vājā sasaiste (statiskā sasaiste) – datu apmaiņa notiek neatkarīgi no izveduma realizēšanas procesa, vienā datu apmaiņas procesā tiek izgūti visi nepieciešamie fakti;

b) ciešā sasaiste (dinamiska sasaiste) - datu apmaiņa notiek izveduma realizēšanas procesā, kad jāiegūst kārtējie konkrētie fakti.

2. Integrācija – jaunas vienotas sistēmas izveide, loģiskās programmēšanas valodas iekļaušana datu bāzes servera programmēšanas valodu kopā.

Loģiskās programmēšanas

valoda

Datu bāzes sistēma

Page 6: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Prologa sistēma

Likumi

Izveduma mehānisms

Lietotāja interfeiss

Lietotājs

Savienojums (SQL)

Datu bāzes sistēma

Fakti

Prolog sistēma ar savienojumu ar datu bāzes sistēmu

Page 7: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

PrologSQL tilts PROLOG sistēma DBS

1. Import two tables from a database.

2. Create a nondeterministic query predicate as an join between two tables.

3. Call the query predicate.

:- use_module(oracle).go :-db_open('Your Database Name', 'scott', 'tiger'),

db_import('DEPT'('DEPTNO', 'DNAME', 'LOC'), dept),db_import('EMP'('EMPNO', 'ENAME', 'JOB', 'MGR', 'HIREDATE', 'SAL', 'COMM', 'DEPTNO'), emp),

%% Uncomment it, if you do not want to see SQL statements.%% db_flag(show_query, _, off),db_query(empinfo(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC),(emp(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO),dept(DEPTNO, DNAME, LOC) ) ),get_result,db_close.

get_result:-empinfo(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC),write_ln([EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC]),

Page 8: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Deduktīvās datu bāzes realizācija.Prologa sistēmas SQL interfeisa izmantošana

Page 9: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Rūjiena

Valmiera

Mazsalaca

Cēsis

Stalbe 31 km

18 km

44 km

28 km

Aloja

Limbaži

Saulkrasti

Deduktīvas datu bāzes sistēmas čaula

Page 10: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

LDL++ sistēma

Page 11: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Datalog Educational system3

3 http://des.sourceforge.net/

Page 12: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby
Page 13: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

DBMS_SQL programmu paketes izmantošanaThe DBMS_SQL package provides an interface to use dynamic SQL to parse (sadalīt, analizēt) any data manipulation language (DML) or data definition language (DDL) statement using PL/SQL.

Page 14: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

DBMS_SQL programmu paketes izmantošanas piemērs

create or replace procedure DEMO(sal IN number) as cursor_name integer; rows_processed integer;BEGINcursor_name := DBMS_SQL.OPEN_CURSOR;DBMS_SQL.PARSE(cursor_name, 'delete from EMP where SALARY > :x', DBMS_SQL.NATIVE);DBMS_SQL.BIND_VARIABLE(cursor_name, ':x', sal);rows_processed := DBMS_SQL.EXECUTE(cursor_name);DBMS_SQL.CLOSE_CURSOR(cursor_name);EXCEPTIONWHEN OTHERS THEN DBMS_SQL.CLOSE_CURSOR(cursor_name);END;

Page 15: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Deduktīvās datu bāzes realizācija

Page 16: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Faktu tabula

Likumu tabula

Page 17: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Deduktīvās datu bāzes interfeiss

Page 18: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Datalog valodaDatalog is a declarative logic programming language that syntactically is a subset of Prolog.

It is often used as a query language for deductive databases. In recent years, Datalog has found new application in:

1) data integration;2) information extraction;3) networking;4) program analysis;5) security;6) cloud computing.

Its origins date back to the beginning of logic programming, but it became prominent as a separate area around 1977 when Hervé Gallaire and Jack Minker organized a workshop on logic and databases. David Maier is credited with coining the term Datalog.Unlike in Prolog, statements of a Datalog program can be stated in any order. Furthermore, Datalog queries on finite sets are guaranteed to terminate, so Datalog does not have Prolog's cut operator. This makes Datalog a truly declarative language.In contrast to Prolog, Datalog:

1) disallows complex terms as arguments of predicates, e.g., p (1, 2) is admissible but not p (f (1);

2) imposes certain stratification restrictions on the use of negation and recursion;

3) requires that every variable that appears in the head of a clause also appears in a nonarithmetic positive (i.e. not negated) literal in the body of the clause;

4) requires that every variable appearing in a negative literal in the body of a clause also appears in some positive literal in the body of the clause.

Query evaluation with Datalog is based on first order logic, and is thus sound and complete. However, Datalog is not Turing complete, and is thus used as a domain-specific language that can take advantage of efficient algorithms developed for query resolution. Indeed, various methods have been proposed to efficiently perform queries.Several extensions have been made to Datalog, e.g., to support aggregate functions, to allow object-oriented programming, or to allow disjunctions as heads of clauses.

Page 19: LDL++ sistēma - Web viewThe other major influence on the nature of this first Prolog was that it was designed to facilitate natural language processing. ... language, and thereby

Example Datalog program: parent(bill, mary). parent(mary, john).

These two lines define two facts, i.e. things that always hold. They can be intuitively understood as: the parent of mary is bill and the parent of john is mary. ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y).

These two lines describe the rules that define the ancestor relationship. A rule consists of two main parts separated by the :- symbol. The part to the left of this symbol is the head of the rule, the part to the right is the body. A rule is read (and can be intuitively understood) as <head> if it is known that <body>. Uppercase letters stand for variables. Hence in the example the first rule can be read as X is the ancestor of Y if it is known that X is the parent of Y. And the second rule as X is the ancestor of Y if it is known that X is the parent of some Z and Z is the ancestor of Y . The ordering of the clauses is irrelevant in Datalog in contrast to Prolog which depends on the ordering of clauses for computing the result of the query call.Datalog distinguishes between Extensional predicate symbols (defined by facts) and intensional predicate symbols (defined by rules). In the example above ancestor is an intensional predicate symbol, and parent is extensional. Predicates may also be defined by facts and rules and therefore neither be purely extensional nor intensional, but any Datalog program can be rewritten into an equivalent program without such predicate symbols with duplicate roles. ?- ancestor(bill,X).The query above asks for all that bill is ancestor of, and would return mary and john when posed against a Datalog system containing the facts and rules described above.