<commit_before>package net.weverwijk.address.cleaner;

import lombok.Data;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.document.Document;

@Data
public class Address {
  private String postcode;
  private String city;
  private String street;
  private String houseNumber;
  private String houseNumberAffix;

  public Address(String postcode, String city, String street, String houseNumber, String houseNumberAffix) {
    this.postcode = StringUtils.isNotEmpty(postcode) ? postcode.trim() : null;
    this.city = StringUtils.isNotEmpty(city) ? city.trim() : null;
    this.street = StringUtils.isNotEmpty(street) ? street.trim() : null;
    this.houseNumber = StringUtils.isNotEmpty(houseNumber)? houseNumber.trim() : null;
    this.houseNumberAffix = StringUtils.isNotEmpty(houseNumberAffix) ? houseNumberAffix.trim() : null;

    this.cleanUpHouseNumbers();
  }

  private void cleanUpHouseNumbers() {
    if (StringUtils.isEmpty(this.getHouseNumber())) {
      String[] addressSplit = this.getStreet().split(" ");
      String potentialHousenumber = addressSplit[addressSplit.length - 1];
      try {
        Integer.parseInt(potentialHousenumber);
        this.setStreet(StringUtils.join(ArrayUtils.remove(addressSplit, addressSplit.length - 1), " "));
        this.setHouseNumber(potentialHousenumber);
      } catch (NumberFormatException nfe) {
        // nothing to see walk through
      }
    }
  }

  public Address(Document fields) {
    this.postcode = fields.get("postcode");
    this.city = fields.get("city");
    this.street = fields.get("street");
//    this.houseNumber = Integer.parseInt(fields.get("houseNumber"));
//    this.houseNumberAffix = fields.get("houseNumberAffix");
  }

  public Address getUpperVersion() {<commit_msg>Street should not be empty if we want to use it...<commit_after>package net.weverwijk.address.cleaner;

import lombok.Data;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.document.Document;

@Data
public class Address {
  private String postcode;
  private String city;
  private String street;
  private String houseNumber;
  private String houseNumberAffix;

  public Address(String postcode, String city, String street, String houseNumber, String houseNumberAffix) {
    this.postcode = StringUtils.isNotEmpty(postcode) ? postcode.trim() : null;
    this.city = StringUtils.isNotEmpty(city) ? city.trim() : null;
    this.street = StringUtils.isNotEmpty(street) ? street.trim() : null;
    this.houseNumber = StringUtils.isNotEmpty(houseNumber)? houseNumber.trim() : null;
    this.houseNumberAffix = StringUtils.isNotEmpty(houseNumberAffix) ? houseNumberAffix.trim() : null;

    this.cleanUpHouseNumbers();
  }

  private void cleanUpHouseNumbers() {
    if (StringUtils.isEmpty(this.getHouseNumber()) && StringUtils.isNotEmpty(this.getStreet())) {
      String[] addressSplit = this.getStreet().split(" ");
      String potentialHousenumber = addressSplit[addressSplit.length - 1];
      try {
        Integer.parseInt(potentialHousenumber);
        this.setStreet(StringUtils.join(ArrayUtils.remove(addressSplit, addressSplit.length - 1), " "));
        this.setHouseNumber(potentialHousenumber);
      } catch (NumberFormatException nfe) {
        // nothing to see walk through
      }
    }
  }

  public Address(Document fields) {
    this.postcode = fields.get("postcode");
    this.city = fields.get("city");
    this.street = fields.get("street");
//    this.houseNumber = Integer.parseInt(fields.get("houseNumber"));
//    this.houseNumberAffix = fields.get("houseNumberAffix");
  }

  public Address getUpperVersion() {
{'fraction_non_alphanumeric': 0.11899006177813591, 'fraction_numerical': 0.0021488047273704003, 'mean_word_length': 4.186629526462395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033963', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1084, 'n_words': 217}