Feature Structures in Python (Part I)

James Tauber jtauber at jtauber.com
Thu Jun 19 09:32:24 CEST 2003

On Thu, 19 Jun 2003 15:59:03 +1000, "Andrew Bennetts"
<andrew-pythonlist at puzzling.org> said:
> On Thu, Jun 19, 2003 at 01:31:41PM +0800, James Tauber wrote:
> > 
> > This is the first part of a tutorial/cookbook I'm writing up on
> > implementing feature structures in Python.
> What's a "feature structure"?

It's a data structure commonly used in linguistics. Its use in phonology
goes back to the early twentieth century and it was first used for syntax
by Chomsky in 1955. Recently (the last twenty years, say), it has become
the prominent formal structure in a number of approaches to grammar
(particularly head-driven phrase structure grammar and related
constraint-based approaches) and computational linguistics.

Part I of my doc pretty much covers the actual data structure (there's
not really much more I could tell you without getting in to the specific
application to linguistics). The next two parts (which I'll send soon)
cover "subsumption" which is the feature-structure equivalent of
set-theoretic subset and "unification" which is the equivalent of
set-theoretic union.

A lot of feature-structure-based tools are written in Lisp or Prolog. I
believe there is at least one Java library too. I'd like to see Python
used more in linguistics and this is part of my contribution towards that
goal :-)

> > I'd love any feedback (particularly on the Pythonicity of my approach).
> [...]
> > # The del operator can be used to remove features. For example
> Actually, del is a statement.

Thanks for that catch. Normally I'm more careful about such things :-)

> > del fs5[HEAD][AGR][NUMBER]
> [...]
> > # If you wish to delete all features in a particular structure or
> > # sub-structure, you can iterate over the keys of the dictionary and
> > # delete each one.
> But you'd be better off just using the .clear() method of dicts.
> > for f in fs5[HEAD][SUBJ][AGR].keys():
> >     del fs5[HEAD][SUBJ][AGR][f]
> So this would become simply:
>     fs5[HEAD][SUBJ][AGR][f].clear()

Oops. Forgot about clear(). Thanks!

  James Tauber

More information about the Python-list mailing list