it.tidalwave.bluebill.taxonomy.birds.roberts.RobertsVIIImporter Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueBill Resources - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it
* SCM: https://java.net/hg/bluebill~resources-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.taxonomy.birds.roberts;
import javax.annotation.Nonnull;
import java.util.Scanner;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import it.tidalwave.role.LocalizedDisplayable;
import it.tidalwave.util.logging.Logger;
import org.openrdf.repository.Repository;
import it.tidalwave.bluebill.taxonomy.Taxonomy;
import it.tidalwave.bluebill.taxonomy.Taxon;
import it.tidalwave.bluebill.taxonomy.birds.BirdTaxonomyImporter;
import static it.tidalwave.bluebill.taxonomy.elmo.ElmoTaxonomyVocabulary.*;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class RobertsVIIImporter extends BirdTaxonomyImporter
{
private static final String CLASS = RobertsVIIImporter.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
private static final String[] LANGUAGES = new String[] { "en_us", "fr_ca"};
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Taxonomy run (final @Nonnull Repository repository,
final @Nonnull String taxonomyName)
throws Exception
{
init(repository);
final String idPrefix = ID_TAXONOMY_PREFIX + "Roberts/VII";
final Taxonomy taxonomy = createTaxonomy(repository, idPrefix, RobertsVIIImporter.class, LANGUAGES);
final Taxon aves = createAves(taxonomy, idPrefix);
final InputStream is = getClass().getResourceAsStream("RobertsVII.csv");
final BufferedReader br = new BufferedReader(new InputStreamReader(is, "iso-8859-1"));
br.readLine();
br.readLine();
for (;;)
{
String s = br.readLine();
if (s == null)
{
break;
}
s = s.trim();
logger.fine(s);
s = taxonTranslator.fixTypos(s);
// Order;Family;Latin Name;English Name;Afrikaans Name;German Name
final Scanner scanner = new Scanner(s).useDelimiter(";");
final String orderName = scanner.next().trim();
final String familyName = scanner.next().trim();
final String scientificName = scanner.next().trim();
final Scanner scanner2 = new Scanner(scientificName).useDelimiter(" ");
final String genusName = scanner2.next().trim();
final String speciesName = scanner2.next().trim();
String englishName = scanner.next().trim();
String afrikaansName = scanner.next().trim();
String germanName = scanner.next().trim();
logger.info("%s %s %s %s %s %s %s", orderName, familyName, orderName, speciesName, englishName, afrikaansName, germanName);
final LocalizedDisplayable commonNames = createDisplayable("en", englishName,
"de", germanName,
"af", afrikaansName);
createPath(aves, idPrefix, orderName, familyName, genusName, speciesName, null, NO_COMMON_NAMES, commonNames);
}
br.close();
taxonUniqueIdManager.close();
return taxonomy;
}
}