Exemplo n.º 1
0
  public static ArrayList<TokenDetails> sortByCount(ArrayList<TokenDetails> tdList) {
    int size = tdList.size();
    float currentProb = tdList.get(0).getProb();
    ArrayList<TokenDetails> finalList = new ArrayList<TokenDetails>();
    ArrayList<TokenDetails> tmpList = new ArrayList<TokenDetails>();
    TokenComparatorCount tcc = new TokenComparatorCount();
    int i = 0;
    while (i < size) {
      float probToCompare = tdList.get(i).getProb();

      if (probToCompare == currentProb) {
        tmpList.add(tdList.get(i));
        i = i + 1;
      } else {
        Collections.sort(tmpList, tcc);
        finalList = Utility.copyList(tmpList, finalList);
        currentProb = tdList.get(i).getProb();
        tmpList.clear();
      }

      if (i == size) {
        Collections.sort(tmpList, tcc);
        finalList = Utility.copyList(tmpList, finalList);
        tmpList.clear();
      }
    }
    return finalList;
  }
Exemplo n.º 2
0
  public TurboIssue(String repoId, Issue issue) {
    this.id = issue.getNumber();
    this.title = issue.getTitle() == null ? "" : issue.getTitle();
    this.creator = issue.getUser().getLogin();
    this.createdAt = Utility.dateToLocalDateTime(issue.getCreatedAt());
    this.isPullRequest = isPullRequest(issue);

    this.description = issue.getBody() == null ? "" : issue.getBody();
    this.updatedAt =
        issue.getUpdatedAt() != null
            ? Utility.dateToLocalDateTime(issue.getUpdatedAt())
            : this.createdAt;
    this.commentCount = issue.getComments();
    this.isOpen = issue.getState().equals(STATE_OPEN);
    this.assignee =
        issue.getAssignee() == null
            ? Optional.empty()
            : Optional.of(issue.getAssignee().getLogin());
    this.labels = issue.getLabels().stream().map(Label::getName).collect(Collectors.toList());
    this.milestone =
        issue.getMilestone() == null
            ? Optional.empty()
            : Optional.of(issue.getMilestone().getNumber());

    this.metadata = IssueMetadata.empty();
    this.repoId = repoId;
    this.markedReadAt = Optional.empty();
  }
Exemplo n.º 3
0
  public void filterRetweets2(String fileName) {
    ArrayList<String> tweets = Utility.readFile(fileName);
    ArrayList<String> filteredTweets = new ArrayList<String>();
    HashMap<String, Boolean> tweetsToBeAdded = new HashMap<String, Boolean>();

    for (String tweet : tweets) {
      tweet = tweet.toLowerCase().trim();

      /*if(!Utility.isEnglish(tweet))
      {
      	System.out.println("Ignoring tweet: ["+tweet+"], since I don't think it's english...");
      	continue;
      }*/

      /*if(tweet.contains("ã")||tweet.startsWith("@")||tweet.startsWith("http")||tweet.startsWith("rt") || tweet.equals("")
      		||tweet.startsWith("\"rt"))
      	continue;


      //what we have here are the tweets that survived.

      String tokens [] = tweet.split(Utility.space);
      StringBuilder sb = new StringBuilder();

      for(int i=0;i<tokens.length;i++)
      {
      	String token = tokens[i];
      	token = Utility.processToken(token);
      	if(token != null)
      	{
      		token = token.trim();
      		sb.append(token).append(Utility.space);
      	}
      }*/

      // String t = sb.toString().trim();
      String t = tweet.toLowerCase().trim();

      // if(!tweetsToBeAdded.containsKey(t) && t.length() >25)
      if (!tweet.contains("#sarcasm")) {
        tweetsToBeAdded.put(t, true);
      }
    }

    Iterator<Map.Entry<String, Boolean>> it = tweetsToBeAdded.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<String, Boolean> pair = (Map.Entry<String, Boolean>) it.next();
      filteredTweets.add(pair.getKey());
    }

    Utility.writeFile("files/RandomOutput", filteredTweets);
  }
