The answer to your question lies beyond programming. It is the area of Natural Language Processing (NLP), an AI field of studies overarching intersection of linguistic with computer science. Simply put it, how to make machines understand human (natural) languages. Initially, it started with hard-coded rule-based (grammars) machine learning which requires knowledge of the language concerned and large linguistic resources such as dictionary; it then moved on to statistical approaches where some sort of similarity measures are used to infer the meaning and closeness of texts.
Read more:
turing-test-revisited[
^]