My goal is to take simple sentence such as Grass is green and convert it to Prolog rule/fact. It does not have to be Prolog, but any other functional programming language with which I can perform semantic reasoning.

I know that LKB allows to do it. But I am not sure how to use it. I am reading guide to LKB by its original developer Ann Copestake "Implementing Typed Feature Structure Grammars", but it looks very involved. Is there shorter illustration? Or maybe another tool for it?

  • I'm voting to close this question as off-topic because implementation questions about programming are not considered on-topic. Feb 28, 2019 at 23:54
  • 4
    Questions about computational linguistics are on-topic. The question does not ask for help with the detailled implementation of a progam they are trying to write (which would of course not be suited for a linguistics site, but a question for SO), but - as I understand it - is a resource request ("illustrations" and "tools") on parsing or computational semantics, which I find perfectly fine. Mar 1, 2019 at 0:23

1 Answer 1


You will likely not find a program that "converts" natural language sentences into plain Prolog code like Green(X) :- Grass(X). because natural language is way too involved to be accuarately expressed as facts and rules when taking the linguistic predications directly as logic programming predications. For example, how would you represent mass nouns (does it really make sense to treat "grass" as a predicate which ranges over a set of individuals - what would those individuals be?), questions, adverbs (like "quickly(run)" - this is a a property of a property and thus not directly first-order definable!), quantifiers like "more than" (again, not first-order definable), ...

So what you actually want is a parser that understands the syntax of a natural language sentence converts it into some representation language, like typed feature structures, which can then be encoded in Prolog. Using such a representation language rather than trying to express natural language expressions directly as logical formulas solves many of the above mentioned problems; for example event semantics (which is usually expressed in a more or less formal language that's roughly predicate logic with lambdas, but with a specific sets of constants and special predicates) can treat adverbs. You can model lambda terms in Prolog, e.g. abstr(x,appl(f,x)) for λx.f(x), but at that point the predicate and function symbols in your program involve expressions of the representation language (like abstr for abstraction and appl for application in the language of lambda calculus) and no longer consist of (just) the natural language expressions,which is what I mean by not doing a direct mapping from natural language to logic programs.

To get an idea of how formal semantics can be done in Prolog, Patrick Blackburn & Johan Bos offer a software package that goes along with their book; you could have a look into that. They provide Prolog encodings for representations like lambda calculus or hole semantics (used to represent quantifier ambiguities) with a basic parser for English.
It's nice for educational purposes or to play around with in order to get an impression of how natural language can be treated in Prolog, but not at all suited for real-life NLP applications. The program fails at comparatively simple sentences like "Every man or a woman sleeps" (the hole semantics converter outputs readings which are logically impossible) and deals only with an extremely limited subset of English - it's more of a toy grammar to demonstrate how such things can be done in Prolog principially, not something that intends to be used professionally.

For more stable systems which are able to deal with a larger lexicon and variety of linguistic phenomena, you will have to dive into more complex theories and representation devices. The most prominent one is presumably HPSG (= head-driven phrase structure grammar, which is heavily based on typed feature structures), which has been implemented in Prolog in the TRALE system. This tool is very powerful, but a mess to get into. But that's the deal: You keep it very simple but can then only deal with a tiny textbook examples snippet of actual language, or you attempt to give an accurate description of anything that natural language allows to express but then the formalism explodes.

Systems like slot grammar, which has implementations in Prolog that are actually still being used in the industry (although this being very much of a niche), are, although sometimes guided by additional semantic information, more about syntactic parsing and even further away from semantics than e.g. HPSG is (and as I understad it's the linguistic-semantic representation, i.e. a language-to-program "translation" you are interested in, not parsing techniques).

Nowadays, noone really does compuational semantics like this anymore. Modern NLP uses sophisticated statistical models and methodology from linear algebra, neural nets and whatnot, sometimes combined with lexical information from databases like WordNet, to perform semantic reasoning. But if you are genuinely interested in computational semantics with logic programming, try starting with the Blackburn & Bos implementation, it's the simplest I know.

BTW: Prolog is not a functional programming language: Predications allow in principle for more than one possible output for any given input - of course, particular instances of a predicates applied to a tuple of arguments may only have one solution due to their semantics, but the programmming language does not express this syntactically in a way that there would be a distinguishable construction for functions which have unique output values. A one-place function f(x) = y is expressed as a two-place relation f(x,y) (functions are special relations). The relation f(x,y) captures the fact that y is a value of f at argument x, but does not exclude the possibility that there may be other z such that f(x,z). This is different from functions, for which there is always one unique value, which is why we can write ... = y, and nest applications of functions into each other - this is not in possible for relations. Facts and rules in general express relations rather than functions, so Prolog is relational. Function symbols do exist, but function terms are not evaluated, more treated like constants. These distinctions might seem a bit hair-splitty, and compared to programming languages that work completely differently (say, Java) some concepts might seem very similar (for example, programming languages that are well-suited for representing propositions will probably fall under the declarative paradigm), but if you compare Prolog to a classic functional programming language like Haskell, the differences are striking. The definition even of simple function like Fibonacci looks quite different in a relational language than it does in a purely functional one, and just as different is the way in which these programs are evaluated under the hood.

  • 1
    Thank you for your reply! LBK (moin.delph-in.net/LkbTop) uses HPSG and DELPH-IN. I am reading through Blackburn and Bos, but I wonder if I can find working system that convert natural language to some computable logical form (including lambdas and etc.). It looks like LBK can do it, I just need to figure out how to use it. I understand it will be far from perfect, but at least something to start. Mar 1, 2019 at 15:51
  • 1
    Yes; see Siva Reddy's work & references; also, github.com/sivareddyg/UDepLambda
    – user21043
    Mar 2, 2019 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.