Using AGLIB (AGAPI) with Python AG wrapper


Unix-like systems

The Python AG wrapper module is installed in a standard python package directory (site-packages) unless the --disable-python-pkgdir option is used at configuration time. If this option is used, the module is installed in <prefix>/lib/ag/python, where <prefix> is the installation prefix, which can be specified with the --prefix option. The default value for <prefix> is /usr/local.

If the wrapper module is not installed in a standard Python package directory, or if Python has any trouble locating the module, the PYTHONPATH environment variable can be set to help Python find the module. PYTHONPATH should contain the location of the module.

Here is an example of using AGLIB interactively in a Python session:

sh$ export PYTHONPATH=/home/haepal/pkg/aglib-2.0/lib/ag/python
sh$ python
...
>>> import ag
>>> agsetId = ag.CreateAGSet("TIMIT")
>>> ...

Here is an example of a python script (a .py file) that uses AGLIB:

#! /usr/local/bin/python2.1

import ag

agsetId = ag.CreateAGSet("TIMIT")
timelineId = ag.CreateTimeline(agsetId)
agId = ag.CreateAG(agsetId, timelineId)
a1 = ag.CreateAnchor(agId)
ag.SetAnchorOffset(a1, 1.0)
a2 = ag.CreateAnchor(agId)
ag.SetAnchorOffset(a2, 2.0)
ann = ag.CreateAnnotation(agId, a1, a2, "word")
ag.SetFeature(ann, "label", "cat")
print ag.toXML(agsetId)

NOTE: Please don't forget to set LD_LIBRARY_PATH properly for the required shared libraries (libag and plugins). See Post-installation for details.


Annotation Graph Toolkit