Exemplo n.º 4
0
 private void writeDoCommand(PrintWriter pw, String indent) {
   String str = indent + "fCommandStatus = fUMart.do" + fCmdDef.getCmdName() + "(";
   str += Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
   str += ", userID";
   Iterator itr = fCmdDef.getArgList().iterator();
   while (itr.hasNext()) {
     HashMap argInfo = (HashMap) itr.next();
     String argName = Utility.makeFieldString((String) argInfo.get("NAME"));
     str += ", " + argName;
   }
   str += ");";
   pw.println(str);
 }
Exemplo n.º 5
0
 private void writeSendingHashMap(PrintWriter pw, String indent, HashMap item, String hashName) {
   String coreClassName = "UC" + fCmdDef.getCmdName() + "Core";
   String type = (String) item.get("TYPE");
   ArrayList contents = (ArrayList) item.get("CONTENTS");
   Iterator itr = contents.iterator();
   while (itr.hasNext()) {
     HashMap item2 = (HashMap) itr.next();
     String type2 = (String) item2.get("TYPE");
     String name2 = (String) item2.get("NAME");
     String key2 = Utility.makeKeyString(type2, name2);
     String comment2 = (String) item2.get("COMMENT");
     String localVariableName = Utility.makeLocalVariable(name2);
     if (type2.equals("HashMap")) {
       pw.print(
           indent
               + "HashMap "
               + localVariableName
               + " = (HashMap)"
               + hashName
               + ".get("
               + coreClassName
               + "."
               + key2
               + ");");
       pw.println(" // " + comment2);
       writeSendingHashMap(pw, indent, item2, localVariableName);
     } else if (type2.equals("ArrayList")) {
       pw.print(
           indent
               + "ArrayList "
               + localVariableName
               + " = (ArrayList)"
               + hashName
               + ".get("
               + coreClassName
               + "."
               + key2
               + ");");
       pw.println(" // " + comment2);
       writeSendingArrayList(pw, indent, item2, localVariableName);
     } else {
       String str = indent + "fAgent.sendMessage(" + hashName + ".get(";
       str += "UC" + fCmdDef.getCmdName() + "Core." + key2 + ").toString());";
       pw.print(str);
       pw.println(" // " + comment2);
     }
   }
 }
Exemplo n.º 6
0
  /**
   * Tests that a PageHeaderIterator correctly retrieves ETag headers for 3 pages from a mocked
   * server that conform to GitHub API's pagination specifications and terminates afterwards.
   *
   * @throws NoSuchElementException
   */
  @Test
  public void testHeaderIterator() throws NoSuchElementException, IOException {
    MockServerClient mockServer = ClientAndServer.startClientAndServer(8888);

    HttpRequest page1Request = createMockServerPagedHeaderRequest(1);
    List<Header> page1Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page1-header.txt"));
    String page1Etag = "aaf65fc6b10d5afbdc9cd0aa6e6ada4c";

    HttpRequest page2Request = createMockServerPagedHeaderRequest(2);
    List<Header> page2Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page2-header.txt"));
    String page2Etag = "731501e0f7d9816305782bc4c3f70d9f";

    HttpRequest page3Request = createMockServerPagedHeaderRequest(3);
    List<Header> page3Headers =
        TestUtils.parseHeaderRecord(
            TestUtils.readFileFromResource(this, "tests/PagedHeadersSample/page3-header.txt"));
    String page3Etag = "a6f367d674155d6fbbacbc2fca04917b";

    setUpHeadRequestOnMockServer(mockServer, page1Request, page1Headers);
    setUpHeadRequestOnMockServer(mockServer, page2Request, page2Headers);
    setUpHeadRequestOnMockServer(mockServer, page3Request, page3Headers);

    PagedRequest<Milestone> request = new PagedRequest<>();
    Map<String, String> params = new HashMap<>();
    params.put("state", "all");

    GitHubClientEx client = new GitHubClientEx("localhost", 8888, "http");

    String path = SEGMENT_REPOS + "/hubturbo/hubturbo" + SEGMENT_PULLS;
    request.setUri(path);
    request.setResponseContentType(CONTENT_TYPE_JSON);
    request.setParams(params);

    PageHeaderIterator iter = new PageHeaderIterator(request, client, "ETag");
    assertEquals(page1Etag, Utility.stripQuotes(iter.next()));
    assertEquals(page2Etag, Utility.stripQuotes(iter.next()));
    assertEquals(page3Etag, Utility.stripQuotes(iter.next()));
    assertFalse(iter.hasNext());

    mockServer.stop();
  }
