NAME

Lingua::Generic::Interface::Fragment - module to interact with strings of words of any language

VERSION

version v0.03

SYNOPSIS

use parent 'Lingua::Generic::Interface::Fragment';

say $fragment->as_string;

foreach my Lingua::Generic::Interface::Word $word ($fragment->words) {
    say $word->as_string;
}

(since v0.03)

This module is a generic interface to strings of words. Fragments can be large sections of texts, sentences, or parts of sentences.

This module inherits from Lingua::Generic::Interface::Element (since v0.03).

Packages may also want to implement Data::Identifier::Interface::Known.

METHODS

words

my @words = $fragment->words;

(since v0.03)

Returns the list of all the words in the fragment. The words are to be returned in-order. This also means that if any word is repreated within the fragment it is returned more than once.

Note: Non word parts of the fragment such as punctuation are not returned. This means that the returned list is not considered a truthful representation of the fragment.

When no parameters are passed an instances of Lingua::Generic::Interface::Word must be returned.

The implementation must die if any parameters are passed. The implementation must die if the value can not evaluated. The implementation can return an empty list if the fragment does not contain any words.

Default implementation

The default implementation dies.

natural_language

my Data::Identifier $natural_language = $fragment->natural_language;

(since v0.03)

Returns the natural language of this fragment. Note that a fragment can contrain parts that are of other languages.

See also "natural_language" in Lingua::Generic::Interface::Element for the interface.

Default implementation

The default implementation will return the language of the words in the fragment if all words are of the same language. The default implementation may, but will likely not cache the result.

RESERVED METHODS

See Lingua::Generic::Interface::Base for a list of reserved methods.

AUTHOR

Philipp Schafft <lion@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2026 by Philipp Schafft <lion@cpan.org>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)