// Determine F(k+1) by support counting on (C(K+1), T) and retaining itemsets from C(k+1) with
  // support at least minsup
  private static List<Itemset> determineFrequentItemsets(
      List<Itemset> candicates, List<Transaction> transactions, double minsup) {
    if (candicates.isEmpty()) {
      return null;
    }

    HashTree hashTree = new HashTree(candicates, candicates.get(0).getNumOfItems());
    HashMap<Itemset, Integer> frequentCount = new HashMap<>();
    for (Itemset itemset : candicates) {
      frequentCount.put(itemset, 0);
    }

    for (Transaction transaction : transactions) {
      Set<Itemset> candidatesInTranscation = hashTree.candidatesInTransaction(transaction);
      if (candidatesInTranscation == null) {
        continue;
      }
      for (Itemset itemset : candidatesInTranscation) {
        if (transaction.containItemset(itemset)) {
          frequentCount.put(itemset, frequentCount.get(itemset) + 1);
        }
      }
    }

    List<Itemset> result = new ArrayList<>();
    for (Itemset itemset : candicates) {
      if ((double) (frequentCount.get(itemset)) / transactions.size() >= minsup) {
        result.add(itemset);
      }
    }
    return result;
  }
示例#2
0
  public synchronized void messageReceived(int to, Message m) {

    DrainMsg mhMsg = (DrainMsg) m;

    log.debug(
        "incoming: localDest: "
            + to
            + " type:"
            + mhMsg.get_type()
            + " hops:"
            + (16 - mhMsg.get_ttl())
            + " seqNo:"
            + mhMsg.get_seqNo()
            + " source:"
            + mhMsg.get_source()
            + " finalDest:"
            + mhMsg.get_dest());

    // lets assume that the network cannot buffer more than 25 drain msgs from a single source at a
    // time (should be more than reasonable)
    if (seqNos.containsKey(new Integer(mhMsg.get_source()))) {
      int oldSeqNo = ((Integer) seqNos.get(new Integer(mhMsg.get_source()))).intValue();
      int upperBound = mhMsg.get_seqNo() + 25;
      int wrappedUpperBound = 25 - (255 - mhMsg.get_seqNo());
      if ((oldSeqNo >= mhMsg.get_seqNo() && oldSeqNo < upperBound)
          || (oldSeqNo >= 0 && oldSeqNo < wrappedUpperBound)) {
        log.debug(
            "Dropping message from "
                + mhMsg.get_source()
                + " with duplicate seqNo: "
                + mhMsg.get_seqNo());
        return;
      }
    }
    seqNos.put(new Integer(mhMsg.get_source()), new Integer(mhMsg.get_seqNo()));

    if (to != spAddr && to != MoteIF.TOS_BCAST_ADDR && to != TOS_UART_ADDR) {
      log.debug("Dropping message not for me.");
      return;
    }

    HashSet promiscuousSet = (HashSet) idTable.get(new Integer(BCAST_ID));
    HashSet listenerSet = (HashSet) idTable.get(new Integer(mhMsg.get_type()));

    if (listenerSet != null && promiscuousSet != null) {
      listenerSet.addAll(promiscuousSet);
    } else if (listenerSet == null && promiscuousSet != null) {
      listenerSet = promiscuousSet;
    }

    if (listenerSet == null) {
      log.debug("No Listener for type: " + mhMsg.get_type());
      return;
    }

    for (Iterator it = listenerSet.iterator(); it.hasNext(); ) {
      MessageListener ml = (MessageListener) it.next();
      ml.messageReceived(to, mhMsg);
    }
  }
示例#3
0
 /**
  * Returns the index of the given relation in the relation sort order, or the index of "*" if the
  * relation is not explicitly listed.
  */
 public Integer getRelationSortIndex(String rel) {
   Integer retval = _relationIndexMap.get(rel);
   if (retval != null) return retval;
   retval = _relationIndexMap.get("*");
   if (retval != null) return retval;
   return new Integer(-1);
 }
