Example #1
0
  @Test
  public void testGetTargetCodesToNodeList() throws Exception {
    LexBIGService lbs = ServiceHolder.instance().getLexBIGService();

    CodedNodeGraph mappingGraph = lbs.getNodeGraph(MAPPING_SCHEME_URI, null, null);

    CodedNodeSet cns =
        mappingGraph.restrictToTargetCodeSystem(PARTS_SCHEME).toNodeList(null, false, true, 0, -1);

    ResolvedConceptReferencesIterator itr = cns.resolve(null, null, null);

    int count = 0;

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

    while (itr.hasNext()) {
      count++;
      foundCodes.add(itr.next().getCode());
    }

    assertEquals(3, foundCodes.size());

    assertTrue(foundCodes.contains("R0001"));
    assertTrue(foundCodes.contains("E0001"));
    assertTrue(foundCodes.contains("P0001"));
  }
  /**
   * Test map synonymto preferred names.
   *
   * @throws LBException the LB exception
   */
  public void testMapSynonymtoPreferredNames() throws LBException {

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns =
        cns.restrictToMatchingDesignations(
            "skeleton", SearchDesignationOption.ALL, "exactMatch", null);

    ResolvedConceptReference[] rcr =
        cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    assertTrue(rcr.length == 2);

    boolean found = false;
    for (int i = 0; i < rcr.length; i++) {

      if (rcr[i].getConceptCode().equals("C12788")) {
        found = true;
        assertTrue(rcr[i].getReferencedEntry().getPropertyCount() == 5);
        assertTrue(
            rcr[i]
                .getReferencedEntry()
                .getEntityDescription()
                .getContent()
                .equals("Skeletal System"));
      }
    }
    assertTrue(found);
  }
  /**
   * Instantiates a new Iterator. Be sure that any desired restrictions have already been placed on
   * the CodedNodeSets before passing into this constructor
   *
   * @param codedNodeSets the coded node sets
   * @param sortOptions the sort options
   * @param filterOptions the filter options
   * @param restrictToProperties the restrict to properties
   * @param restrictToPropertyTypes the restrict to property types
   * @param resolve the resolve
   * @throws LBException the LB exception
   */
  public QuickUnionIterator(
      Vector<CodedNodeSet> codedNodeSets,
      SortOptionList sortOptions,
      LocalNameList filterOptions,
      LocalNameList restrictToProperties,
      PropertyType[] restrictToPropertyTypes,
      boolean resolve)
      throws LBException {

    for (CodedNodeSet cns : codedNodeSets) {
      // KLO 012310
      if (cns != null) {
        try {
          ResolvedConceptReferencesIterator iterator =
              cns.resolve(
                  sortOptions,
                  filterOptions,
                  restrictToProperties,
                  restrictToPropertyTypes,
                  resolve);
          if (iterator != null) {
            _iterators.add(iterator);
          }
        } catch (Exception ex) {
          _logger.error("QuickUnionIterator constructor - cns.resolve throws exception???");
          // ex.printStackTrace();
          System.out.println(
              "WARNING: QuickUnionIteratorWrapper constructor - cns.resolve throws exception???");
        }
      }
    }

    Collections.sort(_iterators, new IteratorSizeComparator());
  }
Example #4
0
  private static ResolvedConceptReferenceList searchConceptCode(
      LexEVSApplicationService evsService, String dtsVocab, String CCode, int sMetaLimit) {

    ResolvedConceptReferenceList concepts = new ResolvedConceptReferenceList();

    int codesSize = 0;
    try {
      CodedNodeSet metaNodes = evsService.getNodeSet(dtsVocab, null, null);

      ConceptReferenceList crefs =
          ConvenienceMethods.createConceptReferenceList(new String[] {CCode}, dtsVocab);
      metaNodes = metaNodes.restrictToCodes(crefs);

      metaNodes.restrictToStatus(ActiveOption.ACTIVE_ONLY, null);

      concepts =
          metaNodes.resolveToList(
              null, // Sorts used to sort results (null means sort by match score)
              null, // PropertyNames to resolve (null resolves all)
              null, // PropertyTypess to resolve (null resolves all)
              sMetaLimit // cap the number of results returned (-1 resolves all)
              );

      codesSize = concepts.getResolvedConceptReferenceCount();

    } catch (Exception ex) {
      System.out.println("Error do_EVSSearch get concept: " + ex.toString());
    }
    return concepts;
  }
  public void testT1_FNC_02() throws LBException {

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns.restrictToCodes(
        Constructors.createConceptReferenceList(
            new String[] {"Vallecula", "Palate", "Hard_Palate"}, THES_SCHEME));

    // this test is really lacking... but here is how you subset. You can
    // serialize however
    // you want from here...
    assertTrue(cns.resolveToList(null, null, null, 0).getResolvedConceptReference().length == 3);
  }
  /**
   * Test retrieve most recent versionof concept.
   *
   * @throws LBException the LB exception
   */
  public void testRetrieveMostRecentVersionofConcept() throws LBException {

    // not providing a version number gets you the PRODUCTION (which can be assumed to be the latest
    // good version)

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns =
        cns.restrictToCodes(
            Constructors.createConceptReferenceList(new String[] {"C12223"}, THES_SCHEME));

    assertTrue(cns.resolveToList(null, null, null, 0).getResolvedConceptReference().length == 1);
  }
