Ejemplo n.º 1
0
        def __init__(
            self,
            endpoint_url,
            logger,
            object_id,
            omeka_item
        ):
            self._object_builder = \
                Object.builder()\
                    .setCollectionId(object_id.getCollectionId())\
                    .setInstitutionId(object_id.getInstitutionId())
            self.__logger = logger
            self.__object_id = object_id
            self.__omeka_item = omeka_item

            self.agents = []
            self.categories = []
            self.cultural_contexts = []
            self.dc_date_builder = Date.builder().setType(DateType.CREATION)
            self.dc_date_certainty = None
            self.dates = []
            self.descriptions = []
            self.identifiers = []
            self.images = []
            self.inscriptions = []
            self.locations = []
            self.materials = []
            self.measurements = []
            self.relation_builders = []
            self.subjects = []
            self.techniques = []
            self.textrefs = []
            self.titles = []
            self.work_types = []

            self.textrefs.append(
                Textref.builder()
                    .setName(
                        TextrefName.builder()
                            .setText("Omeka item URL")
                            .setType(TextrefNameType.ELECTRONIC)
                            .build()
                    )
                    .setRefid(
                        TextrefRefid.builder()
                            .setHref(Url.parse(str(endpoint_url) + 'items/show/' + str(omeka_item.id)))
                            .setText(str(endpoint_url) + 'items/show/' + str(omeka_item.id))
                            .setType(TextrefRefidType.URI)
                            .build()
                    )
                    .build()
            )
 def _map_omeka_item_element_itm_references(self, object_builder, text):
     object_builder.textrefs.append(
         Textref.builder()
             .setName(
                 TextrefName.builder()
                     .setText(text)
                     .setType(TextrefNameType.CORPUS)
                     .build()
             )
             .setRefid(
                 TextrefRefid.builder()
                     .setText("unparsed")
                     .setType(TextrefRefidType.CITATION)
                     .build()
             )
             .build()
     )
Ejemplo n.º 3
0
        def build(self):
            if len(self.agents) > 0:
                self._object_builder.setAgents(AgentSet.builder().setElements(ImmutableList.copyOf(self.agents)).build())
            if len(self.categories) > 0:
                self._object_builder.setCategories(ImmutableList.copyOf(set(self.categories)))
            if len(self.cultural_contexts) > 0:
                self._object_builder.setCulturalContexts(CulturalContextSet.builder().setElements(ImmutableList.copyOf(self.cultural_contexts)).build())
            if self.dc_date_builder.getEarliestDate() is not None and self.dc_date_builder.getLatestDate() is not None:
                if self.dc_date_certainty is not None:
                    assert self.dc_date_certainty == 'circa'
                    self.dc_date_builder.setEarliestDate(
                        DateBound.builder(self.dc_date_builder.earliestDate)\
                            .setCirca(True)\
                            .build()
                        )
                    self.dc_date_builder.setLatestDate(
                        DateBound.builder(self.dc_date_builder.latestDate)\
                            .setCirca(True)\
                            .build()
                    )
                self.dates.append(self.dc_date_builder.build())
            if len(self.dates) > 0:
                self._object_builder.setDates(DateSet.builder().setElements(ImmutableList.copyOf(self.dates)).build())
            if len(self.descriptions) > 0:
                description_texts = {}
                description_i = 0
                while description_i < len(self.descriptions):
                    description = self.descriptions[description_i]
                    if description.text in description_texts:
                        del self.descriptions[description_i]
                    else:
                        description_texts[description.text] = None
                        description_i = description_i + 1
                self._object_builder.setDescriptions(DescriptionSet.builder().setElements(ImmutableList.copyOf(self.descriptions)).build())
            for identifier in self.identifiers:
                self.textrefs.append(
                    Textref.builder()
                        .setName(
                            TextrefName.builder()
                                .setText("Identifier")
                                .setType(TextrefNameType.CATALOG)
                                .build()
                        )
                        .setRefid(
                            TextrefRefid.builder()
                                .setText(identifier)
                                .setType(TextrefRefidType.OTHER)
                                .build()
                        )
                        .build()
                )
            if len(self.images) > 0:
                self._object_builder.setImages(ImmutableList.copyOf(self.images))
            if len(self.inscriptions) > 0:
                self._object_builder.setInscriptions(InscriptionSet.builder().setElements(ImmutableList.copyOf(self.inscriptions)).build())
            if len(self.locations) > 0:
                self._object_builder.setLocations(LocationSet.builder().setElements(ImmutableList.copyOf(self.locations)).build())
            if len(self.materials) > 0:
                self._object_builder.setMaterials(MaterialSet.builder().setElements(ImmutableList.copyOf(self.materials)).build())
            if len(self.measurements) > 0:
                self._object_builder.setMeasurements(MeasurementsSet.builder().setElements(ImmutableList.copyOf(self.measurements)).build())
            if len(self.relation_builders) > 0:
                unique_relation_builders_by_text = {}
                for relation_builder in self.relation_builders:
                    assert relation_builder.text is not None
                    existing_relation_builders = unique_relation_builders_by_text.setdefault(relation_builder.text, [])
                    unique = True
                    for existing_relation_builder in existing_relation_builders:
                        if existing_relation_builder.type == relation_builder.type:
                            unique = False
                            break
                    if unique:
                        existing_relation_builders.append(relation_builder)
                    else:
                        self.__logger.warn("item %d has duplicate relation type=%s, text=%s", self.__omeka_item.id, relation_builder.type, relation_builder.text)
                unique_relation_builders = []
                for relation_builders in unique_relation_builders_by_text.values():
                    unique_relation_builders.extend(relation_builders)
                self._object_builder.setRelations(
                        RelationSet.builder()
                            .setElements(ImmutableList.copyOf(relation_builder.build()
                                                for relation_builder in unique_relation_builders))
                            .build())
            if len(self.subjects) > 0:
                self._object_builder.setSubjects(SubjectSet.builder().setElements(ImmutableList.copyOf(self.subjects)).build())
            if len(self.techniques) > 0:
                self._object_builder.setTechniques(TechniqueSet.builder().setElements(ImmutableList.copyOf(self.techniques)).build())
            if len(self.textrefs) > 0:
                self._object_builder.setTextrefs(TextrefSet.builder().setElements(ImmutableList.copyOf(self.textrefs)).build())
            if len(self.titles) > 0:
                self._object_builder.setTitles(TitleSet.builder().setElements(ImmutableList.copyOf(self.titles)).build())
            else:
                raise ValueError('no titles')
            if len(self.work_types) > 0:
                self._object_builder.setWorkTypes(WorkTypeSet.builder().setElements(ImmutableList.copyOf(self.work_types)).build())
            else:
                raise ValueError('no work types')

            return self._object_builder.build()