package edu.mit.civic.mediacloud.where.disambiguation;

import java.util.ArrayList;
import java.util.List;

import com.bericotech.clavin.resolver.ResolvedLocation;

public class TopPreferringColocatedPass extends GenericPass {

    @Override
    protected List<List<ResolvedLocation>> disambiguate(
            List<List<ResolvedLocation>> possibilitiesToDo,
            List<ResolvedLocation> bestCandidates) {
        List<List<ResolvedLocation>> possibilitiesToRemove = new ArrayList<List<ResolvedLocation>>();

        for( List<ResolvedLocation> candidates: possibilitiesToDo){
            boolean foundOne = false;
            // check for one in the same country
            for( ResolvedLocation candidate: candidates) {
                if(!foundOne && inSameCountry(candidate,bestCandidates) ){
                    bestCandidates.add(candidate);
                    possibilitiesToRemove.add(candidates);
                    foundOne = true;
                }
            }
            if(!foundOne){
                ResolvedLocation candidate = candidates.get(0);
                logResolvedLocationInfo(candidate);
                bestCandidates.add(candidate);
                possibilitiesToRemove.add(candidates);
            }
        }

        return possibilitiesToRemove;
    }

    @Override
    public String getDescription() {
        return "Pick the top result, preferrring ones in the a country found already (last ditch effort)";
    }
}

@@ -968,32 +968,482 @@
 %7D%0A            %7D%0A
+            // still nothing? pick the first city%0A            if(!foundOne)%7B%0A                for( ResolvedLocation candidate: candidates) %7B%0A                    if(!foundOne && isCity(candidate) )%7B%0A                        bestCandidates.add(candidate);%0A                        possibilitiesToRemove.add(candidates);%0A                        foundOne = true;%0A                    %7D%0A                %7D    %0A            %7D%0A            // just pick SOMETHING!%0A
             if(!

make last ditch effort slightly more preferential to cities