Example #1
0
 /** {@inheritDoc} */
 public boolean isPrecomputed(InferenceType inferenceType) {
   switch (inferenceType) {
     case CLASS_HIERARCHY:
       return kb.isClassified();
     case CLASS_ASSERTIONS:
       return kb.isRealized();
     case OBJECT_PROPERTY_HIERARCHY:
       return kb.getRBox().isObjectTaxonomyPrepared();
     case DATA_PROPERTY_HIERARCHY:
       return kb.getRBox().isDataTaxonomyPrepared();
     default:
       return false;
   }
 }
Example #2
0
  /**
   * Create a reasoner for the given ontology and configuration.
   *
   * @param ontology
   */
  public PelletReasoner(
      OWLOntology ontology, OWLReasonerConfiguration config, BufferingMode bufferingMode)
      throws IllegalConfigurationException {

    individualNodeSetPolicy = config.getIndividualNodeSetPolicy();

    if (!getFreshEntityPolicy().equals(config.getFreshEntityPolicy())) {
      throw new IllegalConfigurationException(
          "PelletOptions.SILENT_UNDEFINED_ENTITY_HANDLING conflicts with reasoner configuration",
          config);
    }

    this.ontology = ontology;
    monitor = config.getProgressMonitor();

    kb = new KnowledgeBase();
    kb.setTaxonomyBuilderProgressMonitor(new ProgressAdapter(monitor));
    if (config.getTimeOut() > 0) {
      kb.timers.mainTimer.setTimeout(config.getTimeOut());
    }

    this.manager = ontology.getOWLOntologyManager();
    this.factory = manager.getOWLDataFactory();
    this.visitor = new PelletVisitor(kb);

    this.bufferingMode = bufferingMode;

    manager.addOntologyChangeListener(this);

    this.shouldRefresh = true;
    this.pendingChanges = new ArrayList<OWLOntologyChange>();

    refresh();
  }
