NIH | National Cancer Institute | NCI Wiki  

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Code Block
languageJava
titleJava Code Snippet
    public void getTransitiveClosure() {
        //Calculate the transitive closure (all subconcepts) of a given concept
        ResolvedConceptReferencesIterator iterator = null;
        try {
            String codingSchemeName = "NCI Thesaurus";
            String code = "C20181";
            String associationName = "subClassOf";
            boolean resolveForward = false;
            boolean excludeAnonymous = true;
            CodingSchemeVersionOrTag csvt = new CodingSchemeVersionOrTag();
            csvt.setTag("PRODUCTION");
            ConceptReference graphFocus = new ConceptReference();
            graphFocus.setConceptCode(code);
            CodedNodeGraph cng = lbSvc.getNodeGraph(codingSchemeName, csvt, null);
            NameAndValueList asso_list =
                    Constructors.createNameAndValueList(new String[] { associationName }, null);
            cng = cng.restrictToAssociations(asso_list, null);
            boolean resolveBackward = false;
            if (!resolveForward) {
                resolveBackward = true;
            }
            int resolveAssociationDepth = -1;
            int maxReturns = -1;
            CodedNodeSet cns = cng.toNodeList(graphFocus, resolveForward, resolveBackward,
                    resolveAssociationDepth, maxReturns);
            if (excludeAnonymous) {
                CodedNodeSet.AnonymousOption restrictToAnonymous = 

<ac:macro ac:name="code">
  <ac:parameter ac:name="title">Java Code Snippet</ac:parameter>
  <ac:parameter ac:name="language">Java</ac:parameter>
  <ac:plain-text-body><![CDATA[      

    public void testTransitiveClosure(){

        /*

         * Check for all descendants of a given concept

         *         

         */

        System.out.println("***********************");

        System.out.println("Testing transitive closure");

        System.out.println("***********************");

        String scheme = "NCI Thesaurus";

        String code = "C20181";

        ConceptReference cr = ConvenienceMethods.createConceptReference(code,

                scheme);

        CodingSchemeVersionOrTag vt = new CodingSchemeVersionOrTag();

        vt.setTag("PRODUCTION");

        try {

            NameAndValueList nvList = Constructors.createNameAndValueList("subClassOf");

            CodedNodeGraph cng =  lbSvc.getNodeGraph(scheme, vt, null);

            cng.restrictToAssociations(nvList, null);

            CodedNodeSet nodeset = cng.toNodeList(ConvenienceMethods.createConceptReference(code, scheme), false, true,-1, -1);

...

CodedNodeSet.AnonymousOption.NON_ANONYMOUS_ONLY;

...


                cns = cns.restrictToAnonymous(restrictToAnonymous);

...


            }
            iterator = cns.resolve(null, null,

...

 null, null, false);

...


            while (iterator.hasNext()){

...


                ResolvedConceptReference rcr = iterator.next();

...


                String codeReturn = rcr.getCode();

...


                System.out.println(codeReturn);

...

            }

        } catch (Exception e) {

            e.printStackTrace();

        }

  }

...


            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }