Next / Previous / Contents / Shipman's homepage

Abstract

This document describes the internals of a Python-language module to represent birdwatching field notes in XML.

This publication is available in Web form and also as a PDF document. Please forward any comments to john@nmt.edu.

Table of Contents

1. Overview
2. Module prologue
3. Module imports
4. Manifest constants
4.1. SCHEMA_RNG: Schema file name
5. Generic node readers and writers: .readNode() and .writeNode()
6. class BirdNoteSet: One file's worth of notes
6.1. BirdNoteSet.__init__(): Constructor
6.2. BirdNoteSet.addDay(): Add one day list
6.3. BirdNoteSet.genDays(): Generate days in self
6.4. BirdNoteSet.readFile(): Add a file's content
6.5. BirdNoteSet.__fileTime(): Update the most recent modification time
6.6. BirdNoteSet.__validate(): Open and validate the file
6.7. BirdNoteSet.__readDayNotes(): Read one day-notes node
6.8. BirdNoteSet.writeFile(): Translate to XML
7. class DayNotes: Notes from one date and state
7.1. DayNotes.title(): Daily full title
7.2. DayNotes.defaultLoc(): Return the default location
7.3. DayNotes.lookupLoc(): Look up a location code
7.4. DayNotes.addForm(): Add a form to one day's notes
7.5. DayNotes.genForms(): Generate forms in phylogenetic order
7.6. DayNotes.genFormsSeq(): Generate forms in the order they were added
7.7. DayNotes.__init__(): Constructor
7.8. DayNotes.writeNode(): Internal form to XML
7.9. DayNotes.readNode(): XML to internal form
7.10. DayNotes.readForm(): Process one contained form
8. class DaySummary: Daily summary
8.1. DaySummary.__init__()
8.2. DaySummary.defaultLoc(): Return the default location
8.3. DaySummary.addLoc(): Add a location definition
8.4. DaySummary.lookupLoc(): Find a location by its code
8.5. DaySummary.genLocs(): Generate all locations
8.6. DaySummary.readNode(): Convert from XML (static method)
8.7. DaySummary.dayAnnotation(): Process day-annotation content
8.8. DaySummary.writeNode(): Translate to XML
9. class Loc: Locality code definition
9.1. Loc.__init__(): Constructor
9.2. Loc.addGps(): Add a waypoint
9.3. Loc.genGps(): Generate waypoints
9.4. Loc.readNode(): Convert from XML (static method)
9.5. Loc-writeNode(): Translate to XML
10. class Gps: GPS waypoint
10.1. Gps.__init__()
10.2. Gps.readNode() (static method)
10.3. Gps.writeNode(): Convert to XML
11. class BirdForm: Notes for one kind of bird
11.1. BirdForm.__len__(): Number of sightings
11.2. BirdForm.__getitem__(): Index function
11.3. BirdForm.addSighting()
11.4. BirdForm.genSightings()
11.5. BirdForm.__init__()
11.6. BirdForm.getLocGroup(): Find the effective locality
11.7. BirdForm.readNode() (static method)
11.8. BirdForm.getTaxonGroup() (static method)
11.9. BirdForm.singleSighting(): Read a single sighting
11.10. BirdForm.multiSighting(): Read the multi-sighting case
11.11. BirdForm.readFloc(): Read one floc element
11.12. BirdForm.writeNode(): Translate to XML
11.13. BirdForm.__writeTaxonGroup()
11.14. BirdForm.writeSingle(): Create single-sighting XML
11.15. BirdForm.writeMulti(): Create multi-sighting XML
12. class Sighting: Sighting group
12.1. Sighting.__init__()
12.2. Sighting.getLocGroup(): Find a sighting's effective locality
12.3. Sighting.writeNode(): Translate to XML
13. class LocGroup: Sighting's locality
13.1. LocGroup.__init__()
13.2. LocGroup.readNode(): Extract loc-group content
13.3. LocGroup.inherit(): Implement inheritance for locations
13.4. LocGroup.writeNode(): Translate to XML
14. class AgeSexGroup: Sighting core data
14.1. AgeSexGroup.__init__()
14.2. AgeSexGroup.readNode() (static method)
14.3. AgeSexGroup.writeNode()
15. class SightNotes: Optional notes
15.1. SightNotes.__init__()
15.2. SightNotes.addPhoto()
15.3. SightNotes.genPhotos(): Generate photos
15.4. SightNotes.addPara(): Add a paragraph of notes
15.5. SightNotes.readNode() (static method)
15.6. SightNotes.writeNode()
15.7. SightNotes.writeChild(): Attach narrative to a child
16. class Photo: Photo link
16.1. Photo.__init__()
16.2. Photo.readNode() (static method)
16.3. Photo.writeNode()
17. class Narrative: Narrative elements
17.1. Narrative.__init__(): Constructor
17.2. Narrative.addPara(): Add a paragraph
17.3. Narrative.__len__(): How many paragraphs?
17.4. Narrative.__getitem__(): Get one paragraph
17.5. Narrative.genParas(): Generate self's contained paragraphs
17.6. Narrative.writeNode(): Write as XML
17.7. Narrative.readNode(): Read XML (static method)
17.8. Narrative.readChild() (static method)
18. class Paragraph: One paragraph of mixed text
18.1. Paragraph.__init__(): Constructor
18.2. Paragraph.addContent()
18.3. Paragraph.genContent(): Generate the content
18.4. Paragraph.writeNode(): Write as XML
18.5. Paragraph.writeContent(): Write the content of a paragraph
18.6. Paragraph.__writeParaChild()
18.7. Paragraph.readNode(): Process a para element (static method)
18.8. Paragraph.addPhrase(): Add one phrase to the paragraph
19. Testing
19.1. Sample XML input file
19.2. identitest: Round-trip test script

1. Overview

A system for encoding bird field notes describes an XML schema for encoding birdwatching field notes, along with a Python module that reads and writes XML files conforming to that schema. This document contains the actual code for the module, in literate programming style. For more information, see the author's literate programming page.

The birdnotes.py module reads and writes XML using techniques described in Python XML processing with lxml. The reader should be familiar with Python and XML.

Files referred to in this document:

The module exports a number of classes. Each represents an XML element.