Example #1
0
class Thing(Owl, Model):
    classification = ArrayProperty(Ncal, 'categories')  # todo fix with popolo
    meta = Relation(Meta, 'meta')
    canonical_iri = StringProperty(Meta, 'canonical_iri')
    canonical_id = StringProperty(Meta, 'canonical_id')
    # has_organization_name is used to set the municipality or province ID on every item (see issue #141)
    has_organization_name = Relation(Vcard, 'hasOrganizationName')
Example #2
0
class ContactDetail(Opengov, owl.Thing):
    type = StringProperty(Rdf, 'type')
    value = StringProperty(Rdf, 'value')
    label = StringProperty(Rdfs, 'label')
    valid_from = DateTimeProperty(Schema, 'validFrom')
    note = StringProperty(Skos, 'note')
    valid_until = DateTimeProperty(Opengov, 'validUntil')
Example #3
0
class Vote(Opengov, owl.Thing):
    group = Relation(Opengov, 'politicalGroup')
    role = StringProperty(Opengov, 'role')
    voter = Relation(Schema, 'agent')
    vote_event = Relation(Opengov, 'voteEvent')
    option = StringProperty(Opengov, 'voteOption')
    weight = IntegerProperty(Opengov, 'weight')
Example #4
0
class Membership(Org, owl.Thing):
    label = StringProperty(Skos, 'prefLabel')
    member = Relation(Org, 'member')
    organization = Relation(Org, 'organization')
    role = StringProperty(Org, 'role')
    start_date = DateTimeProperty(Schema, 'validFrom')
    end_date = DateTimeProperty(Opengov, 'validUntil')
Example #5
0
class CreativeWork(Schema, owl.Thing):
    legislative_session = Relation(Opengov, 'legislativeSession')
    creator = Relation(Schema, 'creator')
    date_created = DateTimeProperty(Schema, 'dateCreated')
    name = StringProperty(Schema, 'name')
    organizer = Relation(Schema, 'organizer')
    text = StringProperty(Schema, 'text')
Example #6
0
class Metadata(Meta, owl.Thing):
    # todo needs to be formalized in a ontology
    status = StringProperty(Meta, 'status')
    processing_started = DateTimeProperty(Meta, 'processingStarted')
    source_id = StringProperty(Meta, 'sourceId')
    collection = StringProperty(Meta, 'collection')
    rights = StringProperty(Meta, 'rights')

    skip_validation = True
Example #7
0
class VoteEvent(Opengov, schema.Event):
    classification = ArrayProperty(Ncal, 'categories')
    created_at = DateTimeProperty(Dcterms, 'created')
    updated_at = DateTimeProperty(Dcterms, 'modified')
    motion = Relation(Opengov, 'motion')
    result = StringProperty(Opengov, 'result')
    organization = Relation(Schema, 'organizer')
    legislative_session = StringProperty(Opengov, 'legislativeSession')
    votes = Relation(Opengov, 'vote')
    counts = Relation(Opengov, 'count')
Example #8
0
class ImageObject(Schema, owl.Thing):
    content_url = URLProperty(Schema, 'contentUrl')
    is_based_on = URLProperty(Schema, 'isBasedOn')
    file_format = StringProperty(Schema, 'fileFormat')
    content_size = StringProperty(Schema, 'contentSize')
    encoding_format = StringProperty(Schema, 'encodingFormat')
    exif_data = ArrayProperty(Schema, 'exifData')
    width = StringProperty(Schema, 'width')
    height = StringProperty(Schema, 'height')

    enricher_task = 'image_metadata'
Example #9
0
class Motion(Opengov, owl.Thing):
    attachment = Relation(Schema, 'attachment')
    legislative_session = StringProperty(Opengov, 'legislativeSession')
    requirement = StringProperty(Opengov, 'requirement')
    classification = StringProperty(Schema, 'additionalType')
    creator = Relation(Schema, 'creator')
    cocreator = Relation(Meeting, 'cocreator')
    date = DateTimeProperty(Schema, 'dateSubmitted')
    name = StringProperty(Schema, 'name')
    organization = Relation(Schema, 'publisher')
    text = StringProperty(Schema, 'text')
    vote_events = Relation(Opengov, 'voteEvent')
