Module BIParser :: Class BIParser
[show private | hide private]
[frames | no frames]

Class BIParser

        object --+
                 |
ContentHandler --+
                 |
    DTDHandler --+
                 |
EntityResolver --+
                 |
  ErrorHandler --+
                 |
                BIParser


The parser used to process the BioInfer XML file. The parsing process is implemented so that most of the logic of building the corpus objects lies on the __init__ methods of the classes. The parser has very little logic of its own.

The parsing works as follows:

It is the responsibility of the __init__ method of an instance to integrate the instance into the data representation of the corpus. In particular oStack[-1] is useful, because it is the instance above the current one hierarchically. For example, when a Sentence instance is created, there will be a Sentences instance in oStack[-1]. The Sentence instance would then call oStack[-1].addSentence(self) to integrate itself to the data representation.

A typical way to extend the capabilities of the basic classes is to subclass and extend some of them. For example, if one would like to extend the Sentence class, one would create a MySentence class inherited from Sentence. It is then necessary to create instances of MySentence when parsing the XML file. This is achieved by passing a named parameter of the form sentenceCls=MySentence in the __init__ method of the parser: myParser=BIParser(sentenceCls=MySentence). Any named argument whose name ends with Cls is recognized as an assignment of a class to XML tag. The default assignment is specified in the class variable defaultClasses.
Method Summary
  __init__(self, **args)
  endElement(self, name)
Signals the end of an element in non-namespace mode.
  parse(self, lines)
  startElement(self, name, attrs)
Signals the start of an element in non-namespace mode.
    Inherited from ContentHandler
  characters(self, content)
Receive notification of character data.
  endDocument(self)
Receive notification of the end of a document.
  endElementNS(self, name, qname)
Signals the end of an element in namespace mode.
  endPrefixMapping(self, prefix)
End the scope of a prefix-URI mapping.
  ignorableWhitespace(self, whitespace)
Receive notification of ignorable whitespace in element content.
  processingInstruction(self, target, data)
Receive notification of a processing instruction.
  setDocumentLocator(self, locator)
Called by the parser to give the application a locator for locating the origin of document events.
  skippedEntity(self, name)
Receive notification of a skipped entity.
  startDocument(self)
Receive notification of the beginning of a document.
  startElementNS(self, name, qname, attrs)
Signals the start of an element in namespace mode.
  startPrefixMapping(self, prefix, uri)
Begin the scope of a prefix-URI Namespace mapping.
    Inherited from DTDHandler
  notationDecl(self, name, publicId, systemId)
Handle a notation declaration event.
  unparsedEntityDecl(self, name, publicId, systemId, ndata)
Handle an unparsed entity declaration event.
    Inherited from EntityResolver
  resolveEntity(self, publicId, systemId)
Resolve the system identifier of an entity and return either the system identifier to read from as a string, or an InputSource to read from.
    Inherited from ErrorHandler
  error(self, exception)
Handle a recoverable error.
  fatalError(self, exception)
Handle a non-recoverable error.
  warning(self, exception)
Handle a warning.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)
    Inherited from type
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T

Class Variable Summary
dict defaultClasses = {'tokenCls': <class 'BasicClasses.Token...

Method Details

endElement(self, name)

Signals the end of an element in non-namespace mode.

The name parameter contains the name of the element type, just as with the startElement event.
Overrides:
_xmlplus.sax.handler.ContentHandler.endElement (inherited documentation)

startElement(self, name, attrs)

Signals the start of an element in non-namespace mode.

The name parameter contains the raw XML 1.0 name of the element type as a string and the attrs parameter holds an instance of the Attributes class containing the attributes of the element.
Overrides:
_xmlplus.sax.handler.ContentHandler.startElement (inherited documentation)

Class Variable Details

defaultClasses

Type:
dict
Value:
{'bioinferCls': <class 'BasicClasses.BioInfer'>,
 'entityCls': <class 'BasicClasses.Entity'>,
 'entitynestingCls': <class 'BasicClasses.EntityNesting'>,
 'entitynodeCls': <class 'BasicClasses.EntityNode'>,
 'entitytypeCls': <class 'OntologyClasses.EntityType'>,
 'formulaCls': <class 'BasicClasses.Formula'>,
 'formulasCls': <class 'BasicClasses.Formulas'>,
 'linkCls': <class 'BasicClasses.Link'>,
...                                                                    

Generated by Epydoc 2.0 on Tue Nov 21 15:32:22 2006 http://epydoc.sf.net