Ejemplo n.º 1
0
  protected void doCommonConstructorStuff(
      DisplayableConcept[] conceptEntries, String[] badWords, String descriptionOfConcept) {
    this.conceptEntries = conceptEntries;
    this.badWords = badWords;
    this.descriptionOfConcept = descriptionOfConcept;

    schemeAndValuePairsToConceptEntries = new HashMap();
    meaningsAndSynonymsToConceptEntries = new HashMap();
    codeStringEquivalentToConceptEntries = new HashMap();

    for (DisplayableConcept concept : conceptEntries) {
      {
        String codeValue = concept.getCodeValue();
        String codingSchemeDesignator = concept.getCodingSchemeDesignator();
        SchemeAndValuePair key = new SchemeAndValuePair(codeValue, codingSchemeDesignator);
        schemeAndValuePairsToConceptEntries.put(key, concept);
        String legacyCodingSchemeDesignator = concept.getLegacyCodingSchemeDesignator();
        if (legacyCodingSchemeDesignator != null) {
          key = new SchemeAndValuePair(codeValue, legacyCodingSchemeDesignator);
          schemeAndValuePairsToConceptEntries.put(key, concept);
        }
      }
      {
        String codeMeaning = concept.getCodeMeaning();
        String key = codeMeaning.toLowerCase(java.util.Locale.US);
        meaningsAndSynonymsToConceptEntries.put(key, concept);
      }
      {
        String codeStringEquivalent = concept.getCodeStringEquivalent();
        if (codeStringEquivalent != null) {
          codeStringEquivalentToConceptEntries.put(
              codeStringEquivalent /* NOT lower case; want exact match*/, concept);
          String key = codeStringEquivalent.toLowerCase(java.util.Locale.US);
          meaningsAndSynonymsToConceptEntries.put(key, concept);
        }
      }
      {
        String[] synonyms = concept.getSynonyms();
        if (synonyms != null) {
          for (String synonym : synonyms) {
            String key = synonym.toLowerCase(java.util.Locale.US);
            meaningsAndSynonymsToConceptEntries.put(key, concept);
          }
        }
      }
      {
        String key = concept.getConceptUniqueIdentifier();
        conceptUniqueIdentifierToConceptEntries.put(key, concept);
      }
      {
        String key = concept.getConceptIdentifier();
        conceptIdentifierToConceptEntries.put(key, concept);
      }
    }
  }
Ejemplo n.º 2
0
 protected DisplayableConcept findLongestIndividualEntryContainedWithin(String keyText) {
   DisplayableConcept entry = null;
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin(): keyText
   // = "+keyText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin(): keyText
   // = \n"+com.pixelmed.utils.HexDump.dump(keyText));
   // try { System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // keyText = \n"+com.pixelmed.utils.HexDump.dump(keyText.findBytes("UTF8"))); } catch
   // (java.io.UnsupportedEncodingException e) {}
   String cleanedText = keyText.toLowerCase(java.util.Locale.US);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText as lowercase = "+cleanedText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText lowercase = \n"+com.pixelmed.utils.HexDump.dump(cleanedText));
   cleanedText = removeAccentsFromLowerCaseString(cleanedText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText without accents = "+cleanedText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText without accents = \n"+com.pixelmed.utils.HexDump.dump(cleanedText));
   cleanedText =
       cleanedText
           .replaceAll("[^\\p{L}\\d]", " ")
           .replaceAll("[ ][ ]*", " ")
           .trim()
           .replaceAll(
               "^[ ]$",
               ""); // replace all non-letters and non-digits and runs of spaces with single space,
   // trim leading and trailing white space, and replace entirely space string
   // with zero length
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText after punctuation removal and space collapse = "+cleanedText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText punctuation removal and space collapse =
   // \n"+com.pixelmed.utils.HexDump.dump(cleanedText));
   cleanedText = removeAnyBadWords(cleanedText);
   // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
   // cleanedText punctuation removal and space collapse and bad word removal = "+cleanedText);
   if (cleanedText.length() > 0) {
     // linear search ... :(
     int lengthFound = 0;
     for (DisplayableConcept concept : conceptEntries) {
       // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
       // trying concept = "+concept);
       String codeMeaning = concept.getCodeMeaning().toLowerCase(java.util.Locale.US);
       if (cleanedText.contains(codeMeaning)) {
         int tryLength = codeMeaning.length();
         if (tryLength > lengthFound) {
           // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
           // candidate from codeMeaning= "+codeMeaning);
           entry = concept;
           lengthFound = tryLength;
         }
       }
       // do NOT automatically check codeStringEquivalent contained with in string ... only use
       // these as exact match; if appropriate, include explicitly as synonyms
       // String codeStringEquivalent = concept.getCodeStringEquivalent();
       // if (codeStringEquivalent != null) {
       //	codeStringEquivalent=codeStringEquivalent.toLowerCase(java.util.Locale.US);
       //	codeStringEquivalent = removeAccentsFromLowerCaseString(codeStringEquivalent);
       //	if (cleanedText.contains(codeStringEquivalent)) {
       //		int tryLength = codeStringEquivalent.length();
       //		if (tryLength > lengthFound) {
       // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
       // candidate from codeStringEquivalent = "+codeStringEquivalent);
       //			entry = concept;
       //			lengthFound = tryLength;
       //		}
       //	}
       // }
       String[] synonyms = concept.getSynonyms();
       if (synonyms != null) {
         for (String synonym : synonyms) {
           // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
           // trying synonym = "+synonym);
           synonym = synonym.toLowerCase(java.util.Locale.US);
           synonym = removeAccentsFromLowerCaseString(synonym);
           // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin():
           // trying synonym without accents = "+synonym);
           if (cleanedText.contains(synonym)) {
             int tryLength = synonym.length();
             if (tryLength > lengthFound) {
               // System.err.println("DictionaryOfConcepts.findLongestIndividualEntryContainedWithin(): candidate from synonyms = "+synonym);
               entry = concept;
               lengthFound = tryLength;
             }
           }
         }
       }
     }
   }
   return entry;
 }