Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.filter(Languoid.category.in_(CATEGORIES))
if req:
macroarea = req.params.get('macroarea')
if macroarea:
query = query.filter(Languoid.macroareas.contains(macroarea))
families = [f for f in req.params.get('family', '').split(',') if f]
if families:
family = aliased(Languoid)
query = query.join(family, Languoid.family_pk == family.pk)\
.filter(family.id.in_(families))
countries = []
for c in req.params.getall('country'):
countries.extend(c.split())
if countries:
query = query\
.join(common.ValueSet)\
.join(common.Parameter)\
.join(common.Value)\
.join(common.DomainElement)\
.filter(common.Parameter.id == 'country')\
.filter(common.DomainElement.name.in_(countries))
return query
lastyear = year
meds[lpk] = relevant
med_param = common.Parameter.get('med')
med_domain = {de.id: de for de in med_param.domain}
contrib = common.Contribution.get('glottolog')
for l in DBSession.query(common.Language).filter(common.Language.pk.in_(list(meds.keys()))):
l.update_jsondata(meds=[
(sid, med_type, year, pages, sname) for spk, sid, sname, med_type, year, pages in meds[l.pk]])
if not meds[l.pk]:
continue
med = meds[l.pk][0]
# Record the overall MED as value for the 'med' Parameter:
vs = common.ValueSet(
id=idjoin('med', l.id),
contribution=contrib,
parameter=med_param,
language=l,
)
DBSession.add(common.Value(
id=idjoin('med', l.id),
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()
args.log.error('invalid redirect loop: %s' % (cfg.value,))
new = cfg.value
if new != cfg.value:
args.log.info('fixed redirect: %s %s' % (cfg.value, new))
cfg.value = new
def repl(m):
try:
new = redirect_map.get_final(m.group('id'))
except ValueError:
new = m.group('id')
return '**%s**' % new
vs_rid = select([
ValueSet.pk,
func.unnest(func.regexp_matches(
ValueSet.description, '\*\*(\d+)\*\*', 'g')).label('ref_id')]).alias()
for vs in DBSession.query(ValueSet) \
.filter(ValueSet.pk.in_(
DBSession.query(vs_rid.c.pk)
.filter(
~DBSession.query(Ref)
.filter_by(id=vs_rid.c.ref_id).exists()))) \
.order_by(ValueSet.id):
new = ref_in_markup_pattern.sub(repl, vs.description)
if new != vs.description:
args.log.info(
'fixed obsolete ref id in markup: %s %s' % (vs.description, new))
vs.description = new
def feature_iterator(self, ctx, req):
q = self.get_query(ctx, req)
return groupby(q.order_by(ValueSet.language_pk), lambda vs: vs.language)
def refined_query(self, query, model, req):
if model == Language:
query = query.options(
joinedload(models.Languoid.family),
joinedload(models.Languoid.children),
joinedload(Language.valuesets)
.joinedload(ValueSet.references)
.joinedload(ValueSetReference.source),
joinedload(Language.valuesets).joinedload(ValueSet.values),
joinedload(Language.valuesets).joinedload(ValueSet.parameter),
)
return query
return q.options(joinedload(Sentence.language))
if model == DomainElement:
return q.order_by(None).order_by(model.parameter_pk, model.number, model.pk)
if model == Value:
return q.join(ValueSet)\
.order_by(None)\
.order_by(
ValueSet.parameter_pk,
ValueSet.language_pk,
ValueSet.contribution_pk,
Value.pk)\
.options(
joinedload(
Value.valueset
).joinedload(
ValueSet.references
),
joinedload(Value.domainelement))
return q
def base_query(self, query):
query = query.join(ValueSet).options(
joinedload(
Value.valueset
).joinedload(
ValueSet.references
).joinedload(
ValueSetReference.source
)
)
if self.language:
query = query.join(ValueSet.parameter)
return query.filter(ValueSet.language_pk == self.language.pk)
if self.parameter:
query = query.join(ValueSet.language)
query = query.outerjoin(DomainElement).options(
def add_values(data, dblang, pid, values, with_de=True, **vskw):
vs = None
for i, (vid, vname) in enumerate(values):
if i == 0:
vs = common.ValueSet(
id=idjoin(pid, dblang.id),
language=dblang,
parameter=data['Parameter'][pid],
contribution=data['Contribution']['glottolog'],
**vskw)
vkw = dict(id=idjoin(pid, slug(vid), dblang.id), name=vname, valueset=vs)
if with_de:
vkw['domainelement'] = data['DomainElement'][pid, vid]
DBSession.add(common.Value(**vkw))
return super(Resource, cls).__new__(cls, name, model, interface, with_index, with_rdfdump)
@property
def plural(self):
return self.name + 's'
RESOURCES = [
Resource('dataset', common.Dataset, interfaces.IDataset, with_index=False),
Resource('contribution', common.Contribution, interfaces.IContribution),
Resource('parameter', common.Parameter, interfaces.IParameter),
Resource('language', common.Language, interfaces.ILanguage),
Resource('contributor', common.Contributor, interfaces.IContributor),
Resource('source', common.Source, interfaces.ISource),
Resource('sentence', common.Sentence, interfaces.ISentence),
Resource('valueset', common.ValueSet, interfaces.IValueSet),
Resource('value', common.Value, interfaces.IValue),
Resource('unitparameter', common.UnitParameter, interfaces.IUnitParameter),
Resource('unit', common.Unit, interfaces.IUnit),
Resource('unitvalue', common.UnitValue, interfaces.IUnitValue),
Resource(
'combination',
common.Combination,
interfaces.ICombination,
with_index=False,
with_rdfdump=False),
]