Example #10
0
class Speech(Opengov, owl.Thing):
    attribution_text = StringProperty(Opengov, 'attributionText')
    audience = Relation(Dcterms, 'audience')
    event = Relation(Bibframe, 'event')
    role = Relation(Opengov, 'role')
    audio = Relation(Schema, 'audio')
    creator = Relation(Schema, 'creator')
    end_date = DateTimeProperty(Schema, 'endDate')
    position = IntegerProperty(Schema, 'position')
    start_date = DateTimeProperty(Schema, 'startDate')
    text = StringProperty(Schema, 'text')
    video = StringProperty(Schema, 'video')
Example #11
0
class AgendaItem(MeetingNS, schema.Event):
    """An item in a list of topics to be discussed at an event. Subclass of
    :class:`.schema.Event`
    """
    attachment = Relation(MeetingNS, 'attachment')
    motion = Relation(Opengov, 'motion')
    description = StringProperty(Schema, 'description')
    name = StringProperty(Schema, 'name')
    position = IntegerProperty(Schema, 'position')
    parent = Relation(Schema, 'superEvent')
    vote_event = Relation(Opengov, 'voteEvent')
    attendee = Relation(Schema, 'attendee')
    absentee = Relation(Schema, 'absentee')
    agenda = Relation(MeetingNS, 'agenda')
Example #12
0
class Organization(Org, foaf.Agent):
    area = Relation(Opengov, 'area')
    contact_details = Relation(Opengov, 'contactDetail')
    abstract = StringProperty(Dcterms, 'abstract')
    description = StringProperty(Dcterms, 'description')
    classification = StringProperty(Org, 'classification')
    parent = OrderedRelation(Org, 'subOrganizationOf')
    other_names = StringProperty(Opengov, 'otherName')
    links = StringProperty(Rdf, 'seeAlso')
    dissolution_date = StringProperty(Schema, 'dissolutionDate')
    founding_date = StringProperty(Schema, 'foundingDate')
    image = StringProperty(Schema, 'image')
    alt_label = StringProperty(Skos, 'altLabel')
    name = StringProperty(Skos, 'prefLabel')
Example #13
0
class MediaObject(Schema, owl.Thing):
    name = StringProperty(Schema, 'name')
    url = URLProperty(Schema, 'contentUrl')
    size_in_bytes = IntegerProperty(Schema, 'fileSize')
    file_type = StringProperty(Schema, 'fileType')
    additional_type = StringProperty(Schema, 'additionalType')
    creator = Relation(Schema, 'creator')
    content_type = StringProperty(Schema, 'encodingFormat')
    upload_date = DateProperty(Schema, 'uploadDate')
    caption = StringProperty(Schema, 'caption')
    embed_url = StringProperty(Schema, 'embedUrl')
    file_name = StringProperty(Dbo, 'filename')
    date_modified = DateTimeProperty(Schema, 'dateModified')
    original_url = URLProperty(Schema, 'isBasedOn')
    text = ArrayProperty(Schema, 'text')
    enriched_text = ArrayProperty(MeetingNS, 'enrichedText')
    text_pages = JsonProperty(MeetingNS,
                              'textPages',
                              ignore_for_loader=[DeltaLoader])
    is_referenced_by = Relation(Dcterms, 'isReferencedBy')
    last_discussed_at = DateTimeProperty(MeetingNS,
                                         'lastDiscussedAt',
                                         ignore_for_loader=[DeltaLoader])
    tags = JsonProperty(MeetingNS, 'tags')
    neighborhood_polygons = JsonProperty(MeetingNS, 'neighborhood_polygons')
    geometry = JsonProperty(MeetingNS, 'geometry')
    districts = ArrayProperty(Cbs, 'Wijk')
    neighborhoods = ArrayProperty(Cbs, 'Buurt')

    enricher_task = ['theme_classifier', 'waaroverheid']