示例#4
0
 public static void main(String[] args) throws IOException {
   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
   String[] temp = in.readLine().split(" ");
   int n = Integer.parseInt(temp[0]);
   int s = Integer.parseInt(temp[1]);
   HashMap<Integer, Integer> buy = new HashMap<>();
   HashMap<Integer, Integer> sell = new HashMap<>();
   for (int i = 1; i <= n; i++) {
     temp = in.readLine().split(" ");
     int p = Integer.parseInt(temp[1]);
     int q = Integer.parseInt(temp[2]);
     if (temp[0].charAt(0) == 'B') {
       if (buy.containsKey(p)) buy.put(p, buy.get(p) + q);
       else buy.put(p, q);
     } else {
       if (sell.containsKey(p)) sell.put(p, sell.get(p) + q);
       else sell.put(p, q);
     }
   }
   ArrayList<Integer> buyArr = new ArrayList<>();
   ArrayList<Integer> sellArr = new ArrayList<>();
   for (Integer i : buy.keySet()) buyArr.add(i);
   for (Integer i : sell.keySet()) sellArr.add(i);
   Collections.sort(buyArr, Comparator.reverseOrder());
   Collections.sort(sellArr);
   for (int i = Math.min(s, sellArr.size()) - 1; i >= 0; i--)
     System.out.println("S " + sellArr.get(i) + " " + sell.get(sellArr.get(i)));
   for (int i = 0; i < s && i < buyArr.size(); i++)
     System.out.println("B " + buyArr.get(i) + " " + buy.get(buyArr.get(i)));
 }
示例#5
0
  @Override
  public void sendMessage(final FriendMessage message) {

    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
    Friend friend = friends.get(message.getTo());
    Screenname buddy = new Screenname(friend.getUserName());
    Conversation c = (Conversation) friend.getUserInfo();
    if (c == null) {
      c = connection.getIcbmService().getImConversation(buddy);
      friend.setUserInfo(c);
    }
    Message oscarMessage =
        new Message() {

          public boolean isAutoResponse() {
            return false;
          }

          public String getMessageBody() {
            return message.getMessage();
          }
        };
    c.sendMessage(oscarMessage);
    Friend recipient = friends.get(message.getTo());
    accountListener.didReceiveMessageForFriend(message, recipient);
  }
示例#6
0
 public void setObjectValues() {
   ((JTextField) (fields.get("board"))).setText(sketch.getBoard().getName());
   ((JTextField) (fields.get("core"))).setText(sketch.getCore().getName());
   ((JTextField) (fields.get("compiler"))).setText(sketch.getCompiler().getName());
   ((JTextField) (fields.get("port"))).setText(sketch.getDevice().toString());
   ((JTextField) (fields.get("programmer"))).setText(sketch.getProgrammer());
 }
示例#7
0
  public void exportMainlineDataToText() throws IOException {

    for (int key : detectors.keySet()) {

      Double[] flow =
          MyUtilities.scaleVector(
              detectors.get(key).getFlowDataArray(),
              (double) detectors.get(key).getNumberOfLanes());
      Double[] speed = detectors.get(key).getSpeedDataArray();
      Double[] density =
          MyUtilities.scaleVector(
              detectors.get(key).getDensityDataArray(),
              (double) detectors.get(key).getNumberOfLanes());

      PrintWriter outFlow = new PrintWriter(new FileWriter(key + "_flw.txt"));
      PrintWriter outSpeed = new PrintWriter(new FileWriter(key + "_spd.txt"));
      PrintWriter outDensity = new PrintWriter(new FileWriter(key + "_dty.txt"));

      for (int i = 0; i < flow.length; i++) {

        outFlow.println(flow[i]);
        outSpeed.println(speed[i]);
        outDensity.println(density[i]);
      }

      outFlow.close();
      outSpeed.close();
      outDensity.close();
    }
  }
  public static void countPairs(Integer[] arr) {

    HashMap<Integer, Integer> seenElements = new HashMap<Integer, Integer>();

    // ArrayList<Integer> countList = new ArrayList<Integer

    for (int i = 0; i < arr.length; i++) {

      if (!seenElements.containsKey(arr[i])) {
        seenElements.put(arr[i], 1);
      } else {

        seenElements.put(arr[i], seenElements.get(arr[i]) + 1);
      }
    }

    BigInteger count = null;
    for (int element : seenElements.keySet()) {
      if (seenElements.get(element) > 1) {
        System.out.println("count is :" + seenElements.get(element));
        count.add(
            factorial(seenElements.get(element)).divide(factorial(seenElements.get(element) - 2)));
        System.out.println(count);
      }
    }

    if (count == null) {
      System.out.println("0");
    }
  }
示例#9
0
  public void composition_tokenizer(String comp_line) {
    comp_line = remove_for_agg(comp_line);

    String c_name = get_first(comp_line, "COMPOSITION");
    String comp_name = get_latter(comp_line, "COMPOSITION");

    StringBuilder construct_param = new StringBuilder();

    construct_param.append(comp_name);
    construct_param.append("_");
    construct_param.append(Integer.toString(param_count));

    String param = construct_param.toString();

    param_count++;

    if (output.get(c_name) != null) {
      comp_name = get_latter(comp_line, "COMPOSITION");
      output.get(c_name).add_parameters(param);
      output.get(c_name).add_comp(param);
    } else {
      comp_name = get_first(comp_line, "COMPOSITION");
      output.put(c_name, classes[object_count]);
      output.get(c_name).set_weird_name(c_name);
      current_class = c_name;
      object_count++;
      output.get(c_name).add_parameters(param);
      output.get(c_name).add_comp(param);
    }
  }
示例#10
0
文件: uva10763.java 项目: de-yu/uva
  public static void main(String[] args) throws IOException {

    Scanner scanner = new Scanner(new BufferedInputStream(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
      int a = Integer.parseInt(br.readLine());
      if (a == 0) break;
      HashMap<String, Integer> map = new HashMap<String, Integer>();
      int sum = 0;

      while (a-- > 0) {
        StringTokenizer st = new StringTokenizer(br.readLine());
        int one = Integer.parseInt(st.nextToken()), two = Integer.parseInt(st.nextToken());
        country c = new country(one, two);
        country c_rev = new country(two, one);
        int s = 0;

        if (map.get(c.tostring()) != null) {
          s = map.get(c.tostring()) + 1;
          map.put(c.tostring(), s);
          sum++;
        } else if (map.get(c_rev.tostring()) != null) {
          s = map.get(c_rev.tostring()) - 1;
          map.put(c_rev.tostring(), s);
          sum--;
        } else {
          map.put(c.tostring(), 1);
          sum++;
        }
      }
      if (sum != 0) System.out.println("NO");
      else System.out.println("YES");
    }
  }
示例#11
0
 public static void main(String[] args) throws IOException {
   Scanner s = new Scanner(new File("gift1.in"));
   PrintWriter out = new PrintWriter(new FileWriter("gift1.out"));
   int people = s.nextInt();
   HashMap<String, Integer> moneyGiven = new HashMap<String, Integer>();
   HashMap<String, Integer> moneyReceived = new HashMap<String, Integer>();
   String[] names = new String[people];
   for (int x = 0; x < people; x++) {
     String name = s.next();
     names[x] = name;
     moneyGiven.put(name, 0);
     moneyReceived.put(name, 0);
   }
   for (int x = 0; x < people; x++) {
     String person = s.next();
     int give = s.nextInt();
     int receivers = s.nextInt();
     if (receivers == 0) continue;
     give = give - give % receivers;
     moneyGiven.put(person, give);
     for (int y = 0; y < receivers; y++) {
       String name = s.next();
       moneyReceived.put(name, give / receivers + moneyReceived.get(name));
     }
   }
   for (int x = 0; x < people; x++) {
     out.println(names[x] + " " + (moneyReceived.get(names[x]) - moneyGiven.get(names[x])));
   }
   out.close();
 }
    @Override
    public void reduce(Text key, Iterable<HMapStIW> values, Context context)
        throws IOException, InterruptedException {
      Iterator<HMapStIW> iter = values.iterator();
      HMapStIW map = new HMapStIW();

      while (iter.hasNext()) {
        map.plus(iter.next());
      }

      HMapStFW writeMap = new HMapStFW();

      double pmi = 0.0;
      for (MapKI.Entry<String> entry : map.entrySet()) {
        String k = entry.getKey();

        if (map.get(k) >= 10) {
          if (wordCounts.containsKey(key.toString()) && wordCounts.containsKey(k)) {
            int px = wordCounts.get(key.toString());
            int py = wordCounts.get(k);
            pmi = Math.log10(((double) (map.get(k)) / (px * py)) * wordCounts.get("numLines*"));
            writeMap.put(k, (float) pmi);
          }
        }
      }
      if (writeMap.size() > 0) {
        context.write(key, writeMap);
      }
    }
示例#13
0
  private static void getTopDocuments(int num, HashMap<String, Float> scoremap, String filename)
      throws FileNotFoundException {
    PrintWriter out = new PrintWriter(filename);
    Iterator<String> itr = scoremap.keySet().iterator();
    ArrayList<String> urls = new ArrayList<String>();
    ArrayList<Float> scores = new ArrayList<Float>();

    while (itr.hasNext()) {
      String key = itr.next();
      if (scores.size() < num) {
        scores.add(scoremap.get(key));
        urls.add(key);
      } else {
        int index = scores.indexOf(Collections.min(scores));
        if (scores.get(index) < scoremap.get(key)) {
          scores.set(index, scoremap.get(key));
          urls.set(index, key);
        }
      }
    }

    while (scores.size() > 0) {
      int index = scores.indexOf(Collections.max(scores));
      out.println(urls.get(index) + "\t" + scores.get(index));
      urls.remove(index);
      scores.remove(index);
    }
    out.close();
  }
示例#14
0
  /*
   * Adds nodes to graph
   */
  private static void addNodes() {
    String current;
    Node node;
    Node fromNode;

    try {
      line = br.readLine();

      while (line.indexOf(",") != -1) {
        current = line.substring(0, line.indexOf(","));
        current = current.trim();
        line = line.substring(line.indexOf(",") + 1);

        if (nodeMap.get(current.charAt(1)) == null) {
          node = new Node(current.charAt(1));
          nodeMap.put(current.charAt(1), node);
        }
        if (nodeMap.get(current.charAt(0)) == null) {
          node = new Node(current.charAt(1));
          nodeMap.put(current.charAt(0), node);
        }
        fromNode = nodeMap.get(current.charAt(0));
        fromNode.addEdge(nodeMap.get(current.charAt(1)), current.charAt(2) - '0');
      }
    } catch (IOException e) {
      System.out.println(e);
    }
  }
示例#15
0
 public Document processRecord(Document record, int position) throws Exception {
   for (HashMap<String, String> map : check_fields) {
     String fieldXpath = map.get("Field Name");
     String regexp = map.get("Field Value");
     Filter.apply(record, new OpDelete(), fieldXpath, new TextMatches(regexp));
   }
   return record;
 }
  public final String correct(String word) {
    if (nWords.containsKey(word)) return word;
    ArrayList<String> list = edits(word);
    HashMap<Integer, String> candidates = new HashMap<Integer, String>();
    for (String s : list) if (nWords.containsKey(s)) candidates.put(nWords.get(s), s);

    if (candidates.size() > 0) return candidates.get(Collections.max(candidates.keySet()));
    return candidates.size() > 0 ? candidates.get(Collections.max(candidates.keySet())) : word;
  }
示例#17
0
  private boolean validateTables(TSelectSqlStatement stmt) {
    HashMap<String, Integer> present = new HashMap<String, Integer>();
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {

      int cols = stmt.getResultColumnList().size();
      for (int a = 0; a < cols; a++) {
        present.put(
            stmt.getResultColumnList()
                .getResultColumn(a)
                .toString()
                .toLowerCase()
                .replace("(", "")
                .replace(")", ""),
            0);
      }
    }

    TJoinList joins = stmt.joins;
    int j = joins.size();
    int invalid = 1;
    for (int i = 0; i < j; i++) {
      Iterator<Table> it = DBSystem.tableList.iterator();
      Table table = null;
      while (it.hasNext()) {
        table = it.next();
        if (table.getName().equalsIgnoreCase(joins.getJoin(i).toString())) {
          invalid = 0;
          if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
            Iterator it1 = table.getColumnData().entrySet().iterator();

            while (it1.hasNext()) {
              Map.Entry pairs = (Map.Entry) it1.next();
              if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 0) {
                present.put(pairs.getKey().toString(), 1);
              } else if (present.get(pairs.getKey().toString().toLowerCase()) != null
                  && present.get(pairs.getKey().toString().toLowerCase()) == 1) return false;
            }
          }
        }
      }
      if (invalid == 1) return false;
      else {
        invalid = 1;
      }
    }
    if (!stmt.getResultColumnList().getResultColumn(0).toString().equals("*")) {
      Iterator it2 = present.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry pairs = (Map.Entry) it2.next();
        if ((Integer) pairs.getValue() == 0) {
          return false;
        }
      }
    }
    return true;
  }
示例#18
0
  /**
   * Build a list of installed plugins.
   *
   * @return a list of plugin names and version numbers.
   */
  public static EventList<NameAndVersion> findInstalledPlugins() {
    EventList<NameAndVersion> plugins = new BasicEventList<NameAndVersion>();
    if (!PluginCore.userPluginDir.exists()) return plugins;
    String[] files =
        PluginCore.userPluginDir.list(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".jar");
              }
            });

    HashMap<String, PluginDescriptor> urls = new HashMap<String, PluginDescriptor>();
    Collection<PluginDescriptor> descriptors =
        PluginCore.getManager().getRegistry().getPluginDescriptors();
    for (PluginDescriptor desc : descriptors) {
      if ((desc.getPluginClassName() == null)
          || !desc.getPluginClassName().equals("net.sf.jabref.plugin.core.JabRefPlugin")) {
        urls.put(desc.getId(), desc);
      }
    }

    for (String file1 : files) {
      File file = new File(PluginCore.userPluginDir, file1);
      String[] nav = getNameAndVersion(file);
      if (nav != null) {
        VersionNumber vn = nav[1] != null ? new VersionNumber(nav[1]) : null;
        NameAndVersion nameAndVersion = new NameAndVersion(nav[0], vn, true, file);
        for (Iterator<String> it = urls.keySet().iterator(); it.hasNext(); ) {
          String loc = it.next();
          if (loc.contains(nav[0])) {
            PluginDescriptor desc = urls.get(loc);
            // System.out.println("Accounted for: "+desc.getId()+" "+desc.getVersion().toString());
            if (!PluginCore.getManager().isPluginEnabled(urls.get(loc)))
              nameAndVersion.setStatus(BAD);
            else nameAndVersion.setStatus(LOADED);
            it.remove();
          }
        }
        plugins.add(nameAndVersion);
      }
    }

    for (String url : urls.keySet()) {
      PluginDescriptor desc = urls.get(url);
      File location = new File(desc.getLocation().getFile());
      if (location.getPath().contains(PluginCore.userPluginDir.getPath()))
        continue; // This must be a loaded user dir plugin that's been deleted.
      // System.out.println("File: "+desc.getLocation().getFile());
      NameAndVersion nameAndVersion =
          new NameAndVersion(
              desc.getId(), new VersionNumber(desc.getVersion().toString()), false, location);
      if (!PluginCore.getManager().isPluginEnabled(urls.get(url))) nameAndVersion.setStatus(BAD);
      else nameAndVersion.setStatus(LOADED);
      plugins.add(nameAndVersion);
    }
    return plugins;
  }
 public String getResult() {
   for (int i = 1; i < (sql.totalQuestionAsked() + 1); i++) {
     if (((String) storeAnswer.get(i)).equalsIgnoreCase((String) retriveAnswer.get(i))) {
       ++r;
     }
   }
   r = (r * 100) / sql.totalQuestionAsked();
   System.out.println("storeAnswe== " + r);
   return "" + r;
 }
示例#20
0
 public static long checkValue(long n) {
   if (n <= 0) {
     return 0;
   } else if (hasm.get(n) != null) {
     return hasm.get(n);
   } else {
     long v = Math.max(n, checkValue(n / 2) + checkValue(n / 3) + checkValue(n / 4));
     hasm.put(n, v);
     return v;
   }
 }
示例#21
0
  public Main() {
    try {
      BufferedReader in;
      in = new BufferedReader(new InputStreamReader(System.in)); // Used for CCC
      int numLights = Integer.parseInt(in.readLine());
      int[] states = new int[numLights];
      for (int i = 0; i < numLights; i++) {
        states[i] = Integer.parseInt(in.readLine());
      }
      ArrayDeque<Scenario> Q = new ArrayDeque<Scenario>();
      HashMap<String, Integer> dp = new HashMap<String, Integer>();

      int moves = 0;
      Q.addLast(new Scenario(states));
      while (!Q.isEmpty()) {
        int size = Q.size();
        for (int q = 0; q < size; q++) {
          Scenario temp = Q.removeFirst();
          if (isEmpty(temp.states)) {
            System.out.println(moves);
            return;
          } else {
            for (int i = 0; i < temp.states.length; i++) {
              if (temp.states[i] == 0) {
                int[] newArr = Arrays.copyOf(temp.states, temp.states.length);
                newArr[i] = 1;
                newArr = fixArray(newArr);
                String arr = "";
                for (int p = 0; p < newArr.length; p++) arr += newArr[p];
                if (dp.get(arr) == null) {
                  dp.put(arr, moves);
                  Q.addLast(new Scenario(newArr));
                } else {
                  int val = dp.get(arr);
                  if (val != 0 && moves < val) {
                    dp.put(arr, moves);
                    Q.addLast(new Scenario(newArr));
                  }
                }

                // outputArr(newArr);
              }
            }
          }
        }
        moves++;
      }

    } catch (IOException e) {
      System.out.println("IO: General");
    }
  }
示例#22
0
  /**
   * Reads the data from database and writes into detectors hashmap
   *
   * @throws SQLException
   */
  public void readDataIntoDetectorListFromDatabase() throws SQLException {

    // TestConfiguration.dbSetup();

    PeMSStationAggregateReader stationAggregateReader =
        new PeMSStationAggregateReader(oraDatabase.doConnect());
    ArrayList<Long> vdsIDs = new ArrayList<Long>();

    for (int key : detectors.keySet()) {
      vdsIDs.add((long) key);
    }
    List<PeMSStationAggregate> stationsAggregate =
        stationAggregateReader.read(
            this.timeInterval, vdsIDs, PeMSAggregate.AggregationLevel.PEMS_5MIN);

    // Read absolute detector info into the hashmap
    VDSReader stationReader = new VDSReader(oraDatabase.doConnect());
    for (int key : detectors.keySet()) {
      VDS station = stationReader.read((long) key);
      Detector d = detectors.get(key);
      d.setAbsolutePM(station.getAbsolutePostmile());
      d.setDetectorLength(station.getDetectorLength());
      d.setDetectorName(station.getDetectorName());
      d.setFreewayDirection(station.getDirection());
      d.setFreewayNumber(station.getFreewayNum());
      d.setLatitude(station.getPosition().getPoint().get(0).getLat());
      d.setLongitude(station.getPosition().getPoint().get(0).getLng());
      d.setNumberOfLanes(station.getLaneCount());
    }

    // Read 5 minute data into the hashmap
    for (int i = 0; i < stationsAggregate.size(); i++) {
      // find the detector corresponding to the current ID in the data vector and fill the fields
      // accordingly
      Detector d = detectors.get((int) stationsAggregate.get(i).getVdsId());
      d.addDatumToSpeed(stationsAggregate.get(i).getTotal().getAvgSpeed());
      d.addDatumToFlow(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / d
                  .getNumberOfLanes()); // to get the hourly rate at 5 minute granularity, multiply
                                        // by 12
      d.addDatumToDensity(
          stationsAggregate.get(i).getTotal().getFlow()
              * 12
              / stationsAggregate.get(i).getTotal().getAvgSpeed()
              / d.getNumberOfLanes());
      if (i < detectors.size()) {
        d.setHealthStatus(stationsAggregate.get(i).getTotal().getObserved());
      }
    }
  }
