Package opennlp.tools.dictionary

Examples of opennlp.tools.dictionary.Dictionary$StringListWrapper


      System.exit(1);
    }

    int ai = 0;

    Dictionary abbreviations = null;
    if ("-abbreviationsDictionary".equals(args[ai])) {
      ai++;
      abbreviations = new Dictionary(new FileInputStream(args[ai++]));
    }

    boolean useTokenEnd = false;
    if ("-useTokenEnd".equals(args[ai])) {
      useTokenEnd = true;
View Full Code Here


    if (params.getMisclassified()) {
      listener = new TokenEvaluationErrorListener();
    }
   
    try {
      Dictionary dict = TokenizerTrainerTool.loadDict(params.getAbbDict());

      validator = new opennlp.tools.tokenize.TokenizerCrossValidator(
          params.getLang(), dict, params.getAlphaNumOpt(), mlParams, listener);

      validator.evaluate(sampleStream, params.getFolds());
View Full Code Here

  public static ParserModel train(String languageCode, ObjectStream<Parse> parseSamples, HeadRules rules, TrainingParameters mlParams)
          throws IOException {
   
    System.err.println("Building dictionary");
   
    Dictionary mdict = buildDictionary(parseSamples, rules, mlParams);
   
    parseSamples.reset();
   
    Map<String, String> manifestInfoEntries = new HashMap<String, String>();
   
View Full Code Here

    while (partitioner.hasNext()) {

      CrossValidationPartitioner.TrainingSampleStream<POSSample> trainingSampleStream = partitioner
          .next();
     
      Dictionary ngramDict = null;
      if (this.ngramDictionary == null) {
        if(this.ngramCutoff != null) {
          System.err.print("Building ngram dictionary ... ");
          try {
            ngramDict = POSTaggerME.buildNGramDictionary(trainingSampleStream,
View Full Code Here

    OutputStream out = null;
    try {
      in = new InputStreamReader(new FileInputStream(dictInFile), encoding);
      out = new FileOutputStream(dictOutFile);

      Dictionary dict = Dictionary.parseOneEntryPerLine(in);
      dict.serialize(out);

    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    } finally {
View Full Code Here

  public static Dictionary createOptionalDictionary(UimaContext context, String parameter)
    throws ResourceInitializationException {
  String dictionaryName = CasConsumerUtil.getOptionalStringParameter(
    context, parameter);
 
  Dictionary dictionary = null;

  if (dictionaryName != null) {

      Logger logger = context.getLogger();

      try {

    InputStream dictIn = CasConsumerUtil.getOptionalResourceAsStream(context,
      dictionaryName);

    if (dictIn == null) {
      String message = "The dictionary file " + dictionaryName +
      " does not exist!";

      if (logger.isLoggable(Level.WARNING)) {
          logger.log(Level.WARNING, message);
      }
     
      return null;
    }
   
    dictionary = new Dictionary(dictIn);

      } catch (IOException e) {
      // if this fails just print error message and continue
      String message = "IOException during dictionary reading, "
        + "running without dictionary: " + e.getMessage();
View Full Code Here

   *    built from the input file.
   * @throws IOException
   */
  public static Dictionary createDictionary(ObjectStream<StringList> sampleStream) throws IOException {

    Dictionary mNameDictionary = new Dictionary(true);
    StringList entry;

    entry = sampleStream.read();
    while (entry != null) {
      if (!mNameDictionary.contains(entry)) {
        mNameDictionary.put(entry);
      }
      entry = sampleStream.read();
    }

    return mNameDictionary;
View Full Code Here

    FileInputStream sampleDataIn = CmdLineUtil.openInFile(testData);
    ObjectStream<StringList> sampleStream = new NameFinderCensus90NameStream(sampleDataIn,
        Charset.forName(params.getEncoding()));
   
    Dictionary mDictionary;
    try {
      System.out.println("Creating Dictionary...");
      mDictionary = createDictionary(sampleStream);
    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    } finally {
      try {
        sampleStream.close();
      } catch(IOException e) {
        // sorry this can fail..
      }
    }

    System.out.println("Saving Dictionary...");
   
    OutputStream out = null;
   
    try {
      out = new FileOutputStream(dictOutFile);
      mDictionary.serialize(out);
    } catch (IOException ex) {
      System.err.println("Error during write to dictionary file: " + ex.getMessage());
      throw new TerminateToolException(-1);
    }
    finally {
View Full Code Here

   * Note: Do all initialization in this method, do not use the constructor.
   */
  public void initialize()
      throws ResourceInitializationException {
 
    Dictionary nameFinderDictionary;
   
    try {
      String modelName = AnnotatorUtil.getRequiredStringParameter(context,
          UimaUtil.DICTIONARY_PARAMETER);
     
      InputStream inModel = AnnotatorUtil
          .getResourceAsStream(context, modelName);
     
      nameFinderDictionary = new Dictionary(inModel);

    } catch (IOException e) {
      throw new ResourceInitializationException(
        ExceptionMessages.MESSAGE_CATALOG,
        ExceptionMessages.IO_ERROR_DICTIONARY_READING,
View Full Code Here

      String dictionaryParameter) throws ResourceInitializationException {

    String dictionaryName = AnnotatorUtil.getOptionalStringParameter(context,
        dictionaryParameter);

    Dictionary dictionary = null;

    if (dictionaryName != null) {

      Logger logger = context.getLogger();

      try {

        InputStream dictIn = AnnotatorUtil.getOptionalResourceAsStream(context,
            dictionaryName);

        if (dictIn == null) {
          String message = "The dictionary file " + dictionaryName
              + " does not exist!";

          if (logger.isLoggable(Level.WARNING)) {
            logger.log(Level.WARNING, message);
          }

          return null;
        }

        dictionary = new Dictionary(dictIn);

      } catch (IOException e) {
        // if this fails just print error message and continue
        String message = "IOException during dictionary reading, "
            + "running without dictionary: " + e.getMessage();
View Full Code Here

TOP

Related Classes of opennlp.tools.dictionary.Dictionary$StringListWrapper

Copyright © 2018 www.massapicom. 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.