Exemplo n.º 7
0
  public void filterRetweets(String inputFile, String outputFile) {
    ArrayList<String> tweets = Utility.readFile(inputFile);
    ArrayList<String> filteredTweets = new ArrayList<String>();
    HashMap<String, Boolean> tweetsToBeAdded = new HashMap<String, Boolean>();

    for (String tweet : tweets) {
      tweet = tweet.toLowerCase().trim();

      if (tweet.contains("ã")
          || tweet.startsWith("rt")
          || tweet.startsWith("@")
          || tweet.startsWith("http")
          || tweet.equals("")
          || tweet.startsWith("\"rt")) continue;

      // what we have here are the tweets that survived.
      String tokens[] = tweet.split(Utility.space);
      StringBuilder sb = new StringBuilder();

      for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i];
        token = Utility.processToken(token);
        if (token != null) {
          token = token.trim();
          sb.append(token).append(Utility.space);
        }
      }
      String t = sb.toString().trim();
      if (!tweetsToBeAdded.containsKey(t) && t.length() > 25) {
        tweetsToBeAdded.put(t, true);
      }
    }

    Iterator<Map.Entry<String, Boolean>> it = tweetsToBeAdded.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<String, Boolean> pair = (Map.Entry<String, Boolean>) it.next();
      filteredTweets.add(pair.getKey());
    }

    Utility.writeFile(outputFile, filteredTweets);
  }
Exemplo n.º 8
0
 private void writeSendingArrayList(
     PrintWriter pw, String indent, HashMap item, String arrayName) {
   String type = (String) item.get("TYPE");
   HashMap contents = (HashMap) item.get("CONTENTS");
   String name = Utility.makeLocalVariable((String) item.get("NAME"));
   String type2 = (String) contents.get("TYPE");
   String name2 = Utility.makeLocalVariable((String) contents.get("NAME"));
   String comment2 = (String) contents.get("COMMENT");
   pw.println(indent + "Iterator itr = " + arrayName + ".iterator();");
   pw.println(indent + "while ( itr.hasNext() ) {");
   if (type2.equals("HashMap")) {
     pw.println(indent + "  HashMap " + name2 + " = " + "(HashMap)itr.next();");
     writeSendingHashMap(pw, indent, contents, name2);
   } else if (type2.equals("ArrayList")) {
     pw.print(indent + "  ArrayList " + name2 + " = (ArrayList)itr.next();");
     writeSendingArrayList(pw, indent, contents, name2);
   } else {
     pw.print(indent + "  fAgent.sendMassage(" + name2 + ".toString());");
     pw.println(" // " + comment2);
   }
   pw.println(indent + "}");
 }
Exemplo n.º 9
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_restaurant, container, false);

    // ((MainActivity)getActivity()).loadRestFragment("menuItems");

    IVBackgroundRestaurant = (ImageView) view.findViewById(R.id.IVBackgroundRestaurant);
    IVBackgroundRestaurant.setImageDrawable(getResources().getDrawable(R.drawable.restaurant));
    IVBackgroundRestaurant.setColorFilter(
        Color.rgb(100, 100, 100), android.graphics.PorterDuff.Mode.MULTIPLY);

    TVRestPageRestName = (TextView) view.findViewById(R.id.TVRestPageRestName);
    TVRestPageRestName.setText(Utility.ucFirst(State.foodItem.getRestName()));

    TVRestPageRestAddress = (TextView) view.findViewById(R.id.TVRestPageRestAddress);
    TVRestPageRestAddress.setText(Utility.ucFirst(State.foodItem.getLocality()));

    menuManager = new MenuManager(getActivity());
    menuManager.execute("");

    return view;
  }
