Package au.csiro.snorocket.core

Examples of au.csiro.snorocket.core.SnorocketReasoner


       
        System.out.println("Running Snorocket API Example");
       
        // Create the reasoner instance - the parametrised type refers to the
        // type of the external identifiers
        IReasoner reasoner = new SnorocketReasoner();
       
        // This set will contain the base axioms
        Set<Axiom> baseAxioms = new HashSet<Axiom>();
       
        // The factory can be used to create axioms using the default
        // implementing classes
        Factory f = new Factory();
       
        // The factory returns IConcepts - in this case the actual type is
        // INamedConcept<String>
        Concept endocardium = f.createNamedConcept("Endocardium");
        Concept tissue = f.createNamedConcept("Tissue");
        Concept heartWall = f.createNamedConcept("HeartWall");
        Concept heartValve = f.createNamedConcept("HeartValve");
        Concept bodyWall = f.createNamedConcept("BodyWall");
        Concept heart = f.createNamedConcept("Heart");
        Concept bodyValve = f.createNamedConcept("BodyValve");
        Concept endocarditis = f.createNamedConcept("Endocarditis");
        Concept inflammation = f.createNamedConcept("Inflammation");
        Concept disease = f.createNamedConcept("Disease");
        Concept heartDisease = f.createNamedConcept("HeartDisease");
        Concept criticalDisease = f.createNamedConcept("CriticalDisease");
       
        // The factory can also be used to create roles
        Role actsOn = f.createNamedRole("acts-on");
        Role partOf = f.createNamedRole("part-of");
        Role contIn = f.createNamedRole("cont-in");
        Role hasLoc = f.createNamedRole("has-loc");
       
        // Finally, the factory can be used to create axioms
        Concept lhs = endocardium;
        Concept rhs = f.createConjunction(
                tissue,
                f.createExistential((NamedRole) contIn, heartWall),
                f.createExistential((NamedRole) contIn, heartValve)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        lhs = heartWall;
        rhs = f.createConjunction(
                bodyWall,
                f.createExistential((NamedRole) partOf, heart)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        lhs = heartValve;
        rhs = f.createConjunction(
                bodyValve,
                f.createExistential((NamedRole) partOf, heart)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        lhs = endocarditis;
        rhs = f.createConjunction(
                inflammation,
                f.createExistential((NamedRole) hasLoc, endocardium)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));

        lhs = inflammation;
        rhs = f.createConjunction(
                disease,
                f.createExistential(actsOn, tissue)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        lhs = f.createConjunction(
                heartDisease,
                f.createExistential(hasLoc, heartValve)
        );
        rhs = criticalDisease;
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        // There is no direct support in the API to create an equivalence axiom
        // so it has to be created using two concept inclusion axioms
        lhs = heartDisease;
        rhs = f.createConjunction(
                disease,
                f.createExistential(hasLoc, heart)
        );
        baseAxioms.add(f.createConceptInclusion(lhs, rhs));
        baseAxioms.add(f.createConceptInclusion(rhs, lhs));
       
        Role[] rlhs = new Role[]{partOf, partOf};
        Role rrhs = partOf;
        baseAxioms.add(f.createRoleInclusion(rlhs, rrhs));
       
        rlhs = new Role[]{partOf};
        rrhs = contIn;
        baseAxioms.add(f.createRoleInclusion(rlhs, rrhs));
       
        rlhs = new Role[]{hasLoc, contIn};
        rrhs = hasLoc;
        baseAxioms.add(f.createRoleInclusion(rlhs, rrhs));
       
        // The first time the classify method is called it runs a full
        // classification
        reasoner.loadAxioms(baseAxioms);
        reasoner.classify();
       
        // If classification worked properly then Endocarditis should be
        // classified not only as an Inflammation but also as a HeartDisease
        // and a CriticalDisease
        Ontology t = reasoner.getClassifiedOntology();
       
        // We use the same id that was used to create the concept to look for
        // the corresponding node in the taxonomy
        Node endocarditisNode = t.getNode("Endocarditis");
        System.out.println("Node for endocarditis:\n  "+
                endocarditisNode.getEquivalentConcepts());
       
       
        // We can now print the equivalent concepts in the node and the parent
        // nodes
        Set<Node> parentNodes = endocarditisNode.getParents();
        System.out.println("Parents of endocarditis:");
        for(Node parentNode : parentNodes) {
            System.out.println("  "+parentNode.getEquivalentConcepts());
        }
       
        // We can now add more axioms to the ontology and re-run the
        // classification
        Set<Axiom> additionalAxioms = new HashSet<Axiom>();
       
        Concept heartInflammation = f.createNamedConcept("HeartInflammation");
       
        lhs = heartInflammation;
        rhs = inflammation;
        additionalAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        lhs = endocarditis;
        rhs = f.createConjunction(
                heartInflammation,
                f.createExistential(hasLoc, endocardium)
        );
        additionalAxioms.add(f.createConceptInclusion(lhs, rhs));
       
        // Subsequent invocations will trigger an incremental classification
        System.out.println("Running incremental classification:");
        reasoner.loadAxioms(additionalAxioms);
        reasoner.classify();
       
        // Now Endocarditis should be a HeartInflammation instead of an
        // Inflammation
        t = reasoner.getClassifiedOntology();
        endocarditisNode = t.getNode("Endocarditis");
        System.out.println("Node for endocarditis:\n  "+
                endocarditisNode.getEquivalentConcepts());

        parentNodes = endocarditisNode.getParents();
View Full Code Here


        System.out.println("Running Chest Pain Lego Example");
       
        // Create the reasoner instance - the parametrised type refers to the
        // type of the external identifiers. In this case String is used and the
        // concepts are identified by sctid (but UUIDs could also be used).
        IReasoner reasoner = new SnorocketReasoner();
       
        // This set will contain the axioms
        Set<Axiom> axioms = new HashSet<Axiom>();
       
        // The factory can be used to create axioms using the default
        // implementing classes
        Factory f = new Factory();
       
        // The factory returns IConcepts - in this case the actual type is
        // INamedConcept<String>
        Concept nonCardiacChestPain = f.createNamedConcept("274668005");
        Concept duringExcersice = f.createNamedConcept("309604004");
        Concept interview = f.createNamedConcept("108217004");
        Concept present = f.createNamedConcept("52101004");
       
        // The factory can also be used to create roles
        Role associatedWith = f.createNamedRole("47429007");
       
        // We need to define exactly what the identifier for the new concept
        // will be
        Concept historyCardioStandardNonAnginalChestPainExertion = f.createNamedConcept("pce_24220");
       
        // This is the axiom created for the discernable
        axioms.add(
            f.createConceptInclusion(
                historyCardioStandardNonAnginalChestPainExertion,
                f.createConjunction(
                        nonCardiacChestPain,
                        f.createExistential(associatedWith, duringExcersice)
                )
        ));
       
        // This is the axiom created for the qualifier
        axioms.add(
            f.createConceptInclusion(
                historyCardioStandardNonAnginalChestPainExertion,
                interview
            )
        );
       
        // This is the axiom created for the value
        axioms.add(
            f.createConceptInclusion(
                historyCardioStandardNonAnginalChestPainExertion,
                present
            )
        );
       
        // The first time the classify method is called it runs a full
        // classification. In this example there is no base state loaded so
        // a full (and not very useful) classification will be excuted.
        reasoner.loadAxioms(axioms);
        reasoner.classify();
       
        // The taxonomy contains the inferred hierarchy
        Ontology t = reasoner.getClassifiedOntology();
       
        // We can look for nodes using the concept ids.
        Node newNode = t.getNode("pce_24220");
        System.out.println("Node for HISTORY_CARDIO_Standard_Non_Anginal_" +
            "Chest_Pain_Exertion:\n  "+
View Full Code Here

   
    public void start() {
       
        // 1. Load the base state
      System.out.println("Loading base state from classifier_uuid.state");
        SnorocketReasoner reasoner = SnorocketReasoner.load(
                this.getClass().getResourceAsStream("/classifier_uuid.state"));
       
        // 2. Load SCT to UUID map
        System.out.println("Loading uuid description map");
        Map<String, String> sctToUuidMap = new HashMap<String, String>();
        Map<String, String> uuidToDescMap = new HashMap<String, String>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(
                    this.getClass().getResourceAsStream("/nid_sctid_uuid_map.txt"),
                    "UTF8"));
            String line = null;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split("[,]");
                String desc = null;
                if(parts.length < 4) {
                    desc = "";
                } else {
                  desc = parts[3];
                }
                if(parts[1].equals("NA")) continue;
                sctToUuidMap.put(parts[1], parts[2]);
                uuidToDescMap.put(parts[2], desc);
            }     
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            if(reader != null) {
                try { reader.close(); } catch(Exception e) {}
            }
        }
       
        // 3. Add test axiom
        System.out.println("Adding test axiom");
        Factory f = new Factory();
        String newId = UUID.randomUUID().toString();
        uuidToDescMap.put(newId, "Special Appendicits");
       
        Concept specialAppendicitis = f.createNamedConcept(newId);
        String appendicitsUuid = "55450fab-6786-394d-89f9-a0fd44bd7e7e";
        Concept appendicitis = f.createNamedConcept(appendicitsUuid);
        Axiom a1 = f.createConceptInclusion(specialAppendicitis, appendicitis);
        Set<Axiom> axioms = new HashSet<Axiom>();
        axioms.add(a1);
       
        // 4. Classify incrementally
        System.out.println("Classifying incrementally");
        reasoner.loadAxioms(axioms);
        reasoner.classify();
       
        // 5. Retrieve taxonomy
        System.out.println("Retrieving taxonomy");
        Ontology ont = reasoner.getClassifiedOntology();
       
        // 6. Get node for new concept
        Node specialAppendicitisNode = ont.getNodeMap().get(appendicitsUuid);
       
        // 7. Print the new node
View Full Code Here

        );
        axioms.add(a5);
        axioms.add(a5b);
       
        // Create a classifier and classify the axioms
        IReasoner r = new SnorocketReasoner();
        r.loadAxioms(axioms);
        r = r.classify();
       
        // Get only the taxonomy
        Ontology res = r.getClassifiedOntology();
        Utils.printTaxonomy(res.getTopNode(), res.getBottomNode());
    }
View Full Code Here

        OWLImporter oi = new OWLImporter(root);
       
        Iterator<Ontology> it = oi.getOntologyVersions(new NullProgressMonitor());
        while(it.hasNext()) {
            Ontology ont = it.next();
            IReasoner r = new SnorocketReasoner();
            r.loadAxioms(ont);
            r = r.classify();
            Ontology co = r.getClassifiedOntology();
            int numConcepts = co.getNodeMap().keySet().size();
            System.out.println("numConcepts: "+numConcepts);
        }
       
    }
View Full Code Here

     */
    public void dispose() {
        owlOntology.getOWLOntologyManager().removeOntologyChangeListener(
                ontologyChangeListener);
        rawChanges.clear();
        reasoner = new SnorocketReasoner();
    }
View Full Code Here

TOP

Related Classes of au.csiro.snorocket.core.SnorocketReasoner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.