Ejemplo n.º 1
0
  private Map<String, CustomValueSortedMap> performClassification(
      String maxVal,
      String imMetric,
      String imFuzz,
      String sampleBaseFolderPath,
      List<String> listOfUnclasifiedPgPth)
      throws IOException, DCMAApplicationException {
    File batchClassFolder = new File(sampleBaseFolderPath);
    String[] documentTypeArray = batchClassFolder.list();

    int maxValue = ImageMagicKConstants.DEFAULT_MAX_VALUE_10;
    try {
      maxValue = Integer.valueOf(maxVal);
      LOGGER.info("maxValue = " + maxValue);
    } catch (NumberFormatException nfe) {
      LOGGER.error(
          "Max value is not a number. Using default value of 10. " + nfe.getMessage(), nfe);
    }
    if (documentTypeArray == null || documentTypeArray.length == 0) {
      throw new DCMAApplicationException(
          " Learning not done for batch class sample folder path:" + sampleBaseFolderPath);
    }
    // CustomValueSortedMap finalUnclasifiedPageConfidenceMap = new CustomValueSortedMap(maxValue);
    Map<String, CustomValueSortedMap> finalUnclasifiedPageConfidenceMap =
        new HashMap<String, CustomValueSortedMap>();
    for (String unclasifiedPagePath : listOfUnclasifiedPgPth) {
      CustomValueSortedMap sampleConfidenceList = new CustomValueSortedMap(maxValue);
      for (String documentName : documentTypeArray) {
        LOGGER.info("documentName = " + documentName);
        File fdocumentName = new File(documentName);
        if (fdocumentName.isHidden()) {
          continue;
        }
        List<String> listOfSamplePages =
            getListOfSamplePagesForDoc(documentName, sampleBaseFolderPath);
        for (String samplePageName : listOfSamplePages) {
          List<String> listOfSambleThumbsPaths =
              getListOfThumbnailPaths(samplePageName, documentName, sampleBaseFolderPath);
          double maxConfidence =
              getMaxCondifence(unclasifiedPagePath, listOfSambleThumbsPaths, imMetric, imFuzz);
          LOGGER.info("samplePageName = " + samplePageName + ", maxConfidence = " + maxConfidence);
          sampleConfidenceList.add(samplePageName, maxConfidence);
        }
      }
      finalUnclasifiedPageConfidenceMap.put(unclasifiedPagePath, sampleConfidenceList);
    }
    return finalUnclasifiedPageConfidenceMap;
  }
Ejemplo n.º 2
0
  private void updateXmlObject(
      Map<String, CustomValueSortedMap> finalUnclasifiedPageConfidenceMap,
      Map<String, Integer> unclassifiedPgIndexMap,
      List<Page> listOfPages) {
    Set<String> unclasifiedPgsSet = finalUnclasifiedPageConfidenceMap.keySet();
    for (String unclassifiedPage : unclasifiedPgsSet) {
      CustomValueSortedMap listOfConfidenceValues =
          finalUnclasifiedPageConfidenceMap.get(unclassifiedPage);
      Integer indexOfPage = unclassifiedPgIndexMap.get(unclassifiedPage);
      if (indexOfPage == null) {
        continue;
      }
      Page unclassifiedPageNode = listOfPages.get(indexOfPage);
      PageLevelFields pageLevelFields = unclassifiedPageNode.getPageLevelFields();
      if (pageLevelFields == null) {
        pageLevelFields = new PageLevelFields();
        unclassifiedPageNode.setPageLevelFields(pageLevelFields);
      }
      List<DocField> listOfPageLevelFields = pageLevelFields.getPageLevelField();
      DocField pageLevelField = new DocField();
      listOfPageLevelFields.add(pageLevelField);

      if (listOfConfidenceValues.size() >= 1) {
        pageLevelField.setName(IImageMagickCommonConstants.IMAGE_COMPARE_CLASSIFICATION);
        pageLevelField.setValue(listOfConfidenceValues.last().getKey());
        pageLevelField.setConfidence(formatDecimalValue(listOfConfidenceValues.last().getValue()));
      }
      AlternateValues alternativeValues = pageLevelField.getAlternateValues();
      if (alternativeValues == null) {
        alternativeValues = new AlternateValues();
        pageLevelField.setAlternateValues(alternativeValues);
      }
      List<Field> listOfAltValues = alternativeValues.getAlternateValue();
      Iterator<CustomMapClass> itr = listOfConfidenceValues.descendingIterator();
      while (itr.hasNext()) {
        CustomMapClass sampleConfidence = itr.next();
        Field alternateValue = new Field();
        alternateValue.setName(IImageMagickCommonConstants.IMAGE_COMPARE_CLASSIFICATION);
        alternateValue.setValue(sampleConfidence.getKey());
        alternateValue.setConfidence(formatDecimalValue(sampleConfidence.getValue()));
        listOfAltValues.add(alternateValue);
      }
    }
  }