Exemplo n.º 10
0
  /**
   * Combines data from a corresponding pull request with data in this issue This method returns a
   * new combined issue and does not mutate this issue
   *
   * @param pullRequest
   * @return new new combined issue
   */
  public TurboIssue combineWithPullRequest(PullRequest pullRequest) {
    TurboIssue newIssue = new TurboIssue(this);

    if (pullRequest.getUpdatedAt() == null) {
      return newIssue;
    }

    LocalDateTime pullRequestUpdatedAt = Utility.dateToLocalDateTime(pullRequest.getUpdatedAt());
    if (pullRequestUpdatedAt.isBefore(newIssue.getUpdatedAt())) {
      return newIssue;
    }

    newIssue.setUpdatedAt(pullRequestUpdatedAt);
    return newIssue;
  }
Exemplo n.º 11
0
 /**
  * Given a list and a ngram, this method will delete all those ngrams present in the list which
  * are superstring of the given ngram and return the updated list.
  *
  * @param list
  * @param ngrams
  * @return
  */
 public static ArrayList<TokenDetails> deleteNgramsSubsumed(
     ArrayList<TokenDetails> list, String ngrams) {
   ArrayList<TokenDetails> returnList = new ArrayList<TokenDetails>();
   int size = list.size();
   for (int i = 0; i < size; i++) {
     TokenDetails td = list.get(i);
     String s = td.getToken();
     if (!Utility.isSubsumedBy(ngrams, s)) {
       // System.out.println("Token added:"+s);
       returnList.add(td);
     } else {
       System.out.println("Removing token:" + s);
     }
   }
   return returnList;
 }
Exemplo n.º 12
0
 private static Optional<String> getRepositoryIdFromJson(Path p) {
   try {
     String repoId =
         new Model(
                 (SerializableModel)
                     new Gson()
                         .fromJson(
                             Utility.readFile(String.valueOf(p.toAbsolutePath())).get(),
                             new TypeToken<SerializableModel>() {}.getType()))
             .getRepoId();
     if (String.valueOf(p.getFileName()).equalsIgnoreCase(escapeRepoName(repoId))) {
       logger.info("Adding " + p.getFileName() + " to stored repository list. ");
       return Optional.of(repoId);
     }
   } catch (NullPointerException | JsonParseException e) {
     logger.error("Unable to load repository from " + p.getFileName());
   }
   return Optional.empty();
 }
Exemplo n.º 13
0
 /**
  * Shows an error dialog for an {@code action} that has been been carried out with an {@code
  * issue} but encountered an {@code Exception}. The error dialog shows the message obtained from
  * calling {@code} getMessage on the exception and removing the Exception Class from the message.
  *
  * @param issue
  * @param action
  * @param exception
  * @return
  */
 private boolean handleActionException(
     TurboIssue issue, Action<TurboIssue> action, Throwable exception) {
   showErrorDialog(issue, action, Utility.removeFirstWord(exception.getMessage()));
   return false;
 }
  public static Integer durToInteger(String meta, String date, String time) {
    Integer index = 0;
    Long y;
    Integer hh, mm, day, year, mo, interInMinutes;
    String part[] = meta.split(",");

    hh = Integer.valueOf(part[1]);
    mm = Integer.valueOf(part[2]);
    day = Integer.valueOf(part[3]);
    year = Integer.valueOf(part[4]);
    interInMinutes = Integer.valueOf(part[5]);

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, hh);
    cal.set(Calendar.MINUTE, mm);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.DAY_OF_YEAR, day);
    cal.set(Calendar.YEAR, year);

    Date d1 = cal.getTime();

    Date t = new Date();
    SimpleDateFormat tf = new SimpleDateFormat("hh:mm a");
    SimpleDateFormat pf = new SimpleDateFormat("HH:mm");
    try {
      t = tf.parse(time);
    } catch (java.text.ParseException e) {
      e.printStackTrace();
    }
    String[] strs = pf.format(t).split(":");

    hh = Integer.valueOf(strs[0]);
    mm = Integer.valueOf(strs[1]);

    String[] spl = date.split(", ");
    String[] spl2 = spl[0].split(" ");

    day = Integer.valueOf(spl2[0]);
    mo = Integer.valueOf(spl2[1]);
    year = Integer.valueOf(spl2[2]);
    Calendar cal2 = Calendar.getInstance();

    cal2.set(Calendar.HOUR_OF_DAY, hh);
    cal2.set(Calendar.MINUTE, mm);
    cal2.set(Calendar.SECOND, 0);
    cal2.set(Calendar.DATE, day);
    cal2.set(Calendar.MONTH, mo - 1);
    cal2.set(Calendar.YEAR, year);

    Date d2 = cal2.getTime();

    date = spl2[0] + " " + new DateFormatSymbols().getMonths()[mo - 1] + ", " + spl[1];
    Map<TimeUnit, Long> DiffMap = Utility.computeDiff(d1, d2);

    y =
        DiffMap.get(TimeUnit.DAYS) * 24 * 60
            + DiffMap.get(TimeUnit.HOURS) * 60
            + DiffMap.get(TimeUnit.MINUTES);
    y = y / interInMinutes + 1;
    index = (int) (long) y;
    return index;
  }
