Пример #1
0
  public HashMap<Integer, Integer> getValuesByProfilesFromOther(int idMo) {

    HashMap<Integer, Integer> result = new HashMap<>();
    int[] profiles = Constants.planPatOther;

    for (int i : profiles) {
      result.put(i, 0);
    }

    try {
      resultSet =
          statement.executeQuery(
              String.format(
                  "SELECT id_profile, offer FROM offers_other WHERE id_mo = '%d' AND year = '%d'",
                  idMo, YEAR));

      while (resultSet.next())
        result.replace(resultSet.getInt("id_profile"), resultSet.getInt("offer"));

    } catch (SQLException sqle) {
      sqle.printStackTrace();
    }

    return result;
  }
Пример #2
0
  public int totalMatches(String[] ngrams) {
    ArrayList<int[]> list = new ArrayList<int[]>(); // list to change letters into numbers
    HashMap calc = new HashMap(); // map to calculate sum of Cn2
    for (int i = 0; i < ngrams.length; i++) {
      int[] nowInts = stringToInts(ngrams[i]);
      list.add(nowInts); // loop every string,change into int[],store in arraylist
    }

    for (int j = 0; j < list.size() - 1; j++) {
      int[] first = list.get(j);
      calc.put(first, 1); // this one must be different from previous ones
      for (int k = j + 1; k < list.size(); k++) {
        int[] second = list.get(k);
        if (check(first, second)) {
          int p = calc.get(first).hashCode();
          calc.replace(first, p, p + 1); // increment of counting in the same int[]
          list.remove(second);
          k--;
          // list is shorted by removal,k should stay at the same position for next test
        }
        if (k == list.size() - 1 && check(first, second) == false) {
          calc.put(second, 1); // if the last one is not the same as last-1,set it as 1
        }
      }
    }
    int totalMatches = calculation(calc);
    return totalMatches;
  }
Пример #3
0
  public static HashMap<Vector, Integer> trainClassifier(ArrayList<Vector> data, int K) {
    HashMap<Vector, Integer> means = new HashMap<Vector, Integer>();
    int dimension = data.get(0).getDimension();
    ArrayList<Vector> mus = new ArrayList<Vector>();
    Random rand = new Random();

    for (int i = 0; i < data.size(); i++) {
      means.put(data.get(i), 0);
    }

    for (int i = 0; i < K; i++) {
      double[] build = new double[dimension];
      for (int j = 0; j < dimension; j++) {
        build[j] = rand.nextDouble();
      }
      mus.add(new Vector(build, 0));
    }

    for (int epoch = 0; epoch < 10000; epoch++) {

      for (Vector x : data) {
        means.replace(x, argmin(x, mus));
      }
      double[][] new_mu = new double[mus.size()][mus.get(0).getDimension()];
      double[] mu_counter = new double[mus.size()];
      Iterator it = means.entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry<Vector, Integer> pair = (Entry<Vector, Integer>) it.next();
        Vector temp = pair.getKey();
        for (int i = 0; i < temp.getDimension(); i++) {
          new_mu[pair.getValue()][i] += temp.get(i);
        }
        mu_counter[pair.getValue()]++;
      }

      for (int i = 0; i < new_mu.length; i++) {
        for (int j = 0; j < new_mu[i].length; j++) {
          if (mu_counter[i] == 0) new_mu[i][j] = mus.get(i).get(j);
          else new_mu[i][j] /= mu_counter[i];
        }
      }

      for (int i = 0; i < mus.size(); i++) {
        mus.set(i, new Vector(new_mu[i], 0));
      }
    }

    return means;
  }
  private Row createRowFrom(IRecordable o) {
    Row lastRow, r;
    String[] data;

    if (dicoLocations.containsKey(o.getClassement()))
      lastRow = dicoLocations.get(o.getClassement());
    else {
      Sheet logSheet = wb.createSheet(o.getClassement());
      lastRow = logSheet.createRow(0);
      data = o.getTitles();
      fillRowWith(lastRow, data);
      dicoLocations.put(o.getClassement(), lastRow);
    }
    r = lastRow.getSheet().createRow(lastRow.getRowNum() + 1);
    data = o.getRecords();
    fillRowWith(r, data);
    dicoLocations.replace(o.getClassement(), r);
    return r;
  }
Пример #5
0
 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
     throws IOException, ServletException {
   String IpAddr = request.getRemoteAddr();
   int count = 1;
   if (register.containsKey(IpAddr)) {
     count += register.get(IpAddr);
     register.replace(IpAddr, count);
   } else {
     register.put(IpAddr, count);
   }
   System.out.println(
       "IP: "
           + IpAddr
           + " count: "
           + count
           + " Type: "
           + request.getDispatcherType().name()
           + " Date/time: "
           + new java.util.Date());
   // pass the request along the filter chain
   chain.doFilter(request, response);
 }
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(br.readLine());
    int lineNo = 1;
    while (lineNo < N) {
      String line = br.readLine();
      if (line.equals("") || line == null) {
        lineNo++;
        continue;
      }
      StringTokenizer tk = new StringTokenizer(line);
      while (tk.hasMoreTokens()) {
        String token = tk.nextToken();
        if (token.charAt(0) == '#') {
          String word = token.substring(1, token.length());
          word = word.toLowerCase();
          if (hm.containsKey(word)) {
            int value = hm.get(word);
            value++;
            hm.replace(word, value);
          } else {
            hm.put(word, 1);
          }
        }
      }
    }

    ArrayList<Tweet> list = new ArrayList<>();
    for (String word : hm.keySet()) {
      int num = hm.get(word);
      list.add(new Tweet(word, num));
    }

    for (Tweet t : list) {
      System.out.print(t.num + " " + t.word);
      System.out.println();
    }
  }
Пример #7
0
  public static void main(String[] args) {

    // DATABASE
    int answ_a = 0;
    int answ_b = 0;

    int answ_c0 = 0;
    int answ_c1 = 0;
    HashMap<Integer, Integer> numbers = new HashMap<>();

    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);

    System.out.println("Podaj nazwê pliku zawieraj¹cego dane:\n");
    String fname = sc.next();

    // LOADING FILE
    ArrayList<String> rows = new ArrayList<>();

    try {
      File f = new File("");
      Path absolute = Paths.get(f.getAbsolutePath(), fname);
      BufferedReader buffer = Files.newBufferedReader(absolute);

      String line;
      while ((line = buffer.readLine()) != null) {
        rows.add(line);
      }
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }

    // MAIN-A

    int zero = 0;
    int one = 0;

    for (String a : rows) {
      if (a.length() % 2 == 0) answ_a++;

      // MAIN-B
      for (char c : a.toCharArray()) {
        if (c == '0') zero++;
        else one++;
      }
      if (zero == one) answ_b++;

      // MAIN-C
      if (zero - one == zero) answ_c0++;
      if (one - zero == one) answ_c1++;

      // MAIN-D
      int l = a.length();
      if (numbers.get(l) == null) {
        numbers.put(l, 1);
      }
      numbers.replace(l, numbers.get(l) + 1);

      zero = 0;
      one = 0;
    }

    System.out.println("\nWYNIKI:\n");
    System.out.print("Odp A: " + answ_a + "\n");
    System.out.print("Odp B: " + answ_b + "\n");
    System.out.print("Odp C0: " + answ_c0 + "\n");
    System.out.print("Odp C1: " + answ_c1 + "\n");
    System.out.print("Odp D: \n");
    for (int a : numbers.keySet()) {
      System.out.println(a + "-znakowych: " + numbers.get(a));
    }
  }