def run(corpus_file_object=None, keep_case=False, max_word_tokens=0): def max_common_prefix(a, b):
def max_common_suffix(a, b):
def make_stems_to_signatures(sigs_to_stems):
def check_affix(word, affix, suffixing):
def make_words_to_sigtransforms(words_to_sigs, suffixing):
def make_words_to_signatures(stems_to_words, stems_to_sigs):
def make_signatures_to_words(words_to_signatures):
def make_signatures_to_stems(stems_to_words, max_affix_length, min_sig_count,
                             suffixing):
def make_stems_to_words(wordlist, min_stem_length, max_affix_length, suffixing,
                        min_sig_count):
def make_bisignatures(wordlist, min_stem_length, max_affix_length, suffixing):
def make_affixes_to_signatures(signatures): def get_array(wordlist, bigram_to_freq, trigram_to_freq,
              min_context_count):
    def contexts_increment():
    def add_word(current_word, current_context, occurrence_count):
def normalize(n_words, shared_context_matrix):
def compute_incidence_graph(n_words, diameter, shared_context_matrix):
def compute_laplacian(diameter, incidence_graph):
def compute_eigenvectors(laplacian):
def compute_words_distance(coordinates):
def compute_closest_neighbors(word_distances, n_neighbors):
def compute_graph(words_to_neighbors):
def run(unigram_counter=None, bigram_counter=None, trigram_counter=None,
        max_word_types=1000, n_neighbors=9, n_eigenvectors=11,
        min_context_count=3):
    class Namespace: def plog(x):
    def __init__(self, spelling, count, freq):
    def __init__(self, phone1, phone2, count, freq):
    def __init__(self, spelling, phones, count, freq, phone_dict,
                 biphone_dict):
def make_word_ngrams(word_unigram_counter, words_to_phones=None):
def make_phone_dict(phone_unigram_counter=None):
def make_biphone_dict(phone_bigram_counter, phone_dict):
def make_word_dict(word_unigram_counter, phone_dict, biphone_dict,
                   words_to_phones=None):
