Examples of SpellChecker


Examples of com.swabunga.spell.event.SpellChecker

  }

  @SuppressWarnings("unchecked")
  private void doSuggest(final String cmd, final String id,
      final JSONArray paramArray) {
    final SpellChecker checker = new SpellChecker(dict);
    String word = paramArray.optString(1);
    List<String> suggestions = checker.getSuggestions(word, 2);

    respond(suggestions.iterator(), cmd, id);
  }
View Full Code Here

Examples of com.swabunga.spell.event.SpellChecker

    respond(suggestions.iterator(), cmd, id);
  }

  private void doSpell(final String cmd, final String id,  final JSONArray paramArray) {
    final SpellChecker checker = new SpellChecker(dict);

    final Set<String> errors = new HashSet<String>();

    checker.addSpellCheckListener(new SpellCheckListener() {
      public void spellingError(SpellCheckEvent event) {
        errors.add(event.getInvalidWord());
      }
    });

    JSONArray words = paramArray.optJSONArray(1);
    checker.checkSpelling(new StringWordTokenizer(words.toString()));
    respond(errors.iterator(), cmd, id);
  }
View Full Code Here

Examples of com.swabunga.spell.event.SpellChecker

  }

  @SuppressWarnings("unchecked")
  private void doSuggest(final String cmd, final String id, final JSONArray paramArray)
  {
    final SpellChecker checker = new SpellChecker(dict);
    String word = paramArray.optString(1);
    List<String> suggestions = checker.getSuggestions(word, 2);

    respond(suggestions.iterator(), cmd, id);
  }
View Full Code Here

Examples of com.swabunga.spell.event.SpellChecker

    respond(suggestions.iterator(), cmd, id);
  }

  private void doSpell(final String cmd, final String id, final JSONArray paramArray)
  {
    final SpellChecker checker = new SpellChecker(dict);

    final Set<String> errors = new HashSet<String>();

    checker.addSpellCheckListener(new SpellCheckListener()
    {
      public void spellingError(SpellCheckEvent event)
      {
        errors.add(event.getInvalidWord());
      }
    });

    JSONArray words = paramArray.optJSONArray(1);
    checker.checkSpelling(new StringWordTokenizer(words.toString()));
    respond(errors.iterator(), cmd, id);
  }
View Full Code Here

Examples of com.swabunga.spell.event.SpellChecker

    @RequestMapping(params="words", method = RequestMethod.POST)
    public ResponseEntity<String> checkWordList(@RequestParam("words") String words){

    JSONObject response = new JSONObject();

    SpellChecker spellChecker = new SpellChecker();
        Configuration cfg = spellChecker.getConfiguration();
        cfg.setBoolean(Configuration.SPELL_IGNOREUPPERCASE, false);
       
        Checker chk = new Checker();
        spellChecker.addSpellCheckListener(chk);
        for (SpellDictionary dictionary : dictionaries) {
            spellChecker.addDictionary(dictionary);
        }
   
        chk.init(response);
        spellChecker.checkSpelling(new StringWordTokenizer(words.trim()));   
           
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        return new ResponseEntity<String>(response.toString(), headers, HttpStatus.OK);
    }
View Full Code Here

Examples of com.swabunga.spell.event.SpellChecker

    @RequestMapping(params="word", method = RequestMethod.POST)
    public ResponseEntity<String> suggestForWord(@RequestParam("word") String word){

    JSONObject response = new JSONObject();
   
    SpellChecker spellChecker = new SpellChecker();
        Configuration cfg = spellChecker.getConfiguration();
        cfg.setBoolean(Configuration.SPELL_IGNOREUPPERCASE, false);
       
        Suggester sug = new Suggester();
        spellChecker.addSpellCheckListener(sug);
        for (SpellDictionary dictionary : dictionaries) {
            spellChecker.addDictionary(dictionary);
        }
   
        sug.init(response);
        spellChecker.checkSpelling(new StringWordTokenizer(word));     
           
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        return new ResponseEntity<String>(response.toString(), headers, HttpStatus.OK);
    }
