Skip to content

Commit

Permalink
Merge pull request #428 from skedgo/feature/21295-update-scoring-for-…
Browse files Browse the repository at this point in the history
…search-results-with-mode-identifiers

[21295] Update scoring strategy for search results with modeIdentifiers
  • Loading branch information
MichaelReyes authored May 8, 2024
2 parents 8b2c284 + 6edcefe commit 4ed8be7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.skedgo.geocoding;


import androidx.annotation.Nullable;

import com.skedgo.geocoding.agregator.GCSkedGoResultInterface;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class GCSkedgoResult extends GCResult implements GCSkedGoResultInterface {

@NotNull
Expand All @@ -12,10 +16,21 @@ public class GCSkedgoResult extends GCResult implements GCSkedGoResultInterface
// popularity json field from skedgo's json
private int popularity;

public GCSkedgoResult(String name, double lat, double lng, @NotNull String resultClass, Integer popularity ){
@Nullable
private List<String> modeIdentifiers;

public GCSkedgoResult(
String name,
double lat,
double lng,
@NotNull String resultClass,
Integer popularity,
@Nullable List<String> modeIdentifiers
){
super(name, lat, lng);
this.popularity = popularity;
this.resultClass = resultClass;
this.modeIdentifiers = modeIdentifiers;
}

@NotNull
Expand All @@ -40,4 +55,10 @@ public void setPopularity(int popularity) {
public boolean isStopLocation(){
return this.resultClass.equalsIgnoreCase("StopLocation");
}

@Nullable
@Override
public List<String> getModeIdentifiers() {
return modeIdentifiers;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.skedgo.geocoding.agregator;

import androidx.annotation.Nullable;

import java.util.List;

public interface GCSkedGoResultInterface extends GCResultInterface {

// skedgo result class (class json field)
String getResultClass();
// skedgo result popularity (popularity json field)
int getPopularity();

@Nullable
List<String> getModeIdentifiers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ private ScoringResult<T> calculateSkedGoScoring(GCQuery query, GCSkedGoResultInt
// int popularityScore = (Math.min(popularity, GOOD_SCORE)) / (GOOD_SCORE / 100)
int popularityScore = ((Math.min(popularity, GOOD_SCORE)) / (GOOD_SCORE / 100)) * 2;

popularityScore = GeocodeUtilities.rangedScoreForScore(popularityScore, 30, 80);
popularityScore = (candidate.getModeIdentifiers() != null && !candidate.getModeIdentifiers().isEmpty()) ?
GeocodeUtilities.rangedScoreForScore(popularityScore, 50, 90) :
GeocodeUtilities.rangedScoreForScore(popularityScore, 30, 80);

if (popularity > GOOD_SCORE) {
int moreThanGood = popularityScore / GOOD_SCORE;
int bonus = GeocodeUtilities.rangedScoreForScore(moreThanGood, 0, 10);
Expand All @@ -208,7 +211,9 @@ private ScoringResult<T> calculateSkedGoScoring(GCQuery query, GCSkedGoResultInt
if (!query.getQueryText().isEmpty()){
int nameScore = GeocodeUtilities.scoreBasedOnNameMatchBetweenSearchTerm(query.getQueryText(), candidate.getName());

int totalScore = GeocodeUtilities.rangedScoreForScore(nameScore,0,50);
int totalScore = (candidate.getModeIdentifiers() != null && !candidate.getModeIdentifiers().isEmpty()) ?
GeocodeUtilities.rangedScoreForScore(nameScore,50,90):
GeocodeUtilities.rangedScoreForScore(nameScore,0,50);
scoringResult.setScore(totalScore);
scoringResult.setNameScore(nameScore);
return scoringResult;
Expand Down Expand Up @@ -284,71 +289,4 @@ private ScoringResult<T> calculateRegionsScoring(GCQuery query, GCAppResultInter

return scoringResult;
}

// private List<MGAResultInterface<T>> removeDuplicates(List<MGAResultInterface<T>> list) {
// int count = list.size();
// List<MGAResultInterface<T>> withoutDuplicates = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// GroupScoringResult groupScoringResult;
// ScoringResult scoringResult;
// if (list.get(i) instanceof ScoringResult) {
// groupScoringResult = new GroupScoringResult();
// groupScoringResult.addDuplicate((ScoringResult) list.get(i));
// scoringResult = (ScoringResult) list.get(i);
// }
// else{
// groupScoringResult = (GroupScoringResult) list.get(i);
// scoringResult = (ScoringResult) groupScoringResult.getDuplicates().get(0);
// }
//
// for (int j = i + 1; j < count; j++) {
// if (scoringResult.equals(list.get(j))) {
// if (list.get(j) instanceof ScoringResult)
// groupScoringResult.addDuplicate((ScoringResult) list.get(j));
// else
// groupScoringResult.addDuplicates(list.get(j).getDuplicates());
// list.remove(j--);
// count--;
// }
// }
// withoutDuplicates.add(i, groupScoringResult);
// }
// return GeocodeUtilities.sortByScore(withoutDuplicates);
// }


// private List<MGAResultInterface<T>> removeDuplicates(List<MGAResultInterface<T>> list) {
//
// Set<MGAResultInterface<T>> treeSet = new TreeSet<>(new Comparator<MGAResultInterface<T>>() {
// @Override
// public int compare(MGAResultInterface<T> o1, MGAResultInterface<T> o2) {
// ScoringResult<T> scoringResult = (ScoringResult<T>) o1.getClassRepresentative();
// if (scoringResult.equals(o2)){
// GroupScoringResult<T> o1Group = (GroupScoringResult<T>) o1;
// if (!o1.equals(o2)) {
// GroupScoringResult<T> o2Group = (GroupScoringResult<T>) o2;
// List<MGAResultInterface<T>> o1Duplicates = new ArrayList<>(o1Group.getDuplicates());
// o1Group.addDuplicates(new ArrayList<>(o2Group.getDuplicates()));
// o2Group.addDuplicates(o1Duplicates);
//
// }
// }
// return scoringResult.equals(o2) ? 0 : 1;
// }
// });
//
// for (MGAResultInterface<T> o : list){
// GroupScoringResult<T> groupScoringResult;
// if (o instanceof ScoringResult) {
// groupScoringResult = new GroupScoringResult();
// groupScoringResult.addDuplicate((ScoringResult<T>) o);
// }
// else{
// groupScoringResult = (GroupScoringResult<T>) o;
// }
// treeSet.add(groupScoringResult);
// }
//
// return new ArrayList<MGAResultInterface<T>>(treeSet);
// }
}

0 comments on commit 4ed8be7

Please sign in to comment.