0
|
1 package de.mpiwg.anteater.results.filter;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.List;
|
|
5
|
|
6 import de.mpiwg.anteater.results.ApplicantResult;
|
|
7 import de.mpiwg.anteater.results.LocationResult;
|
|
8 import de.mpiwg.anteater.results.SpeciesScientificResult;
|
|
9 import de.mpiwg.anteater.text.Paragraph;
|
|
10 import de.mpiwg.anteater.text.TextInformation;
|
|
11 import de.mpiwg.anteater.text.TextPart;
|
|
12 import de.mpiwg.anteater.text.TextType;
|
|
13
|
|
14 public class SpeciesInBetweenRegexApplicantFilter implements IResultFilter {
|
|
15
|
|
16 @Override
|
|
17 public void filterElements(TextInformation info,
|
|
18 List<ApplicantResult> applicantResults,
|
|
19 List<SpeciesScientificResult> speciesResults,
|
|
20 List<LocationResult> locationResults) {
|
|
21
|
|
22 List<TextPart> summaries = info.getSummaries();
|
|
23 List<TextPart> suppleInfs = info.getSupplInfos();
|
|
24 for (ApplicantResult applicant : applicantResults) {
|
|
25
|
|
26 // if applicant was found with regex there can't be a species in it
|
|
27 if (applicant.getPrediction() == 2.0) {
|
|
28 TextPart part;
|
|
29
|
|
30 if (applicant.getResult().getType() == TextType.TYPE_SUMMARY)
|
|
31 part = summaries.get(applicant.getResult().getTextIdx());
|
|
32 else
|
|
33 part = suppleInfs.get(applicant.getResult().getTextIdx());
|
|
34
|
|
35 Paragraph paragraph = part.getParagraphOfIndex(applicant.getFinding().getStart());
|
|
36
|
|
37 List<SpeciesScientificResult> toBeRemoved = new ArrayList<SpeciesScientificResult>();
|
|
38 for (SpeciesScientificResult species : speciesResults) {
|
|
39 // if species is from same text type and text index
|
|
40 if (species.getResult().getType() == applicant.getResult().getType() && species.getResult().getTextIdx() == applicant.getResult().getTextIdx()) {
|
|
41 // if species is not in same paragraph as applicant all is good
|
|
42 if (part.getParagraphOfIndex(species.getFinding().getStart()) != paragraph)
|
|
43 continue;
|
|
44 }
|
|
45 toBeRemoved.add(species);
|
|
46 }
|
|
47
|
|
48 speciesResults.removeAll(toBeRemoved);
|
|
49 }
|
|
50 }
|
|
51 }
|
|
52
|
|
53 }
|