0

I want to build a semi-natural language interface for a data warehouse. A simple data model looks for example like this:

Company
- attribute 'name'
- reference to 'Departments'

Department
- attribute 'type'
- reference to 'Employees'

Employee
- attribute 'age'
- attribute 'salary'

And I would like to make queries like so:

ACME employees, Bugs Bunny salary, ACME department types etc.

For input that is not in the grammar, I would call the database and resolve say ACME into Company.

... and turn the queries into paths that my database language will understand:

[Company].departments.employees, [Employee].salary, [Company].departments.type.

I remember using SWI-Prolog way back when to parse English sentences and say if they are correct. Is Prolog still the way to go in this case?

Thanks

false
  • 10,264
  • 13
  • 101
  • 209
Radek
  • 3,913
  • 3
  • 42
  • 37

3 Answers3

1

In SWI-Prolog, there is Chat80 ready to install. I think could be very similar to what you are after, mutatis mutandis.

Just a sample query from the session log (note: was my own old port of chat80 to SWI-Prolog, the pack is presumably more functional, but I haven't tried to run):

what rivers are there ? 

Parse: 0.0168457sec.
whq
   $VAR
      1
   s
      np
         3+plu
         np_head
            int_det(B)
            []
            river
         []
      verb(be,active,pres+fin,[],pos)
      void
      []



Semantics: 0.0170898sec.
answer([B]) :-
   river(B)
 & exists B 
     true

Planning: 0.0sec.
answer([B]) :-
   river(B)
 & exists B 
     true
amazon, amu_darya, amur, brahmaputra, colorado, congo_river, cubango, danube, don, elbe, euphrates, ganges, hwang_ho, indus, irrawaddy, lena, limpopo, mackenzie, mekong, mississippi, murray, niger_river, nile, ob, oder, orange, orinoco, parana, rhine, rhone, rio_grande, salween, senegal_river, tagus, vistula, volga, volta, yangtze, yenisei, yukon and zambesi.

Reply: 0.166992sec.

The logical form required by discourse to answer a query it's the central point of the system. Not really easy to craft from ground!

I read the book Prolog and Natural Language Analysis, F.Pereira, S.Shieber, 1987 (translated in Italian), still my preferred! The english original it's freely available here.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Thanks for the Chat80 reference. Luckily, the scope of the queries I am making is smaller and the language is way simpler. – Radek Apr 09 '12 at 10:55
1

Even, better, I now use DCG with embedded Prolog rules.

So, for a model that has classes and attributes like this:

c(company, class(company)) --> [company].
a(company, attribute(name)) --> [name].

I can ask for attributes of a class of a class:

q(q(A,C1,C2)) --> a(T1,A), [of], c(T1,C1)
    ,[of], c(T2,C2), {is_child(T1, T2)}.

And get a tree back as an answer.

Radek
  • 3,913
  • 3
  • 42
  • 37
0

Have ended up with this example that translates a 'sentence' into a path in the model:

% root classes
class(ceo).

% model relations
attribute_of(age, ceo).
attribute_of(salary, ceo).

% grammar of relations
attribute('age', age).
attribute('salary', salary).
attribute('money', salary).

% answer format
answer([Class, Attribute], Class, Attribute).

% language rules
% query(Attribute,'of',Object, Answer).
query(AttributeQ, 'of', ClassQ, Answer) :-
    db(ClassQ, Class), attribute(AttributeQ, Attribute), attribute_of(Attribute, Class), answer(Answer, Class, Attribute).

% database
db('Bugs Bunny', ceo).

As an example, the following query:

?- query('age','of','Bugs Bunny', Answer).

...gives me:

Answer = [ceo, age].

Radek
  • 3,913
  • 3
  • 42
  • 37