Example #3
0
 public boolean isConsistent() throws ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   try {
     return kb.isConsistent();
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #4
0
 /** {@inheritDoc} */
 public void precomputeInferences(InferenceType... inferenceTypes)
     throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException {
   for (InferenceType inferenceType : inferenceTypes) {
     switch (inferenceType) {
       case CLASS_HIERARCHY:
         kb.classify();
       case CLASS_ASSERTIONS:
         kb.realize();
       case OBJECT_PROPERTY_HIERARCHY:
         kb.getRBox().getObjectTaxonomy();
       case DATA_PROPERTY_HIERARCHY:
         kb.getRBox().getDataTaxonomy();
       default:
         break;
     }
   }
 }
Example #5
0
 public Node<OWLClass> getUnsatisfiableClasses()
     throws ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   try {
     return toClassNode(kb.getAllUnsatisfiableClasses());
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #6
0
 public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce, boolean direct)
     throws InconsistentOntologyException, ClassExpressionNotInProfileException,
         FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   try {
     return getIndividualNodeSet(kb.getInstances(term(ce), direct));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #7
0
 public Node<OWLNamedIndividual> getSameIndividuals(OWLNamedIndividual ind)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     return toIndividualNode(kb.getAllSames(term(ind)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #8
0
 public Node<OWLDataProperty> getEquivalentDataProperties(OWLDataProperty pe)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     return toDataPropertyNode(kb.getAllEquivalentProperties(term(pe)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #9
0
 public Node<OWLClass> getEquivalentClasses(OWLClassExpression ce)
     throws InconsistentOntologyException, ClassExpressionNotInProfileException,
         FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   try {
     return toClassNode(kb.getAllEquivalentClasses(term(ce)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #10
0
 public boolean isSatisfiable(OWLClassExpression classExpression)
     throws ReasonerInterruptedException, TimeOutException, ClassExpressionNotInProfileException,
         FreshEntitiesException, InconsistentOntologyException {
   refreshCheck();
   try {
     return kb.isSatisfiable(term(classExpression));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #11
0
 public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual ind, OWLDataProperty pe)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     return toLiteralSet(kb.getDataPropertyValues(term(pe), term(ind)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #12
0
 public Node<OWLObjectPropertyExpression> getInverseObjectProperties(
     OWLObjectPropertyExpression pe)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     return toObjectPropertyNode(kb.getInverses(term(pe)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #13
0
 public NodeSet<OWLNamedIndividual> getObjectPropertyValues(
     OWLNamedIndividual ind, OWLObjectPropertyExpression pe)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     return getIndividualNodeSet(kb.getObjectPropertyValues(term(pe), term(ind)));
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #14
0
 public NodeSet<OWLClass> getTypes(OWLNamedIndividual ind, boolean direct)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     Set<Set<ATermAppl>> result = kb.getTypes(term(ind), direct);
     return toClassNodeSet(result);
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #15
0
 public NodeSet<OWLClass> getSuperClasses(OWLClassExpression ce, boolean direct)
     throws InconsistentOntologyException, ClassExpressionNotInProfileException,
         FreshEntitiesException, ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   try {
     Set<Set<ATermAppl>> result = kb.getSuperClasses(term(ce), direct);
     return toClassNodeSet(result);
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #16
0
  public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce)
      throws InconsistentOntologyException, ClassExpressionNotInProfileException,
          FreshEntitiesException, ReasonerInterruptedException, TimeOutException {

    refreshCheck();
    try {
      Set<Set<ATermAppl>> disjoints = kb.getDisjointClasses(term(ce));
      return toClassNodeSet(disjoints);
    } catch (PelletRuntimeException e) {
      throw convert(e);
    }
  }
Example #17
0
  private NodeSet<OWLNamedIndividual> getIndividualNodeSetByName(
      Collection<ATermAppl> individuals) {
    Set<Node<OWLNamedIndividual>> instances = new HashSet<Node<OWLNamedIndividual>>();

    for (ATermAppl ind : individuals) {
      for (ATermAppl equiv : kb.getAllSames(ind)) {
        instances.add(toIndividualNode(equiv));
      }
    }

    return new OWLNamedIndividualNodeSet(instances);
  }
Example #18
0
  public NodeSet<OWLClass> getObjectPropertyRanges(OWLObjectPropertyExpression pe, boolean direct)
      throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
          TimeOutException {
    refreshCheck();
    try {
      ATermAppl some = ATermUtils.makeSomeValues(ATermUtils.makeInv(term(pe)), ATermUtils.TOP);

      Set<ATermAppl> equivalents = kb.getEquivalentClasses(some);
      if (direct && !equivalents.isEmpty()) {
        return toClassNodeSet(Collections.singleton(equivalents));
      }

      Set<Set<ATermAppl>> result = kb.getSuperClasses(some, direct);
      if (!equivalents.isEmpty()) {
        result.add(equivalents);
      }

      return toClassNodeSet(result);
    } catch (PelletRuntimeException e) {
      throw convert(e);
    }
  }
Example #19
0
  /** Clears the reasoner and reloads all the axioms in the imports closure. */
  public void refresh() {
    visitor.clear();
    kb.clear();

    importsClosure = ontology.getImportsClosure();

    visitor.setAddAxiom(true);
    for (OWLOntology ont : importsClosure) {
      ont.accept(visitor);
    }
    visitor.verify();

    shouldRefresh = false;
  }
Example #20
0
  private NodeSet<OWLNamedIndividual> getIndividualNodeSetBySameAs(
      Collection<ATermAppl> individuals) {
    Set<Node<OWLNamedIndividual>> instances = new HashSet<Node<OWLNamedIndividual>>();
    Set<ATermAppl> seen = new HashSet<ATermAppl>();
    for (ATermAppl ind : individuals) {
      if (!seen.contains(ind)) {
        Set<ATermAppl> equiv = kb.getAllSames(ind);
        instances.add(toIndividualNode(equiv));
        seen.addAll(equiv);
      }
    }

    return new OWLNamedIndividualNodeSet(instances);
  }
Example #21
0
 public NodeSet<OWLDataProperty> getSuperDataProperties(OWLDataProperty pe, boolean direct)
     throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
         TimeOutException {
   refreshCheck();
   try {
     Set<Node<OWLDataProperty>> values = new HashSet<Node<OWLDataProperty>>();
     for (Set<ATermAppl> val : kb.getSuperProperties(term(pe), direct)) {
       values.add(toDataPropertyNode(val));
     }
     return new OWLDataPropertyNodeSet(values);
   } catch (PelletRuntimeException e) {
     throw convert(e);
   }
 }
Example #22
0
  public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties(
      OWLObjectPropertyExpression pe)
      throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException,
          TimeOutException {
    refreshCheck();
    try {
      Set<Node<OWLObjectPropertyExpression>> values =
          new HashSet<Node<OWLObjectPropertyExpression>>();
      for (Set<ATermAppl> val : kb.getDisjointProperties(term(pe))) {
        values.add(toObjectPropertyNode(val));
      }

      return new OWLObjectPropertyNodeSet(values);
    } catch (PelletRuntimeException e) {
      throw convert(e);
    }
  }
Example #23
0
 /** {@inheritDoc} */
 public void prepareReasoner() throws ReasonerInterruptedException, TimeOutException {
   refreshCheck();
   if (kb.isConsistent()) {
     kb.realize();
   }
 }
Example #24
0
 public Node<OWLObjectPropertyExpression> getTopObjectPropertyNode() {
   refreshCheck();
   return toObjectPropertyNode(kb.getAllEquivalentProperties(ATermUtils.TOP_OBJECT_PROPERTY));
 }
Example #25
0
 public Node<OWLDataProperty> getTopDataPropertyNode() {
   refreshCheck();
   return toDataPropertyNode(kb.getAllEquivalentProperties(ATermUtils.TOP_DATA_PROPERTY));
 }
Example #26
0
 public Node<OWLClass> getTopClassNode() {
   refreshCheck();
   return toClassNode(kb.getAllEquivalentClasses(ATermUtils.TOP));
 }