Tuesday, April 5, 2016

Introduction To The Refcards Project

Hi, all. I've been semi-secretly working on a project that I internally am calling The Refcards Project. It has gone by mamy names, and in any case for now let's just call it that.

So here it is. I am doing many things as a burgeoning young programmer, and here is some of that. First of all, I'm working on what I am calling "Internals". In Python, since everything I do in Python, "internals" just means the stuff that happens "internally", like at the level of compilation, at the level of the interpreter and so forth. I'm only interested in the stuff that happens "under the hood" when you actually "run Python" (whatever that means!).

So that's one project. Another is called The Datatypes Project: Abstract Assembly. I will get into that later. Another is called The Archives-Project, and in part it is a new novel I've been working on for many years, but it goes much further than that. Also a topic for another time.

Right now, though, I want to introduce this cute little Python module simply called "wikipedia". The wikipedia module is going to help me actually compose the very first official Refcards app.

Installing it is simple, type:

$ pip install wikipedia

You can instantly start doing interesting things. Check out the documentation. Here is a simple example of what you can do, from the documentation:

>>> import wikipedia
>>> wikipedia.search("Barack")
[u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama']
>>> wikipedia.suggest("Barak Obama")
u'Barack Obama'

That's all there is to it, really. The possibilities are endless, though. Also from the quickstart guide, you can get a summary of an article simply, by using  wikipedia.summary:

>>> wikipedia.summary("GitHub")
2011, GitHub was the most popular open source code repository site.\nGitHub Inc. was founded in 2008 and is based in San Francisco, California.\nIn July 2012, the company received $100 million in Series A funding, primarily from Andreessen Horowitz.'
>>> wikipedia.summary("Apple III", sentences=1)
u'The Apple III (often rendered as Apple ///) is a business-oriented personal computer produced and released by Apple Computer that was intended as the successor to the Apple II series, but largely considered a failure in the market'

Anyway that's it for now. I will be coming back to this. Just keep an eye out for future blog posts on both The Internals Project AND The Refcards Project. The idea is that I can create a simple app that does nothing more, really, than reading out the first couple of lines from any given Wikipedia article.

The thing is, though, that with other Pythonic magic, it's pretty easy to take a module like the wikipedia module and make it do interesting things. For instance, I can not only fetch the first few lines of an article, I can also basically "crawl" the page for certain links. With a little Pythonic magic, some regular expressions or whatnot, or an interesting chunk of code called "pattern", I can do amazing things just with a simple Wikipedia page.

The module already lets me fetch the "categories" for a given page. Granted, I will need to do some Natural Language Processing magic, but that's pretty easy in Python. So basically I can create a simple app that interfaces with Wikipedia in amazing ways. I can make it get more intelligent AS YOU USE IT, and I can make everything get stored automatically on Dropbox, or even as Gist on Github using the Github API.

Python is amazing in that way, it has a million and one ways it has been extended, and the tools exist to do just about everything. Anything you can think, you can likely do in Python. With that being said, I don't like Python as a language. I think it is too slow. I think that if you're going to write code in Python, you should just learn to write it in C. Period. Don't use Python, use C. You're just wasting your time with just a bunch of bloat and candy and sugar. Fuck it, it's not worth it.

But it's the only language I currently know how to code in. So I "tolerate" it, at least until I finish learning how to write in C. And I'm getting there. But that might just have to be on another blog, since this blog is called Pythonic Reflections. But that's what the output of my reflections have been, so far, that if you're going to write in Python, learn to write in C. Don't waste everyone's time. It ends up in C in any case. Python is just bloated complicated and slow C code. It's like deciding to speak in English, but deciding to speak in English but backwards. Okay, people will understand you as long as they have a "Reverse The Backwards" interpreter. But it's a waste of time, you are better to speak "Forwards English rather than the Backwards variety.

In short, that's what Python is: Backwards C.


No comments:

Post a Comment