-
Notifications
You must be signed in to change notification settings - Fork 7
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read code aloud #111
Labels
completed
For completed novels!
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! I though I'd give a try a this. I already had the idea of turning PHP code into plain natural language.
The idea is to take PHP code, and read it aloud, in English. Not read the tokens one by one, but turn an expression like 'class x extends y {}' into a full, meaningful sentence : the definition of the class x, which extends the class y'.
This relies on the Abstract Syntactic Tree of PHP 7.0+, so the internal tokens are non-ambiguous. Then, the native PHP functions and operator are organized in a dictionary to be able to turn 'trim($a)' into 'the trimming of the spaces at the beginning and the end of $a'.
While preparing this entry, I realized that is close to #80 (made in Python) and dariusk/NaNoGenMo-2015#173 (with the phone line twist).
The result is an ugly text file, with a lot of repetition.
The code : https://github.com/dseguy/php2natural
An example of output : https://github.com/dseguy/php2natural/blob/master/out.txt
It is about 83k words : it was actually difficult to go beyond the threshold of 50k words in one file. Even the self-reading is about 20k.
The code won't work on every PHP code ATM : some tokens are not processed yet, some features silently ignored. It should run on a fair number of them.
I might keep working on this some more, as this PHP -> NL process is very interesting in terms of code understanding.
The text was updated successfully, but these errors were encountered: