コード例 #1
0
 public void visit(OWLDisjointClassesAxiom axiom) {
   Set<OWLClassExpression> added = new HashSet<OWLClassExpression>();
   for (OWLClassExpression descA : axiom.getClassExpressions()) {
     for (OWLClassExpression descB : axiom.getClassExpressions()) {
       if (!descA.equals(descB) && !added.contains(descA) && !added.contains(descB)) {
         addChildParent(descA, descB, axiom);
         added.add(descA);
         added.add(descB);
         descA.accept(this);
         descB.accept(this);
       }
     }
   }
 }
コード例 #2
0
 public boolean canLoad(OWLOntologyDocumentSource documentSource) {
   if (documentSource.isReaderAvailable()) {
     return true;
   }
   if (documentSource.isInputStreamAvailable()) {
     return true;
   }
   if (parsableSchemes.contains(documentSource.getDocumentIRI().getScheme())) {
     return true;
   }
   // If we can open an input stream then we can attempt to parse the ontology
   // TODO: Take into consideration the request type!
   try {
     InputStream is = documentSource.getDocumentIRI().toURI().toURL().openStream();
     is.close();
     return true;
   } catch (UnknownHostException e) {
     logger.info("Unknown host: " + e.getMessage());
   } catch (MalformedURLException e) {
     logger.info("Malformed URL: " + e.getMessage());
   } catch (FileNotFoundException e) {
     logger.info("File not found: " + e.getMessage());
   } catch (IOException e) {
     logger.info("IO Exception: " + e.getMessage());
   }
   return false;
 }
コード例 #3
0
 /** @return true if the two subgraphs can be merged because they form a complete graph */
 private boolean canMerge(Set<O> g1, Set<O> g2) {
   for (O vertexInG2 : g2) {
     if (!g1.contains(vertexInG2)) {
       for (O vertexInG1 : g1) {
         if (!isEdge(vertexInG2, vertexInG1)) {
           return false; // found a vertex in g2 that is not adjacent to a vertex in g1
         }
       }
     }
   }
   return true;
 }
コード例 #4
0
    public Set<Set<O>> getResults() {
      if (resultCliques == null) {
        resultCliques = new HashSet<Set<O>>();
        Set<Integer> skip = new HashSet<Integer>();

        List<Set<O>> workingCliques = new ArrayList<Set<O>>(originalCliques);
        for (int i = 0; i < workingCliques.size(); i++) {
          if (!skip.contains(i)) {
            Set<O> g1 = new HashSet<O>(workingCliques.get(i));
            for (int j = i + 1; j < workingCliques.size(); j++) {
              if (!skip.contains(j)) {
                Set<O> g2 = workingCliques.get(j);
                if (canMerge(g1, g2)) {
                  g1.addAll(g2);
                  skip.add(j);
                }
              }
            }
            resultCliques.add(g1);
          }
        }
      }
      return resultCliques;
    }
コード例 #5
0
  public void actionPerformed(ActionEvent actionEvent) {
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    int axiomsRemoved = 0;
    int axiomsAdded = 0;
    int numberOfDisjoints = 0;

    for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) {

      // act on each ontology in turn
      CliqueFinder<OWLClassExpression> merger = new CliqueFinder<OWLClassExpression>();

      Set<OWLDisjointClassesAxiom> oldAxioms = ont.getAxioms(AxiomType.DISJOINT_CLASSES);
      numberOfDisjoints += oldAxioms.size();
      for (OWLDisjointClassesAxiom ax : oldAxioms) {
        merger.add(ax.getClassExpressions());
      }

      for (Set<OWLClassExpression> newAxioms : merger.getResults()) {
        OWLDisjointClassesAxiom newAxiom =
            getOWLModelManager().getOWLDataFactory().getOWLDisjointClassesAxiom(newAxioms);
        if (oldAxioms.contains(newAxiom)) {
          oldAxioms.remove(newAxiom);
        } else {
          changes.add(new AddAxiom(ont, newAxiom));
          axiomsAdded++;
        }
      }

      for (OWLDisjointClassesAxiom oldAxiom : oldAxioms) {
        changes.add(new RemoveAxiom(ont, oldAxiom));
        axiomsRemoved++;
      }
    }
    getOWLModelManager().applyChanges(changes);
    logger.info(
        axiomsRemoved
            + " (of "
            + numberOfDisjoints
            + " total) disjoint class axioms replaced with "
            + axiomsAdded);
  }
コード例 #6
0
 public boolean contains(Object obj) {
   return nodes.contains(obj);
 }