Example #14
0
class Meeting(MeetingNS, schema.Event):
    """An assembly of people for a particular purpose, especially for formal
    discussion. Subclass of :class:`.schema.Event`
    """
    agenda = Relation(MeetingNS, 'agenda')
    attachment = Relation(MeetingNS, 'attachment')
    motion = Relation(Opengov, 'motion')
    attendee = Relation(Schema, 'attendee')
    audio = Relation(Schema, 'audio')
    description = StringProperty(Schema, 'description')
    status = Relation(Schema, 'eventStatus')
    location = StringProperty(Schema, 'location')
    name = StringProperty(Schema, 'name', required=True)
    organization = Relation(Schema, 'organizer')
    committee = Relation(MeetingNS, 'committee')
    parent = Relation(Schema, 'superEvent')
    chair = StringProperty(MeetingNS, 'chair')
    absentee = Relation(Schema, 'absentee')
    invitee = Relation(Schema, 'invitee')
Example #15
0
class AgendaItem(MeetingNS, schema.Event):
    """An item in a list of topics to be discussed at an event. Subclass of
    :class:`.schema.Event`
    """
    attachment = Relation(MeetingNS, 'attachment')
    motion = Relation(Opengov, 'motion')
    description = StringProperty(Schema, 'description')
    name = StringProperty(Schema, 'name', required=True)
    position = IntegerProperty(Schema, 'position')
    parent = Relation(Schema, 'superEvent', required=True)
    vote_event = Relation(Opengov, 'voteEvent')
    attendee = Relation(Schema, 'attendee')
    absentee = Relation(Schema, 'absentee')
    agenda = Relation(MeetingNS, 'agenda')
    last_discussed_at = DateTimeProperty(MeetingNS,
                                         'lastDiscussedAt',
                                         ignore_for_loader=[
                                             DeltaLoader,
                                         ])
Example #16
0
class Activity(Prov, owl.Thing):
    started_at_time = DateTimeProperty(Prov, 'startedAtTime')
    ended_at_time = DateTimeProperty(Prov, 'endedAtTime')
    used = StringProperty(Prov, 'used')
    generated = StringProperty(Prov, 'generated')
    had_primary_source = StringProperty(Prov, 'hadPrimarySource')
    same_as = StringProperty(Owl, 'sameAs')
    app_semver = StringProperty(Meeting, 'semver')
    original_identifier = StringProperty(Meeting, 'originalIdentifier')
    reference_identifier = StringProperty(Meeting, 'referenceIdentifier')
Example #17
0
class MediaObject(Schema, owl.Thing):
    name = StringProperty(Schema, 'name')
    url = StringProperty(Schema, 'contentUrl')
    size_in_bytes = IntegerProperty(Schema, 'fileSize')
    file_type = StringProperty(Schema, 'fileType')
    additional_type = StringProperty(Schema, 'additionalType')
    creator = Relation(Schema, 'creator')
    content_type = StringProperty(Schema, 'fileFormat')
    original_url = StringProperty(Schema, 'isBasedOn')
    text = StringProperty(Schema, 'text')

    enricher_task = 'file_to_text'
Example #18
0
class Motion(Opengov, owl.Thing):
    attachment = Relation(Schema, 'attachment')
    legislative_session = StringProperty(Opengov, 'legislativeSession')
    requirement = StringProperty(Opengov, 'requirement')
    classification = StringProperty(Schema, 'additionalType')
    status = StringProperty(Meeting, 'status')
    creator = Relation(Schema, 'creator')
    cocreator = Relation(Meeting, 'cocreator')
    date = DateProperty(Schema, 'dateSubmitted')
    name = StringProperty(Schema, 'name')
    organization = Relation(Schema, 'publisher')
    is_referenced_by = Relation(Dcterms, 'isReferencedBy')
    text = StringProperty(Schema, 'text')
    result = StringProperty(Opengov, 'result')
    vote_event = Relation(Opengov, 'voteEvent')
Example #19
0
class MediaObject(Schema, owl.Thing):
    name = StringProperty(Schema, 'name')
    url = URLProperty(Schema, 'contentUrl')
    size_in_bytes = IntegerProperty(Schema, 'fileSize')
    file_type = StringProperty(Schema, 'fileType')
    additional_type = StringProperty(Schema, 'additionalType')
    creator = Relation(Schema, 'creator')
    content_type = StringProperty(Schema, 'encodingFormat')
    upload_date = DateProperty(Schema, 'uploadDate')
    caption = StringProperty(Schema, 'caption')
    embed_url = StringProperty(Schema, 'embedUrl')
    file_name = StringProperty(Dbo, 'filename')
    date_modified = DateTimeProperty(Schema, 'dateModified')
    original_url = URLProperty(Schema, 'isBasedOn')
    text = ArrayProperty(Schema, 'text')
    isReferencedBy = Relation(Dcterms, 'isReferencedBy')

    enricher_task = 'file_to_text'
