How to use the lingpy.util function in lingpy

To help you get started, we’ve selected a few lingpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lingpy / lingpy / lingpy / sequence / tokenizer.py View on Github external
def _init_rules(self, f):
        # Process the orthography rules file.
        for line in util.read_config_file(f, normalize='NFD'):
            rule, replacement = line.split("\t")
            rule = rule.strip()  # just in case there's trailing whitespace
            replacement = replacement.strip()  # because there's probably trailing whitespace!
            self.op_rules.append(re.compile(rule))
            self.op_replacements.append(replacement)

        # check that num rules == num replacements; if not fail
        if len(self.op_rules) != len(self.op_replacements):
            raise ValueError("Number of inputs does not match number of outputs in the rules file.")
github lingpy / lingpy / lingpy / align / sca.py View on Github external
combiners=rcParams['combiners'],
            breaks=rcParams['breaks'],
            stress=rcParams["stress"],
            merge_vowels=rcParams['merge_vowels'],
        )
        # add comment-char
        self.comment = keywords['comment']

        self.infile, suffix = os.path.splitext(os.path.basename(infile))

        # import the data from the input file
        data = []
        if not suffix and os.path.exists(infile + '.psq'):
            infile = infile + '.psq'

        for line in util.read_text_file(infile, lines=True):
            if not line.startswith(self.comment):
                data.append(line)

        # set the first parameters
        # delete the first line of the data, since they are no longer needed
        self.dataset = data.pop(0)

        # append the other lines of the data, they consist of triplets,
        # separated by double line breaks
        self.taxa = []
        self.pairs = []
        self.seq_ids = []

        # check the ending of the infile
        if suffix == '.psa':
            self.alignments = []
github lingpy / lingpy / lingpy / meaning / basvoc.py View on Github external
def __init__(self):
        wlpath = partial(util.data_path, 'conceptlists')

        D = {}

        concepticon = csv2list(wlpath('concepticon.tsv'))
        header = [c.lower() for c in concepticon[0]][1:]
        D['base'] = {}
        D['base'][0] = header
        for line in concepticon[1:]:
            D['base'][line[0]] = line[1:]

        # create an artificial id for those entries which don't have one yet
        artid = -1

        for l in [lst for lst in glob(wlpath('*.tsv')) if 'concepticon' not in lst]:
            curlist = csv2list(l)