Mercurial > hg > anteater
comparison src/de/mpiwg/anteater/results/filter/ApplicantLocWithoutApplicantFilter.java @ 0:036535fcd179
anteater
author | jdamerow |
---|---|
date | Fri, 14 Sep 2012 10:30:43 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:036535fcd179 |
---|---|
1 package de.mpiwg.anteater.results.filter; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import de.mpiwg.anteater.ml.PlaceClasses; | |
7 import de.mpiwg.anteater.persons.APerson; | |
8 import de.mpiwg.anteater.places.PlaceInformation; | |
9 import de.mpiwg.anteater.results.ApplicantResult; | |
10 import de.mpiwg.anteater.results.LocationResult; | |
11 import de.mpiwg.anteater.results.SpeciesScientificResult; | |
12 import de.mpiwg.anteater.text.Paragraph; | |
13 import de.mpiwg.anteater.text.TextInformation; | |
14 import de.mpiwg.anteater.text.TextPart; | |
15 import de.mpiwg.anteater.text.TextType; | |
16 | |
17 /** | |
18 * This filter removes all applicant location that are not in a paragraph where | |
19 * there is also an applicant. | |
20 * | |
21 * @author Julia Damerow | |
22 * | |
23 */ | |
24 public class ApplicantLocWithoutApplicantFilter implements IResultFilter { | |
25 | |
26 @Override | |
27 public void filterElements(TextInformation info, | |
28 List<ApplicantResult> applicantResults, | |
29 List<SpeciesScientificResult> speciesResults, | |
30 List<LocationResult> locationResults) { | |
31 | |
32 List<TextPart> summaries = info.getSummaries(); | |
33 List<TextPart> suppleInfs = info.getSupplInfos(); | |
34 | |
35 List<LocationResult> toBeRemoved = new ArrayList<LocationResult>(); | |
36 LocationLoop: for (LocationResult locResult : locationResults) { | |
37 PlaceInformation placeCandidate = locResult.getFinding(); | |
38 if (locResult.getPrediction() != PlaceClasses.APPLICANT_LOCATION) | |
39 continue; | |
40 | |
41 TextPart text = null; | |
42 if (locResult.getResult().getType() == TextType.TYPE_SUMMARY) { | |
43 text = summaries.get(locResult.getResult().getTextIdx()); | |
44 } else | |
45 text = suppleInfs.get(locResult.getResult().getTextIdx()); | |
46 | |
47 Paragraph paragraphOfLocation = text | |
48 .getParagraphOfIndex(placeCandidate.getStart()); | |
49 | |
50 for (ApplicantResult appResult : applicantResults) { | |
51 APerson applicant = appResult.getFinding(); | |
52 | |
53 if (appResult.getResult().getType() == locResult.getResult() | |
54 .getType() | |
55 && appResult.getResult().getTextIdx() == locResult | |
56 .getResult().getTextIdx()) { | |
57 // if the paragraph where the applicant is in is the same as | |
58 // the paragraph of the location | |
59 // all good | |
60 if (paragraphOfLocation == text | |
61 .getParagraphOfIndex(applicant.getStart())) | |
62 continue LocationLoop; | |
63 } | |
64 } | |
65 | |
66 // if there can be no applicant found in same paragraph remove | |
67 // applicant location | |
68 toBeRemoved.add(locResult); | |
69 } | |
70 | |
71 locationResults.removeAll(toBeRemoved); | |
72 } | |
73 | |
74 } |