コード例 #1
0
    /**
     * This method return those memory locations that exceed the threshold.
     *
     * @return the memory locations that exceed the threshold
     */
    public Set<MemoryLocation> getMemoryLocationsExceedingThreshold() {
      Set<MemoryLocation> exceedingMemoryLocations = new HashSet<>();
      for (MemoryLocation memoryLocation : mapping.keys()) {
        if (mapping.get(memoryLocation).size() > threshold) {
          exceedingMemoryLocations.add(memoryLocation);
        }
      }

      return exceedingMemoryLocations;
    }
コード例 #2
0
  public TextAnalysis analyse(String text) throws ModelException {
    String[] words = semanticService.getWords(text);

    semanticService.lowercaseWords(words);

    List<String> uniqueWords = Strings.asList(semanticService.getUniqueWords(words));

    WordListPerspectiveQuery query = new WordListPerspectiveQuery().withWords(uniqueWords);

    List<WordListPerspective> list = modelService.list(query);

    List<String> unknownWords = Lists.newArrayList();

    Set<String> knownWords = new HashSet<String>();

    Multimap<String, String> wordsByLanguage = HashMultimap.create();

    for (WordListPerspective perspective : list) {
      String word = perspective.getText().toLowerCase();
      knownWords.add(word);
      if (perspective.getLanguage() != null) {
        wordsByLanguage.put(perspective.getLanguage(), word);
      }
    }

    Multiset<String> languages = wordsByLanguage.keys();
    String language = null;
    for (String lang : languages) {
      if (language == null
          || (wordsByLanguage.get(lang).size() > wordsByLanguage.get(language).size())) {
        language = lang;
      }
    }

    for (String word : uniqueWords) {
      if (!knownWords.contains(word)) {
        unknownWords.add(word);
      }
    }

    Locale possibleLocale = Locale.ENGLISH;
    String[] sentences = semanticService.getSentences(text, possibleLocale);

    TextAnalysis analysis = new TextAnalysis();
    analysis.setLanguage(language);
    analysis.setSentences(Strings.asList(sentences));
    analysis.setWordsByLanguage(wordsByLanguage.asMap());
    analysis.setUniqueWords(uniqueWords);
    analysis.setKnownWords(list);
    analysis.setUnknownWords(unknownWords);
    return analysis;
  }
コード例 #3
0
  /**
   * @param source the input source that need to be searched
   * @param searchInput the searchInput to be searched
   * @return the result that matched with the searchInput(case sensitive)
   */
  public ArrayList<Task> searchSensitive(Multimap<String, Task> multimap, String searchInput) {
    ArrayList<Task> searchList = new ArrayList<Task>();
    if (invalidList(multimap) || invalidSearchInput(searchInput)) {
      return searchList;
    }

    for (String key : multimap.keys()) {
      for (Task task : multimap.get(key)) {

        if (task.getDescription().contains(searchInput)) {
          searchList.add(task);
        }
      }
    }
    return searchList;
  }
