class SCHEMAOrganization(RDFClass): type = RDFField(predicate=RDF.type, object=ns.SCHEMA.Organization) title_pl = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='en'), allow_null=False)
class GeonamesDCTLocation(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.Location) geonames_url = RDFField(predicate=ns.DCT.identifier, object_type=URIRef, required=False) centroid = RDFField(predicate=ns.DCAT.centroid, object_type=partial(Literal, datatype=ns.GSP.asWKT), required=False)
class SKOSConceptScheme(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.SKOS.ConceptScheme) title_pl = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='pl'), required=False) title_en = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='en'), required=False)
class SKOSConcept(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.SKOS.Concept) title_pl = RDFField(predicate=ns.SKOS.prefLabel, object_type=partial(Literal, lang='pl'), required=False) title_en = RDFField(predicate=ns.SKOS.prefLabel, object_type=partial(Literal, lang='en'), required=False) scheme = RDFNestedField('SKOSConceptScheme', predicate=ns.SKOS.inScheme)
class VCARDKind(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.VCARD.Kind) type = RDFField(predicate=RDF.type, object=ns.VCARD.Kind) name = RDFField(predicate=ns.VCARD.fn, object_type=partial(Literal, datatype=XSD.string), allow_null=False) email = RDFField(predicate=ns.VCARD.hasEmail, object_type=URIRef, required=False)
class BaseDCATDeserializer(RDFClass): ext_ident = RDFField(predicate=ns.DCT.identifier) title_pl = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='pl'), try_non_lang=True) title_en = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='en')) description_pl = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='pl'), try_non_lang=True) description_en = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='en')) created = RDFField(predicate=ns.DCT.issued, object_type=partial(Literal, datatype=XSD.dateTime)) modified = RDFField(predicate=ns.DCT.modified, object_type=partial(Literal, datatype=XSD.dateTime)) def get_ext_ident_object(self, triple_store, subject, field): ident = [ value.split('/')[-1] if _is_valid_uri(value) else value for value in triple_store.objects(subject=subject, predicate=field.predicate) ] if not ident and _is_valid_uri(subject): ident = [subject.split('/')[-1]] return ident
class FOAFAgent(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.FOAF.Agent) title_pl = RDFField(predicate=ns.FOAF.name, object_type=partial(Literal, lang='pl'), allow_null=False) title_en = RDFField(predicate=ns.FOAF.name, object_type=partial(Literal, lang='en'), allow_null=False) email = RDFField(predicate=ns.FOAF.mbox, object_type=Literal, required=False) homepage = RDFField(predicate=ns.FOAF.homepage, object_type=URIRef, required=False) agent_type = RDFNestedField('SKOSConcept', predicate=ns.DCT.type, required=False)
class DCATDatasetDeserializer(BaseDCATDeserializer): rdf_type = RDFField(predicate=RDF.type, object=ns.DCAT.Dataset) categories = DCATVocabularyField(predicate=ns.DCAT.theme, vocabulary_name='theme', many=True) resources = RDFNestedField('DCATDistributionDeserializer') update_frequency = DCATVocabularyField(predicate=ns.DCT.AccrualPeriodicity, vocabulary_name='frequency') tags = RDFField(predicate=ns.DCAT.keyword, many=True) def get_tags_object(self, triple_store, subject, field): return [{ 'name': value.value, 'lang': value.language } if value.language in ('pl', 'en') else { 'name': value.value } if not value.language else {} for value in triple_store.objects(subject=subject, predicate=field.predicate)]
class HYDRAPagedCollection(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.HYDRA.PagedCollection) count = RDFField(predicate=ns.HYDRA.totalItems) per_page = RDFField(predicate=ns.HYDRA.itemsPerPage) next_page = RDFField(predicate=ns.HYDRA.nextPage, required=False) last_page = RDFField(predicate=ns.HYDRA.lastPage, required=False) prev_page = RDFField(predicate=ns.HYDRA.previousPage, required=False) first_page = RDFField(predicate=ns.HYDRA.firstPage, required=False) def get_subject(self, data): return BNode('PagedCollection')
class SCHEMACatalog(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.SCHEMA.DataCatalog) language_pl = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='pl') language_en = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='en') title_pl = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='en'), allow_null=False) description_pl = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='pl'), allow_null=False) description_en = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='en'), allow_null=False) modified = RDFField(predicate=ns.SCHEMA.dateModified) homepage = RDFField(predicate=ns.SCHEMA.url) dataset = RDFField(predicate=ns.SCHEMA.dataset, object_type=URIRef, many=True) def get_subject(self, data): return URIRef(CATALOG_URL) def get_data(self, data): return { 'title_pl': config.CATALOG__TITLE_PL, 'title_en': config.CATALOG__TITLE_EN, 'description_pl': config.CATALOG__DESCRIPTION_PL, 'description_en': config.CATALOG__DESCRIPTION_EN, 'modified': data.get('catalog_modified'), 'homepage': settings.BASE_URL, 'dataset': data.get('dataset_refs'), }
class DCATDistributionDeserializer(BaseDCATDeserializer): rdf_type = RDFField(predicate=RDF.type, object=ns.DCAT.Distribution) format = DCATVocabularyField(predicate=ns.DCT['format'], vocabulary_name='file-type') file_mimetype = DCATVocabularyField(predicate=ns.DCAT.mediaType, vocabulary_name='media-type') description_pl = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='pl')) description_en = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='en')) created = RDFField(predicate=ns.DCT.issued, object_type=partial(Literal, datatype=XSD.dateTime)) modified = RDFField(predicate=ns.DCT.modified, object_type=partial(Literal, datatype=XSD.dateTime)) link = RDFField(predicate=ns.DCAT.accessURL, object_type=URIRef) license = LicenseDCATVocabularyField()
class SCHEMADataset(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.SCHEMA.Dataset) resources = RDFNestedField('SCHEMADistribution', predicate=ns.SCHEMA.distribution, many=True) organization = RDFNestedField('SCHEMAOrganization', predicate=ns.SCHEMA.creator) language_pl = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='pl') language_en = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='en') identifier = RDFField(predicate=ns.SCHEMA.url) id = RDFField(predicate=ns.SCHEMA.identifier) title_pl = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='en'), allow_null=False) notes_pl = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='pl'), allow_null=False) notes_en = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='en'), allow_null=False) status = RDFField(predicate=ns.SCHEMA.creativeWorkStatus) created = RDFField(predicate=ns.SCHEMA.dateCreated) modified = RDFField(predicate=ns.SCHEMA.dateModified) version = RDFField(predicate=ns.SCHEMA.version) tags = RDFField(predicate=ns.SCHEMA.keywords) license = RDFField(predicate=ns.SCHEMA.license, required=False) def get_subject(self, data): return URIRef(data['frontend_absolute_url']) def get_data(self, data): data['tags'] = ', '.join(data['tags']) data['catalog'] = CATALOG_URL return data def get_organization_subject(self, data): return URIRef(data['access_url']) def get_resources_subject(self, data): return URIRef(data['access_url'])
class SCHEMADistribution(RDFClass): type = RDFField(predicate=RDF.type, object=ns.SCHEMA.DataDownload) language_pl = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='pl') language_en = RDFField(predicate=ns.SCHEMA.inLanguage, object_value='en') title_pl = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.SCHEMA.name, object_type=partial(Literal, lang='en'), allow_null=False) description_pl = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='pl'), allow_null=False) description_en = RDFField(predicate=ns.SCHEMA.description, object_type=partial(Literal, lang='en'), allow_null=False) status = RDFField(predicate=ns.SCHEMA.creativeWorkStatus) created = RDFField(predicate=ns.SCHEMA.dateCreated) modified = RDFField(predicate=ns.SCHEMA.dateModified) access_url = RDFField(predicate=ns.SCHEMA.url) download_url = RDFField(predicate=ns.SCHEMA.contentUrl) file_mimetype = RDFField(predicate=ns.SCHEMA.encodingFormat) license = RDFField(predicate=ns.SCHEMA.license) def get_subject(self, data): return URIRef(data['access_url'])
class DCATDataset(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCAT.Dataset) resources = RDFNestedField('DCATDistribution', predicate=ns.DCAT.distribution, many=True) organization = RDFNestedField('FOAFAgent', predicate=ns.DCT.publisher) contact_point = RDFNestedField('VCARDKind', predicate=ns.DCAT.contactPoint) categories = RDFNestedField('SKOSConcept', predicate=ns.DCAT.theme, many=True) landing_page = RDFNestedField('FOAFDocument', predicate=ns.DCAT.landingPage) update_frequency = RDFNestedField('DCTFrequency', predicate=ns.DCT.accrualPeriodicity) language_pl = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) language_en = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) if is_enabled('S38_dcat_spatial_data.be'): spatial = RDFNestedField('GeonamesDCTLocation', predicate=ns.DCT.spatial, many=True) identifier = RDFField(predicate=ns.DCT.identifier) title_pl = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='en'), allow_null=False) notes_pl = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='pl'), allow_null=False) notes_en = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='en'), allow_null=False) created = RDFField(predicate=ns.DCT.issued) modified = RDFField(predicate=ns.DCT.modified) version = RDFField(predicate=ns.OWL.versionInfo) tags = RDFField(predicate=ns.DCAT.keyword, many=True) def get_subject(self, data): return URIRef(data['frontend_absolute_url']) def get_organization_subject(self, data): return URIRef(data['access_url']) def get_resources_subject(self, data): return URIRef(data['access_url']) def get_landing_page_subject(self, data): return URIRef(data) def get_update_frequency_data(self, data): update_frequency = data['update_frequency'] if update_frequency is None: update_frequency = f"{VOCABULARIES['frequency']}UNKNOWN" return { 'subject': URIRef(update_frequency), 'scheme': URIRef(VOCABULARIES['frequency'].rstrip('/')) } def get_language_pl_data(self, data): return { 'subject': URIRef(VOCABULARIES['language'] + 'POL'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) } def get_language_en_data(self, data): return { 'subject': URIRef(VOCABULARIES['language'] + 'ENG'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) } def get_categories_subject(self, data): return URIRef(VOCABULARIES['theme'] + data['code']) def get_categories_data(self, data): for category in data['categories']: category['scheme'] = { 'subject': URIRef(VOCABULARIES['theme'].rstrip('/')), 'title_pl': 'Kategoria danych', 'title_en': 'Data theme', } return data['categories'] def get_contact_point_subject(self, data): return BNode('VcardKind') def get_contact_point_data(self, data): result = { 'name': config.DATASET__CONTACT_POINT__FN, } if config.DATASET__CONTACT_POINT__HAS_EMAIL: result['email'] = config.DATASET__CONTACT_POINT__HAS_EMAIL return result def get_spatial_data(self, data): spatial_details = [{ 'centroid': d['centroid'] } if d['geonames_url'] is None else { 'geonames_url': d['geonames_url'] } for d in data['spatial']] return spatial_details def get_spatial_subject(self, data): data_str = data.get('geonames_url', data.get('centroid', '')) return BNode('DCTLocation' + hashlib.sha256(data_str.encode('utf-8')).hexdigest())
class DCTMediaType(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.MediaType)
class DCATCatalog(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCAT.Catalog) publisher = RDFNestedField('FOAFAgent', predicate=ns.DCT.publisher ) # TODO warning, brak słownika kontrolowanego language_pl = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) language_en = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) homepage = RDFNestedField('FOAFDocument', predicate=ns.FOAF.homepage) spatial = RDFNestedField('DCTLocation', predicate=ns.DCT.spatial) theme_taxonomy = RDFNestedField('SKOSConceptScheme', predicate=ns.DCAT.themeTaxonomy) dataset = RDFField(predicate=ns.DCAT.dataset, object_type=URIRef, many=True) title_pl = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='pl'), allow_null=False) title_en = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='en'), allow_null=False) description_pl = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='pl'), allow_null=False) description_en = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='en'), allow_null=False) issued = RDFField(predicate=ns.DCT.issued, object_type=partial(Literal, datatype=XSD.date)) modified = RDFField(predicate=ns.DCT.modified, object_type=partial(Literal, datatype=XSD.dateTime)) def get_subject(self, data): return URIRef(CATALOG_URL) def get_publisher_subject(self, data): return BNode('CatalogPublisher') def get_data(self, data): result = { 'title_pl': config.CATALOG__TITLE_PL, 'title_en': config.CATALOG__TITLE_EN, 'description_pl': config.CATALOG__DESCRIPTION_PL, 'description_en': config.CATALOG__DESCRIPTION_EN, 'issued': config.CATALOG__ISSUED, 'spatial': { 'subject': URIRef(VOCABULARIES['country'] + 'POL'), 'scheme': URIRef(VOCABULARIES['country'].rstrip('/')) }, 'language_pl': { 'subject': URIRef(VOCABULARIES['language'] + 'POL'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) }, 'language_en': { 'subject': URIRef(VOCABULARIES['language'] + 'ENG'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) }, 'modified': data.get('catalog_modified'), 'homepage': settings.BASE_URL, 'publisher': { 'title_pl': config.CATALOG__PUBLISHER__NAME_PL, 'title_en': config.CATALOG__PUBLISHER__NAME_EN, 'agent_type': { 'subject': URIRef(VOCABULARIES['publishertype-prefix'] + 'NationalAuthority'), 'scheme': { 'subject': URIRef(VOCABULARIES['publishertype'].rstrip('/')), 'title_en': 'Publisher Type', }, 'title_pl': 'Organ krajowy', 'title_en': 'National authority', } }, 'theme_taxonomy': { 'subject': URIRef(VOCABULARIES['theme'].rstrip('/')), 'title_pl': 'Kategoria danych', 'title_en': 'Data theme', }, 'dataset': data.get('dataset_refs'), } if config.CATALOG__PUBLISHER__EMAIL: result['publisher']['email'] = config.CATALOG__PUBLISHER__EMAIL if config.CATALOG__PUBLISHER__HOMEPAGE: result['publisher'][ 'homepage'] = config.CATALOG__PUBLISHER__HOMEPAGE return result def get_homepage_subject(self, data): return URIRef(data)
class DCTMediaTypeOrExtent(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.MediaTypeOrExtent) scheme = RDFField(predicate=ns.SKOS.inScheme, object_type=URIRef)
class DCTFrequency(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.Frequency) scheme = RDFField(predicate=ns.SKOS.inScheme, object_type=URIRef)
class FOAFDocument(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.FOAF.Document)
class DCATDistribution(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCAT.Distribution) format = RDFNestedField('DCTMediaTypeOrExtent', predicate=ns.DCT['format'], required=False) file_mimetype = RDFNestedField('DCTMediaType', predicate=ns.DCAT.mediaType) language_pl = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) language_en = RDFNestedField('DCTLinguisticSystem', predicate=ns.DCT.language) status = RDFNestedField('SKOSConcept', predicate=ns.ADMS.status) title_pl = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='pl')) title_en = RDFField(predicate=ns.DCT.title, object_type=partial(Literal, lang='en'), allow_null=False) description_pl = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='pl'), allow_null=False) description_en = RDFField(predicate=ns.DCT.description, object_type=partial(Literal, lang='en'), allow_null=False) created = RDFField(predicate=ns.DCT.issued, object_type=partial(Literal, datatype=XSD.dateTime)) modified = RDFField(predicate=ns.DCT.modified, object_type=partial(Literal, datatype=XSD.dateTime)) access_url = RDFField(predicate=ns.DCAT.accessURL, object_type=URIRef) download_url = RDFField(predicate=ns.DCAT.downloadURL, object_type=URIRef, allow_null=False) file_size = RDFField(predicate=ns.DCAT.byteSize, object_type=partial(Literal, datatype=XSD.decimal)) license = RDFField(predicate=ns.DCAT.license, object_type=URIRef) def get_subject(self, data): return URIRef(data['access_url']) def get_format_data(self, data): if data['format'] is not None: return { 'subject': URIRef(VOCABULARIES['file-type'] + data['format'].upper()), 'scheme': URIRef(VOCABULARIES['file-type'].rstrip('/')) } def get_file_mimetype_subject(self, data): if data is not None: return URIRef(VOCABULARIES['media-type'] + data) def get_status_data(self, data): return { 'subject': URIRef(VOCABULARIES['status-prefix'] + 'Completed'), 'scheme': { 'subject': URIRef(VOCABULARIES['status']), 'title_en': 'Status', }, 'title_en': 'Completed', } def get_language_pl_data(self, data): return { 'subject': URIRef(VOCABULARIES['language'] + 'POL'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) } def get_language_en_data(self, data): return { 'subject': URIRef(VOCABULARIES['language'] + 'ENG'), 'scheme': URIRef(VOCABULARIES['language'].rstrip('/')) }
class DCTLocation(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.Location) scheme = RDFField(predicate=ns.SKOS.inScheme, object_type=URIRef)
class DCTLinguisticSystem(RDFClass): rdf_type = RDFField(predicate=RDF.type, object=ns.DCT.LinguisticSystem) scheme = RDFField(predicate=ns.SKOS.inScheme, object_type=URIRef)