Examples of TagExtractor


Examples of com.cybozu.labs.langdetect.util.TagExtractor

        InputStream is = null;
        try {
            is = new BufferedInputStream(new FileInputStream(file));
            if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is);

            TagExtractor tagextractor = new TagExtractor("abstract", 100);

            XMLStreamReader reader = null;
            try {
                XMLInputFactory factory = XMLInputFactory.newInstance();
                reader = factory.createXMLStreamReader(is);
                while (reader.hasNext()) {
                    switch (reader.next()) {
                    case XMLStreamReader.START_ELEMENT:
                        tagextractor.setTag(reader.getName().toString());
                        break;
                    case XMLStreamReader.CHARACTERS:
                        tagextractor.add(reader.getText());
                        break;
                    case XMLStreamReader.END_ELEMENT:
                        tagextractor.closeTag(profile);
                        break;
                    }
                }
            } catch (XMLStreamException e) {
                throw new LangDetectException(ErrorCode.TrainDataFormatError, "Training database file '" + file.getName() + "' is an invalid XML.");
            } finally {
                try {
                    if (reader != null) reader.close();
                } catch (XMLStreamException e) { /* ignore exception */ }
            }
            System.out.println(lang + ":" + tagextractor.count());

        } catch (IOException e) {
            throw new LangDetectException(ErrorCode.CantOpenTrainData, "Can't open training database file '" + file.getName() + "'");
        } finally {
            IOUtils.closeQuietly(is);
View Full Code Here

Examples of com.cybozu.labs.langdetect.util.TagExtractor

        try {
            InputStream is = new FileInputStream(file);
            if (file.getName().endsWith(".gz")) is = new GZIPInputStream(is);
            br = new BufferedReader(new InputStreamReader(is, "utf-8"));

            TagExtractor tagextractor = new TagExtractor("abstract", 100);

            XMLStreamReader reader = null;
            try {
                XMLInputFactory factory = XMLInputFactory.newInstance();
                reader = factory.createXMLStreamReader(br);
                while (reader.hasNext()) {
                    switch (reader.next()) {
                    case XMLStreamReader.START_ELEMENT:
                        tagextractor.setTag(reader.getName().toString());
                        break;
                    case XMLStreamReader.CHARACTERS:
                        tagextractor.add(reader.getText());
                        break;
                    case XMLStreamReader.END_ELEMENT:
                        String text = tagextractor.closeTag();
                        if (text != null) profile.update(text);
                        break;
                    }
                }
            } catch (XMLStreamException e) {
                throw new LangDetectException(ErrorCode.TrainDataFormatError, "Training database file '" + file.getName() + "' is an invalid XML.");
            } finally {
                try {
                    if (reader != null) reader.close();
                } catch (XMLStreamException e) {}
            }
            System.out.println(lang + ":" + tagextractor.count());

        } catch (IOException e) {
            throw new LangDetectException(ErrorCode.CantOpenTrainData, "Can't open training database file '" + file.getName() + "'");
        } finally {
            try {
View Full Code Here

Examples of opennlp.ccg.realize.hypertagger.TagExtractor

    htVocabFile = options.valueOf(ht_vocab_s);
    if(options.has("q"))
      quiet = true;
    LFLoader lfs = new LFLoader(options.valueOf(gr_s), options.valueOf(corpusDir_s), options.nonOptionArguments());
    if(options.has("pos")) {
      TagExtractor tex = new ZLPOSTagger();
      if(posPriorModelFile != null && posVocabFile != null) {
        debug("Loading POS model priors from " + posPriorModelFile);
        debug("Loading POS model vocab from " + posVocabFile);
        tex.loadPriorModel(posPriorModelFile, posVocabFile);
      }
      debug("Extracting POS features...");
      t = new TagExtract(tex);
    }
    else {
      // extracting hypertags
      // using GS pos tags
      TagExtractor tex = new ZLMaxentHypertagger();
      if(htPriorModelFile != null && htVocabFile != null) {
        debug("Loading HT model priors from " + htPriorModelFile);
        debug("Loading HT model vocab from " + htVocabFile);
        tex.loadPriorModel(htPriorModelFile,htVocabFile);
      }
      if(hyperModelFile != null) {
        debug("Loading proto-HT model from " + hyperModelFile);
        tex.loadProtoModel(hyperModelFile);
      }
      debug("Extracting hypertagger features...");
      t = new TagExtract(tex);
    }
    t.setOutput(output);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.