Ejemplo n.º 1
0
  /**
   * Creates a translation part of word card, it corresponds to one meaning.
   *
   * @return true if there are any translations in this translation block.
   */
  public boolean create(Connect conn, TTranslation _ttranslation, TLang _lang) {
    meaning_summary = _ttranslation.getMeaningSummary();

    TTranslationEntry[] trans_entries = TTranslationEntry.getByTranslation(conn, _ttranslation);
    // System.out.println("WCTranslation.create() _lang=" + _lang.getLanguage().toString() + ";
    // trans_entries.length=" + trans_entries);

    List<TranslationEntryItem> data_trans = new ArrayList();

    //  listview_trans.items length =" + trans_entries.length);
    trans_entry_items_size = trans_entries.length;
    // trans_entry_items = new TranslationEntryItem[trans_entries.length];
    for (int i = 0; i < trans_entries.length; i++) {
      TTranslationEntry e = trans_entries[i];

      LanguageType l = e.getLang().getLanguage();
      String lang_name_value = l.getName();
      String lang_code_value = l.getCode();
      String translation_text = e.getWikiText().getText();

      TranslationEntryItem item = new TranslationEntryItem();
      item.create(lang_name_value, lang_code_value, translation_text);
      data_trans.add(item);
    }
    //  TranslationEntryItem[] trans_entry_items = data_trans.toArray();
    // insert trans_entry_items into listview_trans.items;

    ObservableList<TranslationEntryItem> data = FXCollections.observableArrayList(data_trans);

    listview_trans.setCellFactory(
        new Callback<
            ListView<wiwordik.word_card.TranslationEntryItem>,
            ListCell<wiwordik.word_card.TranslationEntryItem>>() {
          @Override
          public ListCell<wiwordik.word_card.TranslationEntryItem> call(
              ListView<wiwordik.word_card.TranslationEntryItem> list) {
            return new wiwordik.word_card.TranslationCell();
          }
        });
    listview_trans.setItems(data);
    setMinMaxTranslationBoxHeight(listview_trans, data.size());

    // GUI                          right - indent for translation list words
    //                          top right bottom left
    group.setPadding(new Insets(0, 20, 0, 0));

    Text t_meaning_summary = new Text();
    t_meaning_summary.setText(meaning_summary);

    group.getChildren().addAll(t_meaning_summary);
    group.getChildren().addAll(listview_trans);

    return trans_entries.length > 0;
  }
Ejemplo n.º 2
0
  /**
   * Counts number of translations of native word's meaning into each foreign language by selecting
   * all records from the table 'translation' from the database of the parsed Wiktionary.<br>
   * <br>
   * SELECT * FROM translation;
   *
   * @param connect connection to the database of the parsed Wiktionary
   * @return map from the language into a number of translation boxes which contain synonyms,
   *     antonyms, etc. in English (etc.)
   */
  public static Map<LanguageType, Integer> countTranslationPerLanguage(Connect wikt_parsed_conn) {
    // translation -> lang -> count

    Statement s = null;
    ResultSet rs = null;
    long t_start;

    int n_unknown_lang_pos = 0; // translations into unknown languages

    int n_total = Statistics.Count(wikt_parsed_conn, "translation");
    // System.out.println("Total translation boxes (translated meanings of words): " + n_total);
    t_start = System.currentTimeMillis();

    Map<LanguageType, Integer> m_lang_n = new HashMap<LanguageType, Integer>();
    LanguageType native_lang = wikt_parsed_conn.getNativeLanguage();

    try {
      s = wikt_parsed_conn.conn.createStatement();
      StringBuilder str_sql = new StringBuilder();
      // SELECT id,lang_pos_id,meaning_summary,meaning_id FROM translation
      str_sql.append("SELECT id,lang_pos_id,meaning_summary FROM translation");
      s.executeQuery(str_sql.toString());
      rs = s.getResultSet();
      int n_cur = 0;
      while (rs.next()) {
        n_cur++;
        int id = rs.getInt("id");
        TLangPOS lang_pos = TLangPOS.getByID(wikt_parsed_conn, rs.getInt("lang_pos_id"));
        String meaning_summary = Encodings.bytesToUTF8(rs.getBytes("meaning_summary"));

        TLang tlang = lang_pos.getLang();
        LanguageType lt = tlang.getLanguage(); // see: Wiktionary:About Translingual
        if (null != tlang && native_lang != lt && LanguageType.mul != lt) {
          System.out.print(
              "Error (TranslationTableAll.countTranslationPerLanguage()): There is a translation box from a foreign language, code="
                  + tlang.getLanguage().getCode());
          TPage p = lang_pos.getPage();
          if (null != p) System.out.println(", page_title=" + p.getPageTitle());
        }

        if (null != lang_pos) {
          TTranslation trans =
              new TTranslation(id, lang_pos, meaning_summary, null); // meaning = null

          TTranslationEntry[] t_entries =
              TTranslationEntry.getByTranslation(wikt_parsed_conn, trans);

          for (TTranslationEntry entry : t_entries) {
            LanguageType lang = entry.getLang().getLanguage();
            if (m_lang_n.containsKey(lang)) {
              int n = m_lang_n.get(lang);
              m_lang_n.put(lang, n + 1);
            } else m_lang_n.put(lang, 1);
          }

          if (DEBUG && 0 == n_cur % 1000) { // % 100
            // if(n_cur > 333)
            //  break;
            long t_cur, t_remain;

            t_cur = System.currentTimeMillis() - t_start;
            t_remain = (long) ((n_total - n_cur) * t_cur / (60f * 1000f * (float) (n_cur)));
            // where time for 1 page = t_cur / n_cur
            // in min, since /(60*1000)
            t_cur = (long) (t_cur / (60f * 1000f));
            // t_cur = t_cur/(60f*1000f));

            TPage tpage = lang_pos.getPage();
            if (null != tpage) {
              System.out.println(
                  n_cur
                      + ": "
                      + tpage.getPageTitle()
                      + ", duration: "
                      + t_cur
                      + // t_cur/(60f*1000f) +
                      " min, remain: "
                      + t_remain
                      + " min");
            }
          }
        } else n_unknown_lang_pos++;
      }
    } catch (SQLException ex) {
      System.out.println(
          "SQLException (TranslationTableAll.countTranslationPerLanguage()): " + ex.getMessage());
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException sqlEx) {
        }
        rs = null;
      }
      if (s != null) {
        try {
          s.close();
        } catch (SQLException sqlEx) {
        }
        s = null;
      }
    }

    // long  t_end;
    // float   t_work;
    // t_end  = System.currentTimeMillis();
    // t_work = (t_end - t_start)/1000f; // in sec
    System.out.println( // "\nTime sec:" + t_work +
        "\nTotal translation boxes (translated meanings of words): "
            + n_total
            + "\n\nUnknown<ref>'''Unknown''' - words which have translations but have unknown language code and POS</ref>: "
            + n_unknown_lang_pos);

    return m_lang_n;
  }