Example #20
0
class Model(object):
    __metaclass__ = ModelMetaclass

    # Top-level definitions
    ori_identifier = StringProperty(Mapping, 'ori/identifier')
    had_primary_source = StringProperty(Prov, 'hadPrimarySource')

    def absolute_uri(self):
        return '%s%s' % (self.uri, self.verbose_name())

    def compact_uri(self):
        return '%s:%s' % (self.prefix, self.verbose_name())

    def verbose_name(self):
        # if hasattr(cls, 'verbose_name'):
        #     return cls.verbose_name
        return type(self).__name__

    @classmethod
    def definitions(cls, props=True, rels=True):
        """ Return properties and relations objects from model definitions """
        props_list = list()
        for name, definition in cls._definitions.items():  # pylint: disable=no-member
            if (props and isinstance(definition, Property)
                    or (rels and isinstance(definition, Relation))):
                props_list.append((
                    name,
                    definition,
                ))
        return props_list

    @classmethod
    def definition(cls, name):
        try:
            return cls._definitions[name]  # pylint: disable=no-member
        except KeyError:
            return

    @classmethod
    def inflate(cls, **deflated_props):
        instance = cls()
        for absolute_uri, value in deflated_props.items():
            definitions_mapping = {
                v.absolute_uri(): k
                for k, v in cls.definitions()
            }
            try:
                prop_name = definitions_mapping[absolute_uri]
                setattr(instance, prop_name, value)
            except KeyError:
                raise  # todo raise correct exception

        return instance

    def __init__(self,
                 source_id=None,
                 organization=None,
                 source=None,
                 source_id_key=None):
        # Set defaults
        #self.uri = None
        #self.prefix = None
        self.skip_validation = None
        # self.verbose_name = None
        self.values = dict()

        # https://argu.co/voc/mapping/<organization>/<source>/<source_id_key>/<source_id>
        # i.e. https://argu.co/voc/mapping/nl/ggm/vrsnummer/6655476
        if source_id:
            assert organization
            assert source
            assert source_id_key
            self.had_primary_source = Uri(
                Mapping, '{}/{}/{}/{}'.format(organization, source,
                                              source_id_key, source_id))
            self._source = source
        else:
            # Individuals also need a primary source or some queries will fail
            # As a solution the definition will be set as the primary source
            self.had_primary_source = self.absolute_uri()

    def __getattr__(self, item):
        try:
            return self.__dict__['values'][item]
        except KeyError:
            try:
                return self.__dict__[item]
            except KeyError:
                raise AttributeError(item)

    def __setattr__(self, key, value):
        definition = self.definition(key)

        # if key[0:1] != '_' and not definition:
        #     raise AttributeError("'%s' is not defined in %s" % (key, self.compact_uri()))

        if definition:
            value = definition.sanitize(value)
            self.values[key] = value
            return

        super(Model, self).__setattr__(key, value)

    def __contains__(self, item):
        try:
            if self.__getattribute__(item) is not None:
                return True
        except AttributeError:
            pass
        return False

    def __repr__(self):
        return '<%s Model>' % self.compact_uri()

    def get_ori_identifier(self):
        if not self.values.get('ori_identifier'):
            try:
                self.ori_identifier = self.db.get_identifier_by_source_id(
                    self,
                    self.had_primary_source,
                )
            except AttributeError:
                raise
            except MissingProperty:
                raise MissingProperty('OriIdentifier is not present, has the '
                                      'model been saved?')
        return self.ori_identifier

    def generate_ori_identifier(self):
        self.ori_identifier = Uri(
            Ori, celery_app.backend.increment("ori_identifier_autoincrement"))
        return self.ori_identifier

    def properties(self, props=True, rels=True):
        """ Returns namespaced properties with their inflated values """
        props_list = list()
        for name, prop in iterate(
            {k: v
             for k, v in self.values.items() if k[0:1] != '_'}):
            definition = self.definition(name)
            if not definition:
                continue
            if (props and not isinstance(prop, Model)) or \
                    (rels and (isinstance(prop, Model) or isinstance(prop, Relationship))):
                props_list.append((
                    self.serializer.uri_format(definition),
                    prop,
                ))  # pylint: disable=no-member
        return props_list

    def save(self):
        self.db.replace(self)  # pylint: disable=no-member

        # Recursive save
        for _, value in self.properties(rels=True, props=False):
            if isinstance(value, Model):
                value.save()

        self.attach_recursive()

        # Todo needs to be executed only once
        self.db.copy_relations()  # pylint: disable=no-member

    def attach_recursive(self):
        attach = list()
        for rel_type, other_object in self.properties(rels=True, props=False):
            attach.append(self.db.attach(self, other_object, rel_type))  # pylint: disable=no-member

            # End the recursive loop when self-referencing
            if self != other_object:
                attach.extend(other_object.attach_recursive())

        return attach
