What exactly are ontologies in AI? How should I write them and why are they important?
An ontology at its most abstract is a model of the world. It describes concepts that exist in the world and how those concepts are related.
Ontologies are similar to taxonomies. A taxonomy is a tree-like hierarchy that organizes concepts in increasing levels of specificity. What an ontology adds is a second type of link between those concepts that explains how they are connected. So a taxonomy could say $isA(DOG, ANIMAL)$ ("a dog is an animal"). An ontology may also describe something like: $chase(DOG, CAT)$ ("dogs chase cats").
Why use an ontology? It can be used to reason about the world. I subscribe to a very particular kind of language-centric ontology that isn't worth addressing here. Instead, the Semantic Web project (Tim Berners-Lee) is probably closer to what would interest you. Semantic Web uses a type of description logic, which is outside my realm of expertise. But there are tools for processing these kinds of DL and gaining "understanding" from them. To work with this kind of ontology you'll want to be familiar with the idea of Resource Description Framework triples.