0

I would like to take a set of English sentences and convert those to a set of relations. e.g.

"A pilot flies an airplane." would map to something like the following relation:

flies(pilot, airplane)

"Bob is the father of Alice and Doug." would map to

father(Bob, Alice)
father(Bob, Doug)

I know that I have seen a python library to do something like this before, but despite all of my searching I haven't been able to find that. I have never done NLP programing before, so I may be using terms incorrectly. My apologies.

UPDATE: This is not an effort to generate Prolog, but to generate binary (and other) facts about a universe of discourse. These facts could then be inserted into an object-role model, and help to generate a database schema. The "flies" fact above is just to illustrate, and there is no requirement around the syntax of the output. It just has to be a regular output.

In linguistic terms, I guess I would like to see a verb phrase and two noun phrases to capture a binary fact. The way those are structured is not as important as being able to discern the structure in an automated manner.

Gabe
  • 1,910
  • 2
  • 11
  • 11

1 Answers1

1

You seem to be converting natural language into Prolog (XSB?). In general, there is no easy (or even reasonably difficult) way to automate this process. For simple sentences like the ones in your question, however, you need to use typed dependency parsing. This will give you the subject, object and verb. Once you have these, you can then write a simple script to get your tuples.

Python's natural language toolkit (NLTK) does not support type dependency. (see this answer

Stanford's parser will help you with that (as Prateek mentions in the comment). Note that you need to use typed dependency.

Your example sentence "A pilot flies an airplane." will yield

det(pilot-2, A-1)
nsubj(flies-3, pilot-2)
root(ROOT-0, flies-3)
det(airplane-5, an-4)
dobj(flies-3, airplane-5)

root is the predicate (the main verb), nsubj denotes the subject, and dobj denotes the direct object.

Hope this helps :-)

Community
  • 1
  • 1
Chthonic Project
  • 8,216
  • 1
  • 43
  • 92
  • While that wasn't quite what I was looking for (I recall seeing a more fully baked solution) it will have to be my starting point. Thanks! – Gabe Nov 19 '13 at 19:17