@Test public void testExtractProperties() { QueryStringToPropertiesExtractor extractor = new GenusSpeciesInfraspeciesToPropertiesConverter(); Property expectedGenus = new Property(); Property expectedSpecies = new Property(); Property expectedInfraspecies = new Property(); Property expectedAuthors = new Property(); expectedGenus.setP("genus"); expectedGenus.setPid("genus"); expectedSpecies.setP("species"); expectedSpecies.setPid("species"); expectedInfraspecies.setP("infraspecies"); expectedInfraspecies.setPid("infraspecies"); expectedAuthors.setP("authors"); expectedAuthors.setPid("authors"); expectedGenus.setV("Fagaceae"); assertThat(asList(extractor.extractProperties("Fagaceae")), hasItems(expectedGenus)); assertThat(asList(extractor.extractProperties("Fagaceae")).size(), equalTo(1)); expectedGenus.setV("Fagaceae"); expectedAuthors.setV("Juss."); assertThat(asList(extractor.extractProperties("Fagaceae Juss.")), hasItems(expectedGenus, expectedAuthors)); assertThat(asList(extractor.extractProperties("Fagaceae Juss.")).size(), equalTo(2)); expectedGenus.setV("Barnadesioidae"); expectedAuthors.setV("K.Bremer & R.K.Jansen"); assertThat(asList(extractor.extractProperties("Barnadesioidae K.Bremer & R.K.Jansen")), hasItems(expectedGenus, expectedAuthors)); assertThat(asList(extractor.extractProperties("Barnadesioidae K.Bremer & R.K.Jansen")).size(), equalTo(2)); expectedGenus.setV("Chaenactideae"); expectedAuthors.setV("B.G.Baldwin"); assertThat(asList(extractor.extractProperties("Chaenactideae B.G.Baldwin")), hasItems(expectedGenus, expectedAuthors)); assertThat(asList(extractor.extractProperties("Chaenactideae B.G.Baldwin")).size(), equalTo(2)); expectedGenus.setV("Quercus"); assertThat(asList(extractor.extractProperties("Quercus")), hasItems(expectedGenus)); assertThat(asList(extractor.extractProperties("Quercus")).size(), equalTo(1)); expectedGenus.setV("Quercus"); expectedAuthors.setV("L."); assertThat(asList(extractor.extractProperties("Quercus L.")), hasItems(expectedGenus, expectedAuthors)); assertThat(asList(extractor.extractProperties("Quercus L.")).size(), equalTo(2)); expectedGenus.setV("Quercus"); expectedSpecies.setV("alba"); assertThat(asList(extractor.extractProperties("Quercus alba")), hasItems(expectedGenus, expectedSpecies)); assertThat(asList(extractor.extractProperties("Quercus alba")).size(), equalTo(2)); expectedGenus.setV("Quercus"); expectedSpecies.setV("alba"); expectedAuthors.setV("L."); assertThat(asList(extractor.extractProperties("Quercus alba L.")), hasItems(expectedGenus, expectedSpecies, expectedAuthors)); assertThat(asList(extractor.extractProperties("Quercus alba L.")).size(), equalTo(3)); expectedGenus.setV("Quercus"); expectedSpecies.setV("alba"); expectedInfraspecies.setV("alba"); assertThat(asList(extractor.extractProperties("Quercus alba f. alba")), hasItems(expectedGenus, expectedSpecies, expectedInfraspecies)); assertThat(asList(extractor.extractProperties("Quercus alba f. alba")).size(), equalTo(3)); expectedGenus.setV("Quercus"); expectedSpecies.setV("alba"); expectedInfraspecies.setV("viridis"); expectedAuthors.setV("Trel."); assertThat(asList(extractor.extractProperties("Quercus alba f. viridis Trel.")), hasItems(expectedGenus, expectedSpecies, expectedInfraspecies, expectedAuthors)); assertThat(asList(extractor.extractProperties("Quercus alba f. viridis Trel.")).size(), equalTo(4)); expectedGenus.setV("Quercus"); expectedSpecies.setV("alba"); expectedInfraspecies.setV("latiloba"); expectedAuthors.setV("(Sarg.) E.J.Palmer & Steyerm."); assertThat(asList(extractor.extractProperties("Quercus alba f. latiloba (Sarg.) E.J.Palmer & Steyerm.")), hasItems(expectedGenus, expectedSpecies, expectedInfraspecies, expectedAuthors)); assertThat(asList(extractor.extractProperties("Quercus alba f. latiloba (Sarg.) E.J.Palmer & Steyerm.")).size(), equalTo(4)); expectedGenus.setV("Jaffueliobryum"); expectedSpecies.setV("arsenei"); expectedAuthors.setV("(Thér.) Thér."); assertThat(asList(extractor.extractProperties("Jaffueliobryum arsenei (Thér.) Thér.")), hasItems(expectedGenus, expectedSpecies, expectedAuthors)); assertThat(asList(extractor.extractProperties("Jaffueliobryum arsenei (Thér.) Thér.")).size(), equalTo(3)); }
@Override public Property[] extractProperties(String queryString) { queryString = queryString.replace(" ", " "); String[] parts = queryString.split(" "); String genus = null, species = null, infraspecies = null, authors = null; genus = parts[0]; if (parts.length == 1) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[1].charAt(0)) || parts[1].charAt(0) == '(') { authors = joinRest(parts, 1); } else { species = parts[1]; if (parts.length == 2) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[2].charAt(0)) || parts[2].charAt(0) == '(') { authors = joinRest(parts, 2); } else { if (parts.length == 3) return makeProperties(genus, species, infraspecies, authors); infraspecies = parts[3]; if (parts.length == 4) return makeProperties(genus, species, infraspecies, authors); authors = joinRest(parts, 4); } } return makeProperties(genus, species, infraspecies, authors); }
GenusSpeciesInfraspeciesToPropertiesConverter implements QueryStringToPropertiesExtractor { @Override public Property[] extractProperties(String queryString) { queryString = queryString.replace(" ", " "); String[] parts = queryString.split(" "); String genus = null, species = null, infraspecies = null, authors = null; genus = parts[0]; if (parts.length == 1) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[1].charAt(0)) || parts[1].charAt(0) == '(') { authors = joinRest(parts, 1); } else { species = parts[1]; if (parts.length == 2) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[2].charAt(0)) || parts[2].charAt(0) == '(') { authors = joinRest(parts, 2); } else { if (parts.length == 3) return makeProperties(genus, species, infraspecies, authors); infraspecies = parts[3]; if (parts.length == 4) return makeProperties(genus, species, infraspecies, authors); authors = joinRest(parts, 4); } } return makeProperties(genus, species, infraspecies, authors); } }
GenusSpeciesInfraspeciesToPropertiesConverter implements QueryStringToPropertiesExtractor { @Override public Property[] extractProperties(String queryString) { queryString = queryString.replace(" ", " "); String[] parts = queryString.split(" "); String genus = null, species = null, infraspecies = null, authors = null; genus = parts[0]; if (parts.length == 1) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[1].charAt(0)) || parts[1].charAt(0) == '(') { authors = joinRest(parts, 1); } else { species = parts[1]; if (parts.length == 2) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[2].charAt(0)) || parts[2].charAt(0) == '(') { authors = joinRest(parts, 2); } else { if (parts.length == 3) return makeProperties(genus, species, infraspecies, authors); infraspecies = parts[3]; if (parts.length == 4) return makeProperties(genus, species, infraspecies, authors); authors = joinRest(parts, 4); } } return makeProperties(genus, species, infraspecies, authors); }  }
GenusSpeciesInfraspeciesToPropertiesConverter implements QueryStringToPropertiesExtractor { @Override public Property[] extractProperties(String queryString) { queryString = queryString.replace(" ", " "); String[] parts = queryString.split(" "); String genus = null, species = null, infraspecies = null, authors = null; genus = parts[0]; if (parts.length == 1) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[1].charAt(0)) || parts[1].charAt(0) == '(') { authors = joinRest(parts, 1); } else { species = parts[1]; if (parts.length == 2) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[2].charAt(0)) || parts[2].charAt(0) == '(') { authors = joinRest(parts, 2); } else { if (parts.length == 3) return makeProperties(genus, species, infraspecies, authors); infraspecies = parts[3]; if (parts.length == 4) return makeProperties(genus, species, infraspecies, authors); authors = joinRest(parts, 4); } } return makeProperties(genus, species, infraspecies, authors); }  @Override Property[] extractProperties(String queryString); }
GenusSpeciesInfraspeciesToPropertiesConverter implements QueryStringToPropertiesExtractor { @Override public Property[] extractProperties(String queryString) { queryString = queryString.replace(" ", " "); String[] parts = queryString.split(" "); String genus = null, species = null, infraspecies = null, authors = null; genus = parts[0]; if (parts.length == 1) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[1].charAt(0)) || parts[1].charAt(0) == '(') { authors = joinRest(parts, 1); } else { species = parts[1]; if (parts.length == 2) return makeProperties(genus, species, infraspecies, authors); if (isCapital(parts[2].charAt(0)) || parts[2].charAt(0) == '(') { authors = joinRest(parts, 2); } else { if (parts.length == 3) return makeProperties(genus, species, infraspecies, authors); infraspecies = parts[3]; if (parts.length == 4) return makeProperties(genus, species, infraspecies, authors); authors = joinRest(parts, 4); } } return makeProperties(genus, species, infraspecies, authors); }  @Override Property[] extractProperties(String queryString);  }