Esempio n. 1
0
  def _append_attributes_to_title(self, product: Dict[str, Any],
                                  chars_to_preserve: int, language: str,
                                  country: str) -> None:
    """Appends mined attributes to the title.

    Args:
      product: Product data.
      chars_to_preserve: The num of chars to leave unchanged (used to make sure
        the original title is preserved).
      language: The language to use for this optimizer.
      country: The country to use for this optimizer.
    """
    if not self._mined_attributes:
      return

    product_id = product.get('offerId', '')
    size_checker = size_miner.SizeMiner(language, country)
    fields_to_append_to_title = []
    for attribute_name, mined_attribute_values in self._mined_attributes.get(
        product_id, {}).items():
      if attribute_name == 'sizes' and size_checker.is_size_in_attribute(
          product, 'title'):
        # Does not append the size when size information is already in title.
        continue
      if isinstance(mined_attribute_values, str):
        fields_to_append_to_title.append(mined_attribute_values)
      elif isinstance(mined_attribute_values, list):
        fields_to_append_to_title.extend(mined_attribute_values)

    if fields_to_append_to_title:
      base_optimizer.set_optimization_tracking(product,
                                               base_optimizer.OPTIMIZED)
      _append_fields_to_title(product, fields_to_append_to_title,
                              chars_to_preserve)
Esempio n. 2
0
    def test_mine_size_mines_size_from_sizes_field_with_language(self):
        product = {
            'title': 'TシャツM',
            'description': 'TシャツM',
            'googleProductCategory': 'ファッション・アクセサリー > 衣料品',
            'sizes': ['L', 'S'],
        }
        miner = size_miner.SizeMiner(language=constants.LANGUAGE_CODE_JA,
                                     country=constants.COUNTRY_CODE_JP)

        mined_size = miner.mine_size(product)

        self.assertEqual('L', mined_size)
Esempio n. 3
0
    def test_mine_size_mines_clothing_size_from_title_with_language_ja(
            self, title, expected_size):
        product = {
            'title': title,
            'description': '',
            'googleProductCategory': 'ファッション・アクセサリー > 衣料品',
            'sizes': [],
        }
        miner = size_miner.SizeMiner(language=constants.LANGUAGE_CODE_JA,
                                     country=constants.COUNTRY_CODE_JP)

        mined_size = miner.mine_size(product)

        self.assertEqual(expected_size, mined_size)
Esempio n. 4
0
    def test_mine_size_mines_shoes_size_from_title_with_language_en_and_country_us(
            self, title, expected_size):
        product = {
            'title': title,
            'description': '',
            'googleProductCategory': 'Apparel & Accessories > Shoes',
            'sizes': [],
        }
        miner = size_miner.SizeMiner(language=constants.LANGUAGE_CODE_EN,
                                     country=constants.COUNTRY_CODE_US)

        mined_size = miner.mine_size(product)

        self.assertEqual(expected_size, mined_size)
Esempio n. 5
0
    def __init__(self, language: str, country: str) -> None:
        """Initializes AttributeMiner.

    Args:
      language: The configured language code.
      country: The configured country code.
    """
        super(AttributeMiner, self).__init__()
        brand_blocklist_config = current_app.config.get('CONFIGS', {}).get(
            'brand_blocklist', {})
        self._brand_blocklist = set(
            [brand.lower() for brand in brand_blocklist_config])
        self._gender_config = current_app.config.get('CONFIGS', {}).get(
            f'gender_optimizer_config_{language}', {})
        self._color_miner = color_miner.ColorMiner(language)
        self._size_miner = size_miner.SizeMiner(language, country)