I'm writing a program that will do some language processing in French, spitting out sentences composed from various data points. For example, "Jean t'a appelé hier à 15h12", because in the database there is a record for an inbound phone call yesterday at 3:12PM from one of your contacts, Jean, just to give you an idea of what I mean.

So I'm looking for a library (in Python preferably) that has already implemented the logic of, for a given location, whether one should say "à" ou "en", etc. For example:

"Tu as été à Paris l'année dernière"

"Tu as été en Angleterre cette année"

Does such a library/API exist? Merci beaucoup !

  • 1
    It probably exists inside some complex natural language processing models, but a library/API... Commented Jun 22, 2023 at 14:43
  • 1
    I've had good luck with various NLP packages in python.
    – Frank
    Commented Jun 22, 2023 at 14:49
  • @Frank any examples?
    – daveslab
    Commented Jun 26, 2023 at 21:43
  • @daveslab nltk.org, but not specifically for this problem when I used it.
    – Frank
    Commented Jun 26, 2023 at 21:45

1 Answer 1


I suggest you to use the Language tool API which seems to be remarkably good at correcting preposition usage errors:

example of languagetool correction

Unfortunately, with great power comes great price. The API isn't free.

Otherwise, if you have access to the location category of your sentence (city or country, for example) you can implement the grammar rules and known exceptions yourself, even if it's a bit tedious.

  • Thank you very much for your answer, unfortunately the library would need offline access. You're right that I could implement the rules myself, but indeed it would be quite tedious.
    – daveslab
    Commented Jun 26, 2023 at 21:43

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.