Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_conf(conf=''):
# load the configuration file
if not conf:
conf = util.data_path('conf', 'qlc.rc')
# read the file defined by its path in conf
tmp = [line.split('\t') for line in util.read_config_file(conf)]
aliasD, classD, class_stringD, alias2D = {}, {}, {}, {}
for name, cls, alias in tmp:
# make sure the name itself is there
aliasD[name.lower()] = aliasD[name.upper()] = name
classD[name.lower()] = classD[name.upper()] = eval(cls)
class_stringD[name.lower()] = class_stringD[name.upper()] = cls
# add the aliases
for a in alias.split(','):
aliasD[a.lower()] = aliasD[a.upper()] = name
classD[a.lower()] = classD[a.upper()] = eval(cls)
class_stringD[a.lower()] = class_stringD[a.upper()] = cls
def __init__(self, filename, row='head', col='translation', conf=None):
# initialize the qlc_parser
QLCParser.__init__(
self, filename, conf or util.data_path('conf', 'dictionary.rc'))
# build a doculect->iso map for @doculect meta data
self.doculect2iso = {}
# do we have more than one doculect in the header?
if type(self._meta["doculect"]) is list:
for doculect in self._meta["doculect"]:
doculect_entry = re.split(", ?", doculect)
self.doculect2iso[doculect_entry[0]] = doculect_entry[1]
else:
doculect_entry = self._meta["doculect"]
self.doculect2iso[doculect_entry[0]] = doculect_entry[1]
# save ISO for heads and translations in list
self.head_iso = []
if type(self._meta["head_iso"]) is list:
for iso in self._meta["head_iso"]:
def __init__(self, infile=None, col='list', row='key', conf=None):
QLCParserWithRowsAndCols.__init__(
self,
infile or util.data_path('swadesh', 'swadesh.qlc'),
row,
col,
conf or util.data_path('conf', 'swadesh.rc'))
# get row and key index
if not hasattr(self, '_rowidx'):
# add indices to alias dictionary for swadesh lists
for i, col in enumerate(self.cols):
self._meta[col] = self._array[np.nonzero(self._array[:, i]), i][0]
zip(
self.alms.concepts,
[str(x) for x in range(1, len(self.alms.concepts) + 1)]))
id2gloss = dict([[b, a] for a, b in gloss2id])
gloss2id = dict(gloss2id)
txt = ''
txt += 'CORRS = ' + json.dumps(corrs) + ';\n'
txt += 'LANGS = ' + json.dumps(self.alms.taxa) + ';\n'
txt += 'OCCS = ' + json.dumps(occs) + ';\n'
txt += 'WLS = ' + json.dumps(wl) + ';\n'
txt += 'GlossId = ' + json.dumps(gloss2id) + ';\n'
txt += 'IdGloss = ' + json.dumps(id2gloss) + ';\n'
txt += 'FILE = "' + kw['outfile'] + '.tsv";\n'
tpath = partial(util.data_path, 'templates')
tname = 'jcov.{0}.html'.format(
'remote' if 'remote' in kw['export'] else 'direct')
content = util.read_text_file(tpath(tname))
util.write_text_file(
kw['outfile'] + '.html',
content.format(
CORRS=txt,
JCOV=util.read_text_file(tpath('jcov.js')),
STYLE=util.read_text_file(tpath('jcov.css')),
VENDOR=util.read_text_file(tpath('jcov.vendor.js')),
DIGHL=util.read_text_file(tpath('jcov.dighl.js'))))
variables, one simply has to change the text files :file:`diacritics`,
:file:`tones`, and
:file:`vowels` in the :file:`data/models/dv` directory. The structure of
these files is fairly simple: Each line contains a vowel or a diacritic
character, whereas diacritics are preceded by a dash.
See also
--------
lingpy.data.model.Model
lingpy.data.derive.compile_model
"""
log.info("Compiling diacritics and vowels...")
# get the path to the models
if not path:
file_path = util.data_path('models', 'dvt')
elif path in ['evolaemp', 'el']:
file_path = util.data_path('models', 'dvt_el')
else:
file_path = path
def _read_string(name):
# normalize stuff
# TODO: this is potentially dangerous and it is important to decide whether
# TODO: switching to NFD might not be a better choice
return util.read_text_file(
os.path.join(file_path, name), normalize='NFC').replace('\n', '')
diacritics = _read_string('diacritics').replace('-', '')
vowels = ''.join([v for v in _read_string('vowels') if v not in diacritics])
tones = _read_string('tones')
def __init__(self, infile=None, col='list', row='key', conf=None):
QLCParserWithRowsAndCols.__init__(
self,
infile or util.data_path('swadesh', 'swadesh.qlc'),
row,
col,
conf or util.data_path('conf', 'swadesh.rc'))
# get row and key index
if not hasattr(self, '_rowidx'):
# add indices to alias dictionary for swadesh lists
for i, col in enumerate(self.cols):
self._meta[col] = self._array[np.nonzero(self._array[:, i]), i][0]
def __init__(self, filename, row='concept', col='doculect', conf=None):
QLCParserWithRowsAndCols.__init__(
self, filename, row, col, conf or util.data_path('conf', 'wordlist.rc'))
# setup other local temporary storage
self._etym_dict = {}
# check for taxa in meta
if 'taxa' in self._alias:
if self._alias['taxa'] not in self._meta:
self._meta[self._alias['taxa']] = self.cols
new_path = lambda *cmps: \
os.path.join(path or util.data_path('models'), model, *cmps)
self.name = model
hsv = [(x * 1.0 / number, 0.5, 0.5) for x in range(number)]
# convert hsv to rgb
rgb = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv))
# convert rgb to html
for i in range(number):
rgb[i] = tuple([int(rgb[i][k] * brightness) for k in range(3)])
html = []
for i in range(number):
html.append("#%02x%02x%02x" % rgb[i])
return html
template_path = partial(util.data_path, 'templates')
def alm2html(
infile,
title='',
shorttitle='',
filename='',
colored=False,
main_template='',
table_template='',
dataset='',
confidence=False,
**keywords
):
"""
Convert files in ``alm``-format into colored ``html``-format.