aibox.nlp.features.portuguese.word_segmentation
Características relacionadas com segmentação de palavras.
Classes
|
Norvig's hiposegmentation algorithm adapted from https://norvig.com/ngrams/index.html |
|
|
|
Extrator de características relacionadas com a segmentação de palavras. |
Características de segmentação de palavras. |
- class aibox.nlp.features.portuguese.word_segmentation.WordSegmentationFeatures(hypo_segmentation_score: float, hyper_segmentation_score: float)[código-fonte]
Base:
DataclassFeatureSet
Características de segmentação de palavras.
Para informações sobre as características, acessar as referências.
- Referências:
[1]: Silva Filho, M. W. da, Nascimento, A. C. A., Miranda, P., Rodrigues, L., Cordeiro, T., Isotani, S., Bittencourt, I. I., & Mello, R. F. (2023). Automated Formal Register Scoring of Student Narrative Essays Written in Portuguese. In Anais do II Workshop de Aplicações Práticas de Learning Analytics em Instituições de Ensino no Brasil (WAPLA 2023) (pp. 1–11). Workshop de Aplicações Práticas de Learning Analytics em Instituições de Ensino no Brasil. Sociedade Brasileira de Computação.
- as_dict() dict[str, float]
Retorna os valores das características desse conjunto para um dado texto.
- as_numpy() ndarray[float32]
Retorna as características como uma NumPy array. Os valores de cada índice são correspondentes às características na ordem de
names()
.- Retorna:
array de np.float32 representando os valores das características.
- Tipo de retorno:
ndarray[float32]
- class aibox.nlp.features.portuguese.word_segmentation.NorvigHypoSegmentaton(dictionary: SpellChecker)[código-fonte]
Base:
object
Norvig’s hiposegmentation algorithm adapted from https://norvig.com/ngrams/index.html
- Parâmetros:
dictionary (SpellChecker)
- segment(text: str) list[str] [código-fonte]
Return a list of words that is the best segmentation of text.
- class aibox.nlp.features.portuguese.word_segmentation.UspSpellChecker(distance: int = 2, case_sensitive: bool = False)[código-fonte]
Base:
SpellChecker
- candidates(word: str | bytes) Set[str] | None
Generate possible spelling corrections for the provided word up to an edit distance of two, if and only when needed
- Args:
word (str): The word for which to calculate candidate spellings
- Returns:
set: The set of words that are possible candidates or None if there are no candidates
- correction(word: str | bytes) str | None
The most probable correct spelling for the word
- Args:
word (str): The word to correct
- Returns:
str: The most likely candidate or None if no correction is present
- property distance: int
int: The maximum edit distance to calculate
- Note:
Valid values are 1 or 2; if an invalid value is passed, defaults to 2
- edit_distance_1(word: str | bytes) Set[str]
Compute all strings that are one edit away from word using only the letters in the corpus
- Args:
word (str): The word for which to calculate the edit distance
- Returns:
set: The set of strings that are edit distance one from the provided word
- edit_distance_2(word: str | bytes) List[str]
Compute all strings that are two edits away from word using only the letters in the corpus
- Args:
word (str): The word for which to calculate the edit distance
- Returns:
set: The set of strings that are edit distance two from the provided word
- export(filepath: Path | str, encoding: str = 'utf-8', gzipped: bool = True) None
Export the word frequency list for import in the future
- Args:
filepath (str): The filepath to the exported dictionary encoding (str): The encoding of the resulting output gzipped (bool): Whether to gzip the dictionary or not
- known(words: Iterable[str | bytes]) Set[str]
The subset of words that appear in the dictionary of words
- Args:
words (list): List of words to determine which are in the corpus
- Returns:
set: The set of those words from the input that are in the corpus
- classmethod languages() Iterable[str]
list: A list of all official languages supported by the library
- split_words(text: str | bytes) Iterable[str]
Split text into individual words using either a simple whitespace regex or the passed in tokenizer
- Args:
text (str): The text to split into individual words
- Returns:
list(str): A listing of all words in the provided text
- unknown(words: Iterable[str | bytes]) Set[str]
The subset of words that do not appear in the dictionary
- Args:
words (list): List of words to determine which are not in the corpus
- Returns:
set: The set of those words from the input that are not in the corpus
- property word_frequency: WordFrequency
WordFrequency: An encapsulation of the word frequency dictionary
- Note:
Not settable
- word_usage_frequency(word: str | bytes, total_words: int | None = None) float
Calculate the frequency to the word provided as seen across the entire dictionary
- Args:
word (str): The word for which the word probability is calculated total_words (int): The total number of words to use in the calculation; use the default for using the whole word frequency
- Returns:
float: The probability that the word is the correct word
- class aibox.nlp.features.portuguese.word_segmentation.WordSegmentationExtractor(nlp: Language | None = None)[código-fonte]
Base:
FeatureExtractor
Extrator de características relacionadas com a segmentação de palavras.
- Parâmetros:
nlp (Language) – modelo do spaCy para ser utilizado.
Exemplo de uso em
FeatureExtractor
- property feature_set: type[WordSegmentationFeatures]
Retorna a classe que contém o conjunto de características retornado por esse extrator.
- Retorna:
classe do conjunto de características retornado por esse extrator.
- extract(text: str, **kwargs) WordSegmentationFeatures [código-fonte]
Realiza a extração de características para o texto de entrada.
- Parâmetros:
text (str) – texto.
**kwargs – argumentos extras que pode ser utilizados por alguns extratores para controlar o processo de extração.
- Retorna:
características para o texto de entrada.
- Tipo de retorno:
- vectorize(text: str | list[str] | ndarray[str_], vector_type: str = 'numpy', device: str | None = None, **kwargs) ndarray | Tensor
Método para vetorização de textos. A vetorização de múltiplos textos é realizada de forma paralela sempre que possível.
Aceita os campos n_workers (default=`min(4, cpu_count)`) e show_bar (default=`true`) quando array-like de string. Demais parâmetros são passados para
_vectorize()
.n_workers é utilizado quando a implementação utiliza
multiprocessing
. Caso n_workers <= 1, um for.- Parâmetros:
text (str | list[str] | ndarray[str_]) – texto ou textos de entrada.
vector_type (str, opcional) – tipo do vetor de saída (‘numpy ou ‘torch’).
device (str, opcional.) – dispositivo para armazenamento do tensor Torch. Padrão é CPU.
**kwargs – parâmetros extras que podem ser utilizados por alguns vetorizadores para controlar o processo de vetorização.
- Retorna:
representação numérica do texto.
- Tipo de retorno: