예제 #1
0
 private void populateResultUsingVisitor(List<OWLAxiom> result, OWLAxiomToTurtleVisitor visitor) {
   if (result != null) {
     for (OWLAxiom axiom : result) {
       axiom.accept(visitor);
     }
   }
 }
 @Override
 public void removeDataProperty(String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLAxiom axiom = factory.getOWLDeclarationAxiom(dataProperty);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
   for (OWLAxiom ax : localContext.getReferencingAxioms(dataProperty)) {
     ax = ax.getAxiomWithoutAnnotations();
     ax = changeManager.getAnnotatedAxiom(ax);
     changes.add(new RemoveAxiom(localContext, ax));
   }
   try {
     synchronized (this) {
       changeManager.validateRemovalChange(axiom);
       manager.applyChanges(changes);
     }
   } catch (RemovalException ex) {
     logger.severe(
         ex.getMessage()
             + "Data property not defined in Ontology or not defined by "
             + "this application. Change ( removeDataProperty"
             + dataPropertyName
             + ") will not be applied. ");
   }
 }
 public Integer visit(OWLOntology ontology) {
   int max = _0;
   for (OWLAxiom axiom : ontology.getLogicalAxioms()) {
     int depth = axiom.accept(this);
     if (depth > max) {
       max = depth;
     }
   }
   return max;
 }
 public void visit(OWLOntology ontology) {
   checkOccurrence(ontology.getAnnotations());
   for (AxiomType<?> t : AxiomType.AXIOM_TYPES) {
     for (OWLAxiom ax : ontology.getAxioms(t)) {
       checkOccurrence(ax.getAnnotations());
       ax.accept(this);
     }
   }
   singleAppearance.clear();
 }
예제 #5
0
 private List<Construct> getOrderedConstructs() {
   constructs.clear();
   constructs.add(AL);
   for (OWLOntology ont : ontologies) {
     for (OWLAxiom ax : ont.getLogicalAxioms()) {
       ax.accept(this);
     }
   }
   pruneConstructs();
   List<Construct> cons = new ArrayList<Construct>(constructs);
   Collections.sort(cons, new ConstructComparator());
   return cons;
 }
예제 #6
0
 private Set<OWLAnnotation> duplicateAxiomAnnotations(OWLAxiom axiom) {
   Set<OWLAnnotation> duplicatedAnnos = new HashSet<OWLAnnotation>();
   for (OWLAnnotation anno : axiom.getAnnotations()) {
     anno.accept(this);
     duplicatedAnnos.add((OWLAnnotation) obj);
   }
   return duplicatedAnnos;
 }
 /**
  * Convert.
  *
  * @param axiom axiom to convert
  * @return converted class expression
  */
 public OWLClassExpression convert(OWLAxiom axiom) {
   converter.reset();
   axiom.accept(converter);
   OWLClassExpression result = converter.getResult();
   if (result == null) {
     throw new RuntimeException("Not supported yet");
   }
   return result;
 }
예제 #8
0
  /**
   * <b>Motivation</b>: OWL reasoners do not return superclass expressions If we want to find all
   * class expressions that may hold for a class then we must pre-coordinate all possible
   * expressions within the subset of OWL we care about. <br>
   * This class generates all satisfiable class expressions of the form r some c (for the
   * cross-product of R x C), as well as all class expressions that have been used (which may
   * include nested expressions)
   *
   * <p>The results are stored in queryClassMap
   *
   * @param precomputePropertyClassCombinations
   */
  @Deprecated
  private void generateQueryOntology(boolean precomputePropertyClassCombinations) {
    queryClassMap = new HashMap<OWLClass, OWLClassExpression>();

    getReasoner().flush();

    if (precomputePropertyClassCombinations) {
      LOG.debug("Precomputing all OP x Class combos");
      // cross-product of P x C
      // TODO - reflexivity and local reflexivity?
      for (OWLObjectProperty p : tboxOntology.getObjectPropertiesInSignature(true)) {
        LOG.debug(" materializing P some C for P=:" + p);
        for (OWLClass c : tboxOntology.getClassesInSignature(true)) {
          OWLObjectSomeValuesFrom r = getOWLDataFactory().getOWLObjectSomeValuesFrom(p, c);
          // LOG.debug(" QMAP:"+r);
          addClassExpressionToQueryMap(r);
        }
      }
    }

    // all expressions used in ontology
    for (OWLOntology ont : tboxOntology.getImportsClosure()) {
      LOG.debug("Finding all nested anonymous expressions");
      for (OWLAxiom ax : ont.getAxioms()) {
        // TODO - check if this is the nest closure. ie (r some (r2 some (r3 some ...)))
        for (OWLClassExpression x : ax.getNestedClassExpressions()) {
          if (x.isAnonymous()) {
            // LOG.debug(" QMAP+:"+x);
            addClassExpressionToQueryMap(x);
          }
        }
      }
    }
    if (LOG.isDebugEnabled()) {
      for (OWLOntology ont : collectedAxioms.keySet()) {
        LOG.debug("TOTAL axioms in QMAP: " + collectedAxioms.get(ont).size());
      }
    }
    LOG.debug("Adding collected axioms");
    addCollectedAxioms();
    LOG.debug("Flushing reasoner...");
    reasoner.flush();
    LOG.debug("Flushed reasoner");
  }
  private void reload(OWLOntology ontology, OWLOntologyFormat format) throws Exception {
    Set<OWLAxiom> annotationAxioms = new HashSet<OWLAxiom>();
    for (OWLAxiom ax : ontology.getAxioms()) {
      if (ax.isAnnotationAxiom()) {
        annotationAxioms.add(ax);
      }
    }
    OWLOntologyLoaderConfiguration withAnnosConfig = new OWLOntologyLoaderConfiguration();
    OWLOntology reloadedWithAnnoAxioms = reload(ontology, format, withAnnosConfig);
    assertEquals(ontology.getAxioms(), reloadedWithAnnoAxioms.getAxioms());
    //
    OWLOntologyLoaderConfiguration withoutAnnosConfig =
        new OWLOntologyLoaderConfiguration().setLoadAnnotationAxioms(false);
    OWLOntology reloadedWithoutAnnoAxioms = reload(ontology, format, withoutAnnosConfig);
    assertFalse(ontology.getAxioms().equals(reloadedWithoutAnnoAxioms.getAxioms()));

    Set<OWLAxiom> axiomsMinusAnnotationAxioms = new HashSet<OWLAxiom>(ontology.getAxioms());
    axiomsMinusAnnotationAxioms.removeAll(annotationAxioms);
    assertEquals(axiomsMinusAnnotationAxioms, reloadedWithoutAnnoAxioms.getAxioms());
  }
