Ejemplo n.º 1
0
    def _parse_date(self, text):
        date_bound_builder = DateBound.builder().setText(text)

        if text.endswith('?'):
            date_bound_builder.setCirca(True)
            text = text[:-1]

        DateParser.parse_certain_date(
            date_bound_builder=date_bound_builder,
            text=text
        )

        return date_bound_builder.build()
 def _map_omeka_item_element_itm_accession_year(self, object_builder, text):
     try:
         year = int(text)
     except ValueError:
         self._logger.warn("unable to parse Accession Year '%s'", text)
         return
     earliest_date = \
         DateBound.builder()\
             .setParsedDateTime(java.util.Date(year - 1900, 0, 1))\
             .setParsedDateTimeGranularity(DateTimeGranularity.YEAR)\
             .setText(text)\
             .build()
     object_builder.dates.append(
         Date.builder()
             .setEarliestDate(earliest_date)
             .setLatestDate(earliest_date)
             .setType(DateType.ACCESSION)
             .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()