Ejemplo n.º 1
0
  protected void importInverseOf(OWLOntology o, OWLObjectProperty objectProperty) {
    String iri = objectProperty.getIRI().toString();
    Relationship fromRelationship = null;

    for (OWLObjectPropertyExpression inverseOf : objectProperty.getInverses(o)) {
      if (inverseOf instanceof OWLObjectProperty) {
        if (fromRelationship == null) {
          fromRelationship = getRelationshipByIRI(iri);
        }

        OWLObjectProperty inverseOfOWLObjectProperty = (OWLObjectProperty) inverseOf;
        String inverseOfIri = inverseOfOWLObjectProperty.getIRI().toString();
        Relationship inverseOfRelationship = getRelationshipByIRI(inverseOfIri);
        getOrCreateInverseOfRelationship(fromRelationship, inverseOfRelationship);
      }
    }
  }
Ejemplo n.º 2
0
  private void runWithSeparateFiles() {
    if (owlFile == null) {
      throw new NullPointerException("You have to specify an ontology file!");
    }

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = null;
    OBDADataFactory obdaDataFactory = OBDADataFactoryImpl.getInstance();
    try {
      ontology = manager.loadOntologyFromOntologyDocument((new File(owlFile)));

      if (disableReasoning) {
        /*
         * when reasoning is disabled, we extract only the declaration assertions for the vocabulary
         */
        ontology = extractDeclarations(manager, ontology);
      }

      Collection<Predicate> predicates = new ArrayList<>();

      for (OWLClass owlClass : ontology.getClassesInSignature()) {
        Predicate predicate = obdaDataFactory.getClassPredicate(owlClass.getIRI().toString());
        predicates.add(predicate);
      }
      for (OWLDataProperty owlDataProperty : ontology.getDataPropertiesInSignature()) {
        Predicate predicate =
            obdaDataFactory.getDataPropertyPredicate(owlDataProperty.getIRI().toString());
        predicates.add(predicate);
      }
      for (OWLObjectProperty owlObjectProperty : ontology.getObjectPropertiesInSignature()) {
        Predicate predicate =
            obdaDataFactory.getObjectPropertyPredicate(owlObjectProperty.getIRI().toString());
        predicates.add(predicate);
      }

      OBDAModel obdaModel = loadMappingFile(mappingFile);

      Ontology inputOntology = OWLAPI3TranslatorUtility.translate(ontology);

      obdaModel.declareAll(inputOntology.getVocabulary());

      int numPredicates = predicates.size();

      int i = 1;
      for (Predicate predicate : predicates) {
        System.err.println(String.format("Materializing %s (%d/%d)", predicate, i, numPredicates));
        serializePredicate(ontology, inputOntology, obdaModel, predicate, outputFile, format);
        i++;
      }

    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  protected void importObjectProperty(OWLOntology o, OWLObjectProperty objectProperty) {
    String iri = objectProperty.getIRI().toString();
    String label = getLabel(o, objectProperty);
    checkNotNull(label, "label cannot be null or empty for " + iri);
    LOGGER.info("Importing ontology object property " + iri + " (label: " + label + ")");

    for (Concept domain : getDomainsConcepts(o, objectProperty)) {
      for (Concept range : getRangesConcepts(o, objectProperty)) {
        getOrCreateRelationshipType(domain, range, iri, label);
      }
    }
  }
Ejemplo n.º 4
0
  private Iterable<Concept> getDomainsConcepts(OWLOntology o, OWLObjectProperty objectProperty) {
    String uri = objectProperty.getIRI().toString();
    if (objectProperty.getDomains(o).size() == 0) {
      throw new LumifyException("Invalid number of domain properties on " + uri);
    }

    List<Concept> domains = new ArrayList<Concept>();
    for (OWLClassExpression rangeClassExpr : objectProperty.getDomains(o)) {
      OWLClass rangeClass = rangeClassExpr.asOWLClass();
      String rangeClassUri = rangeClass.getIRI().toString();
      Concept ontologyClass = getConceptByIRI(rangeClassUri);
      checkNotNull(ontologyClass, "Could not find class with uri: " + rangeClassUri);
      domains.add(ontologyClass);
    }
    return domains;
  }