id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
7,700
estnltk/estnltk
estnltk/converters/gt_conversion.py
copy_analysis_dict
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] } if LEMMA in analysis: new_dict[LEMMA] = analysis[LEMMA] if ROOT_TOKENS in analysis: new_dict[ROOT_TOKENS] = analysis[ROOT_TOKENS] return new_dict
python
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] } if LEMMA in analysis: new_dict[LEMMA] = analysis[LEMMA] if ROOT_TOKENS in analysis: new_dict[ROOT_TOKENS] = analysis[ROOT_TOKENS] return new_dict
[ "def", "copy_analysis_dict", "(", "analysis", ")", ":", "assert", "isinstance", "(", "analysis", ",", "dict", ")", ",", "\"(!) Input 'analysis' should be a dict!\"", "new_dict", "=", "{", "POSTAG", ":", "analysis", "[", "POSTAG", "]", ",", "ROOT", ":", "analysis...
Creates a copy from given analysis dict.
[ "Creates", "a", "copy", "from", "given", "analysis", "dict", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L27-L39
7,701
estnltk/estnltk
estnltk/converters/gt_conversion.py
get_unique_clause_indices
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() # Collect (unique) clause indices over the whole text clause_indices = [] sent_id = 0 for sub_text in text.split_by( SENTENCES ): for word, cl_index in zip( sub_text.words, sub_text.clause_indices ): clause_indices.append( sent_id+cl_index ) nr_of_clauses = len(set(sub_text.clause_indices)) sent_id += nr_of_clauses assert len(clause_indices) == len(text.words), '(!) Number of clause indices should match nr of words!' return clause_indices
python
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() # Collect (unique) clause indices over the whole text clause_indices = [] sent_id = 0 for sub_text in text.split_by( SENTENCES ): for word, cl_index in zip( sub_text.words, sub_text.clause_indices ): clause_indices.append( sent_id+cl_index ) nr_of_clauses = len(set(sub_text.clause_indices)) sent_id += nr_of_clauses assert len(clause_indices) == len(text.words), '(!) Number of clause indices should match nr of words!' return clause_indices
[ "def", "get_unique_clause_indices", "(", "text", ")", ":", "# Add clause boundary annotation (if missing)", "if", "not", "text", ".", "is_tagged", "(", "CLAUSES", ")", ":", "text", ".", "tag_clauses", "(", ")", "# Collect (unique) clause indices over the whole text", "cla...
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.
[ "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", "uniqu...
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L42-L58
7,702
estnltk/estnltk
estnltk/converters/gt_conversion.py
get_unique_sentence_indices
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 = [] sent_id = 0 for sub_text in text.split_by( SENTENCES ): for word in sub_text.words: sent_indices.append( sent_id ) sent_id += 1 assert len(sent_indices) == len(text.words), '(!) Number of sent indices should match nr of words!' return sent_indices
python
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 = [] sent_id = 0 for sub_text in text.split_by( SENTENCES ): for word in sub_text.words: sent_indices.append( sent_id ) sent_id += 1 assert len(sent_indices) == len(text.words), '(!) Number of sent indices should match nr of words!' return sent_indices
[ "def", "get_unique_sentence_indices", "(", "text", ")", ":", "# Add sentence annotation (if missing)", "if", "not", "text", ".", "is_tagged", "(", "SENTENCES", ")", ":", "text", ".", "tokenize_sentences", "(", ")", "# Collect (unique) sent indices over the whole text", "s...
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.
[ "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", "u...
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L61-L76
7,703
estnltk/estnltk
estnltk/converters/gt_conversion.py
_convert_nominal_form
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): pattern_str, replacement = pattern_items if pattern_str in analysis[FORM]: analysis[FORM] = analysis[FORM].replace( pattern_str, replacement ) return analysis
python
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): pattern_str, replacement = pattern_items if pattern_str in analysis[FORM]: analysis[FORM] = analysis[FORM].replace( pattern_str, replacement ) return analysis
[ "def", "_convert_nominal_form", "(", "analysis", ")", ":", "assert", "FORM", "in", "analysis", ",", "'(!) The input analysis does not contain \"'", "+", "FORM", "+", "'\" key.'", "for", "idx", ",", "pattern_items", "in", "enumerate", "(", "_noun_conversion_rules", ")"...
Converts nominal categories of the input analysis. Performs one-to-one conversions only.
[ "Converts", "nominal", "categories", "of", "the", "input", "analysis", ".", "Performs", "one", "-", "to", "-", "one", "conversions", "only", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L115-L123
7,704
estnltk/estnltk
estnltk/converters/gt_conversion.py
_convert_amb_verbal_form
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, analysis[FORM]) new_analysis[FORM] = new_form results.append( new_analysis ) # break after the replacement has been made # ( to avoid over-generation ) break if not results: results.append( analysis ) return results
python
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, analysis[FORM]) new_analysis[FORM] = new_form results.append( new_analysis ) # break after the replacement has been made # ( to avoid over-generation ) break if not results: results.append( analysis ) return results
[ "def", "_convert_amb_verbal_form", "(", "analysis", ")", ":", "assert", "FORM", "in", "analysis", ",", "'(!) The input analysis does not contain \"'", "+", "FORM", "+", "'\" key.'", "results", "=", "[", "]", "for", "root_pat", ",", "pos", ",", "form_pat", ",", "...
Converts ambiguous verbal categories of the input analysis. Performs one-to-many conversions.
[ "Converts", "ambiguous", "verbal", "categories", "of", "the", "input", "analysis", ".", "Performs", "one", "-", "to", "-", "many", "conversions", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L152-L170
7,705
estnltk/estnltk
estnltk/converters/gt_conversion.py
_convert_verbal_form
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: assert analysis[POSTAG] == 'V', \ '(!) Expected analysis of verb, but got analysis of "'+str(analysis[POSTAG])+'" instead.' analysis[FORM] = replacement # Inclusion : the case of some_prefix+' '+form ; elif analysis[FORM].endswith(' '+form): parts = analysis[FORM].split() prefix = ' '.join( parts[:len(parts)-1] ) analysis[FORM] = prefix+' '+replacement return analysis
python
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: assert analysis[POSTAG] == 'V', \ '(!) Expected analysis of verb, but got analysis of "'+str(analysis[POSTAG])+'" instead.' analysis[FORM] = replacement # Inclusion : the case of some_prefix+' '+form ; elif analysis[FORM].endswith(' '+form): parts = analysis[FORM].split() prefix = ' '.join( parts[:len(parts)-1] ) analysis[FORM] = prefix+' '+replacement return analysis
[ "def", "_convert_verbal_form", "(", "analysis", ")", ":", "assert", "FORM", "in", "analysis", ",", "'(!) The input analysis does not contain \"'", "+", "FORM", "+", "'\" key.'", "for", "form", ",", "replacement", "in", "_verb_conversion_rules", ":", "# Exact match", "...
Converts ordinary verbal categories of the input analysis. Performs one-to-one conversions.
[ "Converts", "ordinary", "verbal", "categories", "of", "the", "input", "analysis", ".", "Performs", "one", "-", "to", "-", "one", "conversions", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L220-L235
7,706
estnltk/estnltk
estnltk/converters/gt_conversion.py
_make_postfixes_1
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] ) analysis[FORM] = re.sub( ' Aff Neg$', ' Neg', analysis[FORM] ) analysis[FORM] = re.sub( 'neg', 'Neg', analysis[FORM] ) analysis[FORM] = analysis[FORM].rstrip().lstrip() assert 'neg' not in analysis[FORM], \ '(!) The label "neg" should be removed by now.' assert 'Neg' not in analysis[FORM] or ('Neg' in analysis[FORM] and analysis[FORM].endswith('Neg')), \ '(!) The label "Neg" should end the analysis line: '+str(analysis[FORM]) return analysis
python
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] ) analysis[FORM] = re.sub( ' Aff Neg$', ' Neg', analysis[FORM] ) analysis[FORM] = re.sub( 'neg', 'Neg', analysis[FORM] ) analysis[FORM] = analysis[FORM].rstrip().lstrip() assert 'neg' not in analysis[FORM], \ '(!) The label "neg" should be removed by now.' assert 'Neg' not in analysis[FORM] or ('Neg' in analysis[FORM] and analysis[FORM].endswith('Neg')), \ '(!) The label "Neg" should end the analysis line: '+str(analysis[FORM]) return analysis
[ "def", "_make_postfixes_1", "(", "analysis", ")", ":", "assert", "FORM", "in", "analysis", ",", "'(!) The input analysis does not contain \"'", "+", "FORM", "+", "'\" key.'", "if", "'neg'", "in", "analysis", "[", "FORM", "]", ":", "analysis", "[", "FORM", "]", ...
Provides some post-fixes.
[ "Provides", "some", "post", "-", "fixes", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L241-L254
7,707
estnltk/estnltk
estnltk/converters/gt_conversion.py
_disambiguate_neg
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; ... _keep_analyses( word_dict[ANALYSIS], ['Pers Prt Prc'], ['Pers Prt Imprt','Pers Prt Ind Neg','Pers Prt Prc'] ) if ('Impers Prt Ind Neg' in forms and 'Impers Prt Prc' in forms): if (prev_word_lemma == "ei" or prev_word_lemma == "ega"): # ei saadud, ei tehtud _keep_analyses( word_dict[ANALYSIS], ['Impers Prt Ind Neg'], ['Impers Prt Ind Neg','Impers Prt Prc'] ) else: # on, oli saadud tehtud; saadud õun; ... _keep_analyses( word_dict[ANALYSIS], ['Impers Prt Prc'], ['Impers Prt Ind Neg','Impers Prt Prc'] ) prev_word_lemma = word_dict[ANALYSIS][0][ROOT]
python
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; ... _keep_analyses( word_dict[ANALYSIS], ['Pers Prt Prc'], ['Pers Prt Imprt','Pers Prt Ind Neg','Pers Prt Prc'] ) if ('Impers Prt Ind Neg' in forms and 'Impers Prt Prc' in forms): if (prev_word_lemma == "ei" or prev_word_lemma == "ega"): # ei saadud, ei tehtud _keep_analyses( word_dict[ANALYSIS], ['Impers Prt Ind Neg'], ['Impers Prt Ind Neg','Impers Prt Prc'] ) else: # on, oli saadud tehtud; saadud õun; ... _keep_analyses( word_dict[ANALYSIS], ['Impers Prt Prc'], ['Impers Prt Ind Neg','Impers Prt Prc'] ) prev_word_lemma = word_dict[ANALYSIS][0][ROOT]
[ "def", "_disambiguate_neg", "(", "words_layer", ")", ":", "prev_word_lemma", "=", "''", "for", "word_dict", "in", "words_layer", ":", "forms", "=", "[", "a", "[", "FORM", "]", "for", "a", "in", "word_dict", "[", "ANALYSIS", "]", "]", "if", "(", "'Pers Pr...
Disambiguates forms ambiguous between multiword negation and some other form;
[ "Disambiguates", "forms", "ambiguous", "between", "multiword", "negation", "and", "some", "other", "form", ";" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L277-L305
7,708
estnltk/estnltk
estnltk/converters/gt_conversion.py
_make_postfixes_2
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]: analysis[FORM] = re.sub( '(Sg|Pl)([123])', '\\1 \\2', analysis[FORM] ) return words_layer
python
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]: analysis[FORM] = re.sub( '(Sg|Pl)([123])', '\\1 \\2', analysis[FORM] ) return words_layer
[ "def", "_make_postfixes_2", "(", "words_layer", ")", ":", "for", "word_dict", "in", "words_layer", ":", "for", "analysis", "in", "word_dict", "[", "ANALYSIS", "]", ":", "analysis", "[", "FORM", "]", "=", "re", ".", "sub", "(", "'(Sg|Pl)([123])'", ",", "'\\...
Provides some post-fixes after the disambiguation.
[ "Provides", "some", "post", "-", "fixes", "after", "the", "disambiguation", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/converters/gt_conversion.py#L356-L361
7,709
estnltk/estnltk
estnltk/core.py
as_unicode
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 ------- ``str`` for Python3 or ``unicode`` for Python 2. """ if isinstance(s, six.text_type): return s elif isinstance(s, six.binary_type): return s.decode(encoding) else: raise ValueError('Can only convert types {0} and {1}'.format(six.text_type, six.binary_type))
python
def as_unicode(s, encoding='utf-8'): if isinstance(s, six.text_type): return s elif isinstance(s, six.binary_type): return s.decode(encoding) else: raise ValueError('Can only convert types {0} and {1}'.format(six.text_type, six.binary_type))
[ "def", "as_unicode", "(", "s", ",", "encoding", "=", "'utf-8'", ")", ":", "if", "isinstance", "(", "s", ",", "six", ".", "text_type", ")", ":", "return", "s", "elif", "isinstance", "(", "s", ",", "six", ".", "binary_type", ")", ":", "return", "s", ...
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 ------- ``str`` for Python3 or ``unicode`` for Python 2.
[ "Force", "conversion", "of", "given", "string", "to", "unicode", "type", ".", "Unicode", "is", "str", "type", "for", "Python", "3", ".", "x", "and", "unicode", "for", "Python", "2", ".", "x", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/core.py#L141-L168
7,710
estnltk/estnltk
estnltk/core.py
as_binary
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 ------- ``bytes`` for Python3 or ``str`` for Python 2. """ if isinstance(s, six.text_type): return s.encode(encoding) elif isinstance(s, six.binary_type): # make sure the binary is in required encoding return s.decode(encoding).encode(encoding) else: raise ValueError('Can only convert types {0} and {1}'.format(six.text_type, six.binary_type))
python
def as_binary(s, encoding='utf-8'): if isinstance(s, six.text_type): return s.encode(encoding) elif isinstance(s, six.binary_type): # make sure the binary is in required encoding return s.decode(encoding).encode(encoding) else: raise ValueError('Can only convert types {0} and {1}'.format(six.text_type, six.binary_type))
[ "def", "as_binary", "(", "s", ",", "encoding", "=", "'utf-8'", ")", ":", "if", "isinstance", "(", "s", ",", "six", ".", "text_type", ")", ":", "return", "s", ".", "encode", "(", "encoding", ")", "elif", "isinstance", "(", "s", ",", "six", ".", "bin...
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 ------- ``bytes`` for Python3 or ``str`` for Python 2.
[ "Force", "conversion", "of", "given", "string", "to", "binary", "type", ".", "Binary", "is", "bytes", "type", "for", "Python", "3", ".", "x", "and", "str", "for", "Python", "2", ".", "x", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/core.py#L171-L200
7,711
estnltk/estnltk
estnltk/taggers/event_tagger.py
KeywordTagger.tag
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) elif self.search_method == 'naive': events = self._find_keywords_naive(text.text) events = self._resolve_conflicts(events) if self.mapping: for item in events: item['type'] = self.map[ text.text[item['start']:item['end']] ] if self.return_layer: return events else: text[self.layer_name] = events
python
def tag(self, text): if self.search_method == 'ahocorasick': events = self._find_keywords_ahocorasick(text.text) elif self.search_method == 'naive': events = self._find_keywords_naive(text.text) events = self._resolve_conflicts(events) if self.mapping: for item in events: item['type'] = self.map[ text.text[item['start']:item['end']] ] if self.return_layer: return events else: text[self.layer_name] = events
[ "def", "tag", "(", "self", ",", "text", ")", ":", "if", "self", ".", "search_method", "==", "'ahocorasick'", ":", "events", "=", "self", ".", "_find_keywords_ahocorasick", "(", "text", ".", "text", ")", "elif", "self", ".", "search_method", "==", "'naive'"...
Retrieves list of keywords in text. Parameters ---------- text: Text The text to search for events. Returns ------- list of vents sorted by start, end
[ "Retrieves", "list", "of", "keywords", "in", "text", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/taggers/event_tagger.py#L129-L156
7,712
estnltk/estnltk
estnltk/taggers/event_tagger.py
RegexTagger.tag
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 """ matches = self._match(text.text) matches = self._resolve_conflicts(matches) if self.return_layer: return matches else: text[self.layer_name] = matches
python
def tag(self, text): matches = self._match(text.text) matches = self._resolve_conflicts(matches) if self.return_layer: return matches else: text[self.layer_name] = matches
[ "def", "tag", "(", "self", ",", "text", ")", ":", "matches", "=", "self", ".", "_match", "(", "text", ".", "text", ")", "matches", "=", "self", ".", "_resolve_conflicts", "(", "matches", ")", "if", "self", ".", "return_layer", ":", "return", "matches",...
Retrieves list of regex_matches in text. Parameters ---------- text: Text The estnltk text object to search for events. Returns ------- list of matches
[ "Retrieves", "list", "of", "regex_matches", "in", "text", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/taggers/event_tagger.py#L201-L219
7,713
estnltk/estnltk
estnltk/corpus.py
yield_json_corpus
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 ------- generator of Text """ with codecs.open(fnm, 'rb', 'ascii') as f: line = f.readline() while line != '': yield Text(json.loads(line)) line = f.readline()
python
def yield_json_corpus(fnm): with codecs.open(fnm, 'rb', 'ascii') as f: line = f.readline() while line != '': yield Text(json.loads(line)) line = f.readline()
[ "def", "yield_json_corpus", "(", "fnm", ")", ":", "with", "codecs", ".", "open", "(", "fnm", ",", "'rb'", ",", "'ascii'", ")", "as", "f", ":", "line", "=", "f", ".", "readline", "(", ")", "while", "line", "!=", "''", ":", "yield", "Text", "(", "j...
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 ------- generator of Text
[ "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", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/corpus.py#L10-L28
7,714
estnltk/estnltk
estnltk/corpus.py
write_json_corpus
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 path to save the corpus. """ with codecs.open(fnm, 'wb', 'ascii') as f: for document in documents: f.write(json.dumps(document) + '\n') return documents
python
def write_json_corpus(documents, fnm): with codecs.open(fnm, 'wb', 'ascii') as f: for document in documents: f.write(json.dumps(document) + '\n') return documents
[ "def", "write_json_corpus", "(", "documents", ",", "fnm", ")", ":", "with", "codecs", ".", "open", "(", "fnm", ",", "'wb'", ",", "'ascii'", ")", "as", "f", ":", "for", "document", "in", "documents", ":", "f", ".", "write", "(", "json", ".", "dumps", ...
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 path to save the corpus.
[ "Write", "a", "lisst", "of", "Text", "instances", "as", "JSON", "corpus", "on", "disk", ".", "A", "JSON", "corpus", "contains", "one", "document", "per", "line", "encoded", "in", "JSON", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/corpus.py#L47-L61
7,715
estnltk/estnltk
estnltk/corpus.py
read_document
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 """ with codecs.open(fnm, 'rb', 'ascii') as f: return Text(json.loads(f.read()))
python
def read_document(fnm): with codecs.open(fnm, 'rb', 'ascii') as f: return Text(json.loads(f.read()))
[ "def", "read_document", "(", "fnm", ")", ":", "with", "codecs", ".", "open", "(", "fnm", ",", "'rb'", ",", "'ascii'", ")", "as", "f", ":", "return", "Text", "(", "json", ".", "loads", "(", "f", ".", "read", "(", ")", ")", ")" ]
Read a document that is stored in a text file as JSON. Parameters ---------- fnm: str The path of the document. Returns ------- Text
[ "Read", "a", "document", "that", "is", "stored", "in", "a", "text", "file", "as", "JSON", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/corpus.py#L64-L77
7,716
estnltk/estnltk
estnltk/corpus.py
write_document
def write_document(doc, fnm): """Write a Text document to file. Parameters ---------- doc: Text The document to save. fnm: str The filename to save the document """ with codecs.open(fnm, 'wb', 'ascii') as f: f.write(json.dumps(doc, indent=2))
python
def write_document(doc, fnm): with codecs.open(fnm, 'wb', 'ascii') as f: f.write(json.dumps(doc, indent=2))
[ "def", "write_document", "(", "doc", ",", "fnm", ")", ":", "with", "codecs", ".", "open", "(", "fnm", ",", "'wb'", ",", "'ascii'", ")", "as", "f", ":", "f", ".", "write", "(", "json", ".", "dumps", "(", "doc", ",", "indent", "=", "2", ")", ")" ...
Write a Text document to file. Parameters ---------- doc: Text The document to save. fnm: str The filename to save the document
[ "Write", "a", "Text", "document", "to", "file", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/corpus.py#L80-L91
7,717
estnltk/estnltk
estnltk/wordnet/eurown.py
_TypedList.polarisText
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( map(lambda x: x.polarisText, self) ) else: _out = '' return _out return locals()
python
def polarisText(): 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( map(lambda x: x.polarisText, self) ) else: _out = '' return _out return locals()
[ "def", "polarisText", "(", ")", ":", "def", "fget", "(", "self", ")", ":", "_out", "=", "''", "_n", "=", "'\\n'", "if", "len", "(", "self", ")", ":", "if", "self", ".", "parent", ":", "_out", "=", "'%s%s%s'", "%", "(", "_out", ",", "PolarisText",...
polarisText part of _TypedList objects
[ "polarisText", "part", "of", "_TypedList", "objects" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L97-L115
7,718
estnltk/estnltk
estnltk/wordnet/eurown.py
Parser.parse_line
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) self.fieldValue = fv[1:-1] elif iList: if len(iList) == 1: self.fieldValue = iList.pop(0) else: self.fieldValue = ' '.join(iList) try: self.fieldValue = int(self.fieldValue) except ValueError: self.noQuotes = True
python
def parse_line(self,iStr): 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) self.fieldValue = fv[1:-1] elif iList: if len(iList) == 1: self.fieldValue = iList.pop(0) else: self.fieldValue = ' '.join(iList) try: self.fieldValue = int(self.fieldValue) except ValueError: self.noQuotes = True
[ "def", "parse_line", "(", "self", ",", "iStr", ")", ":", "self", ".", "levelNumber", "=", "None", "self", ".", "DRN", "=", "None", "self", ".", "fieldTag", "=", "None", "self", ".", "fieldValue", "=", "None", "self", ".", "noQuotes", "=", "None", "if...
Parses ewn file line
[ "Parses", "ewn", "file", "line" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1126-L1156
7,719
estnltk/estnltk
estnltk/wordnet/eurown.py
Variant.addTranslation
def addTranslation(self,translation): '''Appends one Translation to translations ''' if isinstance(translation, Translation): self.translations.append(translation) else: raise(TranslationError, 'translation Type should be Translation, not %s' % type( translation) )
python
def addTranslation(self,translation): '''Appends one Translation to translations ''' if isinstance(translation, Translation): self.translations.append(translation) else: raise(TranslationError, 'translation Type should be Translation, not %s' % type( translation) )
[ "def", "addTranslation", "(", "self", ",", "translation", ")", ":", "if", "isinstance", "(", "translation", ",", "Translation", ")", ":", "self", ".", "translations", ".", "append", "(", "translation", ")", "else", ":", "raise", "(", "TranslationError", ",",...
Appends one Translation to translations
[ "Appends", "one", "Translation", "to", "translations" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1717-L1726
7,720
estnltk/estnltk
estnltk/wordnet/eurown.py
Variant.addVariantFeature
def addVariantFeature(self,variantFeature): '''Appends one VariantFeature to variantFeatures ''' if isinstance(variantFeature, Feature): self.features.append(variantFeature) else: raise(TypeError, 'variantFeature Type should be Feature, not %s' % type( variantFeature) )
python
def addVariantFeature(self,variantFeature): '''Appends one VariantFeature to variantFeatures ''' if isinstance(variantFeature, Feature): self.features.append(variantFeature) else: raise(TypeError, 'variantFeature Type should be Feature, not %s' % type( variantFeature) )
[ "def", "addVariantFeature", "(", "self", ",", "variantFeature", ")", ":", "if", "isinstance", "(", "variantFeature", ",", "Feature", ")", ":", "self", ".", "features", ".", "append", "(", "variantFeature", ")", "else", ":", "raise", "(", "TypeError", ",", ...
Appends one VariantFeature to variantFeatures
[ "Appends", "one", "VariantFeature", "to", "variantFeatures" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1728-L1737
7,721
estnltk/estnltk
estnltk/wordnet/eurown.py
Variant.addUsage_Label
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, 'usage_label Type should be Usage_Label, not %s' % type( usage_label) )
python
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, 'usage_label Type should be Usage_Label, not %s' % type( usage_label) )
[ "def", "addUsage_Label", "(", "self", ",", "usage_label", ")", ":", "if", "isinstance", "(", "usage_label", ",", "Usage_Label", ")", ":", "self", ".", "usage_labels", ".", "append", "(", "usage_label", ")", "else", ":", "raise", "(", "Usage_LabelError", ",",...
Appends one Usage_Label to usage_labels
[ "Appends", "one", "Usage_Label", "to", "usage_labels" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1739-L1748
7,722
estnltk/estnltk
estnltk/wordnet/eurown.py
Variant.addExample
def addExample(self,example): '''Appends one Example to examples ''' if isinstance(example, Example): self.examples.append(example) else: raise (ExampleError, 'example Type should be Example, not %s' % type(example) )
python
def addExample(self,example): '''Appends one Example to examples ''' if isinstance(example, Example): self.examples.append(example) else: raise (ExampleError, 'example Type should be Example, not %s' % type(example) )
[ "def", "addExample", "(", "self", ",", "example", ")", ":", "if", "isinstance", "(", "example", ",", "Example", ")", ":", "self", ".", "examples", ".", "append", "(", "example", ")", "else", ":", "raise", "(", "ExampleError", ",", "'example Type should be ...
Appends one Example to examples
[ "Appends", "one", "Example", "to", "examples" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1750-L1758
7,723
estnltk/estnltk
estnltk/wordnet/eurown.py
Synset.firstVariant
def firstVariant(): """first variant of Variants Read-only """ def fget(self): if self.variants: return self.variants[0] else: variant = Variant() return variant return locals()
python
def firstVariant(): def fget(self): if self.variants: return self.variants[0] else: variant = Variant() return variant return locals()
[ "def", "firstVariant", "(", ")", ":", "def", "fget", "(", "self", ")", ":", "if", "self", ".", "variants", ":", "return", "self", ".", "variants", "[", "0", "]", "else", ":", "variant", "=", "Variant", "(", ")", "return", "variant", "return", "locals...
first variant of Variants Read-only
[ "first", "variant", "of", "Variants", "Read", "-", "only" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1978-L1990
7,724
estnltk/estnltk
estnltk/wordnet/eurown.py
Synset.literals
def literals(): '''Returns a list of literals in the Synset read-only ''' def fget(self): if self.variants: return map(lambda x: x.literal, self.variants) else: return None return locals()
python
def literals(): '''Returns a list of literals in the Synset read-only ''' def fget(self): if self.variants: return map(lambda x: x.literal, self.variants) else: return None return locals()
[ "def", "literals", "(", ")", ":", "def", "fget", "(", "self", ")", ":", "if", "self", ".", "variants", ":", "return", "map", "(", "lambda", "x", ":", "x", ".", "literal", ",", "self", ".", "variants", ")", "else", ":", "return", "None", "return", ...
Returns a list of literals in the Synset read-only
[ "Returns", "a", "list", "of", "literals", "in", "the", "Synset", "read", "-", "only" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L1994-L2006
7,725
estnltk/estnltk
estnltk/wordnet/eurown.py
Synset.addVariantOld
def addVariantOld(self, literal='', sense=0, gloss='', examples=[]): '''Appends variant sth to do that it would be possible to add Variant object ''' var = Variant(literal=literal, sense=sense, gloss=gloss, examples=examples) self.variants.append(var)
python
def addVariantOld(self, literal='', sense=0, gloss='', examples=[]): '''Appends variant sth to do that it would be possible to add Variant object ''' var = Variant(literal=literal, sense=sense, gloss=gloss, examples=examples) self.variants.append(var)
[ "def", "addVariantOld", "(", "self", ",", "literal", "=", "''", ",", "sense", "=", "0", ",", "gloss", "=", "''", ",", "examples", "=", "[", "]", ")", ":", "var", "=", "Variant", "(", "literal", "=", "literal", ",", "sense", "=", "sense", ",", "gl...
Appends variant sth to do that it would be possible to add Variant object
[ "Appends", "variant", "sth", "to", "do", "that", "it", "would", "be", "possible", "to", "add", "Variant", "object" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L2010-L2024
7,726
estnltk/estnltk
estnltk/wordnet/eurown.py
Synset.addVariant
def addVariant(self,variant): '''Appends one Variant to variants ''' if isinstance(variant, Variant): self.variants.append(variant) else: raise (VariantError, 'variant Type should be Variant, not %s' % type(variant))
python
def addVariant(self,variant): '''Appends one Variant to variants ''' if isinstance(variant, Variant): self.variants.append(variant) else: raise (VariantError, 'variant Type should be Variant, not %s' % type(variant))
[ "def", "addVariant", "(", "self", ",", "variant", ")", ":", "if", "isinstance", "(", "variant", ",", "Variant", ")", ":", "self", ".", "variants", ".", "append", "(", "variant", ")", "else", ":", "raise", "(", "VariantError", ",", "'variant Type should be ...
Appends one Variant to variants
[ "Appends", "one", "Variant", "to", "variants" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L2026-L2034
7,727
estnltk/estnltk
estnltk/wordnet/eurown.py
Synset.named_eq_relations
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 elif self.eqLinks and 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 not in name, self.eqLinks) else: return None #should rise error else: return None
python
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 elif self.eqLinks and 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 not in name, self.eqLinks) else: return None #should rise error else: return None
[ "def", "named_eq_relations", "(", "self", ",", "name", ",", "neg", "=", "False", ")", ":", "if", "self", ".", "eqLinks", "and", "not", "neg", ":", "if", "isinstance", "(", "name", ",", "six", ".", "string_types", ")", ":", "return", "filter", "(", "l...
Returns list of named eqLinks. <name> may be string or list.
[ "Returns", "list", "of", "named", "eqLinks", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/wordnet/eurown.py#L2102-L2131
7,728
estnltk/estnltk
estnltk/syntax/utils.py
Tree.get_root
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. ''' if self.parent == None: return self else: return self.parent.get_root( **kwargs )
python
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. ''' if self.parent == None: return self else: return self.parent.get_root( **kwargs )
[ "def", "get_root", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "parent", "==", "None", ":", "return", "self", "else", ":", "return", "self", ".", "parent", ".", "get_root", "(", "*", "*", "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.
[ "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", ...
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/syntax/utils.py#L596-L604
7,729
estnltk/estnltk
estnltk/syntax/utils.py
Tree.get_tree_depth
def get_tree_depth( self ): ''' Finds depth of this tree. ''' if (self.children): depth = 1 childDepths = [] for child in self.children: childDepths.append( child.get_tree_depth() ) return depth + max(childDepths) else: return 0
python
def get_tree_depth( self ): ''' Finds depth of this tree. ''' if (self.children): depth = 1 childDepths = [] for child in self.children: childDepths.append( child.get_tree_depth() ) return depth + max(childDepths) else: return 0
[ "def", "get_tree_depth", "(", "self", ")", ":", "if", "(", "self", ".", "children", ")", ":", "depth", "=", "1", "childDepths", "=", "[", "]", "for", "child", "in", "self", ".", "children", ":", "childDepths", ".", "append", "(", "child", ".", "get_t...
Finds depth of this tree.
[ "Finds", "depth", "of", "this", "tree", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/syntax/utils.py#L851-L860
7,730
estnltk/estnltk
estnltk/grammar/grammar.py
Symbol.get_matches
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)] matches = self.get_matches_without_cache(text, cache=cache) cache[id(self)] = matches # if this is the root node, resolve the matches if is_root_node and conflict_resolver is not None: return conflict_resolver(matches) return matches
python
def get_matches(self, text, cache=None, conflict_resolver=resolve_using_maximal_coverage): is_root_node = False if cache is None: cache = {} is_root_node = True if id(self) in cache: return cache[id(self)] matches = self.get_matches_without_cache(text, cache=cache) cache[id(self)] = matches # if this is the root node, resolve the matches if is_root_node and conflict_resolver is not None: return conflict_resolver(matches) return matches
[ "def", "get_matches", "(", "self", ",", "text", ",", "cache", "=", "None", ",", "conflict_resolver", "=", "resolve_using_maximal_coverage", ")", ":", "is_root_node", "=", "False", "if", "cache", "is", "None", ":", "cache", "=", "{", "}", "is_root_node", "=",...
Get the matches of the symbol on given text.
[ "Get", "the", "matches", "of", "the", "symbol", "on", "given", "text", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/grammar/grammar.py#L45-L59
7,731
estnltk/estnltk
estnltk/text.py
Text.texts
def texts(self, layer, sep=' '): """Retrieve texts for given layer. Parameters ---------- sep: str Separator for multilayer elements (default: ' '). Returns ------- list of str List of strings that make up given layer. """ return self.texts_from_spans(self.spans(layer), sep)
python
def texts(self, layer, sep=' '): return self.texts_from_spans(self.spans(layer), sep)
[ "def", "texts", "(", "self", ",", "layer", ",", "sep", "=", "' '", ")", ":", "return", "self", ".", "texts_from_spans", "(", "self", ".", "spans", "(", "layer", ")", ",", "sep", ")" ]
Retrieve texts for given layer. Parameters ---------- sep: str Separator for multilayer elements (default: ' '). Returns ------- list of str List of strings that make up given layer.
[ "Retrieve", "texts", "for", "given", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L199-L213
7,732
estnltk/estnltk
estnltk/text.py
Text.starts
def starts(self, layer): """Retrieve start positions of elements if given layer.""" starts = [] for data in self[layer]: starts.append(data[START]) return starts
python
def starts(self, layer): starts = [] for data in self[layer]: starts.append(data[START]) return starts
[ "def", "starts", "(", "self", ",", "layer", ")", ":", "starts", "=", "[", "]", "for", "data", "in", "self", "[", "layer", "]", ":", "starts", ".", "append", "(", "data", "[", "START", "]", ")", "return", "starts" ]
Retrieve start positions of elements if given layer.
[ "Retrieve", "start", "positions", "of", "elements", "if", "given", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L251-L256
7,733
estnltk/estnltk
estnltk/text.py
Text.ends
def ends(self, layer): """Retrieve end positions of elements if given layer.""" ends = [] for data in self[layer]: ends.append(data[END]) return ends
python
def ends(self, layer): ends = [] for data in self[layer]: ends.append(data[END]) return ends
[ "def", "ends", "(", "self", ",", "layer", ")", ":", "ends", "=", "[", "]", "for", "data", "in", "self", "[", "layer", "]", ":", "ends", ".", "append", "(", "data", "[", "END", "]", ")", "return", "ends" ]
Retrieve end positions of elements if given layer.
[ "Retrieve", "end", "positions", "of", "elements", "if", "given", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L258-L263
7,734
estnltk/estnltk
estnltk/text.py
Text.layer_tagger_mapping
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, NAMED_ENTITIES: self.tag_named_entities, CLAUSE_ANNOTATION: self.tag_clause_annotations, CLAUSES: self.tag_clauses, LAYER_CONLL: self.tag_syntax_vislcg3, LAYER_VISLCG3: self.tag_syntax_maltparser, WORDNET: self.tag_wordnet }
python
def layer_tagger_mapping(self): return { PARAGRAPHS: self.tokenize_paragraphs, SENTENCES: self.tokenize_sentences, WORDS: self.tokenize_words, ANALYSIS: self.tag_analysis, TIMEXES: self.tag_timexes, NAMED_ENTITIES: self.tag_named_entities, CLAUSE_ANNOTATION: self.tag_clause_annotations, CLAUSES: self.tag_clauses, LAYER_CONLL: self.tag_syntax_vislcg3, LAYER_VISLCG3: self.tag_syntax_maltparser, WORDNET: self.tag_wordnet }
[ "def", "layer_tagger_mapping", "(", "self", ")", ":", "return", "{", "PARAGRAPHS", ":", "self", ".", "tokenize_paragraphs", ",", "SENTENCES", ":", "self", ".", "tokenize_sentences", ",", "WORDS", ":", "self", ".", "tokenize_words", ",", "ANALYSIS", ":", "self"...
Dictionary that maps layer names to taggers that can create that layer.
[ "Dictionary", "that", "maps", "layer", "names", "to", "taggers", "that", "can", "create", "that", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L346-L360
7,735
estnltk/estnltk
estnltk/text.py
Text.tag
def tag(self, layer): """Tag the annotations of given layer. It can automatically tag any built-in layer type.""" mapping = self.layer_tagger_mapping if layer in mapping: mapping[layer]() return self
python
def tag(self, layer): mapping = self.layer_tagger_mapping if layer in mapping: mapping[layer]() return self
[ "def", "tag", "(", "self", ",", "layer", ")", ":", "mapping", "=", "self", ".", "layer_tagger_mapping", "if", "layer", "in", "mapping", ":", "mapping", "[", "layer", "]", "(", ")", "return", "self" ]
Tag the annotations of given layer. It can automatically tag any built-in layer type.
[ "Tag", "the", "annotations", "of", "given", "layer", ".", "It", "can", "automatically", "tag", "any", "built", "-", "in", "layer", "type", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L362-L367
7,736
estnltk/estnltk
estnltk/text.py
Text.tokenize_paragraphs
def tokenize_paragraphs(self): """Apply paragraph tokenization to this Text instance. Creates ``paragraphs`` layer.""" tok = self.__paragraph_tokenizer spans = tok.span_tokenize(self.text) dicts = [] for start, end in spans: dicts.append({'start': start, 'end': end}) self[PARAGRAPHS] = dicts return self
python
def tokenize_paragraphs(self): tok = self.__paragraph_tokenizer spans = tok.span_tokenize(self.text) dicts = [] for start, end in spans: dicts.append({'start': start, 'end': end}) self[PARAGRAPHS] = dicts return self
[ "def", "tokenize_paragraphs", "(", "self", ")", ":", "tok", "=", "self", ".", "__paragraph_tokenizer", "spans", "=", "tok", ".", "span_tokenize", "(", "self", ".", "text", ")", "dicts", "=", "[", "]", "for", "start", ",", "end", "in", "spans", ":", "di...
Apply paragraph tokenization to this Text instance. Creates ``paragraphs`` layer.
[ "Apply", "paragraph", "tokenization", "to", "this", "Text", "instance", ".", "Creates", "paragraphs", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L369-L377
7,737
estnltk/estnltk
estnltk/text.py
Text.paragraph_texts
def paragraph_texts(self): """The list of texts representing ``paragraphs`` layer elements.""" if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.texts(PARAGRAPHS)
python
def paragraph_texts(self): if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.texts(PARAGRAPHS)
[ "def", "paragraph_texts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "PARAGRAPHS", ")", ":", "self", ".", "tokenize_paragraphs", "(", ")", "return", "self", ".", "texts", "(", "PARAGRAPHS", ")" ]
The list of texts representing ``paragraphs`` layer elements.
[ "The", "list", "of", "texts", "representing", "paragraphs", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L387-L391
7,738
estnltk/estnltk
estnltk/text.py
Text.paragraph_spans
def paragraph_spans(self): """The list of spans representing ``paragraphs`` layer elements.""" if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.spans(PARAGRAPHS)
python
def paragraph_spans(self): if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.spans(PARAGRAPHS)
[ "def", "paragraph_spans", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "PARAGRAPHS", ")", ":", "self", ".", "tokenize_paragraphs", "(", ")", "return", "self", ".", "spans", "(", "PARAGRAPHS", ")" ]
The list of spans representing ``paragraphs`` layer elements.
[ "The", "list", "of", "spans", "representing", "paragraphs", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L394-L398
7,739
estnltk/estnltk
estnltk/text.py
Text.paragraph_starts
def paragraph_starts(self): """The start positions of ``paragraphs`` layer elements.""" if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.starts(PARAGRAPHS)
python
def paragraph_starts(self): if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.starts(PARAGRAPHS)
[ "def", "paragraph_starts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "PARAGRAPHS", ")", ":", "self", ".", "tokenize_paragraphs", "(", ")", "return", "self", ".", "starts", "(", "PARAGRAPHS", ")" ]
The start positions of ``paragraphs`` layer elements.
[ "The", "start", "positions", "of", "paragraphs", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L401-L405
7,740
estnltk/estnltk
estnltk/text.py
Text.paragraph_ends
def paragraph_ends(self): """The end positions of ``paragraphs`` layer elements.""" if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.ends(PARAGRAPHS)
python
def paragraph_ends(self): if not self.is_tagged(PARAGRAPHS): self.tokenize_paragraphs() return self.ends(PARAGRAPHS)
[ "def", "paragraph_ends", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "PARAGRAPHS", ")", ":", "self", ".", "tokenize_paragraphs", "(", ")", "return", "self", ".", "ends", "(", "PARAGRAPHS", ")" ]
The end positions of ``paragraphs`` layer elements.
[ "The", "end", "positions", "of", "paragraphs", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L408-L412
7,741
estnltk/estnltk
estnltk/text.py
Text.tokenize_sentences
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 ] try: # Apply sentences_from_tokens method (if available) sents = tok.sentences_from_tokens( para_word_texts ) except AttributeError as e: raise # Align result of the sentence tokenization with the initial word tokenization # in order to determine the sentence boundaries i = 0 for sentence in sents: j = 0 firstToken = None lastToken = None while i < len(para_words): if para_words[i][TEXT] != sentence[j]: raise Exception('Error on aligning: ', para_word_texts,' and ',sentence,' at positions ',i,j) if j == 0: firstToken = para_words[i] if j == len(sentence) - 1: lastToken = para_words[i] i+=1 break j+=1 i+=1 sentenceDict = \ {'start': firstToken[START], 'end': lastToken[END]} dicts.append( sentenceDict ) # Note: We also need to invalidate the cached properties providing the # sentence information, as otherwise, if the properties have been # called already, new calls would return the old state of sentence # tokenization; for sentence_attrib in ['sentences', 'sentence_texts', 'sentence_spans', \ 'sentence_starts', 'sentence_ends']: try: # invalidate the cache delattr(self, sentence_attrib) except AttributeError: # it's ok, if the cached property has not been called yet pass self[SENTENCES] = dicts return self
python
def tokenize_sentences(self): 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 ] try: # Apply sentences_from_tokens method (if available) sents = tok.sentences_from_tokens( para_word_texts ) except AttributeError as e: raise # Align result of the sentence tokenization with the initial word tokenization # in order to determine the sentence boundaries i = 0 for sentence in sents: j = 0 firstToken = None lastToken = None while i < len(para_words): if para_words[i][TEXT] != sentence[j]: raise Exception('Error on aligning: ', para_word_texts,' and ',sentence,' at positions ',i,j) if j == 0: firstToken = para_words[i] if j == len(sentence) - 1: lastToken = para_words[i] i+=1 break j+=1 i+=1 sentenceDict = \ {'start': firstToken[START], 'end': lastToken[END]} dicts.append( sentenceDict ) # Note: We also need to invalidate the cached properties providing the # sentence information, as otherwise, if the properties have been # called already, new calls would return the old state of sentence # tokenization; for sentence_attrib in ['sentences', 'sentence_texts', 'sentence_spans', \ 'sentence_starts', 'sentence_ends']: try: # invalidate the cache delattr(self, sentence_attrib) except AttributeError: # it's ok, if the cached property has not been called yet pass self[SENTENCES] = dicts return self
[ "def", "tokenize_sentences", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "PARAGRAPHS", ")", ":", "self", ".", "tokenize_paragraphs", "(", ")", "tok", "=", "self", ".", "__sentence_tokenizer", "text", "=", "self", ".", "text", "dicts"...
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;
[ "Apply", "sentence", "tokenization", "to", "this", "Text", "instance", ".", "Creates", "sentences", "layer", ".", "Automatically", "tokenizes", "paragraphs", "if", "they", "are", "not", "already", "tokenized", ".", "Also", "if", "word", "tokenization", "has", "a...
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L414-L480
7,742
estnltk/estnltk
estnltk/text.py
Text.sentence_texts
def sentence_texts(self): """The list of texts representing ``sentences`` layer elements.""" if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.texts(SENTENCES)
python
def sentence_texts(self): if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.texts(SENTENCES)
[ "def", "sentence_texts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "SENTENCES", ")", ":", "self", ".", "tokenize_sentences", "(", ")", "return", "self", ".", "texts", "(", "SENTENCES", ")" ]
The list of texts representing ``sentences`` layer elements.
[ "The", "list", "of", "texts", "representing", "sentences", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L490-L494
7,743
estnltk/estnltk
estnltk/text.py
Text.sentence_spans
def sentence_spans(self): """The list of spans representing ``sentences`` layer elements.""" if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.spans(SENTENCES)
python
def sentence_spans(self): if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.spans(SENTENCES)
[ "def", "sentence_spans", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "SENTENCES", ")", ":", "self", ".", "tokenize_sentences", "(", ")", "return", "self", ".", "spans", "(", "SENTENCES", ")" ]
The list of spans representing ``sentences`` layer elements.
[ "The", "list", "of", "spans", "representing", "sentences", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L497-L501
7,744
estnltk/estnltk
estnltk/text.py
Text.sentence_starts
def sentence_starts(self): """The list of start positions representing ``sentences`` layer elements.""" if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.starts(SENTENCES)
python
def sentence_starts(self): if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.starts(SENTENCES)
[ "def", "sentence_starts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "SENTENCES", ")", ":", "self", ".", "tokenize_sentences", "(", ")", "return", "self", ".", "starts", "(", "SENTENCES", ")" ]
The list of start positions representing ``sentences`` layer elements.
[ "The", "list", "of", "start", "positions", "representing", "sentences", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L504-L508
7,745
estnltk/estnltk
estnltk/text.py
Text.sentence_ends
def sentence_ends(self): """The list of end positions representing ``sentences`` layer elements.""" if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.ends(SENTENCES)
python
def sentence_ends(self): if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.ends(SENTENCES)
[ "def", "sentence_ends", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "SENTENCES", ")", ":", "self", ".", "tokenize_sentences", "(", ")", "return", "self", ".", "ends", "(", "SENTENCES", ")" ]
The list of end positions representing ``sentences`` layer elements.
[ "The", "list", "of", "end", "positions", "representing", "sentences", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L511-L515
7,746
estnltk/estnltk
estnltk/text.py
Text.tokenize_words
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] spans = tok.span_tokenize(sent_text) for start, end in spans: dicts.append({START: start+sent_start, END: end+sent_start, TEXT: sent_text[start:end]}) self[WORDS] = dicts return self
python
def tokenize_words(self): 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] spans = tok.span_tokenize(sent_text) for start, end in spans: dicts.append({START: start+sent_start, END: end+sent_start, TEXT: sent_text[start:end]}) self[WORDS] = dicts return self
[ "def", "tokenize_words", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "SENTENCES", ")", ":", "self", ".", "tokenize_sentences", "(", ")", "tok", "=", "self", ".", "__word_tokenizer", "text", "=", "self", ".", "text", "dicts", "=", ...
Apply word tokenization and create ``words`` layer. Automatically creates ``paragraphs`` and ``sentences`` layers.
[ "Apply", "word", "tokenization", "and", "create", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L517-L534
7,747
estnltk/estnltk
estnltk/text.py
Text.tag_analysis
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] all_analysis = vabamorf.analyze(texts, **self.__kwargs) for word, analysis in zip(sentence, all_analysis): word[ANALYSIS] = analysis[ANALYSIS] word[TEXT] = analysis[TEXT] return self
python
def tag_analysis(self): 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] all_analysis = vabamorf.analyze(texts, **self.__kwargs) for word, analysis in zip(sentence, all_analysis): word[ANALYSIS] = analysis[ANALYSIS] word[TEXT] = analysis[TEXT] return self
[ "def", "tag_analysis", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "sentences", "=", "self", ".", "divide", "(", "WORDS", ",", "SENTENCES", ")", "for", "sentence", "in",...
Tag ``words`` layer with morphological analysis attributes.
[ "Tag", "words", "layer", "with", "morphological", "analysis", "attributes", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L536-L547
7,748
estnltk/estnltk
estnltk/text.py
Text.word_texts
def word_texts(self): """The list of words representing ``words`` layer elements.""" if not self.is_tagged(WORDS): self.tokenize_words() return [word[TEXT] for word in self[WORDS]]
python
def word_texts(self): if not self.is_tagged(WORDS): self.tokenize_words() return [word[TEXT] for word in self[WORDS]]
[ "def", "word_texts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "[", "word", "[", "TEXT", "]", "for", "word", "in", "self", "[", "WORDS", "]", "]" ]
The list of words representing ``words`` layer elements.
[ "The", "list", "of", "words", "representing", "words", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L557-L561
7,749
estnltk/estnltk
estnltk/text.py
Text.word_spans
def word_spans(self): """The list of spans representing ``words`` layer elements.""" if not self.is_tagged(WORDS): self.tokenize_words() return self.spans(WORDS)
python
def word_spans(self): if not self.is_tagged(WORDS): self.tokenize_words() return self.spans(WORDS)
[ "def", "word_spans", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "self", ".", "spans", "(", "WORDS", ")" ]
The list of spans representing ``words`` layer elements.
[ "The", "list", "of", "spans", "representing", "words", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L564-L568
7,750
estnltk/estnltk
estnltk/text.py
Text.word_starts
def word_starts(self): """The list of start positions representing ``words`` layer elements.""" if not self.is_tagged(WORDS): self.tokenize_words() return self.starts(WORDS)
python
def word_starts(self): if not self.is_tagged(WORDS): self.tokenize_words() return self.starts(WORDS)
[ "def", "word_starts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "self", ".", "starts", "(", "WORDS", ")" ]
The list of start positions representing ``words`` layer elements.
[ "The", "list", "of", "start", "positions", "representing", "words", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L571-L575
7,751
estnltk/estnltk
estnltk/text.py
Text.word_ends
def word_ends(self): """The list of end positions representing ``words`` layer elements.""" if not self.is_tagged(WORDS): self.tokenize_words() return self.ends(WORDS)
python
def word_ends(self): if not self.is_tagged(WORDS): self.tokenize_words() return self.ends(WORDS)
[ "def", "word_ends", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "self", ".", "ends", "(", "WORDS", ")" ]
The list of end positions representing ``words`` layer elements.
[ "The", "list", "of", "end", "positions", "representing", "words", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L578-L582
7,752
estnltk/estnltk
estnltk/text.py
Text.analysis
def analysis(self): """The list of analysis of ``words`` layer elements.""" if not self.is_tagged(ANALYSIS): self.tag_analysis() return [word[ANALYSIS] for word in self.words]
python
def analysis(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return [word[ANALYSIS] for word in self.words]
[ "def", "analysis", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "[", "word", "[", "ANALYSIS", "]", "for", "word", "in", "self", ".", "words", "]" ]
The list of analysis of ``words`` layer elements.
[ "The", "list", "of", "analysis", "of", "words", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L585-L589
7,753
estnltk/estnltk
estnltk/text.py
Text.get_analysis_element
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: "|"). As morphological analysis cannot always yield unambiguous results, we return ambiguous values separated by the pipe character as default. """ return [self.__get_key(word[ANALYSIS], element, sep) for word in self.words]
python
def get_analysis_element(self, element, sep='|'): return [self.__get_key(word[ANALYSIS], element, sep) for word in self.words]
[ "def", "get_analysis_element", "(", "self", ",", "element", ",", "sep", "=", "'|'", ")", ":", "return", "[", "self", ".", "__get_key", "(", "word", "[", "ANALYSIS", "]", ",", "element", ",", "sep", ")", "for", "word", "in", "self", ".", "words", "]" ...
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: "|"). As morphological analysis cannot always yield unambiguous results, we return ambiguous values separated by the pipe character as default.
[ "The", "list", "of", "analysis", "elements", "of", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L603-L615
7,754
estnltk/estnltk
estnltk/text.py
Text.roots
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. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ROOT)
python
def roots(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ROOT)
[ "def", "roots", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "ROOT", ")" ]
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.
[ "The", "list", "of", "word", "roots", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L618-L626
7,755
estnltk/estnltk
estnltk/text.py
Text.lemmas
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. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(LEMMA)
python
def lemmas(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(LEMMA)
[ "def", "lemmas", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "LEMMA", ")" ]
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.
[ "The", "list", "of", "lemmas", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L629-L637
7,756
estnltk/estnltk
estnltk/text.py
Text.lemma_lists
def lemma_lists(self): """Lemma lists. Ambiguous cases are separate list elements. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return [[an[LEMMA] for an in word[ANALYSIS]] for word in self[WORDS]]
python
def lemma_lists(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return [[an[LEMMA] for an in word[ANALYSIS]] for word in self[WORDS]]
[ "def", "lemma_lists", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "[", "[", "an", "[", "LEMMA", "]", "for", "an", "in", "word", "[", "ANALYSIS", "]", "]",...
Lemma lists. Ambiguous cases are separate list elements.
[ "Lemma", "lists", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L640-L647
7,757
estnltk/estnltk
estnltk/text.py
Text.endings
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. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ENDING)
python
def endings(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ENDING)
[ "def", "endings", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "ENDING", ")" ]
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.
[ "The", "list", "of", "word", "endings", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L650-L658
7,758
estnltk/estnltk
estnltk/text.py
Text.forms
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. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(FORM)
python
def forms(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(FORM)
[ "def", "forms", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "FORM", ")" ]
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.
[ "Tthe", "list", "of", "word", "forms", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L661-L669
7,759
estnltk/estnltk
estnltk/text.py
Text.postags
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. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(POSTAG)
python
def postags(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(POSTAG)
[ "def", "postags", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "POSTAG", ")" ]
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.
[ "The", "list", "of", "word", "part", "-", "of", "-", "speech", "tags", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L672-L680
7,760
estnltk/estnltk
estnltk/text.py
Text.postag_descriptions
def postag_descriptions(self): """Human-readable POS-tag descriptions.""" if not self.is_tagged(ANALYSIS): self.tag_analysis() return [POSTAG_DESCRIPTIONS.get(tag, '') for tag in self.get_analysis_element(POSTAG)]
python
def postag_descriptions(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return [POSTAG_DESCRIPTIONS.get(tag, '') for tag in self.get_analysis_element(POSTAG)]
[ "def", "postag_descriptions", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "[", "POSTAG_DESCRIPTIONS", ".", "get", "(", "tag", ",", "''", ")", "for", "tag", "i...
Human-readable POS-tag descriptions.
[ "Human", "-", "readable", "POS", "-", "tag", "descriptions", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L689-L693
7,761
estnltk/estnltk
estnltk/text.py
Text.root_tokens
def root_tokens(self): """Root tokens of word roots.""" if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ROOT_TOKENS)
python
def root_tokens(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() return self.get_analysis_element(ROOT_TOKENS)
[ "def", "root_tokens", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "return", "self", ".", "get_analysis_element", "(", "ROOT_TOKENS", ")" ]
Root tokens of word roots.
[ "Root", "tokens", "of", "word", "roots", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L696-L700
7,762
estnltk/estnltk
estnltk/text.py
Text.descriptions
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 = [] if plur_desc is not None: toks.append(plur_desc) if case_desc is not None: toks.append(case_desc) desc = ' '.join(toks) descs.append(desc) return descs
python
def descriptions(self): 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 = [] if plur_desc is not None: toks.append(plur_desc) if case_desc is not None: toks.append(case_desc) desc = ' '.join(toks) descs.append(desc) return descs
[ "def", "descriptions", "(", "self", ")", ":", "descs", "=", "[", "]", "for", "postag", ",", "form", "in", "zip", "(", "self", ".", "postags", ",", "self", ".", "forms", ")", ":", "desc", "=", "VERB_TYPES", ".", "get", "(", "form", ",", "''", ")",...
Human readable word descriptions.
[ "Human", "readable", "word", "descriptions", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L703-L720
7,763
estnltk/estnltk
estnltk/text.py
Text.tag_syntax_vislcg3
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 isinstance(self.__syntactic_parser, VISLCG3Parser): self.__syntactic_parser = VISLCG3Parser() return self.tag_syntax()
python
def tag_syntax_vislcg3(self): if not self.__syntactic_parser or not isinstance(self.__syntactic_parser, VISLCG3Parser): self.__syntactic_parser = VISLCG3Parser() return self.tag_syntax()
[ "def", "tag_syntax_vislcg3", "(", "self", ")", ":", "if", "not", "self", ".", "__syntactic_parser", "or", "not", "isinstance", "(", "self", ".", "__syntactic_parser", ",", "VISLCG3Parser", ")", ":", "self", ".", "__syntactic_parser", "=", "VISLCG3Parser", "(", ...
Changes default syntactic parser to VISLCG3Parser, performs syntactic analysis, and stores the results in the layer named LAYER_VISLCG3.
[ "Changes", "default", "syntactic", "parser", "to", "VISLCG3Parser", "performs", "syntactic", "analysis", "and", "stores", "the", "results", "in", "the", "layer", "named", "LAYER_VISLCG3", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L722-L727
7,764
estnltk/estnltk
estnltk/text.py
Text.tag_syntax_maltparser
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 not isinstance(self.__syntactic_parser, MaltParser): self.__syntactic_parser = MaltParser() return self.tag_syntax()
python
def tag_syntax_maltparser(self): if not self.__syntactic_parser or not isinstance(self.__syntactic_parser, MaltParser): self.__syntactic_parser = MaltParser() return self.tag_syntax()
[ "def", "tag_syntax_maltparser", "(", "self", ")", ":", "if", "not", "self", ".", "__syntactic_parser", "or", "not", "isinstance", "(", "self", ".", "__syntactic_parser", ",", "MaltParser", ")", ":", "self", ".", "__syntactic_parser", "=", "MaltParser", "(", ")...
Changes default syntactic parser to MaltParser, performs syntactic analysis, and stores the results in the layer named LAYER_CONLL.
[ "Changes", "default", "syntactic", "parser", "to", "MaltParser", "performs", "syntactic", "analysis", "and", "stores", "the", "results", "in", "the", "layer", "named", "LAYER_CONLL", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L729-L734
7,765
estnltk/estnltk
estnltk/text.py
Text.tag_labels
def tag_labels(self): """Tag named entity labels in the ``words`` layer.""" if not self.is_tagged(ANALYSIS): self.tag_analysis() if self.__ner_tagger is None: self.__ner_tagger = load_default_ner_tagger() self.__ner_tagger.tag_document(self) return self
python
def tag_labels(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() if self.__ner_tagger is None: self.__ner_tagger = load_default_ner_tagger() self.__ner_tagger.tag_document(self) return self
[ "def", "tag_labels", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "if", "self", ".", "__ner_tagger", "is", "None", ":", "self", ".", "__ner_tagger", "=", "load_default_ner...
Tag named entity labels in the ``words`` layer.
[ "Tag", "named", "entity", "labels", "in", "the", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L812-L819
7,766
estnltk/estnltk
estnltk/text.py
Text.labels
def labels(self): """Named entity labels.""" if not self.is_tagged(LABEL): self.tag_labels() return [word[LABEL] for word in self.words]
python
def labels(self): if not self.is_tagged(LABEL): self.tag_labels() return [word[LABEL] for word in self.words]
[ "def", "labels", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "LABEL", ")", ":", "self", ".", "tag_labels", "(", ")", "return", "[", "word", "[", "LABEL", "]", "for", "word", "in", "self", ".", "words", "]" ]
Named entity labels.
[ "Named", "entity", "labels", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L822-L826
7,767
estnltk/estnltk
estnltk/text.py
Text.tag_named_entities
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: nes.append({START: words[word_start][START], END: words[i-1][END], LABEL: label}) if l.startswith('B-'): word_start = i label = l[2:] else: word_start = -1 self[NAMED_ENTITIES] = nes return self
python
def tag_named_entities(self): 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: nes.append({START: words[word_start][START], END: words[i-1][END], LABEL: label}) if l.startswith('B-'): word_start = i label = l[2:] else: word_start = -1 self[NAMED_ENTITIES] = nes return self
[ "def", "tag_named_entities", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "LABEL", ")", ":", "self", ".", "tag_labels", "(", ")", "nes", "=", "[", "]", "word_start", "=", "-", "1", "labels", "=", "self", ".", "labels", "+", "[...
Tag ``named_entities`` layer. This automatically performs morphological analysis along with all dependencies.
[ "Tag", "named_entities", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L828-L852
7,768
estnltk/estnltk
estnltk/text.py
Text.named_entities
def named_entities(self): """The elements of ``named_entities`` layer.""" if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() phrases = self.split_by(NAMED_ENTITIES) return [' '.join(phrase.lemmas) for phrase in phrases]
python
def named_entities(self): if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() phrases = self.split_by(NAMED_ENTITIES) return [' '.join(phrase.lemmas) for phrase in phrases]
[ "def", "named_entities", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "NAMED_ENTITIES", ")", ":", "self", ".", "tag_named_entities", "(", ")", "phrases", "=", "self", ".", "split_by", "(", "NAMED_ENTITIES", ")", "return", "[", "' '", ...
The elements of ``named_entities`` layer.
[ "The", "elements", "of", "named_entities", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L855-L860
7,769
estnltk/estnltk
estnltk/text.py
Text.named_entity_texts
def named_entity_texts(self): """The texts representing named entities.""" if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return self.texts(NAMED_ENTITIES)
python
def named_entity_texts(self): if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return self.texts(NAMED_ENTITIES)
[ "def", "named_entity_texts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "NAMED_ENTITIES", ")", ":", "self", ".", "tag_named_entities", "(", ")", "return", "self", ".", "texts", "(", "NAMED_ENTITIES", ")" ]
The texts representing named entities.
[ "The", "texts", "representing", "named", "entities", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L863-L867
7,770
estnltk/estnltk
estnltk/text.py
Text.named_entity_spans
def named_entity_spans(self): """The spans of named entities.""" if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return self.spans(NAMED_ENTITIES)
python
def named_entity_spans(self): if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return self.spans(NAMED_ENTITIES)
[ "def", "named_entity_spans", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "NAMED_ENTITIES", ")", ":", "self", ".", "tag_named_entities", "(", ")", "return", "self", ".", "spans", "(", "NAMED_ENTITIES", ")" ]
The spans of named entities.
[ "The", "spans", "of", "named", "entities", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L870-L874
7,771
estnltk/estnltk
estnltk/text.py
Text.named_entity_labels
def named_entity_labels(self): """The named entity labels without BIO prefixes.""" if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return [ne[LABEL] for ne in self[NAMED_ENTITIES]]
python
def named_entity_labels(self): if not self.is_tagged(NAMED_ENTITIES): self.tag_named_entities() return [ne[LABEL] for ne in self[NAMED_ENTITIES]]
[ "def", "named_entity_labels", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "NAMED_ENTITIES", ")", ":", "self", ".", "tag_named_entities", "(", ")", "return", "[", "ne", "[", "LABEL", "]", "for", "ne", "in", "self", "[", "NAMED_ENTIT...
The named entity labels without BIO prefixes.
[ "The", "named", "entity", "labels", "without", "BIO", "prefixes", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L877-L881
7,772
estnltk/estnltk
estnltk/text.py
Text.tag_timexes
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): if self.__timex_tagger is None: self.__timex_tagger = load_default_timex_tagger() self.__timex_tagger.tag_document(self, **self.__kwargs) return self
python
def tag_timexes(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() if not self.is_tagged(TIMEXES): if self.__timex_tagger is None: self.__timex_tagger = load_default_timex_tagger() self.__timex_tagger.tag_document(self, **self.__kwargs) return self
[ "def", "tag_timexes", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "if", "not", "self", ".", "is_tagged", "(", "TIMEXES", ")", ":", "if", "self", ".", "__timex_tagger", ...
Create ``timexes`` layer. Depends on morphological analysis data in ``words`` layer and tags it automatically, if it is not present.
[ "Create", "timexes", "layer", ".", "Depends", "on", "morphological", "analysis", "data", "in", "words", "layer", "and", "tags", "it", "automatically", "if", "it", "is", "not", "present", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L883-L893
7,773
estnltk/estnltk
estnltk/text.py
Text.timex_starts
def timex_starts(self): """The list of start positions of ``timexes`` layer elements.""" if not self.is_tagged(TIMEXES): self.tag_timexes() return self.starts(TIMEXES)
python
def timex_starts(self): if not self.is_tagged(TIMEXES): self.tag_timexes() return self.starts(TIMEXES)
[ "def", "timex_starts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "TIMEXES", ")", ":", "self", ".", "tag_timexes", "(", ")", "return", "self", ".", "starts", "(", "TIMEXES", ")" ]
The list of start positions of ``timexes`` layer elements.
[ "The", "list", "of", "start", "positions", "of", "timexes", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L923-L927
7,774
estnltk/estnltk
estnltk/text.py
Text.timex_ends
def timex_ends(self): """The list of end positions of ``timexes`` layer elements.""" if not self.is_tagged(TIMEXES): self.tag_timexes() return self.ends(TIMEXES)
python
def timex_ends(self): if not self.is_tagged(TIMEXES): self.tag_timexes() return self.ends(TIMEXES)
[ "def", "timex_ends", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "TIMEXES", ")", ":", "self", ".", "tag_timexes", "(", ")", "return", "self", ".", "ends", "(", "TIMEXES", ")" ]
The list of end positions of ``timexes`` layer elements.
[ "The", "list", "of", "end", "positions", "of", "timexes", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L930-L934
7,775
estnltk/estnltk
estnltk/text.py
Text.timex_spans
def timex_spans(self): """The list of spans of ``timexes`` layer elements.""" if not self.is_tagged(TIMEXES): self.tag_timexes() return self.spans(TIMEXES)
python
def timex_spans(self): if not self.is_tagged(TIMEXES): self.tag_timexes() return self.spans(TIMEXES)
[ "def", "timex_spans", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "TIMEXES", ")", ":", "self", ".", "tag_timexes", "(", ")", "return", "self", ".", "spans", "(", "TIMEXES", ")" ]
The list of spans of ``timexes`` layer elements.
[ "The", "list", "of", "spans", "of", "timexes", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L937-L941
7,776
estnltk/estnltk
estnltk/text.py
Text.tag_clause_annotations
def tag_clause_annotations(self): """Tag clause annotations in ``words`` layer. Depends on morphological analysis. """ if not self.is_tagged(ANALYSIS): self.tag_analysis() if self.__clause_segmenter is None: self.__clause_segmenter = load_default_clausesegmenter() return self.__clause_segmenter.tag(self)
python
def tag_clause_annotations(self): if not self.is_tagged(ANALYSIS): self.tag_analysis() if self.__clause_segmenter is None: self.__clause_segmenter = load_default_clausesegmenter() return self.__clause_segmenter.tag(self)
[ "def", "tag_clause_annotations", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "ANALYSIS", ")", ":", "self", ".", "tag_analysis", "(", ")", "if", "self", ".", "__clause_segmenter", "is", "None", ":", "self", ".", "__clause_segmenter", ...
Tag clause annotations in ``words`` layer. Depends on morphological analysis.
[ "Tag", "clause", "annotations", "in", "words", "layer", ".", "Depends", "on", "morphological", "analysis", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L943-L951
7,777
estnltk/estnltk
estnltk/text.py
Text.clause_annotations
def clause_annotations(self): """The list of clause annotations in ``words`` layer.""" if not self.is_tagged(CLAUSE_ANNOTATION): self.tag_clause_annotations() return [word.get(CLAUSE_ANNOTATION, None) for word in self[WORDS]]
python
def clause_annotations(self): if not self.is_tagged(CLAUSE_ANNOTATION): self.tag_clause_annotations() return [word.get(CLAUSE_ANNOTATION, None) for word in self[WORDS]]
[ "def", "clause_annotations", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "CLAUSE_ANNOTATION", ")", ":", "self", ".", "tag_clause_annotations", "(", ")", "return", "[", "word", ".", "get", "(", "CLAUSE_ANNOTATION", ",", "None", ")", "...
The list of clause annotations in ``words`` layer.
[ "The", "list", "of", "clause", "annotations", "in", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L954-L958
7,778
estnltk/estnltk
estnltk/text.py
Text.clause_indices
def clause_indices(self): """The list of clause indices in ``words`` layer. The indices are unique only in the boundary of a single sentence. """ if not self.is_tagged(CLAUSE_ANNOTATION): self.tag_clause_annotations() return [word.get(CLAUSE_IDX, None) for word in self[WORDS]]
python
def clause_indices(self): if not self.is_tagged(CLAUSE_ANNOTATION): self.tag_clause_annotations() return [word.get(CLAUSE_IDX, None) for word in self[WORDS]]
[ "def", "clause_indices", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "CLAUSE_ANNOTATION", ")", ":", "self", ".", "tag_clause_annotations", "(", ")", "return", "[", "word", ".", "get", "(", "CLAUSE_IDX", ",", "None", ")", "for", "wo...
The list of clause indices in ``words`` layer. The indices are unique only in the boundary of a single sentence.
[ "The", "list", "of", "clause", "indices", "in", "words", "layer", ".", "The", "indices", "are", "unique", "only", "in", "the", "boundary", "of", "a", "single", "sentence", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L961-L967
7,779
estnltk/estnltk
estnltk/text.py
Text.tag_clauses
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] for word in words: if word[CLAUSE_IDX] != clause: clauses[clause].append((start, end)) start, clause = word[START], word[CLAUSE_IDX] end = word[END] clauses[clause].append((start, words[-1][END])) clauses = [(key, {START: [s for s, e in clause], END: [e for s, e in clause]}) for key, clause in clauses.items()] return [v for k, v in sorted(clauses)] clauses = [] sentences = self.divide() for sentence in sentences: clauses.extend(from_sentence(sentence)) self[CLAUSES] = clauses return self
python
def tag_clauses(self): 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] for word in words: if word[CLAUSE_IDX] != clause: clauses[clause].append((start, end)) start, clause = word[START], word[CLAUSE_IDX] end = word[END] clauses[clause].append((start, words[-1][END])) clauses = [(key, {START: [s for s, e in clause], END: [e for s, e in clause]}) for key, clause in clauses.items()] return [v for k, v in sorted(clauses)] clauses = [] sentences = self.divide() for sentence in sentences: clauses.extend(from_sentence(sentence)) self[CLAUSES] = clauses return self
[ "def", "tag_clauses", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "CLAUSE_ANNOTATION", ")", ":", "self", ".", "tag_clause_annotations", "(", ")", "def", "from_sentence", "(", "words", ")", ":", "\"\"\"Function that extracts clauses from a si...
Create ``clauses`` multilayer. Depends on clause annotations.
[ "Create", "clauses", "multilayer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L969-L997
7,780
estnltk/estnltk
estnltk/text.py
Text.tag_verb_chains
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 word_spans = [ ( sentence[idx][START], sentence[idx][END] ) \ for idx in sorted( chain[PHRASE] ) ] # 2) Assign to the chain chain[START] = [ span[0] for span in word_spans ] chain[END] = [ span[1] for span in word_spans ] verbchains.extend(chains) self[VERB_CHAINS] = verbchains return self
python
def tag_verb_chains(self): 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 word_spans = [ ( sentence[idx][START], sentence[idx][END] ) \ for idx in sorted( chain[PHRASE] ) ] # 2) Assign to the chain chain[START] = [ span[0] for span in word_spans ] chain[END] = [ span[1] for span in word_spans ] verbchains.extend(chains) self[VERB_CHAINS] = verbchains return self
[ "def", "tag_verb_chains", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "CLAUSES", ")", ":", "self", ".", "tag_clauses", "(", ")", "if", "self", ".", "__verbchain_detector", "is", "None", ":", "self", ".", "__verbchain_detector", "=", ...
Create ``verb_chains`` layer. Depends on ``clauses`` layer.
[ "Create", "verb_chains", "layer", ".", "Depends", "on", "clauses", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1016-L1037
7,781
estnltk/estnltk
estnltk/text.py
Text.verb_chain_texts
def verb_chain_texts(self): """The list of texts of ``verb_chains`` layer elements.""" if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.texts(VERB_CHAINS)
python
def verb_chain_texts(self): if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.texts(VERB_CHAINS)
[ "def", "verb_chain_texts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "VERB_CHAINS", ")", ":", "self", ".", "tag_verb_chains", "(", ")", "return", "self", ".", "texts", "(", "VERB_CHAINS", ")" ]
The list of texts of ``verb_chains`` layer elements.
[ "The", "list", "of", "texts", "of", "verb_chains", "layer", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1047-L1051
7,782
estnltk/estnltk
estnltk/text.py
Text.verb_chain_starts
def verb_chain_starts(self): """The start positions of ``verb_chains`` elements.""" if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.starts(VERB_CHAINS)
python
def verb_chain_starts(self): if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.starts(VERB_CHAINS)
[ "def", "verb_chain_starts", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "VERB_CHAINS", ")", ":", "self", ".", "tag_verb_chains", "(", ")", "return", "self", ".", "starts", "(", "VERB_CHAINS", ")" ]
The start positions of ``verb_chains`` elements.
[ "The", "start", "positions", "of", "verb_chains", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1094-L1098
7,783
estnltk/estnltk
estnltk/text.py
Text.verb_chain_ends
def verb_chain_ends(self): """The end positions of ``verb_chains`` elements.""" if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.ends(VERB_CHAINS)
python
def verb_chain_ends(self): if not self.is_tagged(VERB_CHAINS): self.tag_verb_chains() return self.ends(VERB_CHAINS)
[ "def", "verb_chain_ends", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "VERB_CHAINS", ")", ":", "self", ".", "tag_verb_chains", "(", ")", "return", "self", ".", "ends", "(", "VERB_CHAINS", ")" ]
The end positions of ``verb_chains`` elements.
[ "The", "end", "positions", "of", "verb_chains", "elements", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1101-L1105
7,784
estnltk/estnltk
estnltk/text.py
Text.tag_wordnet
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 wordnet_tagger = WordnetTagger() self.__wordnet_tagger = wordnet_tagger if len(kwargs) > 0: return self.__wordnet_tagger.tag_text(self, **kwargs) return self.__wordnet_tagger.tag_text(self, **self.__kwargs)
python
def tag_wordnet(self, **kwargs): global wordnet_tagger if wordnet_tagger is None: # cached wn tagger wordnet_tagger = WordnetTagger() self.__wordnet_tagger = wordnet_tagger if len(kwargs) > 0: return self.__wordnet_tagger.tag_text(self, **kwargs) return self.__wordnet_tagger.tag_text(self, **self.__kwargs)
[ "def", "tag_wordnet", "(", "self", ",", "*", "*", "kwargs", ")", ":", "global", "wordnet_tagger", "if", "wordnet_tagger", "is", "None", ":", "# cached wn tagger", "wordnet_tagger", "=", "WordnetTagger", "(", ")", "self", ".", "__wordnet_tagger", "=", "wordnet_ta...
Create wordnet attribute in ``words`` layer. See :py:meth:`~estnltk.text.wordnet_tagger.WordnetTagger.tag_text` method for applicable keyword arguments.
[ "Create", "wordnet", "attribute", "in", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1112-L1124
7,785
estnltk/estnltk
estnltk/text.py
Text.wordnet_annotations
def wordnet_annotations(self): """The list of wordnet annotations of ``words`` layer.""" if not self.is_tagged(WORDNET): self.tag_wordnet() return [[a[WORDNET] for a in analysis] for analysis in self.analysis]
python
def wordnet_annotations(self): if not self.is_tagged(WORDNET): self.tag_wordnet() return [[a[WORDNET] for a in analysis] for analysis in self.analysis]
[ "def", "wordnet_annotations", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDNET", ")", ":", "self", ".", "tag_wordnet", "(", ")", "return", "[", "[", "a", "[", "WORDNET", "]", "for", "a", "in", "analysis", "]", "for", "analy...
The list of wordnet annotations of ``words`` layer.
[ "The", "list", "of", "wordnet", "annotations", "of", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1127-L1131
7,786
estnltk/estnltk
estnltk/text.py
Text.synsets
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: for synset in wn_annot.get(SYNSETS, []): word_synsets.append(deepcopy(synset)) synsets.append(word_synsets) return synsets
python
def synsets(self): synsets = [] for wn_annots in self.wordnet_annotations: word_synsets = [] for wn_annot in wn_annots: for synset in wn_annot.get(SYNSETS, []): word_synsets.append(deepcopy(synset)) synsets.append(word_synsets) return synsets
[ "def", "synsets", "(", "self", ")", ":", "synsets", "=", "[", "]", "for", "wn_annots", "in", "self", ".", "wordnet_annotations", ":", "word_synsets", "=", "[", "]", "for", "wn_annot", "in", "wn_annots", ":", "for", "synset", "in", "wn_annot", ".", "get",...
The list of annotated synsets of ``words`` layer.
[ "The", "list", "of", "annotated", "synsets", "of", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1134-L1143
7,787
estnltk/estnltk
estnltk/text.py
Text.word_literals
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): if LITERAL in variant: word_literals.add(variant[LITERAL]) literals.append(list(sorted(word_literals))) return literals
python
def word_literals(self): literals = [] for word_synsets in self.synsets: word_literals = set() for synset in word_synsets: for variant in synset.get(SYN_VARIANTS): if LITERAL in variant: word_literals.add(variant[LITERAL]) literals.append(list(sorted(word_literals))) return literals
[ "def", "word_literals", "(", "self", ")", ":", "literals", "=", "[", "]", "for", "word_synsets", "in", "self", ".", "synsets", ":", "word_literals", "=", "set", "(", ")", "for", "synset", "in", "word_synsets", ":", "for", "variant", "in", "synset", ".", ...
The list of literals per word in ``words`` layer.
[ "The", "list", "of", "literals", "per", "word", "in", "words", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1146-L1156
7,788
estnltk/estnltk
estnltk/text.py
Text.spelling
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): self.tokenize_words() return [data[SPELLING] for data in vabamorf.spellcheck(self.word_texts, suggestions=False)]
python
def spelling(self): if not self.is_tagged(WORDS): self.tokenize_words() return [data[SPELLING] for data in vabamorf.spellcheck(self.word_texts, suggestions=False)]
[ "def", "spelling", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "[", "data", "[", "SPELLING", "]", "for", "data", "in", "vabamorf", ".", "spellcheck", "(", "s...
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.
[ "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", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1163-L1170
7,789
estnltk/estnltk
estnltk/text.py
Text.spelling_suggestions
def spelling_suggestions(self): """The list of spelling suggestions per misspelled word.""" if not self.is_tagged(WORDS): self.tokenize_words() return [data[SUGGESTIONS] for data in vabamorf.spellcheck(self.word_texts, suggestions=True)]
python
def spelling_suggestions(self): if not self.is_tagged(WORDS): self.tokenize_words() return [data[SUGGESTIONS] for data in vabamorf.spellcheck(self.word_texts, suggestions=True)]
[ "def", "spelling_suggestions", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "return", "[", "data", "[", "SUGGESTIONS", "]", "for", "data", "in", "vabamorf", ".", "spellchec...
The list of spelling suggestions per misspelled word.
[ "The", "list", "of", "spelling", "suggestions", "per", "misspelled", "word", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1173-L1177
7,790
estnltk/estnltk
estnltk/text.py
Text.fix_spelling
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 len(fixed) == len(spans) if len(spans) > 0: newtoks = [] lastend = 0 for fix, (start, end) in zip(fixed, spans): newtoks.append(text[lastend:start]) newtoks.append(fix) lastend = end newtoks.append(text[lastend:]) return Text(''.join(newtoks), **self.__kwargs) return self
python
def fix_spelling(self): 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 len(fixed) == len(spans) if len(spans) > 0: newtoks = [] lastend = 0 for fix, (start, end) in zip(fixed, spans): newtoks.append(text[lastend:start]) newtoks.append(fix) lastend = end newtoks.append(text[lastend:]) return Text(''.join(newtoks), **self.__kwargs) return self
[ "def", "fix_spelling", "(", "self", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "WORDS", ")", ":", "self", ".", "tokenize_words", "(", ")", "text", "=", "self", ".", "text", "fixed", "=", "vabamorf", ".", "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.
[ "Fix", "spelling", "of", "the", "text", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1186-L1213
7,791
estnltk/estnltk
estnltk/text.py
Text.clean
def clean(self): """Return a copy of this Text instance with invalid characters removed.""" return Text(self.__text_cleaner.clean(self[TEXT]), **self.__kwargs)
python
def clean(self): return Text(self.__text_cleaner.clean(self[TEXT]), **self.__kwargs)
[ "def", "clean", "(", "self", ")", ":", "return", "Text", "(", "self", ".", "__text_cleaner", ".", "clean", "(", "self", "[", "TEXT", "]", ")", ",", "*", "*", "self", ".", "__kwargs", ")" ]
Return a copy of this Text instance with invalid characters removed.
[ "Return", "a", "copy", "of", "this", "Text", "instance", "with", "invalid", "characters", "removed", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1230-L1232
7,792
estnltk/estnltk
estnltk/text.py
Text.split_given_spans
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 One instance of text per span. """ N = len(spans) results = [{TEXT: text} for text in self.texts_from_spans(spans, sep=sep)] for elem in self: if isinstance(self[elem], list): splits = divide_by_spans(self[elem], spans, translate=True, sep=sep) for idx in range(N): results[idx][elem] = splits[idx] return [Text(res) for res in results]
python
def split_given_spans(self, spans, sep=' '): N = len(spans) results = [{TEXT: text} for text in self.texts_from_spans(spans, sep=sep)] for elem in self: if isinstance(self[elem], list): splits = divide_by_spans(self[elem], spans, translate=True, sep=sep) for idx in range(N): results[idx][elem] = splits[idx] return [Text(res) for res in results]
[ "def", "split_given_spans", "(", "self", ",", "spans", ",", "sep", "=", "' '", ")", ":", "N", "=", "len", "(", "spans", ")", "results", "=", "[", "{", "TEXT", ":", "text", "}", "for", "text", "in", "self", ".", "texts_from_spans", "(", "spans", ","...
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 One instance of text per span.
[ "Split", "the", "text", "into", "several", "pieces", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1262-L1294
7,793
estnltk/estnltk
estnltk/text.py
Text.split_by
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 ---------- layer: str String determining the layer that is used to define the start and end positions of resulting splits. sep: str (default: ' ') The separator to use to join texts of multilayer elements. Returns ------- list of Text """ if not self.is_tagged(layer): self.tag(layer) return self.split_given_spans(self.spans(layer), sep=sep)
python
def split_by(self, layer, sep=' '): if not self.is_tagged(layer): self.tag(layer) return self.split_given_spans(self.spans(layer), sep=sep)
[ "def", "split_by", "(", "self", ",", "layer", ",", "sep", "=", "' '", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "layer", ")", ":", "self", ".", "tag", "(", "layer", ")", "return", "self", ".", "split_given_spans", "(", "self", ".", "spa...
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 ---------- layer: str String determining the layer that is used to define the start and end positions of resulting splits. sep: str (default: ' ') The separator to use to join texts of multilayer elements. Returns ------- list of Text
[ "Split", "the", "text", "into", "multiple", "instances", "defined", "by", "elements", "of", "given", "layer", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1296-L1315
7,794
estnltk/estnltk
estnltk/text.py
Text.split_by_regex
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 spans = [] if gaps: # tag cap spans for mo in regex.finditer(text): start, end = mo.start(), mo.end() if start > last_end: spans.append((last_end, start)) last_end = end if last_end < len(text): spans.append((last_end, len(text))) else: # use matched regions spans = [(mo.start(), mo.end()) for mo in regex.finditer(text)] return self.split_given_spans(spans)
python
def split_by_regex(self, regex_or_pattern, flags=re.U, gaps=True): 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 spans = [] if gaps: # tag cap spans for mo in regex.finditer(text): start, end = mo.start(), mo.end() if start > last_end: spans.append((last_end, start)) last_end = end if last_end < len(text): spans.append((last_end, len(text))) else: # use matched regions spans = [(mo.start(), mo.end()) for mo in regex.finditer(text)] return self.split_given_spans(spans)
[ "def", "split_by_regex", "(", "self", ",", "regex_or_pattern", ",", "flags", "=", "re", ".", "U", ",", "gaps", "=", "True", ")", ":", "text", "=", "self", "[", "TEXT", "]", "regex", "=", "regex_or_pattern", "if", "isinstance", "(", "regex", ",", "six",...
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.
[ "Split", "the", "text", "into", "multiple", "instances", "using", "a", "regex", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1325-L1362
7,795
estnltk/estnltk
estnltk/text.py
Text.divide
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 ------- list of (list of dict) """ if not self.is_tagged(layer): self.tag(layer) if not self.is_tagged(by): self.tag(by) return divide(self[layer], self[by])
python
def divide(self, layer=WORDS, by=SENTENCES): if not self.is_tagged(layer): self.tag(layer) if not self.is_tagged(by): self.tag(by) return divide(self[layer], self[by])
[ "def", "divide", "(", "self", ",", "layer", "=", "WORDS", ",", "by", "=", "SENTENCES", ")", ":", "if", "not", "self", ".", "is_tagged", "(", "layer", ")", ":", "self", ".", "tag", "(", "layer", ")", "if", "not", "self", ".", "is_tagged", "(", "by...
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 ------- list of (list of dict)
[ "Divide", "the", "Text", "into", "pieces", "by", "keeping", "references", "to", "original", "elements", "when", "possible", ".", "This", "is", "not", "possible", "only", "if", "the", "_element_", "is", "a", "multispan", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/text.py#L1368-L1388
7,796
estnltk/estnltk
estnltk/grammar/conflictresolver.py
resolve_using_maximal_coverage
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]) if l >= bestscore: bestscore = l bestprev = prev[j] j = j - 1 scores[i] = bestscore prev[i] = bestprev # first find the matching with highest combined score bestscore = max(scores) bestidx = len(scores) - scores[-1::-1].index(bestscore) -1 # then backtrack the non-conflicting matchings that should be kept keepidxs = [bestidx] bestidx = prev[bestidx] while bestidx != -1: keepidxs.append(bestidx) bestidx = prev[bestidx] # filter the matches return [matches[idx] for idx in reversed(keepidxs)]
python
def resolve_using_maximal_coverage(matches): 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]) if l >= bestscore: bestscore = l bestprev = prev[j] j = j - 1 scores[i] = bestscore prev[i] = bestprev # first find the matching with highest combined score bestscore = max(scores) bestidx = len(scores) - scores[-1::-1].index(bestscore) -1 # then backtrack the non-conflicting matchings that should be kept keepidxs = [bestidx] bestidx = prev[bestidx] while bestidx != -1: keepidxs.append(bestidx) bestidx = prev[bestidx] # filter the matches return [matches[idx] for idx in reversed(keepidxs)]
[ "def", "resolve_using_maximal_coverage", "(", "matches", ")", ":", "if", "len", "(", "matches", ")", "==", "0", ":", "return", "matches", "matches", ".", "sort", "(", ")", "N", "=", "len", "(", "matches", ")", "scores", "=", "[", "len", "(", "match", ...
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
[ "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", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/grammar/conflictresolver.py#L6-L55
7,797
estnltk/estnltk
estnltk/mw_verbs/basic_verbchain_detection.py
_isFollowedByComma
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: if re.match('^.*,$', token[TEXT]): return True elif i+1 < len(clauseTokens) and koma.matches(clauseTokens[i+1]): return True break return False
python
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: if re.match('^.*,$', token[TEXT]): return True elif i+1 < len(clauseTokens) and koma.matches(clauseTokens[i+1]): return True break return False
[ "def", "_isFollowedByComma", "(", "wordID", ",", "clauseTokens", ")", ":", "koma", "=", "WordTemplate", "(", "{", "ROOT", ":", "'^,+$'", ",", "POSTAG", ":", "'Z'", "}", ")", "for", "i", "in", "range", "(", "len", "(", "clauseTokens", ")", ")", ":", "...
Teeb kindlaks, kas etteantud ID-ga s6nale j2rgneb vahetult koma; Tagastab True, kui eeltoodud tingimus on t2idetud, vastasel juhul False;
[ "Teeb", "kindlaks", "kas", "etteantud", "ID", "-", "ga", "s6nale", "j2rgneb", "vahetult", "koma", ";", "Tagastab", "True", "kui", "eeltoodud", "tingimus", "on", "t2idetud", "vastasel", "juhul", "False", ";" ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/mw_verbs/basic_verbchain_detection.py#L92-L106
7,798
estnltk/estnltk
estnltk/grammar/common.py
is_valid_regex
def is_valid_regex(regex): """Function for checking a valid regex.""" if len(regex) == 0: return False try: re.compile(regex) return True except sre_constants.error: return False
python
def is_valid_regex(regex): if len(regex) == 0: return False try: re.compile(regex) return True except sre_constants.error: return False
[ "def", "is_valid_regex", "(", "regex", ")", ":", "if", "len", "(", "regex", ")", "==", "0", ":", "return", "False", "try", ":", "re", ".", "compile", "(", "regex", ")", "return", "True", "except", "sre_constants", ".", "error", ":", "return", "False" ]
Function for checking a valid regex.
[ "Function", "for", "checking", "a", "valid", "regex", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/grammar/common.py#L29-L37
7,799
estnltk/estnltk
estnltk/single_layer_operations/layer_positions.py
iterate_intersecting_pairs
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 for i1, elem1 in enumerate(ri): for i2, elem2 in enumerate(ri): if i1 != i2 and elem1['start'] <= elem2['start'] < elem1['end']: inds = (i1, i2) if i1 < i2 else (i2, i1) if inds not in yielded and in_by_identity(layer, elem1) and in_by_identity(layer, elem2): yielded.add(inds) yield elem1, elem2
python
def iterate_intersecting_pairs(layer): yielded = set() ri = layer[:] # Shallow copy the layer for i1, elem1 in enumerate(ri): for i2, elem2 in enumerate(ri): if i1 != i2 and elem1['start'] <= elem2['start'] < elem1['end']: inds = (i1, i2) if i1 < i2 else (i2, i1) if inds not in yielded and in_by_identity(layer, elem1) and in_by_identity(layer, elem2): yielded.add(inds) yield elem1, elem2
[ "def", "iterate_intersecting_pairs", "(", "layer", ")", ":", "yielded", "=", "set", "(", ")", "ri", "=", "layer", "[", ":", "]", "# Shallow copy the layer", "for", "i1", ",", "elem1", "in", "enumerate", "(", "ri", ")", ":", "for", "i2", ",", "elem2", "...
Given a layer of estntltk objects, yields pairwise intersecting elements. Breaks when the layer is changed or deleted after initializing the iterator.
[ "Given", "a", "layer", "of", "estntltk", "objects", "yields", "pairwise", "intersecting", "elements", ".", "Breaks", "when", "the", "layer", "is", "changed", "or", "deleted", "after", "initializing", "the", "iterator", "." ]
28ae334a68a0673072febc318635f04da0dcc54a
https://github.com/estnltk/estnltk/blob/28ae334a68a0673072febc318635f04da0dcc54a/estnltk/single_layer_operations/layer_positions.py#L153-L166