Example #7
0
  @Test
  public void testT1_FNC_16() throws LBException {

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(AUTO_SCHEME, null);

    cns = cns.restrictToStatus(null, new String[] {"Retired"});
    ResolvedConceptReference[] rcr =
        cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    assertTrue(rcr.length == 1);
    assertTrue(rcr[0].getConceptCode().equals("73"));
  }
  /**
   * Test limit returned values.
   *
   * @throws LBException the LB exception
   */
  public void testLimitReturnedValues() throws LBException {

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);

    cns =
        cns.restrictToMatchingDesignations(
            "heaart", SearchDesignationOption.ALL, "DoubleMetaphoneLuceneQuery", null);

    ResolvedConceptReference[] rcr =
        cns.resolveToList(null, null, null, 1).getResolvedConceptReference();

    assertTrue(rcr.length == 1);
  }
  public void testNextInt() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      ResolvedConceptReferenceList list1 = rcrl.next(10);
      ResolvedConceptReferenceList list2 = rcrl.next(10);

      assertFalse(compareResolvedConceptReferenceList(list1, list2));
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
  /**
   * Get concept Entity by code
   *
   * @param codingScheme
   * @param code
   * @return
   */
  public ResolvedConceptReference getConceptByCode(String codingScheme, String code) {
    CodedNodeSet cns = null;
    ResolvedConceptReferencesIterator iterator = null;

    try {
      LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
      cns = lbSvc.getCodingSchemeConcepts(codingScheme, null);
      ConceptReferenceList crefs = createConceptReferenceList(new String[] {code}, codingScheme);
      cns.restrictToCodes(crefs);
      iterator = cns.resolve(null, null, null);
      if (iterator.numberRemaining() > 0) {
        ResolvedConceptReference ref = (ResolvedConceptReference) iterator.next();
        return ref;
      }
    } catch (LBException e) {
      _logger.info("Error: " + e.getMessage());
    }

    return null;
  }
  public void testNext() {
    try {
      LexBIGService lbs = ServiceHolder.instance().getLexBIGService();
      CodedNodeSet cns = lbs.getCodingSchemeConcepts("NCI Thesaurus", null);
      cns = cns.restrictToMatchingDesignations("heart", null, "startsWith", null);

      ResolvedConceptReferencesIterator rcrl = cns.resolve(null, null, null, null, false);

      String conceptCode = null;

      while (rcrl.hasNext()) {
        ResolvedConceptReference ref = rcrl.next();
        String currentCode = ref.getConceptCode();
        assertFalse(currentCode.equals(conceptCode));
        conceptCode = currentCode;
      }
    } catch (Exception e) {
      fail("Exception Thrown: " + e.getMessage());
      e.printStackTrace();
    }
  }
  /**
   * Return Iterator for codedNodeGraph
   *
   * @param cng
   * @param graphFocus
   * @param resolveForward
   * @param resolveBackward
   * @param resolveAssociationDepth
   * @param maxToReturn
   * @return
   */
  public ResolvedConceptReferencesIterator codedNodeGraph2CodedNodeSetIterator(
      CodedNodeGraph cng,
      ConceptReference graphFocus,
      boolean resolveForward,
      boolean resolveBackward,
      int resolveAssociationDepth,
      int maxToReturn) {
    CodedNodeSet cns = null;

    try {
      cns =
          cng.toNodeList(
              graphFocus, resolveForward, resolveBackward, resolveAssociationDepth, maxToReturn);
      if (cns == null) return null;
      return cns.resolve(null, null, null);
    } catch (Exception ex) {
      _logger.warn(ex.getMessage());
    }

    return null;
  }
  public void testT1_FNC_17() throws LBException {

    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);

    cns =
        cns.restrictToMatchingDesignations(
            "heaart", SearchDesignationOption.ALL, "DoubleMetaphoneLuceneQuery", null);

    ResolvedConceptReference[] rcr =
        cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    // should have found the concept code C48589 - "Base of the Heart"
    boolean found = false;
    for (int i = 0; i < rcr.length; i++) {
      if (rcr[i].getConceptCode().equals("Base_of_the_Heart")) {
        found = true;
      }
    }
    assertTrue(found);
  }
