Skip to content
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

Open
dseguy opened this issue Nov 22, 2017 · 0 comments
Open

Read code aloud #111

dseguy opened this issue Nov 22, 2017 · 0 comments
Labels
completed For completed novels!

Comments

@dseguy
Copy link

dseguy commented Nov 22, 2017

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.

@hugovk hugovk added the completed For completed novels! label Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed For completed novels!
Projects
None yet
Development

No branches or pull requests

2 participants