View Full Code Here

Examples of org.apache.lucene.search.spell.SpellChecker

        try {
          synchronized(spellDictionaryPath) {//o_clusterOK by:pb if service is only configured on one vm, which is recommended way
            File spellDictionaryFile = new File(spellDictionaryPath);
            Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);
            if (spellChecker==null && IndexReader.indexExists(spellIndexDirectory) && isSpellCheckEnabled ) {
              spellChecker = new SpellChecker(spellIndexDirectory);
              spellChecker.setAccuracy(0.7f);
            }
          }
         } catch (IOException e) {
           log.warn("Can not initialze SpellChecker",e);
View Full Code Here

Examples of org.apache.lucene.search.spell.SpellChecker

        Directory indexDir = FSDirectory.open(new File(indexPath));
        indexReader = IndexReader.open(indexDir);
        // 1. Create content spellIndex
        File spellDictionaryFile = new File(spellDictionaryPath);
        Directory contentSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + CONTENT_PATH));//true
        SpellChecker contentSpellChecker = new SpellChecker(contentSpellIndexDirectory);
        Dictionary contentDictionary = new LuceneDictionary(indexReader, OlatDocument.CONTENT_FIELD_NAME);
        contentSpellChecker.indexDictionary(contentDictionary);
        // 2. Create title spellIndex
        Directory titleSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + TITLE_PATH));//true
        SpellChecker titleSpellChecker = new SpellChecker(titleSpellIndexDirectory);
        Dictionary titleDictionary = new LuceneDictionary(indexReader, OlatDocument.TITLE_FIELD_NAME);
        titleSpellChecker.indexDictionary(titleDictionary);
        // 3. Create description spellIndex
        Directory descriptionSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + DESCRIPTION_PATH));//true
        SpellChecker descriptionSpellChecker = new SpellChecker(descriptionSpellIndexDirectory);
        Dictionary descriptionDictionary = new LuceneDictionary(indexReader, OlatDocument.DESCRIPTION_FIELD_NAME);
        descriptionSpellChecker.indexDictionary(descriptionDictionary);
        // 4. Create author spellIndex
        Directory authorSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + AUTHOR_PATH));//true
        SpellChecker authorSpellChecker = new SpellChecker(authorSpellIndexDirectory);
        Dictionary authorDictionary = new LuceneDictionary(indexReader, OlatDocument.AUTHOR_FIELD_NAME);
        authorSpellChecker.indexDictionary(authorDictionary);
       
        // Merge all part spell indexes (content,title etc.) to one common spell index
        Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);//true
        IndexWriter merger = new IndexWriter(spellIndexDirectory, new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
        Directory[] directories = { contentSpellIndexDirectory, titleSpellIndexDirectory, descriptionSpellIndexDirectory, authorSpellIndexDirectory};
        merger.addIndexesNoOptimize(directories);
        merger.optimize();
        merger.close();
        spellChecker = new SpellChecker(spellIndexDirectory);
        spellChecker.setAccuracy(0.7f);
         if (log.isDebug()) log.debug("SpellIndex created in " + (System.currentTimeMillis() - startSpellIndexTime) + "ms");
        log.info("New generated Spell-Index ready to use.");
      } catch(IOException ioEx) {
        log.warn("Can not create SpellIndex",ioEx);
View Full Code Here

Examples of org.apache.lucene.search.spell.SpellChecker

    } else {
      sd = new LevensteinDistance();
    }
    try {
      initIndex();
      spellChecker = new SpellChecker(index, sd, comp);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    if (accuracy != null) {
      try {
View Full Code Here

Examples of org.apache.lucene.search.spell.SpellChecker

        log.info("using spell directory: " + dirDescription);
        spellcheckerIndexDir = FSDirectory.open(f);
      } else {
        log.info("using RAM based spell directory");
      }
      spellChecker = new SpellChecker(spellcheckerIndexDir);
    } catch (IOException e) {
      throw new RuntimeException("Cannot open SpellChecker index", e);
    }
  }
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.