Migrating from 0.4¶
Since 0.5 every source is read through a document of anySeg: a string, a Doc object of spaCy and a Document give one document, and its tokens decide what a word is. The core no longer bridges a string and a Doc, and the hooks of a language library take the document and the words of its tree instead of spaCy objects. This page lists what code written for 0.4 changes.
Removed names¶
| Removed | Replacement |
|---|---|
anyts.utils.add_tokenizer_rules |
the tokenizer of anySeg in a pipeline: anyseg.Tokenizer.v1 in the config |
anyts.components.start_sents_after_blank_lines |
the component anyseg_sentencizer of anySeg; the document of a Doc starts a sentence after every blank line anyway |
anyts.utils.set_sent_starts |
to_document(text, sentenize=...), or the sentences of anyseg_sentencizer in a pipeline |
anyts.utils.joins_previous, iter_doc_tokens, iter_doc_units, iter_doc_words, split_doc_units |
the words of the document: document_words(to_document(doc)), get_tree(...).words |
anyts.utils.find_unit_marks, find_unit_paragraph_starts |
find_marks and find_paragraph_starts on the text |
anyts.utils.has_sents |
doc.has_annotation("SENT_START", require_complete=True) |
anyts.utils.has_pos, is_word |
the columns of the document (document.column("upos")), has_words(token.text) |
from anyts.extractors import BLANK_LINE |
from anyts.utils import BLANK_LINE |
A pipeline with the tokenizer of spaCy and a parser has no replacement for the first three: the tokenizer and the sentencizer of anySeg segment the text otherwise, so the parser builds other trees and the numbers shift. A library keeps its own copies of them until it moves to the pipeline of anySeg. The tokenizer of anySeg goes into the config of the pipeline (spacy.blank(lang, config={"nlp": {"tokenizer": {"@tokenizers": "anyseg.Tokenizer.v1"}}})): a pipeline with one set as nlp.tokenizer is saved by nlp.to_disk without it, and spacy.load fails on it (FileNotFoundError).
Class attributes and hooks¶
The attributes of 0.4 that the core no longer reads raise ParameterError (the messages removed_attribute and removed_attribute_either, and removed_component_attribute for a component, since 0.6) when a class that sets them is defined, since a class that kept them would give other numbers without a sign:
| Removed | Classes | Replacement |
|---|---|---|
words_extractor_class |
BasicStats, StyleStats, PhonStats |
parse to segment a string in the language, doc_words to normalize the forms of its words |
sents_extractor_class |
BasicStats, CohesionStats |
parse |
join_hyphens |
BasicStats, StyleStats, PhonStats, SyntaxStats, CohesionStats, LexicalStatsComponent |
the tokens of the document: parse of the class, or the tokenizer of the pipeline |
doc_units |
CohesionStats |
analyze, word_info |
iter_words, iter_sents |
HighlightedText |
parse, doc_words |
The parameter join_hyphens is gone from kwic, sentence_lengths, sentence_lengths_plot and the functions of anyts.syntax_stats as well. The hooks that remain take other arguments:
doc_words(document)ofStyleStats,PhonStatsandHighlightedTexttakes aDocumentinstead of aDoc;get_doc_wordsanditer_doc_sentstoo.word_info(word)ofCohesionStatstakes aTreeWordinstead of a list of tokens. The hooks ofSyntaxStatsand the functions ofanyts.syntax_statstake aTreeWordinstead of aToken, anddependency_triples(words)a sequence of them; so dohas_feature,is_finite_verbandis_infinitiveofanyts.utils, andtokens_spanandfind_split_predicate_highlightsofanyts.visualizers.highlight.SyntaxStats.parsereturns aDocument, such asto_documentof a parsedDoc, andSyntaxStats.sentsholdsTreeWordobjects.- The
analyzeofMorphStats,LexicalStatsandCohesionStatsgets the source as given, aDocumenttoo, and its default reads the document ofparse, so a library that annotated a string in itsanalyzemoves that intoparse, and ananalyzeof its own reads the document byself.parse(source).CohesionStatschecks the parts of speech and the lemmas byrequires_posandrequires_lemmas, which a library whoseword_infoannotates the words itself turns off. find(document)ofHighlightedTextgets the document instead of aDocorNone, andlayer_annotationsnames the columns of the document:DEP-deprel,POS-upos,LEMMA-lemma,MORPH-feats,TAG-xpos; the named entities are gone.annotation_namestakes the same columns as keys (headanddeprelfor the parse), and the keys of 0.4 are not read.lemmatizeofkwicgets the words of Universal Dependencies of a token (Wordof anySeg withform,lemma,uposandfeats, the string of CoNLL-U such asCase=Nom|Number=Sing) instead of spaCy tokens, and the third item of atokenizetriple is not read.get_stats(flat=True)takesflatas a keyword only.
Words of the tree¶
The words of the tree of a document (get_tree) are TreeWord objects in place of spaCy tokens:
Token |
TreeWord |
|---|---|
text, lower_ |
form, form.lower() |
lemma_, pos_, tag_ |
lemma, upos, xpos: None without a value, not an empty string |
dep_ |
deprel; the root of a spaCy parse is root, not ROOT |
morph.get(name) |
feats.get(name): the values joined by commas (Int,Rel), None without the feature; has_feature(word, name, value) checks one value, and feats is not to be changed |
morph.to_dict(), str(morph) |
feats, the column feats of the document (Case=Nom|PronType=Int,Rel) |
has_morph() |
none for a word: one annotated with no features and one never annotated both have empty feats; bool(feats) says whether a word has features, doc.has_annotation("MORPH") whether the Doc was annotated |
doc, i, doc[i] |
tree, index, tree.words[i]: the positions of the words differ from Token.i where a Doc has tokens of whitespace or of invisible separators alone, or multiword tokens whose words carry columns, and tree.word_at(token.idx, token.idx + len(token)) gives the word of a token |
nbor(n) |
tree.words[word.index + n] |
idx |
start, after idx where the token starts with a separator the document leaves out, such as a byte order mark; end is the end of the token, shared by the words of a multiword token |
head |
head, None at the head of a sentence instead of the token itself |
children, subtree |
children (punctuation marks included), get_subtree(word) of anyts.syntax_stats |
left_edge, right_edge |
get_subtree(word)[0], get_subtree(word)[-1] |
sent, sent.start, sent.end, is_sent_start |
tree.sentences[word.sentence], its first and last word; sentence is its position |
is_punct |
is_punctuation(word.form) of anyts.utils, symbols included |
is_space, whitespace_ |
none: whitespace is no word of the tree, and the text between two words is tree.text[first.end:second.start] |
Sources and segmentation¶
- A blank line ends a sentence of every source, a
Docwith its own sentences included, so a sentence of a parser over a blank line is split: of the words that hung over the line, the first heads the new sentence and the others hang on it withdep. A blank line is that of anySeg: the vertical tab and the form feed break a line, and a line of separators alone is blank. - The tokens of the document decide what a word is: the tokenizer of spaCy splits
well-knowninto three tokens in English or Russian and the words stay split, and so do the default tokens of a string; the tokenizer of anySeg keeps it whole. A multiword token of anySeg (token._.anyseg_words) gives its words of Universal Dependencies toMorphStats,LexicalStatsand the tree; without columns of their own they are one word with the columns of the token. SyntaxStats,CohesionStatsandMorphStatstake a string, which a library annotates inparse: with the defaultparsea string raisesSourceError(no_parse,no_pos) instead ofSourceTypeError.LexicalStatscan be used without a subclass, given a dictionary.to_documentreturns the sameDocumentfor an unchangedDocin a thread, andget_treethe same tree: neither is to be changed, and code that needs other columns builds a document of its own.
Messages¶
A library that merges its messages over the defaults ({**MESSAGES, **own}) gets the new keys in English until it translates them, and drops the removed ones, which check_messages refuses:
- removed:
hook_doc,hook_spans; - new:
bool_param,integer_param,number_param,words_param,connector_words,connector_sent_index,connector_pos_list,connector_breaks_type,connector_blocked_type,document_tokens,hook_document,hook_bounds,hook_words,hook_word_pairs,hook_string,layer_columns,matcher_class,mark_length,negative_words,empty_extension,removed_attribute; - changed:
layer_annotationsspeaks of a document.
The errors of the parameters of a wrong type name the parameter as in the signature under a generic key: The top_n must be an integer, not str instead of The number of the most frequent words must be an integer, not str.