Example #14
0
  private static ResolvedConceptReferenceList searchPrefTerm(
      LexEVSApplicationService evsService,
      String dtsVocab,
      String prefName,
      int sMetaLimit,
      String algorithm) {

    ResolvedConceptReferenceList concepts = new ResolvedConceptReferenceList();
    int codesSize = 0;
    try {
      CodedNodeSet metaNodes = evsService.getNodeSet(dtsVocab, null, null);

      metaNodes =
          metaNodes.restrictToMatchingDesignations(
              prefName, // the text to match
              CodedNodeSet.SearchDesignationOption
                  .ALL, // whether to search all designation, only Preferred or only Non-Preferred
              algorithm, // the match algorithm to use
              null); // the language to match (null matches all)

      metaNodes = metaNodes.restrictToStatus(ActiveOption.ACTIVE_ONLY, null);

      concepts =
          metaNodes.resolveToList(
              null, // Sorts used to sort results (null means sort by match score)
              null, // PropertyNames to resolve (null resolves all)
              new CodedNodeSet.PropertyType[] {
                PropertyType.DEFINITION, PropertyType.PRESENTATION
              }, // PropertyTypess to resolve (null resolves all)
              sMetaLimit // cap the number of results returned (-1 resolves all)
              );
      codesSize = concepts.getResolvedConceptReferenceCount();
    } catch (Exception ex) {
      // ex.printStackTrace();
      System.out.println("Error do_EVSSearch DescLogic: " + ex.toString());
    }

    return concepts;
  }
  /**
   * Testfor current or obsolete conceptb.
   *
   * @throws LBException the LB exception
   */
  public void testforCurrentOrObsoleteConceptb() throws LBException {

    // same as above, but this time, using the new methods (that aren't deprecated)
    CodedNodeSet cns =
        ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns = cns.restrictToStatus(ActiveOption.ACTIVE_ONLY, null);
    cns =
        cns.restrictToCodes(
            Constructors.createConceptReferenceList(new String[] {"C38389"}, THES_SCHEME));
    ResolvedConceptReference[] rcr =
        cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    assertTrue("1", rcr.length == 0);

    cns = ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns = cns.restrictToStatus(ActiveOption.ALL, null);
    cns =
        cns.restrictToCodes(
            Constructors.createConceptReferenceList(new String[] {"C38389"}, THES_SCHEME));
    rcr = cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    assertTrue("2", rcr.length == 1);

    // same test again - no status restriction
    cns = ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns =
        cns.restrictToCodes(
            Constructors.createConceptReferenceList(new String[] {"C38389"}, THES_SCHEME));
    rcr = cns.resolveToList(null, null, null, 0).getResolvedConceptReference();

    assertTrue("3", rcr.length == 1);

    // add a status restriction
    cns = ServiceHolder.instance().getLexBIGService().getCodingSchemeConcepts(THES_SCHEME, null);
    cns =
        cns.restrictToMatchingDesignations(
            "Sex Not Known", SearchDesignationOption.ALL, "exactMatch", null);
    cns = cns.restrictToStatus(ActiveOption.INACTIVE_ONLY, null);
    rcr = cns.resolveToList(null, null, null, 0).getResolvedConceptReference();
    assertTrue("4", rcr.length == 1);

    assertFalse("6", rcr[0].getReferencedEntry().getIsActive().booleanValue());
  }
Example #16
0
  public static String getEVSCode(String prefName, String dtsVocab) {
    LexEVSApplicationService evsService = null;

    try {
      evsService =
          (LexEVSApplicationService)
              ApplicationServiceProvider.getApplicationService("EvsServiceInfo");

    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    if (dtsVocab == null) dtsVocab = "";
    String CCode = "";
    if (dtsVocab.equals("Thesaurus/Metathesaurus")
        || dtsVocab.equals("")
        || dtsVocab.equals("NCI Thesaurus")
        || dtsVocab.equals("NCI_Thesaurus")) dtsVocab = "NCI_Thesaurus";
    ResolvedConceptReferenceList codes2 = null;
    int codesSize = 0;

    try {
      CodedNodeSet metaNodes = evsService.getNodeSet("NCI MetaThesaurus", null, null);

      metaNodes =
          metaNodes.restrictToMatchingDesignations(
              prefName, // the text to match
              CodedNodeSet.SearchDesignationOption
                  .PREFERRED_ONLY, // whether to search all designation, only Preferred or only
                                   // Non-Preferred
              "exactMatch", // the match algorithm to use
              null); // the language to match (null matches all)

      metaNodes = metaNodes.restrictToStatus(ActiveOption.ACTIVE_ONLY, null);

      codes2 =
          metaNodes.resolveToList(
              null, // Sorts used to sort results (null means sort by match score)
              null, // PropertyNames to resolve (null resolves all)
              new CodedNodeSet.PropertyType[] {
                PropertyType.DEFINITION, PropertyType.PRESENTATION
              }, // PropertyTypess to resolve (null resolves all)  //PropertyTypess to resolve (null
                 // resolves all)
              10 // cap the number of results returned (-1 resolves all)
              );
      codesSize = codes2.getResolvedConceptReferenceCount();

    } catch (Exception ex) {
      System.err.println("Error do_getEVSCode:resolveToList: " + ex.toString());
      ex.printStackTrace();
    }

    if (codes2 != null) {
      ResolvedConceptReference conceptReference = new ResolvedConceptReference();
      // logger.debug("Got "+codesSize+" results for the do_getEVSCode search using prefName and
      // exactMatch");
      for (int i = 0; i < codesSize; i++) {
        conceptReference = (ResolvedConceptReference) codes2.getResolvedConceptReference(i);
        CCode = (String) conceptReference.getConceptCode();
      }
    }

    evsService = null;
    return CCode;
  }