예제 #10
0
  @Override
  public boolean compare(JSONObject jsonObject, OWLClass owlClass, OWLOntology owlOntology) {
    Set<OWLClass> allClassesInAxiomsRelated = new HashSet<OWLClass>();
    JSONArray jsonAnnotationsArray = (JSONArray) jsonObject.get("annotations");

    Set<OWLAxiom> owlAxiomSet = owlClass.getReferencingAxioms(owlOntology);
    Iterator<OWLAxiom> owlAxiomSetIterator = owlAxiomSet.iterator();
    while (owlAxiomSetIterator.hasNext()) {
      OWLAxiom owlAxiom = owlAxiomSetIterator.next();
      Set<OWLClass> owlClassesInAxiom = owlAxiom.getClassesInSignature();
      allClassesInAxiomsRelated.addAll(owlClassesInAxiom);
    }

    Set<String> owlClassesIds = new HashSet<String>();
    Iterator<OWLClass> allClassesInAxiomsRelatedIterator = allClassesInAxiomsRelated.iterator();
    while (allClassesInAxiomsRelatedIterator.hasNext()) {
      OWLClass currentClass = allClassesInAxiomsRelatedIterator.next();
      owlClassesIds.add(
          OwlDataExtrators.getAttribute("id", currentClass, owlOntology).replace(":", "_"));
    }

    Set<String> jsonAnnotationsIdsSet = new HashSet<String>();
    Iterator<JSONObject> jsonAnnotationsArrayIterator = jsonAnnotationsArray.iterator();
    while (jsonAnnotationsArrayIterator.hasNext()) {
      JSONObject jsonAnnottation = jsonAnnotationsArrayIterator.next();
      String jsonAnnotationIdentifier = (String) jsonAnnottation.get("identifier");
      jsonAnnotationsIdsSet.add(jsonAnnotationIdentifier);
    }

    Set<Set<String>> jsonAnnotationsIdPowerSet = SetsOperations.powerSet(jsonAnnotationsIdsSet);
    Iterator<Set<String>> jsonAnnotationsIdPowerSetIterator = jsonAnnotationsIdPowerSet.iterator();
    while (jsonAnnotationsIdPowerSetIterator.hasNext()) {
      Set<String> idsSet = jsonAnnotationsIdPowerSetIterator.next();
      if (idsSet.containsAll(owlClassesIds)) {
        return true;
      }
    }

    return false;
  }
 public Object getRelationshipType(Object parentObject, Object childObject) {
   AxiomEdge edge = new AxiomEdge(childObject, parentObject);
   OWLObject edgeObject = edgeMap.get(edge);
   if (edgeObject != null) {
     edgeNameGenerator.reset();
     if (edgeObject instanceof OWLClassExpression) {
       ((OWLClassExpression) edgeObject).accept(edgeNameGenerator);
     } else {
       ((OWLAxiom) edgeObject).accept(edgeNameGenerator);
     }
     return edgeNameGenerator.edgeName;
   } else {
     return null;
   }
 }
 public int getRelationshipDirection(Object parentObject, Object childObject) {
   AxiomEdge edge = new AxiomEdge(childObject, parentObject);
   OWLObject edgeObject = edgeMap.get(edge);
   if (edgeObject != null) {
     edgeNameGenerator.reset();
     if (edgeObject instanceof OWLAxiom) {
       ((OWLAxiom) edgeObject).accept(edgeNameGenerator);
     } else {
       ((OWLClassExpression) edgeObject).accept(edgeNameGenerator);
     }
     return edgeNameGenerator.direction;
   }
   return -1; // if no edge found, negative direction for handling in
   // DefaultEdgeFactory
 }
 private boolean isOBOAxiom(OWLAxiom axiom) {
   return axiom.accept(checker);
 }
예제 #14
0
 public AxiomType<?> getAxiomType(OWLAxiom axiom) {
   axiom.accept(this);
   return axiomType;
 }
 // ////////////////////////////////////////////////////////////////////////////////////////////
 //
 // Axiom Visitor stuff
 //
 // ////////////////////////////////////////////////////////////////////////////////////////////
 protected void processAxiomAnnotations(OWLAxiom ax) {
   // default behavior: iterate over the annotations outside the axiom
   for (OWLAnnotation anno : ax.getAnnotations()) {
     anno.accept(this);
   }
 }
 /**
  * This method clears all the map (invokes the clearMaps-method) at first. Then it iterates over
  * all axioms and invokes their accept-Method with "this" as parameter.
  *
  * @param axioms The axioms to visualize
  */
 public void addAndClearAxioms(Set<OWLAxiom> axioms) {
   this.clearMaps();
   for (OWLAxiom ax : axioms) {
     ax.accept(this);
   }
 }