コード例 #4
0
  /**
   * Traverse the tree in postorder and update tree values
   *
   * @param node
   */
  private static void postorderWithParticularNode(TreeNode node, TreeNode projectTreeNode) {

    if (node == null) {
      return;
    }

    if (projectTreeNode == null) {
      return;
    }

    logger.debug("------------postorder: " + projectTreeNode.getName() + "---------------");

    logger.debug("Traversing project tree in postorder..." + projectTreeNode.toString());
    // Update the value
    try {
      InitialContext ic = new InitialContext();
      AdapterDataService adapterDataService = new AdapterDataService();
      TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");

      if (projectTreeNode instanceof Metric) {
        Metric metric = (Metric) projectTreeNode;
        logger.debug("Recomputing the value of the Metric " + projectTreeNode);
        Float value = null;
        if (metric.getMetricSource() == MetricSource.Manual) {
          metric.updateQualityStatus();
        } else {
          value =
              adapterDataService.getMetricValue(
                  metric.getMetricSource(), metric.getMetricType(), metric.getProject());
          metric.setValue(value);
        }
        metric.setLastUpdated(getLatestTreeUpdateDate());
        metric.addHistoricValue();
        // End Metric node treatment
      } else if (projectTreeNode instanceof QualityIndicator) {
        logger.info("Recomputing the value of the Quality Indicator " + projectTreeNode);
        QualityIndicator qi = (QualityIndicator) projectTreeNode;
        if (qi.getUseFormula()) {
          String formulaToEval = Formula.parseFormula(qi.getViewFormula());
          if (formulaToEval != null && !formulaToEval.isEmpty()) {

            Float computedValue = Formula.evalFormula(formulaToEval);
            if (computedValue != null && !computedValue.isNaN()) {
              qi.setValue(computedValue);
              qi.setLastUpdated(getLatestTreeUpdateDate());
              treeNodeService.update(qi);
            }
          }
        } else {
          float achieved = 0;
          float denominator = 0;
          for (final TreeNode me : qi.getChildren()) {
            float weight = ((Metric) me).getWeight();
            if (me.getQualityStatus() == QualityStatus.Green) {
              achieved += weight;
            }
            denominator += weight;
          }
          if (denominator == 0) qi.getChildren().size();
          qi.setValue(achieved * 100 / denominator);
        }
        qi.setLastUpdated(getLatestTreeUpdateDate());
        qi.addHistoricValue();
        // End Q.Indicator node treatment
      } else if (projectTreeNode instanceof QualityObjective) {
        logger.info("Recomputing the value of the Quality Objective " + projectTreeNode);
        QualityObjective qo = (QualityObjective) projectTreeNode;
        if (qo.getUseFormula()) {
          String formulaToEval = Formula.parseFormula(qo.getViewFormula());
          if (formulaToEval != null && !formulaToEval.isEmpty()) {

            Float computedValue = Formula.evalFormula(formulaToEval);
            if (computedValue != null && !computedValue.isNaN()) {
              qo.setValue(computedValue);
              qo.setLastUpdated(getLatestTreeUpdateDate());
            }
          }
        } else {
          float denominator = 0;
          float achieved = 0;
          for (final TreeNode qi : qo.getChildren()) {
            float weight = ((QualityIndicator) qi).getWeight();
            if (qi.getQualityStatus() == QualityStatus.Green) {
              achieved += weight;
            }
            denominator += weight;
          }
          qo.setValue(achieved * 100 / denominator);
        }
        qo.setLastUpdated(getLatestTreeUpdateDate());
        qo.addHistoricValue();
        // End Quality Objective node treatment
      } else if (projectTreeNode instanceof Project) {
        logger.info("Recomputing the value of the Project " + projectTreeNode);
        Project prj = (Project) projectTreeNode;
        double qoValueSum = 0;
        double denominator = 0;
        for (Object o : projectTreeNode.getChildren()) {
          QualityObjective qo = (QualityObjective) o;
          if (qo.getWeight() == 0) {
            continue;
          }
          qoValueSum += qo.getValue() * (prj.isFormulaAverage() ? qo.getWeight() : 1);
          denominator += prj.isFormulaAverage() ? qo.getWeight() : 1;
        }

        // bad idea to divide something under 0
        if (denominator == 0) {
          denominator = 1;
        }

        Double computedValue = qoValueSum / denominator;

        if (computedValue != null && !computedValue.isNaN() && !computedValue.isInfinite()) {
          prj.setValue(computedValue);
        }

        prj.setLastUpdated(getLatestTreeUpdateDate());
        prj.addHistoricValue();
        logger.debug(" [" + qoValueSum + "] denominator [" + denominator + "] " + computedValue);
        // End Project node treatment
      }

      // Get a (possible) suggestion for the tree node
      Multimap<?, ?> suggestions = getSuggestionForNode(projectTreeNode);
      // TODO: take all the suggestions into account
      Object[] types = suggestions.keys().toArray();
      Object[] suggestionsValues = suggestions.values().toArray();
      if (types.length > 0) {
        // for now use the first item as suggestion
        SuggestionType stype = (SuggestionType) types[0];
        projectTreeNode.setSuggestionType(stype);
        if (suggestionsValues[0] != null && !suggestionsValues[0].equals("")) {
          projectTreeNode.setSuggestionValue((String) suggestionsValues[0]);
        }
      }

      treeNodeService.update(projectTreeNode);

    } catch (NamingException e) {
      e.printStackTrace();
    }

    // Iterate the node children
    TreeNode nodeChild = projectTreeNode.getParent();
    UQasarUtil.postorderWithParticularNode(projectTreeNode, nodeChild);

    return;
  }
コード例 #5
0
 @Override
 public Multiset<K> keys() {
   return _forward.keys();
 }