NAME

Text::CaboCha::Tree - CaboCha Tree Object

SYNOPSIS

use utf8;
use Encode;
use Text::CaboCha;
my $cabocha = Text::CaboCha->new();
my $text = encode(Text::CaboCha::ENCODING, "太郎は次郎が持っている本を花子に渡した。");
my $tree = $cabocha->parse($text);

$tree->tostr(Text::CaboCha::CABOCHA_FORMAT_TREE); # You can check the tree.

$tree->size;

# Way to get token - (1)
my $token_size = $tree->token_size;
for (my $i = 0; $i < $token_size; $i++) {
    my $token = $tree->token($i);
    # do something
}

# Way to get token - (2)
foreach my $token (@{ $tree->tokens }) {
    # do something
}

# Way to get chunk - (1)
my $chunk_size = $tree->chunk_size;
for (my $i = 0; $i < $chunk_size; $i++) {
    my $chunk = $tree->chunk($i);
    # do something
}

# Way to get chunk - (2)
foreach my $chunk (@{ $tree->chunks }) {
    # do something
}

DESCRIPTION

Text::CaboCha::Tree encapsulates the cabocha tree object returned by parsing some text.

METHODS

tostr($format)

It will express of the tree as sring that you specified format. You can follow below format.

CABOCHA_FORMAT_TREE
CABOCHA_FORMAT_LATTICE
CABOCHA_FORMAT_TREE_LATTICE
CABOCHA_FORMAT_XML
CABOCHA_FORMAT_CONLL
CABOCHA_FORMAT_NONE

$tree_size = $tree->size;

It will return size of tree.

$tokens = $tree->tokens;

It will return array reference of Text::CaboCha::Token object.

$chunks = $tree->chunks;

It will return array reference of Text::CaboCha::Chunk object.

$token_size = $tree->token_size;

It will return size of token.

$chunk_size = $tree->chunk_size;

It will return size of chunk.

my $token = $tree->token($i :Int);

It will return Text::CaboCha::Token object.

my $chunk = $tree->chunk($i :Int);

It will return Text::CaboCha::Chunk object.

SEE ALSO

Text::CaboCha Text::CaboCha::Token Text::CaboCha::Chunk

LICENSE

Copyright (C) Kei Kamikawa.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html

AUTHOR

Kei Kamikawa <x00.x7f@gmail.com> @codehex