예제 #1
0
  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));
  }
  public void actionPerformed(ActionEvent e) {
    OWLClass selCls = getOWLClass();
    if (selCls == null) {
      return;
    }
    // TODO: Extract this and make less dependent on hierarchy provider
    OWLObjectHierarchyProvider<OWLClass> provider =
        getOWLModelManager().getOWLHierarchyManager().getOWLClassHierarchyProvider();
    Set<OWLClass> clses = new HashSet<>();
    for (OWLClass par : provider.getParents(selCls)) {
      clses.addAll(provider.getChildren(par));
    }
    for (Iterator<OWLClass> it = clses.iterator(); it.hasNext(); ) {
      OWLClass cls = it.next();
      for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) {
        if (EntitySearcher.isDefined(cls, ont)) {
          it.remove();
          break;
        }
      }
    }

    if (clses.size() > 1) {
      OWLAxiom ax = getOWLDataFactory().getOWLDisjointClassesAxiom(clses);
      getOWLModelManager().applyChange(new AddAxiom(getOWLModelManager().getActiveOntology(), ax));
    }
    // 2) Get the named subs

    //        try {
    //            OWLOntology owlOntology = getOWLModelManager().getActiveOntology();
    //            DisjointAxiomCreator creator = new
    // DisjointAxiomCreator(getOWLModelManager().getOWLClassHierarchyProvider(),
    //                                                                    owlOntology,
    //
    // getOWLModelManager().getActiveOntologies());
    //
    //            getOWLModelManager().applyChanges(creator.getChanges());
    //        } catch (OWLException ex) {
    //            logger.error(ex);
    //        }
  }