Beispiel #1
0
  private void ImportRelationsInheritanceOrEquivalence(int typeRelation) throws Exception {

    List<OntClass> classes = this.jena.listClasses().toList();
    for (OntClass jenaClass : classes) {
      Class mobiClass = new Class(jenaClass.getLocalName());
      // this.mobi.getClass(jenaClass.getLocalName());

      if (mobiClass != null) {
        List<OntClass> subClasses = null;

        if (typeRelation == Relation.INHERITANCE)
          subClasses = this.OntClassInheritanceChain(jenaClass.listSubClasses().toList());
        else if (typeRelation == Relation.EQUIVALENCE)
          subClasses = jenaClass.listEquivalentClasses().toList();

        for (OntClass jenaSubClass : subClasses) {
          if (jenaSubClass != null
              && !jenaSubClass.getLocalName().equals(mobiClass.getUri())
              && jenaSubClass.listInstances().hasNext()) {

            // this.mobi.addConcept(mobiClass);
            Class mobiSubClass = new Class(jenaSubClass.getLocalName());

            Relation relation = null;
            if (typeRelation == Relation.INHERITANCE)
              relation = this.mobi.createInheritanceRelation("isSuper");
            else if (typeRelation == Relation.EQUIVALENCE)
              relation = this.mobi.createEquivalenceRelation("equals");

            relation.setClassA(mobiClass);
            relation.setClassB(mobiSubClass);

            List<? extends OntResource> individualsClassA = jenaClass.listInstances().toList();
            List<? extends OntResource> individualsClassB = jenaSubClass.listInstances().toList();

            for (OntResource resourceA : individualsClassA) {
              Individual individualA = resourceA.asIndividual();

              Instance instanceA = new Instance(individualA.getLocalName());
              // this.mobi.getInstance(individualA.getLocalName());

              for (OntResource resourceB : individualsClassB) {
                Individual individualB = resourceB.asIndividual();
                Instance instanceB = new Instance(individualB.getLocalName());
                // this.mobi.getInstance(individualB.getLocalName());

                if (instanceB != null && instanceA.getUri().equals(instanceB.getUri())) {

                  this.mobi.addConcept(mobiClass);
                  this.mobi.addConcept(mobiSubClass);
                  this.mobi.addConcept(instanceA);
                  this.mobi.addConcept(instanceB);

                  try {
                    this.mobi.isOneOf(instanceA, mobiClass);
                    this.mobi.isOneOf(instanceB, mobiSubClass);
                  } catch (ExceptionURI e) {
                  }

                  this.mobi.addConcept(instanceB);

                  relation.addInstanceRelation(instanceA, instanceB);
                }
              }
            }

            relation.processCardinality();
            if (relation.getInstanceRelationMapA().size() > 0) this.mobi.addConcept(relation);
          }
        }
      }
    }
  }
Beispiel #2
0
  private void ImportRelationsComposition() throws Exception {
    List<ObjectProperty> properties = this.jena.listObjectProperties().toList();

    for (ObjectProperty property : properties) {

      OntClass domain = property.listDomain().next().asClass();
      if (domain.isUnionClass()) domain = domain.asUnionClass().listOperands().toList().get(0);

      OntClass range = property.listRange().next().asClass();
      if (range.isUnionClass()) range = range.asUnionClass().listOperands().toList().get(0);

      Relation r = null;

      if (property.isSymmetricProperty())
        r =
            this.mobi.createSymmetricRelation(
                this.getNameObjectProperty(
                    property.getLocalName(),
                    domain.getLocalName().length(),
                    range.getLocalName().length()));
      else if (property.getInverse() == null)
        r =
            this.mobi.createUnidirecionalCompositionRelationship(
                this.getNameObjectProperty(
                    property.getLocalName(),
                    domain.getLocalName().length(),
                    range.getLocalName().length()));
      else if (property.getInverse() != null)
        r =
            this.mobi.createBidirecionalCompositionRelationship(
                this.getNameObjectProperty(
                    property.getLocalName(),
                    domain.getLocalName().length(),
                    range.getLocalName().length()),
                this.getNameObjectProperty(
                    property.getInverse().getLocalName(),
                    range.getLocalName().length(),
                    domain.getLocalName().length()));

      Class mobiDomain = new Class(domain.getLocalName());
      // this.mobi.getClass(domain.getLocalName());
      Class mobiRange = new Class(range.getLocalName());
      // this.mobi.getClass(range.getLocalName());

      if (mobiDomain != null && mobiRange != null) {
        r.setClassA(mobiDomain);
        r.setClassB(mobiRange);

        List<? extends OntResource> individuals = domain.listInstances().toList();

        for (OntResource resourceIndividual : individuals) {
          Individual individualDomain = resourceIndividual.asIndividual();

          NodeIterator propertyValues =
              this.jena.getIndividual(individualDomain.getURI()).listPropertyValues(property);

          while (propertyValues.hasNext()) {
            RDFNode node = propertyValues.next();
            Individual individualValue = node.as(Individual.class);

            this.mobi.addConcept(mobiDomain);
            this.mobi.addConcept(mobiRange);

            Instance instanceDomain = new Instance(individualDomain.getLocalName());
            Instance instanceRange = new Instance(individualValue.getLocalName());

            try {
              this.mobi.isOneOf(instanceDomain, mobiDomain);
              this.mobi.isOneOf(instanceRange, mobiRange);
            } catch (ExceptionURI e) {
            }

            r.addInstanceRelation(instanceDomain, instanceRange);
          }
        }

        r.processCardinality();

        if (r.getInstanceRelationMapA().size() > 0) this.mobi.addConcept(r);
      }
    }
  }