Search code examples
prologartificial-intelligencedcg

Use Prolog to get data model paths from language rules?


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


Solution

  • 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.