I've asked this question in different ways a couple of times already. Each time I get a breakthrough I encounter another issue. This is also due to the fact that I am not proficient in Java yet and have difficulty with collections like Maps. So please bear with me.
I have two maps like this:
Map1 -{ORGANIZATION=[Fulton Tax Commissioner 's Office, Grady Hospital, Fulton Health Department], LOCATION=[Bellwood, Alpharetta]}
Map2 - {ORGANIZATION=[Atlanta Police Department, Fulton Tax Commissioner, Fulton Health Department], LOCATION=[Alpharetta], PERSON=[Bellwood, Grady Hospital]}
The maps are defined as : LinkedHashMap<String, List<String>> sampleMap = new LinkedHashMap<String, List<String>>();
I am comparing these two maps based on the values and there are only 3 keys i.e ORGANIZATION, PERSON and LOCATION. Map1 is my goldset that I am comparing Map2 against. Now the problem that I am facing is when I iterate over the values of ORGANIZATION key in Map1 and check for matches in Map2, even though my first entry does have a partial match in Map2 (Fulton Tax Commissioner) but because the first entry of Map2 (Atlanta Police Department) is not a match I get an incorrect result(I am looking for exact and partial matches both). The result here being increment the true positive, false positive and false negative counters which enable me to ultimately calculate precision and recall for this i.e. Named Entity Recognition.
EDIT
The result I am expecting for this is
Organization:
True Positive Count = 2
False Negative Count = 1
False Positive Count = 1
Person:
False Positive Count = 2
Location:
True Positive Count = 1
False Negative Count = 1
The output I am currently getting is :
Organization:
True Positive Count = 1
False Negative Count = 2
False Positive Count = 0
Person:
True Positive Count = 0
False Negative Count = 0
False Positive Count = 2
Location:
True Positive Count = 0
False Negative Count = 1
False Positive Count = 0
CODE
private static List<Integer> compareMaps(LinkedHashMap<String, List<String>> annotationMap, LinkedHashMap<String, List<String>> rageMap)
{
List<Integer> compareResults = new ArrayList<Integer>();
if (!annotationMap.entrySet().containsAll(rageMap.entrySet())){
for (Entry<String, List<String>> rageEntry : rageMap.entrySet()){
if (rageEntry.getKey().equals("ORGANIZATION") && !(annotationMap.containsKey(rageEntry.getKey()))){
for (int j = 0; j< rageEntry.getValue().size(); j++) {
orgFalsePositiveCount++;
}
}
if (rageEntry.getKey().equals("PERSON") && !(annotationMap.containsKey(rageEntry.getKey()))){
// System.out.println(rageEntry.getKey());
// System.out.println(annotationMap.entrySet());
for (int j = 0; j< rageEntry.getValue().size(); j++) {
perFalsePositiveCount++;
}
}
if (rageEntry.getKey().equals("LOCATION") && !(annotationMap.containsKey(rageEntry.getKey()))){
for (int j = 0; j< rageEntry.getValue().size(); j++) {
locFalsePositiveCount++;
}
}
}
}
for (Entry<String, List<String>> entry : annotationMap.entrySet()){
int i_index = 0;
if (rageMap.entrySet().isEmpty()){
orgFalseNegativeCount++;
continue;
}
// for (Entry<String, List<String>> rageEntry : rageMap.entrySet()){
if (entry.getKey().equals("ORGANIZATION")){
for(String val : entry.getValue()) {
if (rageMap.get(entry.getKey()) == null){
orgFalseNegativeCount++;
continue;
}
recusion: for (int i = i_index; i< rageMap.get(entry.getKey()).size();){
String rageVal = rageMap.get(entry.getKey()).get(i);
if(val.equals(rageVal)){
orgTruePositiveCount++;
i_index++;
break recusion;
}
else if((val.length() > rageVal.length()) && val.contains(rageVal)){ //|| dataB.get(entryA.getKey()).contains(entryA.getValue())){
orgTruePositiveCount++;
i_index++;
break recusion;
}
else if((val.length() < rageVal.length()) && rageVal.contains(val)){
orgTruePositiveCount++;
i_index++;
break recusion;
}
else if(!val.contains(rageVal)){
orgFalseNegativeCount++;
i_index++;
break recusion;
}
else if(!rageVal.contains(val)){
orgFalsePositiveCount++;
i_index++;
break recusion;
}
}
}
}
......................... //(Same for person and location)
compareResults.add(orgTruePositiveCount);
compareResults.add(orgFalseNegativeCount);
compareResults.add(orgFalsePositiveCount);
compareResults.add(perTruePositiveCount);
compareResults.add(perFalseNegativeCount);
compareResults.add(perFalsePositiveCount);
compareResults.add(locTruePositiveCount);
compareResults.add(locFalseNegativeCount);
compareResults.add(locFalsePositiveCount);
System.out.println(compareResults);
return compareResults;
}