Пример #1
0
    def _write_to_catalog_index(self, oai_record):
        """
        Add a record to the catalog index

        :type oai_record: indexer.oai_record.OAIRecord
        :param oai_record:
        :return:
        """
        index_record = oai_record.index_record
        try:
            call_nums_norm = [call_number.normalize(lcc) for lcc in index_record.callnum]
            taxonomies = self.categorizer.categorize(collections=index_record.collections,
                                                     locations=index_record.location,
                                                     lccs_norm=call_nums_norm)
        except ValueError:
            self.logger.info("Strange callnumber {} for ".format(index_record.callnum, oai_record.id))
            taxonomies = []

        tax1 = set()
        tax2 = set()
        tax3 = set()

        for taxonomy in taxonomies:
            tax1.add(taxonomy[1])
            tax2.add(taxonomy[2])
            try:
                tax3.add(taxonomy[3])
            except KeyError as e:
                pass

        index_record.tax1 = list(tax1)
        index_record.tax2 = list(tax2)
        index_record.tax3 = list(tax3)

        self.elasticsearch.add_catalog_record(oai_record)
Пример #2
0
 def test_normalization(self):
     self.assertEqual('QL 073700C250G650 000 2012', CallNumber.normalize('QL737.C25 G65 2012'))
     self.assertEqual('HV 088100P725 000 000 2011', CallNumber.normalize('HV881 .P725 2011'))
     self.assertEqual('E  017300K870 000 000 2013', CallNumber.normalize('E173 .K87 2013'))