Package org.olat.core.commons.services.text

Examples of org.olat.core.commons.services.text.TextService


   * @param m the message
   */
  public void updateCounters(Message m) {
    String body = m.getBody();
    String unQuotedBody = new QuoteAndTagFilter().filter(body);
    TextService txtService = (TextService)ServiceFactory.getService(TextService.class);
    Locale suggestedLocale = txtService.detectLocale(unQuotedBody);
    m.setNumOfWords(txtService.wordCount(unQuotedBody, suggestedLocale));
    m.setNumOfCharacters(txtService.characterCount(unQuotedBody, suggestedLocale));
  }
View Full Code Here


  private void migrateMessages(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_MIGRATE_FORUMS_MESSAGES)) {
      log.audit("+-----------------------------------------------------------------------------+");
      log.audit("+... Calcualating word and character count in existing forum posts         ...+");
      log.audit("+-----------------------------------------------------------------------------+");
      TextService languageService = new TextServiceImpl();
     
      int counter = 0;
      ForumManager fMgr = ForumManager.getInstance();
      List<Long> allForumKeys = fMgr.getAllForumKeys();
      if (log.isDebug()) log.info("Found " + allForumKeys.size() + " forums to migrate.");

      for(Long forumKey:allForumKeys) {
        List<Message> allMessages = fMgr.getMessagesByForumID(forumKey);
        for (Message message : allMessages) {
          try{
            String body = message.getBody();
            Locale locale = languageService.detectLocale(body);
            int characters = languageService.characterCount(body, locale);
            message.setNumOfCharacters(characters);
            int words = languageService.wordCount(body, locale);
            message.setNumOfWords(words);
            counter++;
           
            DBFactory.getInstance().updateObject(message);
           
View Full Code Here

  /**
   * Test pass if the detection is better as 80%
   */
  public void testDetectLanguage() {
    double count = 0;
    TextService languageService = new TextServiceImpl();
    for(TestTextCase.Text text:TestTextCase.getCases()) {
      Locale locale = languageService.detectLocale(text.getText());
      if(locale != null && locale.getLanguage().equals(text.getLanguage())) {
        count++;
      }
    }
    double ratio = count / TestTextCase.getCases().length;
View Full Code Here

    double ratio = count / TestTextCase.getCases().length;
    assertTrue(ratio > 0.8d);
  }
 
  public void testWordCount() {
    TextService languageService = new TextServiceImpl();
    for(TestTextCase.Text text:TestTextCase.getCases()) {
      Locale locale = new Locale(text.getLanguage());
      int words = languageService.wordCount(text.getText(), locale);
      assertTrue(words == text.getWords());
    }
  }
View Full Code Here

      assertTrue(words == text.getWords());
    }
  }
 
  public void testCharacterCount() {
    TextService languageService = new TextServiceImpl();
    for(TestTextCase.Text text:TestTextCase.getCases()) {
      Locale locale = new Locale(text.getLanguage());
      int characters = languageService.characterCount(text.getText(), locale);
      assertTrue(characters == text.getCharacters());
    }
  }
View Full Code Here

TOP

Related Classes of org.olat.core.commons.services.text.TextService

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.