Example #21
0
class Identifier(Thing):
    identifier = StringProperty(Dcterms, 'identifier')
    represent = StringProperty(Meeting, 'represent')
Example #22
0
class Person(PersonNS, foaf.Agent):
    biography = StringProperty(Bio, 'biography')
    contact_details = Relation(Opengov, 'contactDetail')
    alternative_name = StringProperty(Dcterms, 'alternative')
    family_name = StringProperty(Foaf, 'familyName')
    gender = StringProperty(Foaf, 'gender')
    given_name = StringProperty(Foaf, 'givenName')
    name = StringProperty(Foaf, 'name')
    national_identity = StringProperty(Opengov, 'nationalIdentity')
    summary = StringProperty(Bio, 'olb')
    other_names = StringProperty(Opengov, 'otherName')
    links = StringProperty(Rdfs, 'seeAlso')
    birth_date = DateTimeProperty(Schema, 'birthDate')
    death_date = DateTimeProperty(Schema, 'deathDate')
    email = StringProperty(Schema, 'email')
    image = Relation(Schema, 'image')
Example #23
0
class Result(Opengov, owl.Thing):
    text = StringProperty(Schema, 'text')
    vote_event = Relation(Opengov, 'voteEvent')
Example #24
0
class AudioObject(Schema, owl.Thing):
    contentUrl = StringProperty(Schema, 'contentUrl')
Example #25
0
class Person(PersonNS, foaf.Agent):
    biography = StringProperty(Bio, 'biography')
    contact_details = Relation(Opengov, 'contactDetail')
    alternative_name = StringProperty(Dcterms, 'alternative')
    family_name = StringProperty(Foaf, 'familyName')
    gender = StringProperty(Foaf, 'gender')
    given_name = StringProperty(Foaf, 'givenName')
    additional_name = StringProperty(Schema, 'additionalName')
    home_location = StringProperty(Schema, 'homeLocation')
    honorific_prefix = StringProperty(Schema, 'honorificPrefix')
    honorific_suffix = StringProperty(Schema, 'honorificSuffix')
    nickname = StringProperty(Vcard, 'nickname')
    initials = StringProperty(Meeting, 'initials')
    name = StringProperty(Foaf, 'name')
    national_identity = StringProperty(Opengov, 'nationalIdentity')
    summary = StringProperty(Bio, 'olb')
    other_names = StringProperty(Opengov, 'otherName')
    links = URLProperty(Rdfs, 'seeAlso')
    birth_place = StringProperty(Schema, 'birthPlace')
    birth_date = DateTimeProperty(Schema, 'birthDate')
    death_date = DateTimeProperty(Schema, 'deathDate')
    email = StringProperty(Schema, 'email')
    image = Relation(Schema, 'image')
    phone = StringProperty(Schema, 'telephone')
Example #26
0
class Run(Meta, owl.Thing):
    run_identifier = StringProperty(Meeting, 'runIdentifier')

    skip_validation = True
Example #27
0
class PropertyValue(Schema, owl.Thing):
    name = StringProperty(Schema, 'name')
    value = StringProperty(Schema, 'value')
Example #28
0
class Report(MeetingNS, schema.Event, schema.CreativeWork):
    description = StringProperty(Schema, 'description')
    result = StringProperty(Opengov, 'result')
    attachment = Relation(MeetingNS, 'attachment')
Example #29
0
class VideoObject(Schema, owl.Thing):
    content_url = StringProperty(Schema, 'contentUrl')