TM::Ontology::KIF - Topic Map KIF Parser
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 $@;
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).
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.
Currently I am using Parse::RecDescent underneath for parsing. While it is incredibly flexible and powerful, it is also dead slow.
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.
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.
Robert Barta, <rho@bigpond.net.au>
Since version 0.03: Nils Reiter, <reiter@cpan.org>
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.
To install TM::Ontology::KIF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TM::Ontology::KIF
CPAN shell
perl -MCPAN -e shell install TM::Ontology::KIF
For more information on module installation, please visit the detailed CPAN module installation guide.