public void parse(InputStream inputStream, ContentHandler contentHandler, Metadata metadata,
                      ParseContext parseContext) throws IOException, SAXException, TikaException {

        if (!initialized) {
            initialize(parseContext);
        }
        if (!available) {
            return;
        }

        Reader reader =
                MediaType.TEXT_PLAIN.toString().equals(metadata.get(Metadata.CONTENT_TYPE)) ?
                        new InputStreamReader(inputStream, StandardCharsets.UTF_8) :
                        secondaryParser.parse(inputStream);

        String text = IOUtils.toString(reader);
        IOUtils.closeQuietly(reader);

        for (NERecogniser ner : nerChain) {
            Map<String, Set<String>> names = ner.recognise(text);
            if (names != null) {
                for (Map.Entry<String, Set<String>> entry : names.entrySet()) {
                    if (entry.getValue() != null) {
                        String mdKey = MD_KEY_PREFIX + entry.getKey();
                        for (String name : entry.getValue()) {
                            metadata.add(mdKey, name);
                        }
                    }
                }
            }
        }
        XHTMLContentHandler xhtml = new XHTMLContentHandler(contentHandler, metadata);
        extractOutput(text.trim(), xhtml);
    }
@Test
    public void testParse() throws Exception {

        //test config is added to resources directory
        try (InputStream is = getResourceAsStream(CONFIG_FILE)) {
            TikaConfig config = new TikaConfig(is);
            Tika tika = new Tika(config);
            String text = "I am student at University of Southern California (USC)," +
                    " located in Los Angeles . USC's football team is called by name Trojans." +
                    " Mr. John McKay was a head coach of the team from 1960 - 1975";
            Metadata md = new Metadata();
            tika.parse(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)), md);

            HashSet<String> set = new HashSet<>(
                    Arrays.asList(md.getValues(TikaCoreProperties.TIKA_PARSED_BY)));
            assumeTrue(set.contains(NamedEntityParser.class.getName()));

            set.clear();
            set.addAll(Arrays.asList(md.getValues("NER_PERSON")));
            assumeTrue(set.contains("John McKay"));

            set.clear();
            set.addAll(Arrays.asList(md.getValues("NER_LOCATION")));
            assumeTrue(set.contains("Los Angeles"));

            set.clear();
            set.addAll(Arrays.asList(md.getValues("NER_ORGANIZATION")));
            assumeTrue(set.contains("University of Southern California"));

            set.clear();
            set.addAll(Arrays.asList(md.getValues("NER_DATE")));
            assumeTrue(set.contains("1960 - 1975"));
        }
    }