NAME

TM::Ontology::KIF - Topic Map KIF Parser

SYNOPSIS

  use TM::Ontology::KIF;
  my $kif = new TM::Ontology::KIF (start_line_nr  => 42,
				   sentence_limit => 1000,
				   sentence       => sub {
                                                          my $s = shift;
                                                          print "got sentence ";
                                                          ....
                                                     }
                                   );
  use IO::Handle;
  my $input = new IO::Handle;
  ....
  eval {
     $kif->parse ($input);
  }; warn $@ if $@;

DESCRIPTION

This module provides KIF parsing functionality for IO::* streams. The concept is that the parser is reading a text stream and will invoke a subroutine which the calling application provided whenever a KIF sentence has been successfully parsed. (Similar to XML SAX processing).

Caveats

Compliance

Currently, only a subset of the KIF syntax

http://logic.stanford.edu/kif/dpans.html

is supported, just enough to make the SUMO (IEEE) parse. Feel free to patch this module or bribe/contact me if you need more.

Speed

Currently I am using Parse::RecDescent underneath for parsing. While it is incredibly flexible and powerful, it is also dead slow.

INTERFACE

Constructor

The constructor creates a new stream object. As parameters a hash can be provided whereby the following fields are recognized:

sentence:

If this is provided, then the value will be interpreted as subroutine reference. The subroutine will be executed every time a KIF sentence has been parsed whereby the sentence will be based as the only parameter. Otherwise, things will fail horribly.

start_line_nr:

If this is provided, then all lines will be skipped until this line number is reached.

sentence_limit

If this is present it limits the number of sentences which will be delivered back. When this limit is exceeded an exception will be raised.

Methods

parse

This methods takes a text stream and tries to parse this according to KIF. Whenever particular portions of the input stream have been successfully parsed, they exist as an abstract trees and will be handed over to the handlers which have been setup in the stream constructor.

AUTHOR

Robert Barta, <rho@bigpond.net.au>

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Robert Barta

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.