_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q7700 | copy_analysis_dict | train | def copy_analysis_dict( analysis ):
''' Creates a copy from given analysis dict. '''
assert isinstance(analysis, dict), "(!) Input 'analysis' should be a dict!"
new_dict = { POSTAG: analysis[POSTAG],\
ROOT: analysis[ROOT],\
FORM: analysis[FORM],\
CLITIC: analysis[CLITIC],\
ENDING: analysis[ENDING] }
| python | {
"resource": ""
} |
q7701 | get_unique_clause_indices | train | def get_unique_clause_indices( text ):
''' Returns a list of clause indices for the whole text. For each token in text,
the list contains index of the clause the word belongs to, and the indices
are unique over the whole text. '''
# Add clause boundary annotation (if missing)
if not text.is_tagged( CLAUSES ):
text.tag_clauses()
| python | {
"resource": ""
} |
q7702 | get_unique_sentence_indices | train | def get_unique_sentence_indices( text ):
''' Returns a list of sentence indices for the whole text. For each token in text,
the list contains index of the sentence the word belongs to, and the indices
are unique over the whole text. '''
# Add sentence annotation (if missing)
if not text.is_tagged( SENTENCES ):
text.tokenize_sentences()
# Collect (unique) sent indices over the whole text
sent_indices | python | {
"resource": ""
} |
q7703 | _convert_nominal_form | train | def _convert_nominal_form( analysis ):
''' Converts nominal categories of the input analysis.
Performs one-to-one conversions only. '''
assert FORM in analysis, '(!) The input analysis does not contain "'+FORM+'" key.'
for idx, pattern_items in enumerate(_noun_conversion_rules):
| python | {
"resource": ""
} |
q7704 | _convert_amb_verbal_form | train | def _convert_amb_verbal_form( analysis ):
''' Converts ambiguous verbal categories of the input analysis.
Performs one-to-many conversions. '''
assert FORM in analysis, '(!) The input analysis does not contain "'+FORM+'" key.'
results = []
for root_pat, pos, form_pat, replacements in _amb_verb_conversion_rules:
if analysis[POSTAG] == pos and re.match(root_pat, analysis[ROOT]) and \
re.match(form_pat, analysis[FORM]):
for replacement in replacements:
new_analysis = copy_analysis_dict( analysis )
new_form = re.sub(form_pat, replacement, | python | {
"resource": ""
} |
q7705 | _convert_verbal_form | train | def _convert_verbal_form( analysis ):
''' Converts ordinary verbal categories of the input analysis.
Performs one-to-one conversions. '''
assert FORM in analysis, '(!) The input analysis does not contain "'+FORM+'" key.'
for form, replacement in _verb_conversion_rules:
# Exact match
if analysis[FORM] == form:
| python | {
"resource": ""
} |
q7706 | _make_postfixes_1 | train | def _make_postfixes_1( analysis ):
''' Provides some post-fixes. '''
assert FORM in analysis, '(!) The input analysis does not contain "'+FORM+'" key.'
if 'neg' in analysis[FORM]:
analysis[FORM] = re.sub( '^\s*neg ([^,]*)$', '\\1 Neg', analysis[FORM] )
analysis[FORM] = re.sub( ' Neg Neg$', ' Neg', analysis[FORM] )
| python | {
"resource": ""
} |
q7707 | _disambiguate_neg | train | def _disambiguate_neg( words_layer ):
''' Disambiguates forms ambiguous between multiword negation and some
other form;
'''
prev_word_lemma = ''
for word_dict in words_layer:
forms = [ a[FORM] for a in word_dict[ANALYSIS] ]
if ('Pers Prs Imprt Sg2' in forms and 'Pers Prs Ind Neg' in forms):
if (prev_word_lemma == "ei" or prev_word_lemma == "ega"):
# ei saa, ei tee
_keep_analyses( word_dict[ANALYSIS], ['Pers Prs Ind Neg'], ['Pers Prs Imprt Sg2', 'Pers Prs Ind Neg'] )
else:
# saa! tee!
_keep_analyses( word_dict[ANALYSIS], ['Pers Prs Imprt Sg2'], ['Pers Prs Imprt Sg2', 'Pers Prs Ind Neg'] )
if ('Pers Prt Imprt' in forms and 'Pers Prt Ind Neg' in forms and 'Pers Prt Prc' in forms):
if (prev_word_lemma == "ei" or prev_word_lemma == "ega"):
# ei saanud, ei teinud
_keep_analyses( word_dict[ANALYSIS], ['Pers Prt Ind Neg'], ['Pers Prt Imprt','Pers Prt Ind Neg','Pers Prt Prc'] )
else:
# on, oli saanud teinud; kukkunud õun; ...
| python | {
"resource": ""
} |
q7708 | _make_postfixes_2 | train | def _make_postfixes_2( words_layer ):
''' Provides some post-fixes after the disambiguation. '''
for word_dict in words_layer:
for analysis in word_dict[ANALYSIS]:
| python | {
"resource": ""
} |
q7709 | as_unicode | train | def as_unicode(s, encoding='utf-8'):
"""Force conversion of given string to unicode type.
Unicode is ``str`` type for Python 3.x and ``unicode`` for Python 2.x .
If the string is already in unicode, then no conversion is done and the same string is returned.
Parameters
----------
s: str or bytes (Python3), str or unicode (Python2)
The string to convert to unicode.
encoding: str
The encoding of the input string (default: utf-8)
Raises
------
ValueError
In case an input of invalid type was passed to the function.
Returns
| python | {
"resource": ""
} |
q7710 | as_binary | train | def as_binary(s, encoding='utf-8'):
"""Force conversion of given string to binary type.
Binary is ``bytes`` type for Python 3.x and ``str`` for Python 2.x .
If the string is already in binary, then no conversion is done and the same string is returned
and ``encoding`` argument is ignored.
Parameters
----------
s: str or bytes (Python3), str or unicode (Python2)
The string to convert to binary.
encoding: str
The encoding of the resulting binary string (default: utf-8)
Raises
------
ValueError
In case an input of invalid type was passed to the function.
Returns
-------
| python | {
"resource": ""
} |
q7711 | KeywordTagger.tag | train | def tag(self, text):
"""Retrieves list of keywords in text.
Parameters
----------
text: Text
The text to search for events.
Returns
-------
list of vents sorted by start, end
"""
if self.search_method == 'ahocorasick':
events = self._find_keywords_ahocorasick(text.text)
| python | {
"resource": ""
} |
q7712 | RegexTagger.tag | train | def tag(self, text):
"""Retrieves list of regex_matches in text.
Parameters
----------
text: Text
The estnltk text object to search for events.
Returns
-------
list of matches
| python | {
"resource": ""
} |
q7713 | yield_json_corpus | train | def yield_json_corpus(fnm):
"""Function to read a JSON corpus from a file.
A JSON corpus contains one document per line, encoded in JSON.
Each line is yielded after it is read.
Parameters
----------
fnm: str
The filename of the corpus.
Returns
-------
| python | {
"resource": ""
} |
q7714 | write_json_corpus | train | def write_json_corpus(documents, fnm):
"""Write a lisst of Text instances as JSON corpus on disk.
A JSON corpus contains one document per line, encoded in JSON.
Parameters
----------
documents: iterable of estnltk.text.Text
The documents of the corpus
fnm: str
The | python | {
"resource": ""
} |
q7715 | read_document | train | def read_document(fnm):
"""Read a document that is stored in a text file as JSON.
Parameters
----------
fnm: str
The path of the document.
Returns
-------
Text
| python | {
"resource": ""
} |
q7716 | write_document | train | def write_document(doc, fnm):
"""Write a Text document to file.
Parameters
----------
doc: Text
| python | {
"resource": ""
} |
q7717 | _TypedList.polarisText | train | def polarisText():
"""polarisText part of _TypedList objects
"""
def fget(self):
_out = ''
_n = '\n'
if len(self):
if self.parent:
_out = '%s%s%s' % (_out, PolarisText(
*self.parent).out,_n)
_out = _out + _n.join(
| python | {
"resource": ""
} |
q7718 | Parser.parse_line | train | def parse_line(self,iStr):
"""Parses ewn file line
"""
self.levelNumber = None
self.DRN = None
self.fieldTag = None
self.fieldValue = None
self.noQuotes = None
if iStr and not(iStr.strip().startswith('#')):
iList = iStr.strip().split(' ')
self.levelNumber = int(iList.pop(0))
if iList[0].startswith('@') and self.levelNumber != 3:
self.DRN = int(iList.pop(0).strip('@'))
else:
self.DRN = None
self.fieldTag = iList.pop(0)
if iList and (
iList[0].startswith('"') or
iList[0].startswith('@')
):
fv = ' '.join(iList)
| python | {
"resource": ""
} |
q7719 | Variant.addTranslation | train | def addTranslation(self,translation):
'''Appends one Translation to translations
'''
if isinstance(translation, Translation):
self.translations.append(translation)
else:
raise(TranslationError,
| python | {
"resource": ""
} |
q7720 | Variant.addVariantFeature | train | def addVariantFeature(self,variantFeature):
'''Appends one VariantFeature to variantFeatures
'''
if isinstance(variantFeature, Feature):
self.features.append(variantFeature)
else:
raise(TypeError,
| python | {
"resource": ""
} |
q7721 | Variant.addUsage_Label | train | def addUsage_Label(self,usage_label):
'''Appends one Usage_Label to usage_labels
'''
if isinstance(usage_label, Usage_Label):
self.usage_labels.append(usage_label)
else:
raise (Usage_LabelError,
| python | {
"resource": ""
} |
q7722 | Variant.addExample | train | def addExample(self,example):
'''Appends one Example to examples
'''
if isinstance(example, Example):
self.examples.append(example)
else:
raise (ExampleError, | python | {
"resource": ""
} |
q7723 | Synset.firstVariant | train | def firstVariant():
"""first variant of Variants
Read-only
"""
def fget(self):
if self.variants:
return self.variants[0]
| python | {
"resource": ""
} |
q7724 | Synset.literals | train | def literals():
'''Returns a list of literals
in the Synset
read-only
'''
def fget(self):
if self.variants:
return map(lambda x: x.literal,
| python | {
"resource": ""
} |
q7725 | Synset.addVariantOld | train | def addVariantOld(self,
literal='',
sense=0,
gloss='',
examples=[]):
'''Appends variant
sth to do that it would be possible
to add Variant object
| python | {
"resource": ""
} |
q7726 | Synset.addVariant | train | def addVariant(self,variant):
'''Appends one Variant to variants
'''
if isinstance(variant, Variant):
self.variants.append(variant)
else:
raise | python | {
"resource": ""
} |
q7727 | Synset.named_eq_relations | train | def named_eq_relations(self, name, neg=False):
'''Returns list of named eqLinks.
<name> may be string or list.
'''
if self.eqLinks and not neg:
if isinstance(name, six.string_types):
return filter(lambda x: x.relation.name == name,
self.eqLinks)
elif isinstance(name, list):
return filter(lambda x: x.relation.name in name,
self.eqLinks)
else:
return None #should rise error
| python | {
"resource": ""
} |
q7728 | Tree.get_root | train | def get_root( self, **kwargs ):
''' Returns this tree if it has no parents, or, alternatively, moves
up via the parent links of this tree until reaching the tree with
no parents, and returnes the parentless tree as the root.
''' | python | {
"resource": ""
} |
q7729 | Tree.get_tree_depth | train | def get_tree_depth( self ):
''' Finds depth of this tree. '''
if (self.children):
depth = 1
childDepths = []
for child in self.children:
childDepths.append( | python | {
"resource": ""
} |
q7730 | Symbol.get_matches | train | def get_matches(self, text, cache=None, conflict_resolver=resolve_using_maximal_coverage):
"""Get the matches of the symbol on given text."""
is_root_node = False
if cache is None:
cache = {}
is_root_node = True
if id(self) in cache:
return cache[id(self)]
| python | {
"resource": ""
} |
q7731 | Text.texts | train | def texts(self, layer, sep=' '):
"""Retrieve texts for given layer.
Parameters
----------
sep: str
Separator for multilayer elements (default: ' ').
Returns
-------
list of str | python | {
"resource": ""
} |
q7732 | Text.starts | train | def starts(self, layer):
"""Retrieve start positions of elements if given layer."""
starts = []
| python | {
"resource": ""
} |
q7733 | Text.ends | train | def ends(self, layer):
"""Retrieve end positions of elements if given layer."""
ends = []
| python | {
"resource": ""
} |
q7734 | Text.layer_tagger_mapping | train | def layer_tagger_mapping(self):
"""Dictionary that maps layer names to taggers that can create that layer."""
return {
PARAGRAPHS: self.tokenize_paragraphs,
SENTENCES: self.tokenize_sentences,
WORDS: self.tokenize_words,
ANALYSIS: self.tag_analysis,
TIMEXES: self.tag_timexes,
| python | {
"resource": ""
} |
q7735 | Text.tag | train | def tag(self, layer):
"""Tag the annotations of given layer. It can automatically tag any built-in layer type."""
mapping = self.layer_tagger_mapping
| python | {
"resource": ""
} |
q7736 | Text.tokenize_paragraphs | train | def tokenize_paragraphs(self):
"""Apply paragraph tokenization to this Text instance. Creates ``paragraphs`` layer."""
tok = self.__paragraph_tokenizer
| python | {
"resource": ""
} |
q7737 | Text.paragraph_texts | train | def paragraph_texts(self):
"""The list of texts representing ``paragraphs`` layer elements."""
if not self.is_tagged(PARAGRAPHS):
| python | {
"resource": ""
} |
q7738 | Text.paragraph_spans | train | def paragraph_spans(self):
"""The list of spans representing ``paragraphs`` layer elements."""
if not self.is_tagged(PARAGRAPHS):
| python | {
"resource": ""
} |
q7739 | Text.paragraph_starts | train | def paragraph_starts(self):
"""The start positions of ``paragraphs`` layer elements."""
if not self.is_tagged(PARAGRAPHS):
| python | {
"resource": ""
} |
q7740 | Text.paragraph_ends | train | def paragraph_ends(self):
"""The end positions of ``paragraphs`` layer elements."""
if not self.is_tagged(PARAGRAPHS):
| python | {
"resource": ""
} |
q7741 | Text.tokenize_sentences | train | def tokenize_sentences(self):
"""Apply sentence tokenization to this Text instance. Creates ``sentences`` layer.
Automatically tokenizes paragraphs, if they are not already tokenized.
Also, if word tokenization has already been performed, tries to fit
the sentence tokenization into the existing word tokenization;
"""
if not self.is_tagged(PARAGRAPHS):
self.tokenize_paragraphs()
tok = self.__sentence_tokenizer
text = self.text
dicts = []
for paragraph in self[PARAGRAPHS]:
para_start, para_end = paragraph[START], paragraph[END]
para_text = text[para_start:para_end]
if not self.is_tagged(WORDS):
# Non-hack variant: word tokenization has not been applied yet,
# so we proceed in natural order (first sentences, then words)
spans = tok.span_tokenize(para_text)
for start, end in spans:
dicts.append({'start': start+para_start, 'end': end+para_start})
else:
# A hack variant: word tokenization has already been made, so
# we try to use existing word tokenization (first words, then sentences)
para_words = \
[ w for w in self[WORDS] if w[START]>=para_start and w[END]<=para_end ]
para_word_texts = \
[ w[TEXT] for w in para_words ]
| python | {
"resource": ""
} |
q7742 | Text.sentence_texts | train | def sentence_texts(self):
"""The list of texts representing ``sentences`` layer elements."""
if not self.is_tagged(SENTENCES):
| python | {
"resource": ""
} |
q7743 | Text.sentence_spans | train | def sentence_spans(self):
"""The list of spans representing ``sentences`` layer elements."""
if not self.is_tagged(SENTENCES):
| python | {
"resource": ""
} |
q7744 | Text.sentence_starts | train | def sentence_starts(self):
"""The list of start positions representing ``sentences`` layer elements."""
if not self.is_tagged(SENTENCES):
| python | {
"resource": ""
} |
q7745 | Text.sentence_ends | train | def sentence_ends(self):
"""The list of end positions representing ``sentences`` layer elements."""
if not self.is_tagged(SENTENCES):
| python | {
"resource": ""
} |
q7746 | Text.tokenize_words | train | def tokenize_words(self):
"""Apply word tokenization and create ``words`` layer.
Automatically creates ``paragraphs`` and ``sentences`` layers.
"""
if not self.is_tagged(SENTENCES):
self.tokenize_sentences()
tok = self.__word_tokenizer
text = self.text
dicts = []
for sentence in self[SENTENCES]:
sent_start, sent_end = sentence[START], sentence[END]
sent_text = text[sent_start:sent_end]
| python | {
"resource": ""
} |
q7747 | Text.tag_analysis | train | def tag_analysis(self):
"""Tag ``words`` layer with morphological analysis attributes."""
if not self.is_tagged(WORDS):
self.tokenize_words()
sentences = self.divide(WORDS, SENTENCES)
for sentence in sentences:
texts = [word[TEXT] for word in sentence]
| python | {
"resource": ""
} |
q7748 | Text.word_texts | train | def word_texts(self):
"""The list of words representing ``words`` layer elements."""
if not self.is_tagged(WORDS):
| python | {
"resource": ""
} |
q7749 | Text.word_spans | train | def word_spans(self):
"""The list of spans representing ``words`` layer elements."""
if not self.is_tagged(WORDS):
| python | {
"resource": ""
} |
q7750 | Text.word_starts | train | def word_starts(self):
"""The list of start positions representing ``words`` layer elements."""
if not self.is_tagged(WORDS):
| python | {
"resource": ""
} |
q7751 | Text.word_ends | train | def word_ends(self):
"""The list of end positions representing ``words`` layer elements.""" | python | {
"resource": ""
} |
q7752 | Text.analysis | train | def analysis(self):
"""The list of analysis of ``words`` layer elements."""
if not self.is_tagged(ANALYSIS):
| python | {
"resource": ""
} |
q7753 | Text.get_analysis_element | train | def get_analysis_element(self, element, sep='|'):
"""The list of analysis elements of ``words`` layer.
Parameters
----------
element: str
The name of the element, for example "lemma", "postag".
sep: str
The separator for ambiguous analysis (default: "|").
| python | {
"resource": ""
} |
q7754 | Text.roots | train | def roots(self):
"""The list of word roots.
Ambiguous cases are separated with pipe character by default.
Use :py:meth:`~estnltk.text.Text.get_analysis_element` to specify custom separator for ambiguous entries.
"""
| python | {
"resource": ""
} |
q7755 | Text.lemmas | train | def lemmas(self):
"""The list of lemmas.
Ambiguous cases are separated with pipe character by default.
Use :py:meth:`~estnltk.text.Text.get_analysis_element` to specify custom separator for ambiguous entries.
"""
| python | {
"resource": ""
} |
q7756 | Text.lemma_lists | train | def lemma_lists(self):
"""Lemma lists.
Ambiguous cases are separate list elements.
"""
if not self.is_tagged(ANALYSIS):
| python | {
"resource": ""
} |
q7757 | Text.endings | train | def endings(self):
"""The list of word endings.
Ambiguous cases are separated with pipe character by default.
Use :py:meth:`~estnltk.text.Text.get_analysis_element` to specify custom separator for ambiguous entries.
"""
| python | {
"resource": ""
} |
q7758 | Text.forms | train | def forms(self):
"""Tthe list of word forms.
Ambiguous cases are separated with pipe character by default.
Use :py:meth:`~estnltk.text.Text.get_analysis_element` to specify custom separator for ambiguous entries.
"""
| python | {
"resource": ""
} |
q7759 | Text.postags | train | def postags(self):
"""The list of word part-of-speech tags.
Ambiguous cases are separated with pipe character by default.
Use :py:meth:`~estnltk.text.Text.get_analysis_element` to specify custom separator for ambiguous entries.
"""
| python | {
"resource": ""
} |
q7760 | Text.postag_descriptions | train | def postag_descriptions(self):
"""Human-readable POS-tag descriptions."""
if not self.is_tagged(ANALYSIS):
self.tag_analysis()
| python | {
"resource": ""
} |
q7761 | Text.root_tokens | train | def root_tokens(self):
"""Root tokens of word roots."""
if not self.is_tagged(ANALYSIS):
| python | {
"resource": ""
} |
q7762 | Text.descriptions | train | def descriptions(self):
"""Human readable word descriptions."""
descs = []
for postag, form in zip(self.postags, self.forms):
desc = VERB_TYPES.get(form, '')
if len(desc) == 0:
toks = form.split(' ')
if len(toks) == 2:
plur_desc = PLURALITY.get(toks[0], None)
case_desc = CASES.get(toks[1], None)
toks = [] | python | {
"resource": ""
} |
q7763 | Text.tag_syntax_vislcg3 | train | def tag_syntax_vislcg3(self):
""" Changes default syntactic parser to VISLCG3Parser, performs syntactic analysis,
and stores the results in the layer named LAYER_VISLCG3."""
if not self.__syntactic_parser or not | python | {
"resource": ""
} |
q7764 | Text.tag_syntax_maltparser | train | def tag_syntax_maltparser(self):
""" Changes default syntactic parser to MaltParser, performs syntactic analysis,
and stores the results in the layer named LAYER_CONLL."""
if not self.__syntactic_parser or | python | {
"resource": ""
} |
q7765 | Text.tag_labels | train | def tag_labels(self):
"""Tag named entity labels in the ``words`` layer."""
if not self.is_tagged(ANALYSIS):
| python | {
"resource": ""
} |
q7766 | Text.labels | train | def labels(self):
"""Named entity labels."""
if not self.is_tagged(LABEL):
| python | {
"resource": ""
} |
q7767 | Text.tag_named_entities | train | def tag_named_entities(self):
"""Tag ``named_entities`` layer.
This automatically performs morphological analysis along with all dependencies.
"""
if not self.is_tagged(LABEL):
self.tag_labels()
nes = []
word_start = -1
labels = self.labels + ['O'] # last is sentinel
words = self.words
label = 'O'
for i, l in enumerate(labels):
if l.startswith('B-') or l == 'O':
if word_start != -1:
| python | {
"resource": ""
} |
q7768 | Text.named_entities | train | def named_entities(self):
"""The elements of ``named_entities`` layer."""
if not self.is_tagged(NAMED_ENTITIES):
self.tag_named_entities()
| python | {
"resource": ""
} |
q7769 | Text.named_entity_texts | train | def named_entity_texts(self):
"""The texts representing named entities."""
if not self.is_tagged(NAMED_ENTITIES):
| python | {
"resource": ""
} |
q7770 | Text.named_entity_spans | train | def named_entity_spans(self):
"""The spans of named entities."""
| python | {
"resource": ""
} |
q7771 | Text.named_entity_labels | train | def named_entity_labels(self):
"""The named entity labels without BIO prefixes."""
if not self.is_tagged(NAMED_ENTITIES):
| python | {
"resource": ""
} |
q7772 | Text.tag_timexes | train | def tag_timexes(self):
"""Create ``timexes`` layer.
Depends on morphological analysis data in ``words`` layer
and tags it automatically, if it is not present."""
if not self.is_tagged(ANALYSIS):
self.tag_analysis()
if not self.is_tagged(TIMEXES):
| python | {
"resource": ""
} |
q7773 | Text.timex_starts | train | def timex_starts(self):
"""The list of start positions of ``timexes`` layer elements."""
if not self.is_tagged(TIMEXES):
| python | {
"resource": ""
} |
q7774 | Text.timex_ends | train | def timex_ends(self):
"""The list of end positions of ``timexes`` layer elements.""" | python | {
"resource": ""
} |
q7775 | Text.timex_spans | train | def timex_spans(self):
"""The list of spans of ``timexes`` layer elements."""
if not self.is_tagged(TIMEXES):
| python | {
"resource": ""
} |
q7776 | Text.tag_clause_annotations | train | def tag_clause_annotations(self):
"""Tag clause annotations in ``words`` layer.
Depends on morphological analysis.
"""
if not | python | {
"resource": ""
} |
q7777 | Text.clause_annotations | train | def clause_annotations(self):
"""The list of clause annotations in ``words`` layer."""
if not self.is_tagged(CLAUSE_ANNOTATION):
| python | {
"resource": ""
} |
q7778 | Text.clause_indices | train | def clause_indices(self):
"""The list of clause indices in ``words`` layer.
The indices are unique only in the boundary of a | python | {
"resource": ""
} |
q7779 | Text.tag_clauses | train | def tag_clauses(self):
"""Create ``clauses`` multilayer.
Depends on clause annotations."""
if not self.is_tagged(CLAUSE_ANNOTATION):
self.tag_clause_annotations()
def from_sentence(words):
"""Function that extracts clauses from a signle sentence."""
clauses = defaultdict(list)
start = words[0][START]
end = words[0][END]
clause = words[0][CLAUSE_IDX]
| python | {
"resource": ""
} |
q7780 | Text.tag_verb_chains | train | def tag_verb_chains(self):
"""Create ``verb_chains`` layer.
Depends on ``clauses`` layer.
"""
if not self.is_tagged(CLAUSES):
self.tag_clauses()
if self.__verbchain_detector is None:
self.__verbchain_detector = load_default_verbchain_detector()
sentences = self.divide()
verbchains = []
for sentence in sentences:
chains = self.__verbchain_detector.detectVerbChainsFromSent( sentence )
for chain in chains:
# 1) Get spans for all words of the phrase
| python | {
"resource": ""
} |
q7781 | Text.verb_chain_texts | train | def verb_chain_texts(self):
"""The list of texts of ``verb_chains`` layer elements."""
if not self.is_tagged(VERB_CHAINS):
| python | {
"resource": ""
} |
q7782 | Text.verb_chain_starts | train | def verb_chain_starts(self):
"""The start positions of ``verb_chains`` elements."""
if not self.is_tagged(VERB_CHAINS):
| python | {
"resource": ""
} |
q7783 | Text.verb_chain_ends | train | def verb_chain_ends(self):
"""The end positions of ``verb_chains`` elements."""
if not self.is_tagged(VERB_CHAINS):
| python | {
"resource": ""
} |
q7784 | Text.tag_wordnet | train | def tag_wordnet(self, **kwargs):
"""Create wordnet attribute in ``words`` layer.
See :py:meth:`~estnltk.text.wordnet_tagger.WordnetTagger.tag_text` method
for applicable keyword arguments.
"""
global wordnet_tagger
if wordnet_tagger is None: # cached wn tagger
| python | {
"resource": ""
} |
q7785 | Text.wordnet_annotations | train | def wordnet_annotations(self):
"""The list of wordnet annotations of ``words`` layer."""
if not self.is_tagged(WORDNET):
| python | {
"resource": ""
} |
q7786 | Text.synsets | train | def synsets(self):
"""The list of annotated synsets of ``words`` layer."""
synsets = []
for wn_annots in self.wordnet_annotations:
word_synsets = []
for wn_annot in wn_annots:
| python | {
"resource": ""
} |
q7787 | Text.word_literals | train | def word_literals(self):
"""The list of literals per word in ``words`` layer."""
literals = []
for word_synsets in self.synsets:
word_literals = set()
for synset in word_synsets:
for variant in synset.get(SYN_VARIANTS): | python | {
"resource": ""
} |
q7788 | Text.spelling | train | def spelling(self):
"""Flag incorrectly spelled words.
Returns a list of booleans, where element at each position denotes, if the word at the same position
is spelled correctly.
"""
if not self.is_tagged(WORDS):
| python | {
"resource": ""
} |
q7789 | Text.spelling_suggestions | train | def spelling_suggestions(self):
"""The list of spelling suggestions per misspelled word."""
if not self.is_tagged(WORDS):
self.tokenize_words()
| python | {
"resource": ""
} |
q7790 | Text.fix_spelling | train | def fix_spelling(self):
"""Fix spelling of the text.
Note that this method uses the first suggestion that is given for each misspelled word.
It does not perform any sophisticated analysis to determine which one of the suggestions
fits best into the context.
Returns
-------
Text
A copy of this instance with automatically fixed spelling.
"""
if not self.is_tagged(WORDS):
self.tokenize_words()
text = self.text
fixed = vabamorf.fix_spelling(self.word_texts, join=False)
spans = self.word_spans
assert | python | {
"resource": ""
} |
q7791 | Text.clean | train | def clean(self):
"""Return a copy of this Text instance with invalid characters removed."""
| python | {
"resource": ""
} |
q7792 | Text.split_given_spans | train | def split_given_spans(self, spans, sep=' '):
"""Split the text into several pieces.
Resulting texts have all the layers that are present in the text instance that is splitted.
The elements are copied to resulting pieces that are covered by their spans.
However, this can result in empty layers if no element of a splitted layer fits into
a span of a particular output piece.
The positions of layer elements that are copied are translated according to the container span,
so they are consistent with returned text lengths.
Parameters
----------
spans: list of spans.
The positions determining the regions that will end up as individual pieces.
Spans themselves can be lists of spans, which denote multilayer-style text regions.
sep: str
The separator that is used to join together text pieces of multilayer spans.
Returns
-------
list of Text
| python | {
"resource": ""
} |
q7793 | Text.split_by | train | def split_by(self, layer, sep=' '):
"""Split the text into multiple instances defined by elements of given layer.
The spans for layer elements are extracted and feed to :py:meth:`~estnltk.text.Text.split_given_spans`
method.
Parameters
----------
| python | {
"resource": ""
} |
q7794 | Text.split_by_regex | train | def split_by_regex(self, regex_or_pattern, flags=re.U, gaps=True):
"""Split the text into multiple instances using a regex.
Parameters
----------
regex_or_pattern: str or compiled pattern
The regular expression to use for splitting.
flags: int (default: re.U)
The regular expression flags (only used, when user has not supplied compiled regex).
gaps: boolean (default: True)
If True, then regions matched by the regex are not included in the resulting Text instances, which
is expected behaviour.
If False, then only regions matched by the regex are included in the result.
Returns
-------
list of Text
The Text instances obtained by splitting.
"""
text = self[TEXT]
regex = regex_or_pattern
if isinstance(regex, six.string_types):
regex = re.compile(regex_or_pattern, flags=flags)
# else is assumed pattern
last_end = 0
| python | {
"resource": ""
} |
q7795 | Text.divide | train | def divide(self, layer=WORDS, by=SENTENCES):
"""Divide the Text into pieces by keeping references to original elements, when possible.
This is not possible only, if the _element_ is a multispan.
Parameters
----------
element: str
The element to collect and distribute in resulting bins.
by: str
Each resulting bin is defined by spans of this element.
Returns
-------
| python | {
"resource": ""
} |
q7796 | resolve_using_maximal_coverage | train | def resolve_using_maximal_coverage(matches):
"""Given a list of matches, select a subset of matches
such that there are no overlaps and the total number of
covered characters is maximal.
Parameters
----------
matches: list of Match
Returns
--------
list of Match
"""
if len(matches) == 0:
return matches
matches.sort()
N = len(matches)
scores = [len(match) for match in matches]
prev = [-1] * N
for i in range(1, N):
bestscore = -1
bestprev = -1
j = i
while j >= 0:
# if matches do not overlap
if matches[j].is_before(matches[i]):
l = scores[j] + len(matches[i])
if l >= bestscore:
bestscore = l
bestprev = j
else:
# in case of overlapping matches
l = scores[j] - len(matches[j]) + len(matches[i])
| python | {
"resource": ""
} |
q7797 | _isFollowedByComma | train | def _isFollowedByComma( wordID, clauseTokens ):
'''
Teeb kindlaks, kas etteantud ID-ga s6nale j2rgneb vahetult koma;
Tagastab True, kui eeltoodud tingimus on t2idetud, vastasel juhul False;
'''
koma = WordTemplate({ROOT:'^,+$', POSTAG:'Z'})
for i in range(len(clauseTokens)):
token = clauseTokens[i]
if token[WORD_ID] == wordID:
| python | {
"resource": ""
} |
q7798 | is_valid_regex | train | def is_valid_regex(regex):
"""Function for checking a valid regex."""
if len(regex) == 0: | python | {
"resource": ""
} |
q7799 | iterate_intersecting_pairs | train | def iterate_intersecting_pairs(layer):
"""
Given a layer of estntltk objects, yields pairwise intersecting elements.
Breaks when the layer is changed or deleted after initializing the iterator.
"""
yielded = set()
ri = layer[:] # Shallow copy the layer
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.