public static Map<EdamUri, Concept> load(String edamPath) throws OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(edamPath)); String prefix = ontology.getOntologyID().getOntologyIRI().get().toString(); return ontology .classesInSignature() .filter(c -> EdamUri.isEdamUri(c.getIRI().toString(), prefix)) .collect( Collectors.toMap( c -> new EdamUri(c.getIRI().toString(), prefix), c -> { Concept concept = new Concept(); EntitySearcher.getAnnotations(c, ontology) .forEachOrdered( a -> { if (a.getProperty().isLabel()) concept.setLabel(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isDeprecated()) concept.setObsolete(true); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym") && a.getValue().asLiteral().isPresent()) concept.addExactSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym") && a.getValue().asLiteral().isPresent()) concept.addNarrowSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym") && a.getValue().asLiteral().isPresent()) concept.addBroadSynonym(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty() .toStringID() .equals( "http://www.geneontology.org/formats/oboInOwl#hasDefinition") && a.getValue().asLiteral().isPresent()) concept.setDefinition(a.getValue().asLiteral().get().getLiteral()); else if (a.getProperty().isComment() && a.getValue().asLiteral().isPresent()) concept.setComment(a.getValue().asLiteral().get().getLiteral()); }); if (concept.getLabel().isEmpty()) throw new IllegalStateException( String.format("Label of concept %s is empty", c.getIRI())); return concept; }, (u, v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }, LinkedHashMap::new)); }
/** Runs the factory through a standard SISSVoc response XML */ @Test public void testSISSVocRDF() throws Exception { // Build our expectation Concept concept1 = new Concept("urn:concept:1"); Concept concept2 = new Concept("urn:concept:2"); Concept concept3 = new Concept("urn:concept:3"); Concept concept4 = new Concept("urn:concept:4"); NamedIndividual ni1 = new NamedIndividual("urn:ni:1"); NamedIndividual ni2 = new NamedIndividual("urn:ni:2"); NamedIndividual ni3 = new NamedIndividual("urn:ni:3"); concept1.setNarrower(new Concept[] {concept2, concept3, ni2}); concept1.setLabel("LabelConcept1"); concept1.setPreferredLabel("PrefLabelConcept1"); concept2.setBroader(new Concept[] {concept1}); concept2.setRelated(new Concept[] {concept3}); concept2.setLabel("LabelConcept2"); concept2.setPreferredLabel("PrefLabelConcept2"); concept2.setDefinition("DefinitionConcept2"); concept3.setBroader(new Concept[] {concept1}); concept3.setRelated(new Concept[] {concept2}); concept3.setNarrower(new Concept[] {ni1}); concept3.setLabel("LabelConcept3"); concept3.setPreferredLabel("PrefLabelConcept3"); concept4.setNarrower(new Concept[] {ni3}); concept4.setLabel("LabelConcept4"); concept4.setPreferredLabel("PrefLabelConcept4"); concept4.setDefinition("DefinitionConcept4"); ni1.setBroader(new Concept[] {concept3}); ni1.setLabel("LabelNamedIndividual1"); ni1.setPreferredLabel("PrefLabelNamedIndividual1"); ni2.setBroader(new Concept[] {concept1}); ni2.setLabel("LabelNamedIndividual2"); ni2.setPreferredLabel("PrefLabelNamedIndividual2"); ni3.setBroader(new Concept[] {concept4}); ni3.setLabel("LabelNamedIndividual3"); ni3.setPreferredLabel("PrefLabelNamedIndividual3"); Concept[] expectation = new Concept[] {concept1, concept4}; // Build our actual list String responseXml = ResourceUtil.loadResourceAsString( "org/auscope/portal/core/test/responses/sissvoc/SISSVocResponse.xml"); Document responseDoc = DOMUtil.buildDomFromString(responseXml); Node rdfNode = (Node) DOMUtil.compileXPathExpr("rdf:RDF", new VocabNamespaceContext()) .evaluate(responseDoc, XPathConstants.NODE); ConceptFactory cf = new ConceptFactory(); Concept[] actualConcepts = cf.parseFromRDF(rdfNode); Assert.assertNotNull(actualConcepts); assertSameConcept(expectation, actualConcepts, new ArrayList<String>()); }