Beispiel #1
0
  private void findAliases(Term primeTerm, String target, String prefix) {
    Morpher morpher = null;
    try {
      morpher = new Morpher(target);
      if (morpher.getData()) {
        Set<String> aliases = new HashSet<String>();
        for (Morpher.Morph morph : morpher.getAllMorph()) {
          if (morph == null) {
            return;
          }
          String alias = prefix + morph.text;
          if (morph != null && !alias.isEmpty() && !alias.equals(primeTerm.getName())) {
            if (!aliases.contains(alias)) {
              TermMorph termMorph = commonDao.get(TermMorph.class, alias);
              if (termMorph == null) {
                commonDao.save(new TermMorph(alias, primeTerm.getUri()));

                log.info("Alias added: " + alias);
              }
              aliases.add(alias);
            }
          }
        }
        /* for (Map.Entry<String, Term> entry : aliases.entrySet()) {
            if (primeTerm.getUri().equals(entry.getValue().generateUri())) continue;
            commonDao.save(new Link(primeTerm, entry.getValue(), Link.ALIAS, Link.MORPHEME_WEIGHT));
        }*/
      }
    } catch (Exception e) {
      log.throwing(getClass().getName(), "findAliases", e);
      throw new RuntimeException(e);
    }
  }
 public void saveArticle(String title, String text) {
   Assert.hasLength(title);
   Assert.hasLength(text);
   SyncStatus status = commonDao.get(SyncStatus.class, "articleName", title);
   if (status == null) {
     status = new SyncStatus();
     status.setArticleName(title);
   }
   status.setSynchronised(false);
   status.setArticleContent(text);
   commonDao.save(status);
   out.println("[Scheduled] " + title);
 }
 public void push() {
   List<SyncStatus> toBeSync = commonDao.getList(SyncStatus.class, "synchronised", false);
   toBeSync.addAll(commonDao.getList(SyncStatus.class, "synchronised", null));
   for (SyncStatus status : toBeSync) {
     SimpleArticle article = new SimpleArticle(status.getArticleName());
     article.setText(status.getArticleContent());
     getBot().writeContent(article);
     status.setSynchronised(true);
     status.setSyncDate(new Date());
     commonDao.save(status);
     out.println("[Pushed] " + article.getTitle());
   }
 }
Beispiel #4
0
  private void updateCacheSearchResult() throws IOException {
    // clean cache for search results

    String uri = UriGenerator.generate(Term.class, "");
    List<CacheEntity> searchCacheList =
        commonDao.getLike(CacheEntity.class, "uri", uri + "%", Integer.MAX_VALUE);

    for (CacheEntity cache : searchCacheList) {
      final SearchResultPage searchResult =
          (SearchResultPage)
              searchController.searchWithoutCache(
                  getValueFromUri(Term.class, cache.getUri()), 0, null);
      cache.setContent(objectMapper.writeValueAsString(searchResult));
      commonDao.save(cache);
    }
  }