class Phone:
class Biphone:
class Word: def find_breaks(wordlist, min_stem_length):
def break_words(wordlist, break_dict):
def get_successors(wordlist, broken_words):
def common_prefix_length(s1, s2):
def reverse_direction(str_to_sequences_of_strings, is_list=False):
def run(wordlist=None, min_stem_length=4): ENCODING = 'utf8' PARAMETERS = {'max_word_tokens': 0,  # zero means all word tokens
              'min_stem_length': 4,
              'max_affix_length': 4,
              'min_sig_count': 5,
              # 'min_affix_length': 1,
              # 'min_sf_pf_count': 3,
              'n_neighbors': 9,
              'n_eigenvectors': 11,
              'min_context_count': 3,
              'max_word_types': 1000,
              'suffixing': 1,  # 1 means yes, 0 means no
              'keep_case': 0,  # 1 means yes, 0 means no
              } SEP_SIG = '/'           # separator between affixes in a sig (NULL/s/ed/ing) SEP_SIGTRANSFORM = '.'  # separator between sig and affix (NULL-s-ed-ing.ed) def double_sorted(input_object, key=lambda x: x, reverse=False,
                  subkey=lambda x: x, subreverse=False):
    new_sorted_list = list()
    sorted_list = sorted(input_object, key=key, reverse=reverse)

    for _, group in groupby(sorted_list, key=key):  # groupby from itertools

        # must use "list(group)", cannot use just "group"!
        sublist = sorted(list(group), key=subkey, reverse=subreverse)
        # see python 3.4 documentation:
        # https://docs.python.org/3/library/itertools.html#itertools.groupby
        # "The returned group is itself an iterator that shares the underlying
        # iterable with groupby(). Because the source is shared, when the
        # groupby() object is advanced, the previous group is no longer
        # visible. So, if that data is needed later, it should be stored as a
        # list"

        new_sorted_list.extend(sublist)

    return new_sorted_list def fix_punctuations(line):
    import re
    line = line.replace('.', ' . ')
    line = line.replace(',', ' , ')
    line = line.replace(';', ' ; ')
    line = line.replace('!', ' ! ')
    line = line.replace('?', ' ? ')
    line = line.replace(':', ' : ')
    line = line.replace(')', ' ) ')
    line = line.replace('(', ' ( ')
    return re.sub('\s', ' ', line) def output_latex(iter_obj, file_path, title, headers,
                 row_functions, column_widths, index=True,
                 lxa_parameters=None, test=False, encoding=ENCODING,
                 number_of_word_types=0, number_of_word_tokens=0,
                 input_file_path=''):
    """
    Output LaTeX table code for *iter_obj* to *file*.

    :param iter_obj: an iterable object
    :param file_path: file path
    :param title: table title str
    :param headers: list of headers
    :param row_functions: list of row cell rendering functions.
        Each function takes only one argument and returns a str.
    :param column_widths: list of column widths.
    :param index: whether the table has an index column; defaults to True.
    :param lxa_parameters: the parameter dict
    :param test: whether nosetests are being run; defaults to False.
        If True, *file_path* is overridden by `os.devnull`` so that no
        text files are produced.
    """
    if not iter_obj:
        return

    if test:
        file_path = os.devnull

    file = open(file_path, 'w', encoding=encoding)

    if not (len(headers) == len(row_functions) == len(column_widths)):
        raise ValueError('headers, row_format, and column_widths '
                         'not of the same size')

    print('Time:', strftime('%Y-%m-%d %H:%M:%S'), file=file)
    print('Path of this file:', file_path, file=file)
    print(file=file)

    print('System info:\n'
          '=============================================', file=file)

    uname = platform.uname()
    print('System:', uname.system, file=file)
    print('Node:', uname.node, file=file)
    print('Release:', uname.release, file=file)
    print('Version:', uname.version, file=file)
    print('Machine:', uname.machine, file=file)
    print('Processor:', uname.processor, file=file)
    print('Python version:', platform.python_version(), file=file)
    print(file=file)

    print('Packages:\n'
          '=============================================', file=file)

    print('Linguistica', lxa_version, file=file)
    print('SciPy', scipy_version, file=file)
    print('NumPy', numpy_version, file=file)
    print('NetworkX', networkx_version, file=file)
    print(file=file)

    print('Linguistica parameters:\n'
          '=============================================', file=file)
    print(pformat(lxa_parameters), file=file)
    print(file=file)

    print('Input file information:\n'
          '=============================================', file=file)
    print('Path:', input_file_path, file=file)
    print('Number of word types:', number_of_word_types, file=file)
    print('Number of word tokens:', number_of_word_tokens, file=file)
    print(file=file)

    print('Results:\n=============================================', file=file)

    header_list = list()

    index_str_length = 10
    if index:
        header_list = ['Index'.ljust(index_str_length)]

    for header, col_width in zip(headers, column_widths):
        header_list.append(header.ljust(col_width))

    number_of_columns = len(header_list)

    print(title + '\n', file=file)
    print('\\begin{{tabular}}{{{}}}'.format('l' * number_of_columns),
          file=file)
    print('\\toprule', file=file)

    print('{} \\\\'.format(' & '.join(header_list)), file=file)
    print('\\midrule', file=file)

    for i, row_obj in enumerate(iter_obj, 1):
        if index:
            row_list = [str(i).ljust(index_str_length)]
        else:
            row_list = list()

        for row_func, col_width in zip(row_functions, column_widths):
            row_list.append(str(row_func(row_obj)).ljust(col_width))

            print('{} \\\\'.format(' & '.join(row_list)), file=file)

    print('\\bottomrule', file=file)
    print('\\end{tabular}\n', file=file)

    file.close() def vprint(verbose=False, *objects, **kwargs):
    """
    Verbose print; defaults to False.
    """
    if verbose:
        print(*objects, **kwargs)
    else:
        return
import six
import sys
import os
from io import StringIO
from io import open  # not using built-in open(), for py2+3 cross compatibility
from linguistica import (ngram, signature, manifold, phon, trie)
from linguistica.util import (ENCODING, PARAMETERS, SEP_SIG, SEP_SIGTRANSFORM,
                              double_sorted, fix_punctuations,
                              output_latex, vprint)
# -*- encoding: utf8 -*-




try:
    FileNotFoundError
except NameError:
    FileNotFoundError = OSError  # no FileNotFoundError in Python 2


class Lexicon:
    """
    A class for a Linguistica object.
    """

    def __init__(self, file_path=None, wordlist_file=False, corpus_object=None,
                 wordlist_object=None, encoding=ENCODING, **kwargs):
        self.file_abspath = self._check_file_path(file_path)

        if self.file_abspath is None:
            self.directory = None
        else:
            self.directory = os.path.dirname(self.file_abspath)

        self.file_is_wordlist = wordlist_file
        self.encoding = encoding
        self.corpus_object = corpus_object
        self.wordlist_object = wordlist_object
        self.parameters_ = self._determine_parameters(**kwargs)

        self._initialize()

    @staticmethod
    def _check_file_path(file_path):
        """
        Return the absolute path of *file_path*.
        """
        if file_path is None:
            return None

        if type(file_path) != str:
            raise TypeError('file path must be a str -- ' + file_path)

        if sys.platform.startswith('win'):
            file_path = file_path.replace('/', os.sep)
        else:
            file_path = file_path.replace('\\', os.sep)

        file_abspath = os.path.abspath(file_path)
        if not os.path.isfile(file_abspath):
            raise FileNotFoundError
        else:
            return file_abspath

    @staticmethod
    def _determine_parameters(**kwargs):
        """
        Determine the parameter dict.
        """

        temp_parameters = dict(PARAMETERS)