Package opennlp.tools.dictionary

Examples of opennlp.tools.dictionary.Dictionary


        Map<String, Dictionary> dictionaries = new HashMap<String, Dictionary>();
        Iterable<DictionaryEntry> entries = dictionaryEntryRepository.findAll(getUser().getModelUserContext());
        for (DictionaryEntry entry : entries) {

            if (!dictionaries.containsKey(entry.getMetadata().getConcept())) {
                dictionaries.put(entry.getMetadata().getConcept(), new Dictionary());
            }

            dictionaries.get(entry.getMetadata().getConcept()).put(tokensToStringList(entry.getMetadata().getTokens()));
        }
View Full Code Here


        assertTrue("Boston , MA not found", signs.contains("Boston , MA"));
    }

    private List<TokenNameFinder> loadFinders() {
        List<TokenNameFinder> finders = new ArrayList<TokenNameFinder>();
        Dictionary people = new Dictionary();
        people.put(new StringList("Bob Robertson".split(" ")));
        finders.add(new DictionaryNameFinder(people, "person"));

        Dictionary locations = new Dictionary();
        locations.put(new StringList("Boston , MA".split(" ")));
        finders.add(new DictionaryNameFinder(locations, "location"));

        Dictionary organizations = new Dictionary();
        organizations.put(new StringList("Altamira Corporation".split(" ")));
        finders.add(new DictionaryNameFinder(organizations, "organization"));

        return finders;
    }
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

   * 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

  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

    public DummyDictionary(Dictionary dict) {
      this.indict = dict;
    }

    public DummyDictionary(InputStream in) throws IOException {
      this.indict = new Dictionary(in);
    }
View Full Code Here

   *
   * @return a dictionary of the ngrams
   */
  public Dictionary toDictionary(boolean caseSensitive) {

    Dictionary dict = new Dictionary(caseSensitive);

    for (Iterator<StringList> it = iterator(); it.hasNext();) {
      dict.put(it.next());
    }

    return dict;
  }
View Full Code Here

  throws IOException {
   
    Map<String, String> manifestInfoEntries = new HashMap<String, String>();
   
    System.err.println("Building dictionary");
    Dictionary mdict = buildDictionary(parseSamples, rules, mlParams);
   
    parseSamples.reset();
   
    // tag
    POSModel posModel = POSTaggerME.train(languageCode, new PosSampleStream(
View Full Code Here

    return new TokenSampleStream(lineStream);
  }
 
  static Dictionary loadDict(File f) throws IOException {
    Dictionary dict = null;
    if (f != null) {
      CmdLineUtil.checkInputFile("abb dict", f);
      dict = new Dictionary(new FileInputStream(f));
    }
    return dict;
  }
View Full Code Here

    if(mlParams == null)
      mlParams = createTrainingParameters(params.getIterations(), params.getCutoff());

    TokenizerModel model;
    try {
      Dictionary dict = loadDict(params.getAbbDict());
      model = opennlp.tools.tokenize.TokenizerME.train(params.getLang(),
          sampleStream, dict, params.getAlphaNumOpt(), mlParams);
    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
View Full Code Here

TOP

Related Classes of opennlp.tools.dictionary.Dictionary

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.