comparison src/de/mpiwg/anteater/events/processors/EventCreatorProcessor.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.events.processors;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import de.mpiwg.anteater.events.Applicant;
7 import de.mpiwg.anteater.events.ResearchEvent;
8 import de.mpiwg.anteater.results.ApplicantResult;
9 import de.mpiwg.anteater.results.LocationResult;
10 import de.mpiwg.anteater.results.ResultsCarrier;
11 import de.mpiwg.anteater.results.SpeciesScientificResult;
12 import de.mpiwg.anteater.text.TextInformation;
13
14 public class EventCreatorProcessor extends AEventProcessor {
15
16 @Override
17 public void processEvents(List<ResearchEvent> events, ResultsCarrier carrier) {
18 TextInformation info = carrier.getTextInfo();
19
20 // find how many distinct applicants there are
21 List<ApplicantResult> distinctApplicants = getDistinctApplicants(carrier);
22
23 // if there is only one applicant in text
24 if (distinctApplicants.size() == 1) {
25 ResearchEvent event = createEvent(distinctApplicants.get(0), info,
26 carrier.getLocationResults(), carrier.getSpeciesResults());
27 events.add(event);
28 return;
29 }
30
31 // if there are several applicants start new event with each applicant
32 List<ApplicantResult> appsInSummary = new ArrayList<ApplicantResult>();
33 List<ApplicantResult> appsInSuppleInf = new ArrayList<ApplicantResult>();
34
35 sortByTextType(distinctApplicants, appsInSummary, appsInSuppleInf);
36
37 List<SpeciesScientificResult> speciesInSuppleInf = new ArrayList<SpeciesScientificResult>();
38 sortSpeciesByTextType(carrier.getSpeciesResults(), new ArrayList<SpeciesScientificResult>(), speciesInSuppleInf);
39
40 List<LocationResult> locationsInSuppleInf = new ArrayList<LocationResult>();
41 sortLocsByTextType(carrier.getLocationResults(), new ArrayList<LocationResult>(), locationsInSuppleInf);
42
43 // if there are no applicants in summary, start new event with every
44 // applicant
45 // unless there is no species in between
46 if (appsInSummary.isEmpty()) {
47 ResearchEvent event = null;
48 for (int i = 0; i < appsInSuppleInf.size(); i++) {
49 ApplicantResult applicant = appsInSuppleInf.get(i);
50 ApplicantResult nextApplicant = null;
51 if (i < appsInSuppleInf.size() - 1)
52 nextApplicant = appsInSuppleInf.get(i + 1);
53
54 List<SpeciesScientificResult> speciesForApp = new ArrayList<SpeciesScientificResult>();
55 List<LocationResult> locationsForApp = new ArrayList<LocationResult>();
56
57 int endOfApplicant = applicant.getFinding().getStart()
58 + applicant.getFinding().getLength();
59 int startOfNextApplicant = nextApplicant != null ? nextApplicant
60 .getFinding().getStart() : info.getSupplInfos().get(applicant.getResult().getTextIdx()).getText().length();
61
62 // find all species between current applicant and next one
63 for (SpeciesScientificResult speciesResult : speciesInSuppleInf) {
64 if (speciesResult.getFinding().getStart() > endOfApplicant
65 && speciesResult.getFinding().getStart() < startOfNextApplicant)
66 speciesForApp.add(speciesResult);
67 }
68
69 // find all locations between current applicant and next one
70 for (LocationResult locationResult : locationsInSuppleInf) {
71 if (locationResult.getFinding().getStart() >= endOfApplicant
72 && locationResult.getFinding().getStart() < startOfNextApplicant)
73 locationsForApp.add(locationResult);
74 }
75
76 // if there are no specie in between, applicant goes to last
77 // event
78 if (event != null) {
79 List<Applicant> applicantsInEvent = event.getApplicants();
80 List<Applicant> applicantsWithoutLoc = new ArrayList<Applicant>();
81
82 Applicant newApplicant = createApplicant(applicant);
83 event.getApplicants().add(newApplicant);
84
85 for (Applicant applicantInEvent : applicantsInEvent)
86 if (applicantInEvent.getApplicantInstitution()
87 .isEmpty()
88 && applicantInEvent.getLocation().isEmpty())
89 applicantsWithoutLoc.add(applicantInEvent);
90
91 setLocations(applicantsWithoutLoc, locationsForApp, event);
92 setSpecies(speciesForApp, event);
93 }
94
95 if (event == null)
96 event = createEvent(applicant, info, locationsForApp,
97 speciesForApp);
98
99 if (speciesForApp.size() > 0) {
100 events.add(event);
101 event = null;
102 }
103
104 }
105 return;
106 }
107
108 }
109
110 @Override
111 public int getRank() {
112 return 0;
113 }
114
115
116
117
118 }