Exemplo n.º 15
0
 private void writeDataClear(PrintWriter pw, String indent) {
   String str = indent;
   str += Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
   str += ".clear();";
   pw.println(str);
 }
Exemplo n.º 16
0
  public void writeCommandServer() throws FileNotFoundException {
    String className = "USC" + fCmdDef.getCmdName();
    PrintWriter pw = new PrintWriter(new FileOutputStream(className + ".java"));
    System.out.println("Writing " + className + ".java ...");
    pw.println("package cmdServer;");
    pw.println();
    pw.println("import java.util.ArrayList;");
    pw.println("import java.util.HashMap;");
    pw.println("import java.util.Iterator;");
    pw.println("import serverNet.UAgent;");
    pw.println("import serverNet.UMartNetwork;");
    pw.println("import cmdCore.ICommand;");
    String coreClassName = "UC" + fCmdDef.getCmdName() + "Core";
    pw.println("import cmdCore." + coreClassName + ";");
    pw.println("import cmdCore.UCommandStatus;");
    pw.println();
    pw.println(
        "public class "
            + className
            + " extends UC"
            + fCmdDef.getCmdName()
            + "Core implements IServerCmd {");
    pw.println();
    pw.println("  /** このコマンドを実行したエージェント */");
    pw.println("  private UAgent fAgent;");
    pw.println();
    pw.println("  /** サーバーへの参照 */");
    pw.println("  UMartNetwork fUMart;");
    pw.println();
    pw.println("  /** コンストラクタ */");
    pw.println("  public " + className + "() {");
    pw.println("    super();");
    pw.println("    fAgent = null;");
    pw.println("    fUMart = null;");
    pw.println("  }");
    pw.println();
    pw.println("  public void setConnection(UAgent agent, UMartNetwork umart) {");
    pw.println("    fAgent = agent;");
    pw.println("    fUMart = umart;");
    pw.println("  }");
    pw.println();
    pw.println("  public UCommandStatus doIt() {");
    pw.println("    try {");
    pw.println("      int userID = fAgent.getOffice().getUserID();");
    writeDataClear(pw, "      ");
    writeDoCommand(pw, "      ");
    pw.println("      if ( fCommandStatus.getStatus() ) {");
    pw.println("        fAgent.sendMessage(\"+ACCEPT\");");
    String type = (String) fCmdDef.getReturnData().get("TYPE");
    String fieldName = Utility.makeFieldString((String) fCmdDef.getReturnData().get("NAME"));
    if (type.equals("HashMap")) {
      writeSendingHashMap(pw, "        ", fCmdDef.getReturnData(), fieldName);
    } else if (type.equals("ArrayList")) {
      writeSendingArrayList(pw, "        ", fCmdDef.getReturnData(), fieldName);
    }
    pw.println("      } else {");
    pw.println("        fAgent.sendMessage(\"+ERROR \" + fCommandStatus.getErrorCode());");
    pw.println("        fAgent.sendMessage(fCommandStatus.getErrorMessage());");
    pw.println("      }");

    pw.println("    } catch (Exception e) {");
    pw.println("      fAgent.sendMessage(\"+ERROR \" + ICommand.INVALID_ARGUMENTS);");
    pw.println("      fAgent.sendMessage(\"USAGE: " + fCmdDef.getCmdName().toUpperCase() + "\");");
    pw.println("    }");
    pw.println("    fAgent.flushMessage();");
    pw.println("    return fCommandStatus;");
    pw.println("  }");
    pw.println();
    pw.println("}");
    pw.close();
  }