Package opennlp.tools.util

Examples of opennlp.tools.util.InvalidFormatException


    Class<?> generatorFactoryClass = classSerializer.create(in);
   
    try {
      return (FeatureGeneratorFactory) generatorFactoryClass.newInstance();
    } catch (InstantiationException e) {
      throw new InvalidFormatException(e);
    } catch (IllegalAccessException e) {
      throw new InvalidFormatException(e);
    }
  }
View Full Code Here


          break;
        }
      }

      if (nestedGeneratorElement == null) {
        throw new InvalidFormatException("window feature generator must contain" +
            "a agregator element");
      }
     
      AdaptiveFeatureGenerator nestedGenerator = GeneratorFactory.createGenerator(nestedGeneratorElement, resourceManager);
     
      String prevLengthString = generatorElement.getAttribute("prevLength");

      int prevLength;

      try {
        prevLength = Integer.parseInt(prevLengthString);
      } catch (NumberFormatException e) {
        throw new InvalidFormatException("prevLength attribute is not a number!");
      }
     
      String nextLengthString = generatorElement.getAttribute("nextLength");

      int nextLength;

      try {
        nextLength = Integer.parseInt(nextLengthString);
      } catch (NumberFormatException e) {
        throw new InvalidFormatException("nextLength attribute is not a number!");
     
     
      return new WindowFeatureGenerator(nestedGenerator, prevLength, nextLength);
    }
View Full Code Here

     
      AdaptiveFeatureGenerator generator = null;
      try {
        generator = (AdaptiveFeatureGenerator) featureGenClass.newInstance();
      } catch (InstantiationException e) {
        throw new InvalidFormatException("Failed to instantiate custom class!", e);
      } catch (IllegalAccessException e) {
        throw new InvalidFormatException("Failed to instantiate custom class!", e);
      }
     
      return generator;
    }
View Full Code Here

  @Override
  protected void validateArtifactMap() throws InvalidFormatException {
    super.validateArtifactMap();

    if (!(artifactMap.get(POS_MODEL_ENTRY_NAME) instanceof AbstractModel)) {
      throw new InvalidFormatException("POS model is incomplete!");
    }

    // Ensure that the tag dictionary is compatible with the model
    Object tagdictEntry = artifactMap.get(TAG_DICTIONARY_ENTRY_NAME);

    if (tagdictEntry != null) {
      if (tagdictEntry instanceof POSDictionary) {
        POSDictionary posDict = (POSDictionary) tagdictEntry;
       
        Set<String> dictTags = new HashSet<String>();
       
        for (String word : posDict) {
          Collections.addAll(dictTags, posDict.getTags(word));
        }
       
        Set<String> modelTags = new HashSet<String>();
       
        AbstractModel posModel = getPosModel();
       
        for  (int i = 0; i < posModel.getNumOutcomes(); i++) {
          modelTags.add(posModel.getOutcome(i));
        }
       
        if (!modelTags.containsAll(dictTags)) {
          throw new InvalidFormatException("Tag dictioinary contains tags " +
              "which are unkown by the model!");
        }
      }
      else {
        throw new InvalidFormatException("Abbreviations dictionary has wrong type!");
      }
    }

    Object ngramDictEntry = artifactMap.get(NGRAM_DICTIONARY_ENTRY_NAME);

    if (ngramDictEntry != null && !(ngramDictEntry instanceof Dictionary)) {
      throw new InvalidFormatException("NGram dictionary has wrong type!");
    }
  }
View Full Code Here

    };

    try {
      return loader.loadClass(CLASS_SEARCH_NAME);
    } catch (ClassNotFoundException e) {
      throw new InvalidFormatException(e);
    }
  }
View Full Code Here

    for (int i = 0; i < tokenTags.length; i++) {
      int split = tokenTags[i].lastIndexOf("_");

      if (split == -1) {
        throw new InvalidFormatException("Cannot find \"_\" inside token!");
      }

      sentence[i] = tokenTags[i].substring(0, split);
      tags[i] = tokenTags[i].substring(split+1);
    }
View Full Code Here

  @Override
  protected void validateArtifactMap() throws InvalidFormatException {
    super.validateArtifactMap();

    if (!(artifactMap.get(CHUNKER_MODEL_ENTRY_NAME) instanceof AbstractModel)) {
      throw new InvalidFormatException("Chunker model is incomplete!");
    }
  }
View Full Code Here

    } catch (Exception e) {
      String msg = "Could not instantiate the " + subclassName
          + ". The initialization throw an exception.";
      System.err.println(msg);
      e.printStackTrace();
      throw new InvalidFormatException(msg, e);
    }
  }
View Full Code Here

  @Override
  protected void validateArtifactMap() throws InvalidFormatException {
    super.validateArtifactMap();
   
    if (!(artifactMap.get(BUILD_MODEL_ENTRY_NAMEinstanceof AbstractModel)) {
      throw new InvalidFormatException("Missing the build model!");
    }
   
    ParserType modelType = getParserType();
   
    if (modelType != null) {
      if (ParserType.CHUNKING.equals(modelType)) {
        if (artifactMap.get(ATTACH_MODEL_ENTRY_NAME) != null)
            throw new InvalidFormatException("attachModel must be null for chunking parser!");
      }
      else if (ParserType.TREEINSERT.equals(modelType)) {
        if (!(artifactMap.get(ATTACH_MODEL_ENTRY_NAMEinstanceof AbstractModel))
          throw new InvalidFormatException("attachModel must not be null!");
      }
      else {
        throw new InvalidFormatException("Unknown ParserType '" + modelType + "'!");
      }
    }
    else {
      throw new InvalidFormatException("Missing the parser type property!");
    }
   
    if (!(artifactMap.get(CHECK_MODEL_ENTRY_NAMEinstanceof AbstractModel)) {
      throw new InvalidFormatException("Missing the check model!");
    }
   
    if (!(artifactMap.get(PARSER_TAGGER_MODEL_ENTRY_NAMEinstanceof POSModel)) {
      throw new InvalidFormatException("Missing the tagger model!");
    }
   
    if (!(artifactMap.get(CHUNKER_TAGGER_MODEL_ENTRY_NAMEinstanceof ChunkerModel)) {
      throw new InvalidFormatException("Missing the chunker model!");
    }
   
    if (!(artifactMap.get(HEAD_RULES_MODEL_ENTRY_NAMEinstanceof HeadRules)) {
      throw new InvalidFormatException("Missing the head rules!");
    }
  }
View Full Code Here

            if (startDocElement < endDocElement) {
              docs.add(newDocs.substring(startDocElement, endDocElement + DOC_END_ELEMENT.length()));
              docStartOffset = endDocElement + DOC_END_ELEMENT.length();
            }
            else {
              throw new InvalidFormatException("<DOC> element is not closed!");
            }
          }
          else if (startDocElement != endDocElement) {
            throw new InvalidFormatException("Missing <DOC> or </DOC> element!");           
          }
          else {
            break;
          }
        }
View Full Code Here

TOP

Related Classes of opennlp.tools.util.InvalidFormatException

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.