示例#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);
    }
  }
示例#2
0
  public static String getName(String categoryId, String TermId) {
    Term term = getTerm(categoryId, TermId);
    if (term == null) {
      return "";
    }

    return term.getName();
  }
示例#3
0
 public static String getIdByName(String categoryId, String name) {
   List<Term> termList = getTermList(categoryId);
   for (Term term : termList) {
     if (name.equals(term.getName())) {
       return term.getId();
     }
   }
   return "";
 }
 public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx)
     throws TermWareException {
   if (!t.getName().equals("javaStrategy")) return t;
   if (t.getArity() != 2) {
     return t;
   }
   sys.getInstance().addJavaStrategy(t.getSubtermAt(0).getName(), t.getSubtermAt(1).getName());
   ctx.setChanged(true);
   return TermFactory.createBoolean(true);
 }
示例#5
0
  public Term add(String name, String shortDescription, String description) {
    name = name.replace("\"", "").replace("«", "").replace("»", "").trim();
    name =
        WordUtils.capitalize(
            name,
            new char[] {
              '@'
            }); // Делаем первую букву большой, @ - знак который не появляеться в названии, чтобы
    // поднялась только первая буква всей фразы
    Term term = termDao.getByName(name);
    if (term == null) {
      term = termDao.save(new Term(name, shortDescription, description));
      if (shortDescription != null)
        term.setTaggedShortDescription(termsMarker.mark(shortDescription));
      if (description != null) term.setTaggedDescription(termsMarker.mark(description));
      String termName = term.getName();
      log.info("Added: " + termName);
      if (TermUtils.isComposite(termName)) {
        String target = TermUtils.getNonCosmicCodePart(termName);
        if (target != null) {
          findAliases(term, target, termName.replace(target, ""));
        }
      } else if (!TermUtils.isCosmicCode(termName)) {
        findAliases(term, termName, "");
      }
      publisher.publishEvent(new NewTermEvent(term));
    } else {
      String oldShortDescription = null;
      if (shortDescription != null && !shortDescription.isEmpty()) {
        oldShortDescription = term.getShortDescription();
        term.setShortDescription(shortDescription);
        term.setTaggedShortDescription(termsMarker.mark(shortDescription));
      }
      String oldDescription = null;
      if (description != null && !description.isEmpty()) {
        oldDescription = term.getDescription();
        term.setDescription(description);
        term.setTaggedDescription(termsMarker.mark(description));
      }
      termDao.save(term);
      publisher.publishEvent(new TermUpdatedEvent(term, oldShortDescription, oldDescription));
    }

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                termsMap.reload();
              }
            })
        .start();

    return term;
  }
示例#6
0
 public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx)
     throws TermWareException {
   if (!t.getName().equals("printTerm")) return t;
   if (sys.isLoggingMode()) {
     sys.getEnv().getLog().print("native:");
     t.print(sys.getEnv().getLog());
     sys.getEnv().getLog().println();
   }
   Term retval = t;
   if (t.getArity() == 1) {
     t.getSubtermAt(0).print(sys.getEnv().getOutput());
     retval = t.getSubtermAt(0);
   } else if (t.getArity() == 2 || t.getArity() == 3) {
     // TODO:
     //    1.  check that name and language is string
     //    2.  outTag can be parameter.
     String printerName = t.getSubtermAt(1).getName();
     IPrinterFactory printerFactory = sys.getInstance().getPrinterFactory(printerName);
     IPrinter printer;
     Term arg = ((t.getArity() == 2) ? TermFactory.createNIL() : t.getSubtermAt(2));
     printer = printerFactory.createPrinter(sys.getEnv().getOutput(), "unknown", sys, arg);
     printer.writeTerm(t.getSubtermAt(0));
     retval = t.getSubtermAt(0);
   } else {
     if (sys.isLoggingMode()) {
       sys.getEnv().getLog().print("native:");
       t.print(sys.getEnv().getLog());
       sys.getEnv().getLog().println("- not changed.");
     }
     return t;
   }
   ctx.setChanged(true);
   if (sys.isLoggingMode()) {
     sys.getEnv().getLog().print("native:");
     t.print(sys.getEnv().getLog());
     sys.getEnv().getLog().println("- printed.");
   }
   return retval;
 }
示例#7
0
  @RequestMapping(value = "/", method = RequestMethod.GET)
  @Model
  public ModelMap get(
      @RequestParam("name") String termName, @RequestParam(required = false) boolean mark) {
    termName = termName.replace("_", " ");
    TermsMap.TermProvider provider = termsMap.getTermProvider(termName);
    if (provider == null) {
      throw new QuietException(format("Термин `%s` отсутствует", termName));
    }

    if (provider.hasMainTerm()) {
      provider = provider.getMainTermProvider();
    }

    ModelMap modelMap = new ModelMap(); // (ModelMap) getModelMap(term);

    Term term = provider.getTerm();

    modelMap.put("uri", term.getUri());
    modelMap.put("name", term.getName());
    if (mark) {
      if (term.getTaggedShortDescription() == null && term.getShortDescription() != null) {
        term.setTaggedShortDescription(termsMarker.mark(term.getShortDescription()));
        termDao.save(term);
      }
      if (term.getTaggedDescription() == null && term.getDescription() != null) {
        term.setTaggedDescription(termsMarker.mark(term.getDescription()));
        termDao.save(term);
      }
      modelMap.put("shortDescription", term.getTaggedShortDescription());
      modelMap.put("description", term.getTaggedDescription());
    } else {
      modelMap.put("shortDescription", term.getShortDescription());
      modelMap.put("description", term.getDescription());
    }

    // LINKS

    List<ModelMap> quotes = new ArrayList<ModelMap>();
    Set<UID> related = new LinkedHashSet<UID>();
    Set<UID> aliases = new LinkedHashSet<UID>();

    UID code = null;
    List<Link> links = linkDao.getAllLinks(term.getUri());
    for (Link link : links) {
      UID source = link.getUid1().getUri().equals(term.getUri()) ? link.getUid2() : link.getUid1();
      if (link.getQuote() != null || source instanceof Item) {
        quotes.add(getQuote(link, source, mark));
      } else if (ABBREVIATION.equals(link.getType()) || ALIAS.equals(link.getType())) {
        aliases.add(source);
      } else if (CODE.equals(link.getType())) {
        code = source;
      } else {
        related.add(source);
      }
    }

    // Нужно также включить цитаты всех синонимов и сокращений и кода
    Set<UID> aliasesQuoteSources = new HashSet<UID>(aliases);
    if (code != null) {
      aliasesQuoteSources.add(code);
    }
    for (UID uid : aliasesQuoteSources) {
      List<Link> aliasLinksWithQuote = linkDao.getAllLinks(uid.getUri());
      for (Link link : aliasLinksWithQuote) {
        UID source = link.getUid1().getUri().equals(uid.getUri()) ? link.getUid2() : link.getUid1();
        if (link.getQuote() != null || source instanceof Item) {
          quotes.add(getQuote(link, source, mark));
        } else if (ABBREVIATION.equals(link.getType())
            || ALIAS.equals(link.getType())
            || CODE.equals(link.getType())) {
          // Синонимы синонимов :) по идее их не должно быть, но если вдруг...
          // как минимум один есть и этот наш основной термин
          if (!source.getUri().equals(term.getUri())) {
            aliases.add(source);
          }
        } else {
          related.add(source);
        }
      }
    }
    sort(
        quotes,
        new Comparator<ModelMap>() {
          @Override
          public int compare(ModelMap o1, ModelMap o2) {
            return ((String) o1.get("uri")).compareTo((String) o2.get("uri"));
          }
        });

    modelMap.put("code", code);
    modelMap.put("quotes", quotes);
    modelMap.put("related", toPlainObjectWithoutContent(related));
    modelMap.put("aliases", toPlainObjectWithoutContent(aliases));
    modelMap.put("categories", searchController.inCategories(termName));

    return modelMap;
  }
示例#8
0
 @RequestMapping(value = "add", method = RequestMethod.POST)
 @Model
 public void add(Term term) {
   add(term.getName(), term.getShortDescription(), term.getDescription());
 }
示例#9
0
 public static String getHTMLName(String categoryId, String TermId) {
   Term term = getTerm(categoryId, TermId);
   String name = "&nbsp;";
   if ((term != null) && (StringUtils.isNotEmpty(term.getName()))) name = term.getName();
   return name;
 }