Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
163 lines (123 sloc) 4.7 KB
from collections import namedtuple
from zope.interface import implementer
from sqlalchemy import (
from sqlalchemy.orm import relationship, backref
from pyramid.decorator import reify
from clld import interfaces
from clld.db.meta import Base, CustomModelMixin
from clld.db.models.common import (
Parameter, Language, Contribution, Source, Contributor, IdNameDescriptionMixin,
from clld.web.util.htmllib import literal
from apics.interfaces import IWals, ISurvey
# Survey
# - relationship(Lect) if None -> Intro!
# - volume
# - authors -> relationship SurveyAuthor. Intro has None?
# - sortkey -> sort by (volume, number) with intro getting number 0?
class Wals(object):
replacement_id = None
def __init__(self, parameter=None):
self.parameter = parameter
def name(self):
class Phoible(object):
def __init__(self, d): = d['id']
self.segment = d['segment']
def url(self):
return '' +
class WithContributorsMixin(object):
def primary_contributors(self):
return [assoc.contributor for assoc in
key=lambda a: (a.ord,]
def secondary_contributors(self):
return []
def formatted_contributors(self):
return ' and '.join( for c in self.primary_contributors)
class Feature(CustomModelMixin, Parameter, WithContributorsMixin):
pk = Column(Integer, ForeignKey(''), primary_key=True)
feature_type = Column(String)
multivalued = Column(Boolean, default=False)
wals_id = Column(Integer)
wals_representation = Column(Integer)
representation = Column(Integer)
area = Column(Unicode)
def authors(self):
return [a for a in self.primary_contributors]
def format_authors(self):
apics = 'APiCS Consortium'
if self.authors:
return ', '.join( for a in self.authors) + ' and the ' + apics
return 'The ' + apics
def phoible(self):
phoible = self.jsondata.get('phoible')
if phoible:
return Phoible(phoible)
def __unicode__(self):
return literal(super(Feature, self).__unicode__())
def __rdf__(self, request):
if self.phoible:
yield 'owl:sameAs', self.phoible.url
class FeatureAuthor(Base):
feature_pk = Column(Integer, ForeignKey(''))
feature = relationship(Feature, backref='contributor_assocs')
contributor_pk = Column(Integer, ForeignKey(''))
ord = Column(Integer, default=1)
contributor = relationship(Contributor, lazy=False, backref='feature_assocs')
class Survey(Base, IdNameDescriptionMixin, WithContributorsMixin):
def citation_name(self):
return '%s survey' %
class Lect(CustomModelMixin, Language):
pk = Column(Integer, ForeignKey(''), primary_key=True)
region = Column(Unicode)
lexifier = Column(Unicode)
language_pk = Column(Integer, ForeignKey(''))
lects = relationship(
'Lect', foreign_keys=[language_pk], backref=backref('language', remote_side=[pk]))
survey_pk = Column(Integer, ForeignKey(''))
survey = relationship(Survey, backref=backref('languages'))
GlossedText = namedtuple('GlossedText', 'pdf audio')
class ApicsContribution(CustomModelMixin, Contribution):
pk = Column(Integer, ForeignKey(''), primary_key=True)
language_pk = Column(Integer, ForeignKey(''))
language = relationship(Lect, backref=backref('contribution', uselist=False))
survey_reference_pk = Column(Integer, ForeignKey(''))
survey_reference = relationship(Source)
def citation_name(self):
return '%s structure dataset' %
def glossed_text(self):
return GlossedText(
self.files.get('%s-gt.pdf' %,
self.files.get('%s-gt.mp3' %
#missing: 21,51->50, move 51-3.png to 50-4.png
class SurveyContributor(Base):
survey_pk = Column(Integer, ForeignKey(''))
contributor_pk = Column(Integer, ForeignKey(''))
ord = Column(Integer, default=1)
primary = Column(Boolean, default=True)
survey = relationship(Survey, backref='contributor_assocs')
contributor = relationship(Contributor, lazy=False, backref='survey_assocs')