示例#23
0
 /**
  * Returns the necessary exports for the specified platform. If no 32 or 64-bit version of the
  * exports exists, it returns the version that doesn't specify bit depth.
  */
 public String[] getApplicationExportList(int platform, String variant) {
   String platformName = PConstants.platformNames[platform];
   if (variant.equals("32")) {
     String[] pieces = exportList.get(platformName + "32");
     if (pieces != null) return pieces;
   } else if (variant.equals("64")) {
     String[] pieces = exportList.get(platformName + "64");
     if (pieces != null) return pieces;
   } else if (variant.equals("armv6hf")) {
     String[] pieces = exportList.get(platformName + "-armv6hf");
     if (pieces != null) return pieces;
   }
   return exportList.get(platformName);
 }
示例#24
0
  public void parameter_tokenizer(String parameter_line) {
    parameter_line = remove_quotes(parameter_line);

    String c_name = get_first(parameter_line, "PARAMETER");
    String p_name = null;

    if (output.get(c_name) != null) {
      p_name = get_latter(parameter_line, "PARAMETER");
      output.get(c_name).add_parameters(p_name);
    } else {
      p_name = get_first(parameter_line, "PARAMETER");
      output.get(current_class).add_parameters(p_name);
    }
  }
示例#25
0
  /** Write all AIML files. Adds categories for BUILD and DEVELOPMENT ENVIRONMENT */
  public void writeAIMLFiles() {
    if (MagicBooleans.trace_mode) System.out.println("writeAIMLFiles");
    HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
    Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
    brain.addCategory(b);
    // b = new Category(0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version,
    // "update.aiml");
    // brain.addCategory(b);
    ArrayList<Category> brainCategories = brain.getCategories();
    Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
    for (Category c : brainCategories) {

      if (!c.getFilename().equals(MagicStrings.null_aiml_file))
        try {
          // System.out.println("Writing "+c.getCategoryNumber()+" "+c.inputThatTopic());
          BufferedWriter bw;
          String fileName = c.getFilename();
          if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
          else {
            String copyright = Utilities.getCopyright(this, fileName);
            bw = new BufferedWriter(new FileWriter(aiml_path + "/" + fileName));
            fileMap.put(fileName, bw);
            bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<aiml>\n");
            bw.write(copyright);
            // bw.newLine();
          }
          bw.write(Category.categoryToAIML(c) + "\n");
          // bw.newLine();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }
    Set set = fileMap.keySet();
    for (Object aSet : set) {
      BufferedWriter bw = fileMap.get(aSet);
      // Close the bw
      try {
        if (bw != null) {
          bw.write("</aiml>\n");
          bw.flush();
          bw.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    File dir = new File(aiml_path);
    dir.setLastModified(new Date().getTime());
  }
示例#26
0
  /**
   * Translates the link structure into the cell structure depending on healthy detector locations
   */
  public void createCellStructure() {

    int i = 0;

    while (i < mainlineLinks.size() - 1) {

      if (mainlineLinks.get(i).isHasDetector()
          & mainlineLinks.get(i).getDetectorML().getHealthStatus() == 100) {
        Cell c = new Cell((int) totalTimeInHours * 60 / 5);
        c.addLink(mainlineLinks.get(i));
        c.setDetectorML(mainlineLinks.get(i).getDetectorML());
        c.setDetectorHOV(mainlineLinks.get(i).getDetectorHOV());
        while (!mainlineLinks.get(i + 1).isHasDetector() & i < mainlineLinks.size() - 2
            | (mainlineLinks.get(i + 1).isHasDetector()
                & mainlineLinks.get(i + 1).getDetectorML().getHealthStatus() != 100)) {
          c.addLink(mainlineLinks.get(i + 1));
          i++;
        }
        // Onramps and Offramps in the Cell
        for (Link l : c.getLinks()) {

          c.addToOnrampPerLink(l.getUpNode().getInLinks().size() - 1);
          c.addToOfframpPerLink(l.getDownNode().getOutLinks().size() - 1);

          for (int linkID : l.getUpNode().getInLinks()) {
            if (links.get(linkID).getLinkType().equals("onramp")) {
              if (links.get(linkID).getDetectorML().getFlowData().isEmpty()
                  | links.get(linkID).getDetectorML().getHealthStatus() != 100) {
                c.addToImputeOR(true);
                c.appendZeroColumnToMeasuredOnrampFlow();
              } else {
                c.appendColumnToMeasuredOnrampFlow(
                    links.get(linkID).getDetectorML().getFlowDataArray());
                c.addToImputeOR(false);
              }
            }
          }
          for (int linkID : l.getDownNode().getOutLinks()) {
            if (links.get(linkID).getLinkType().equals("offramp")) {
              if (links.get(linkID).getDetectorML().getFlowData().isEmpty()
                  | links.get(linkID).getDetectorML().getHealthStatus() != 100) {
                c.addToImputeFR(true);
                c.appendZeroColumnToMeasuredOfframpFlow();
              } else {
                c.appendColumnToMeasuredOfframpFlow(
                    links.get(linkID).getDetectorML().getFlowDataArray());
                c.addToImputeFR(false);
              }
            }
          }
        }

        cells.add(c);
      }

      i++;
    }
    i = 0;
  }
示例#27
0
  public void method_tokenizer(String method_line) {
    method_line = method_line.replaceAll("\\+ ", "");
    method_line = method_line.replaceAll("\\- ", "");

    String c_name = get_first(method_line, "METHOD");
    String m_name = null;

    if (output.get(c_name) != null) {
      m_name = get_latter(method_line, "METHOD");
      output.get(c_name).add_methods(m_name);
    } else {
      m_name = get_first(method_line, "METHOD");
      output.get(current_class).add_methods(m_name);
    }
  }
示例#28
0
 /** Get a comparator for a {@link WritableComparable} implementation. */
 public static synchronized WritableComparator get(Class<? extends WritableComparable> c) {
   WritableComparator comparator = comparators.get(c);
   if (comparator == null) {
     // force the static initializers to run
     forceInit(c);
     // look to see if it is defined now
     comparator = comparators.get(c);
     // if not, use the generic one
     if (comparator == null) {
       comparator = new WritableComparator(c, true);
       comparators.put(c, comparator);
     }
   }
   return comparator;
 }
示例#29
0
 private static boolean isSimilar(
     HashMap<String, Float> prevscores, HashMap<String, Float> scores) {
   if (prevscores == null) return false;
   double delta = 0.0000000036;
   Iterator<String> keys = scores.keySet().iterator();
   while (keys.hasNext()) {
     String key = (String) keys.next();
     Float currval = scores.get(key);
     Float prevval = prevscores.get(key);
     if (Math.abs(prevval - currval) > delta) {
       return false;
     }
   }
   return true;
 }
示例#30
0
 private HashMap<String, Float> normalizeScores(HashMap<String, Float> scores) {
   Iterator<String> keys = scores.keySet().iterator();
   float mean = 0f;
   while (keys.hasNext()) {
     String key = (String) keys.next();
     mean += ((scores.get(key)) * (scores.get(key)));
   }
   mean = (float) Math.sqrt(mean);
   keys = scores.keySet().iterator();
   while (keys.hasNext()) {
     String key = (String) keys.next();
     scores.put(key, scores.get(key) / (float) mean);
   }
   return scores;
 }