GeoParser extends AbstractParser { @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { GeoParserConfig geoParserConfig = context.get(GeoParserConfig.class, defaultConfig); initialize(geoParserConfig); if (!isAvailable(geoParserConfig)) { return; } NameEntityExtractor extractor = null; try { extractor = new NameEntityExtractor(nameFinder); } catch (Exception e) { LOG.warn("Named Entity Extractor setup failed: {}", e.getMessage(), e); return; } extractor.getAllNameEntitiesfromInput(stream); extractor.getBestNameEntity(); ArrayList<String> locationNameEntities = extractor.locationNameEntities; String bestner = extractor.bestNameEntity; Map<String, List<Location>> resolvedGeonames = searchGeoNames(locationNameEntities); GeoTag geotag = new GeoTag(); geotag.toGeoTag(resolvedGeonames, bestner); metadata.add("Geographic_NAME", geotag.location.getName()); metadata.add("Geographic_LONGITUDE", geotag.location.getLongitude()); metadata.add("Geographic_LATITUDE", geotag.location.getLatitude()); for (int i = 0; i < geotag.alternatives.size(); ++i) { GeoTag alter = (GeoTag) geotag.alternatives.get(i); metadata.add("Optional_NAME" + (i + 1), alter.location.getName()); metadata.add("Optional_LONGITUDE" + (i + 1), alter.location.getLongitude()); metadata.add("Optional_LATITUDE" + (i + 1), alter.location.getLatitude()); } }  @Override Set<MediaType> getSupportedTypes(ParseContext parseContext); void initialize(GeoParserConfig geoParserConfig); @Override void parse(InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); Map<String, List<Location>> searchGeoNames(
            ArrayList<String> locationNameEntities); boolean isAvailable(GeoParserConfig geoParserConfig); @Field void setGazetteerRestEndpoint(String gazetteerRestEndpoint); @Field void setNerModelUrl(String nerModelUrl); String getGazetteerRestEndpoint(); URL getNerModelUrl();  }
@Test public void testNulls() throws IOException, SAXException, TikaException { String text = ""; Metadata metadata = new Metadata(); ParseContext context = new ParseContext(); GeoParserConfig config = new GeoParserConfig(); context.set(GeoParserConfig.class, config); geoparser.parse(new ByteArrayInputStream(text.getBytes(UTF_8)), new BodyContentHandler(), metadata, context); assertNull(metadata.get("Geographic_NAME")); assertNull(metadata.get("Geographic_LONGITUDE")); assertNull(metadata.get("Geographic_LATITUDE")); }