Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update(args):
count = 0
assert args.json
iid = int(DBSession.execute(
"select max(cast(id as integer)) from identifier").fetchone()[0]) + 1
pk = DBSession.execute(
"select max(pk) from identifier").fetchone()[0] + 1
langs = {}
for gid, name in args.json['wikipedia'].items():
if gid not in langs:
langs[gid] = Languoid.get(gid)
langs[gid].update_jsondata(wikipedia=name.split('/')[-1])
for gid, codes in args.json['multitree'].items():
l = langs[gid]
lcodes = [i.name for i in l.identifiers if i.type == 'multitree']
for code in set(codes):
if code not in lcodes:
identifier = DBSession.query(common.Identifier)\
.filter(common.Identifier.type == 'multitree')\
def update(args):
author = 'ISO 639-3 Registration Authority'
pid = 'iso6393'
dtid = 'overview'
dt = Doctype.get(dtid)
provider = Provider.get(pid, default=None)
if provider is None:
provider = Provider(
id=pid,
abbr=pid,
name=author,
description="Change requests submitted to the ISO 639-3 registration authority.")
iid = max(int(DBSession.execute(
"select max(cast(id as integer)) from source").fetchone()[0]), 500000)
pk = int(DBSession.execute("select max(pk) from source").fetchone()[0])
for crno, affected in args.json['changerequests'].items():
year, serial = crno.split('-')
title = 'Change Request Number %s' % crno
ref = Ref.get(title, key='title', default=None)
if not ref:
iid += 1
pk += 1
ref = Ref(
pk=pk,
id=str(iid),
name='%s %s' % (author, year),
bibtex_type=EntryType.misc,
number=crno,
def update(args):
count = 0
assert args.json
iid = int(DBSession.execute(
"select max(cast(id as integer)) from identifier").fetchone()[0]) + 1
pk = DBSession.execute(
"select max(pk) from identifier").fetchone()[0] + 1
langs = {}
for gid, name in args.json['wikipedia'].items():
if gid not in langs:
langs[gid] = Languoid.get(gid)
langs[gid].update_jsondata(wikipedia=name.split('/')[-1])
for gid, codes in args.json['multitree'].items():
l = langs[gid]
lcodes = [i.name for i in l.identifiers if i.type == 'multitree']
for code in set(codes):
if code not in lcodes:
name=getattr(args.repos.med_types, med[3]).name,
domainelement=med_domain[idjoin('med', med[3])],
valueset=vs,
))
DBSession.flush()
DBSession.add(common.ValueSetReference(source_pk=med[0], valueset_pk=vs.pk))
recreate_treeclosure()
macroareas = {r[0]: (r[1], r[2]) for r in DBSession.execute("""\
select de.pk, de.id, de.name
from domainelement as de, parameter as p
where de.parameter_pk = p.pk and p.id = 'macroarea'
""")}
for lid, lpk, cpk, ppk, mas in DBSession.execute("""\
select
l.id, l.pk, vs.contribution_pk, vs.parameter_pk, array_agg(distinct v.domainelement_pk)
from
language as l,
treeclosuretable as t,
parameter as p,
valueset as vs,
value as v
where
l.pk = t.parent_pk and
t.child_pk = vs.language_pk and
vs.parameter_pk = p.pk and
p.id = 'macroarea' and
v.valueset_pk = vs.pk and
l.pk not in (
select language_pk
def ldstatus(ppk):
sql = """\
select
l.id, v.domainelement_pk, vs.source, l.jsondata::json->>'meds'
from
language as l, languoid as ll, valueset as vs, value as v, parameter as p
where
l.jsondata::json->>'meds' is not null and l.pk = vs.language_pk and vs.parameter_pk = p.pk
and v.valueset_pk = vs.pk and vs.parameter_pk = {0}
and ll.pk = l.pk and ll.category in ('Spoken L1 Language', 'Sign Language')
""".format(ppk)
res = {}
for lid, aespk, aes_source, meds in DBSession.execute(sql):
meds = json.loads(meds)
res[lid] = (aespk, meds[0] if meds else None, meds, aes_source)
return res
a, r = update_relationship(
ref.doctypes,
[doctype_map[m.group('name')] for m in
DOCTYPE_PATTERN.finditer(kw['jsondata'].get('hhtype', ''))])
changed = changed or a or r
if not update:
stats.update(['new'])
DBSession.add(ref)
elif changed:
stats.update(['updated'])
args.log.info('%s' % stats)
DBSession.execute("update source set description = title where description is null and title is not null;")
DBSession.execute("update source set description = booktitle where description is null and booktitle is not null;")
for row in list(DBSession.execute(
"select pk, pages, pages_int, startpage_int from source where pages_int < 0")):
pk, pages, number, start = row
_start, _end, _number = compute_pages(pages)
if _number > 0 and _number != number:
DBSession.execute(
"update source set pages_int = %s, startpage_int = %s where pk = %s" %
(_number, _start, pk))
DBSession.execute(
"update ref set endpage_int = %s where pk = %s" %
(_end, pk))
jsondump(changes, args.data_dir.joinpath('references', 'changes.json'))
def main(args):
stats = Counter(new=0, matches=0, migrations=0, nomatches=0)
# The new classification in clld/glottolog:
repos = Glottolog(repos=args.data_dir)
langs_repos = {l.id: l for l in repos.languoids()}
codes_repos = set(langs_repos.keys())
assert langs_repos
l, ll = Language.__table__.alias('l'), Languoid.__table__.alias('ll')
langs_db = {r['l_id']: r for r in DBSession.execute(
select([l, ll], use_labels=True).where(l.c.pk == ll.c.pk)).fetchall()}
langs_db_pk2id = {v['l_pk']: k for k, v in langs_db.items()}
codes_db = set(langs_db.keys())
def ancestors(db_lang):
while db_lang['ll_father_pk'] in langs_db_pk2id:
yield langs_db_pk2id[db_lang['ll_father_pk']]
db_lang = langs_db[langs_db_pk2id[db_lang['ll_father_pk']]]
for code in codes_repos.difference(codes_db):
stats.update(['new'])
print('+++ {0} - {1}'.format(code, langs_repos[code].level))
for code in codes_db.difference(codes_repos):
if langs_db[code]['l_active']:
# In-active languoids will not be touched anyway, obsolete families will be
def load(args):
glottolog = args.repos
fts.index('fts_index', models.Ref.fts, DBSession.bind)
DBSession.execute("CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;")
version = assert_release(glottolog.repos)
dataset = common.Dataset(
id='glottolog',
name="{0} {1}".format(glottolog.publication.web.name, version),
publisher_name=glottolog.publication.publisher.name,
publisher_place=glottolog.publication.publisher.place,
publisher_url=glottolog.publication.publisher.url,
license=glottolog.publication.license.url,
domain=purl.URL(glottolog.publication.web.url).domain(),
contact=glottolog.publication.web.contact,
jsondata={'license_icon': 'cc-by.png', 'license_name': glottolog.publication.license.name},
)
data = Data()
for e in glottolog.editors.values():
if e.current: