In simple terms understanding structure of Gene ontology is all about comprehending the Schema of particular Ontology database. Schema of database gives us clear view of how information are stored, tables, fields and their relationship.
In above figure you can see some parts of database where there are tables, fields, attributes, relationship and along with primary ID. Now programming with the GeneOntology is all about knowing how information are stored and way of querying it in Ontology database.
MySql connection parameters for the GO database mirror at the EBI
Similarly you can manipulate ontology with perl, python, R, Ruby or whatever language you know if you go through documentation.
I strongly believe R is the best choice for programatic manipulation of GO, there are several Bioconductor packages like topGO, GOstats. Further excellent tutorial at Blue Collar Bioinformatics, R & Bioconductor Manual, GO related libraries and more teaching resources
Hope it helps
Edit - Previous Schema image updated!