Skip to content

Commit

Permalink
Vertical categories matching enhancements (offer names integration)
Browse files Browse the repository at this point in the history
  • Loading branch information
goulven authored and goulven committed Dec 10, 2024
1 parent 344f8d6 commit 11dbdc6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.api.services.aggregation.AbstractAggregationService;
Expand Down Expand Up @@ -87,6 +89,42 @@ public void onProduct(Product data, VerticalConfig vConf) throws AggregationSkip
data.setVertical(null);
}


/////////////////////////////////////
// A hard filtering on datasource categories, that must at least contains one of the
// vertical natural names
////////////////////////////////////

// Building offer name bags
StringBuilder productNameBag = new StringBuilder();
data.getOfferNames().forEach(name -> {
productNameBag.append(StringUtils.stripAccents(name).toLowerCase());
});
String pNames = productNameBag.toString();

// TODO : Singularize
// TODO : Cache
Set<String> verticalNames = vConf.getTokenNames(taxonomyService.byId(vConf.getGoogleTaxonomyId()).getGoogleNames().values().stream().map(e->StringUtils.stripAccents(e.toLowerCase())).toList() );


for (String term : verticalNames) {

if (pNames.contains(term)) {
dedicatedLogger.info("Vertical {} confirmed by product names match for {}", vConf,data);
data.setVertical(vConf.getId());
break;
} else {
dedicatedLogger.info("Vertical {} failed on product names match, unsetting vertical for {}", vConf,data);
data.setVertical(null);
}

}






// // Setting no vertical if no category
if (data.getDatasourceCategories().size() == 0) {
dedicatedLogger.info("No category in {}, removing vertical", data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.open4goods.commons.config.yml.ui;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -12,6 +13,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.open4goods.commons.config.yml.CommentsAggregationConfig;
import org.open4goods.commons.config.yml.attributes.AttributeConfig;
import org.open4goods.commons.helper.IdHelper;
Expand Down Expand Up @@ -230,6 +232,10 @@ public class VerticalConfig{
*/
private List<FeatureGroup> featureGroups = new ArrayList<>();


// A local cache for token names
private Set<String> cacheTokenNames;


@Override
public String toString() {
Expand All @@ -250,6 +256,50 @@ public ProductI18nElements i18n(String lang) {
return i18n.getOrDefault(lang, i18n.get("default"));
}


/**
* Compute the token names, used to do a product.offernames matching categories
*
* @param additionalNames
* @return
*/
public Set<String> getTokenNames(Collection<String> additionalNames) {

if (null == cacheTokenNames) {

Set<String> verticalNames = new HashSet<String>();
verticalNames.add(getId());
verticalNames.addAll(additionalNames);

getI18n().entrySet().forEach(e -> {
// verticalNames.add(e.getValue().getH1Title().getPrefix().toLowerCase());
verticalNames.add(e.getValue().getVerticalHomeUrl());
// verticalNames.add(e.getValue().getUrl().getPrefix());

});

// Adding singular derivativs, removing -
Set<String> derivativs = new HashSet<String>();
verticalNames.forEach(e -> {
String derivativ = e.replace("-", " ");
derivativs.add(derivativ);

if (derivativ.endsWith("s")) {
derivativ = derivativ.substring(0, derivativ.length() - 1);
}
derivativs.add(derivativ);

// If composed word (laves linges"
derivativ = derivativ.replace("s ", " ");
derivativs.add(derivativ);

});

verticalNames.addAll(derivativs);
cacheTokenNames = verticalNames;
}
return cacheTokenNames;
}
/**
* Return the participation in percentage of a score in the ecoscore
* @param scoreName
Expand Down Expand Up @@ -767,6 +817,8 @@ public void setGenerationExcludedFromAttributesMatching(Set<String> generationEx
}







Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ public VerticalConfig getVerticalForCategories(Map<String, String> productCatego
}
}



return vc;
}

Expand Down
4 changes: 2 additions & 2 deletions verticals/src/main/resources/verticals/_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ attributesConfig:
synonyms:
all:
- "QTE DE PORTS HDMI"
- "QUANTITE DE PORTS HDMI"
- "QUANTITE DE PORTS HDMI"

parser:
normalize: true
Expand Down Expand Up @@ -557,7 +557,7 @@ attributesConfig:
default: "Weight"
fr: "Poids"
filteringType: "NUMERIC"
asScore: false
asScore: true

synonyms:
all:
Expand Down

0 comments on commit 11dbdc6

Please sign in to comment.