Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Detect Is Text Human Readable?

Tags:

android

ios

nlp

I am wondering if there's a way to tell a given text is human readable. By human readable, I mean: it has some meanings, format like an article written by somebody, or at least generated by a software translator that is intended to be read by a human.

Here's the background story: recently I am making an app that allows user to upload a short text to a database. At the early stage of deployment I noticed some user always uploaded corrupted text due to a problem with encoding. This problem is fixed later, but leaves me wonder if there's a way to pick up non human readable text before serving the text back to users.

Any advice will be appreciated. The scope might be too large to include other languages, so at the moment let's limit the discussion to English only.

like image 889
Craig Zheng Avatar asked Jan 21 '26 07:01

Craig Zheng


1 Answers

You can try a language identification tool, or something similar.

Basically you have to count the characters, or groups of character (character n-grams), and compare the distribution of the letters of the text submitted with the distribution of the letters of a collection of texts written in good english. (Make sure that such collection of texts is representative of the expected input).

In the continuity of a N-gram approach you might want to try a dictionary based approach and check for the presence of 'stop words' (e.g. 'the', 'a', 'an', 'of') in the input text.

like image 94
Pierre Avatar answered Jan 22 '26 20:01

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!