Пример #1
0
  /**
   * C ⊓ D' ⊑ E → {D' ⊑ A, C ⊓ A ⊑ E}
   *
   * @param gcis
   * @return
   */
  boolean rule2(final IFactory factory, final Inclusion[] gcis) {
    boolean result = false;

    if (lhs instanceof Conjunction) {
      Conjunction conjunction = (Conjunction) lhs;
      final AbstractConcept[] concepts = conjunction.getConcepts();

      if (concepts.length == 1) {
        // unwrap redundant conjuncts
        gcis[0] = new GCI(concepts[0], rhs);
        result = true;
      } else if (concepts.length == 0) {
        log.warn("Empty conjunct detected in: " + this);
        gcis[0] = new GCI(IFactory.TOP_CONCEPT, rhs);
        result = true;
      } else {
        // Swap out any non-Concept concepts (ie Existentials)
        for (int i = 0; !result && i < concepts.length; i++) {
          if (!(concepts[i] instanceof Concept)) {
            final Concept a = getA(factory, concepts[i]);
            gcis[0] = new GCI(concepts[i], a);

            final AbstractConcept[] newConcepts = new AbstractConcept[concepts.length];
            System.arraycopy(concepts, 0, newConcepts, 0, concepts.length);
            newConcepts[i] = a;
            gcis[1] = new GCI(new Conjunction(newConcepts), rhs);
            result = true;
          }
        }

        if (!result) {
          if (concepts.length > 2) {
            // Binarise a conjunction of Concepts (expected/assumed
            // by NF1)
            result = true;
            final AbstractConcept[] newConcepts = new AbstractConcept[concepts.length - 1];
            System.arraycopy(concepts, 1, newConcepts, 0, concepts.length - 1);
            final AbstractConcept d = new Conjunction(newConcepts);
            final Concept a = getA(factory, d);
            final AbstractConcept cAndA = new Conjunction(new AbstractConcept[] {concepts[0], a});

            gcis[0] = new GCI(cAndA, rhs);
            gcis[1] = new GCI(d, a);
          } else if (concepts.length < 2) {
            throw new AssertionError(
                "Conjunctions of fewer than "
                    + "two elements should not exist at this point: "
                    + this);
          }
        }
      }
    }

    return result;
  }
Пример #2
0
  @Override
  public NormalFormGCI getNormalForm() {
    final NormalFormGCI result;
    // try {
    if (lhs instanceof Concept) {
      if (rhs instanceof Concept) {
        final int newLhs = lhs.hashCode();
        result = NF1a.getInstance(newLhs, rhs.hashCode());
      } else if (rhs instanceof Existential) {
        final Existential existential = (Existential) rhs;
        result =
            NF2.getInstance(
                lhs.hashCode(), existential.getRole(), existential.getConcept().hashCode());
      } else if (rhs instanceof Datatype) {
        final Datatype datatype = (Datatype) rhs;
        result = NF7.getInstance(lhs.hashCode(), datatype);
      } else {
        throw new IllegalStateException(
            "GCI is not in Normal Form: "
                + "lhs is Concept but rhs is neither Concept, "
                + "Existential nor Datatype; it is "
                + rhs);
      }
    } else if (lhs instanceof Conjunction) {
      final Conjunction conjunction = (Conjunction) lhs;
      final AbstractConcept[] concepts = conjunction.getConcepts();
      if (concepts.length == 1) {
        result = NF1a.getInstance(concepts[0].hashCode(), rhs.hashCode());
      } else if (concepts.length == 2) {
        result = NF1b.getInstance(concepts[0].hashCode(), concepts[1].hashCode(), rhs.hashCode());
      } else {
        throw new IllegalStateException(
            "Conjunction should have exactly one or two "
                + "Concepts not "
                + concepts.length
                + ": "
                + conjunction);
      }
    } else if (lhs instanceof Existential) {
      Existential existential = (Existential) lhs;
      result =
          NF3.getInstance(
              existential.getRole(), existential.getConcept().hashCode(), rhs.hashCode());
    } else if (lhs instanceof Datatype) {
      Datatype datatype = (Datatype) lhs;
      result = NF8.getInstance(datatype, rhs.hashCode());
    } else {
      throw new IllegalStateException("GCI is not in Normal Form: " + lhs + ", " + rhs);
    }

    return result;
  }
Пример #3
0
  /**
   * B &#8849; C &#8851; D &rarr; {B &#8849; C, B &#8849; D}
   *
   * @param gcis
   * @return
   */
  Inclusion[] rule7(Inclusion[] gcis) {
    assert isRule7Applicable();

    final Conjunction conjunction = (Conjunction) rhs;
    final AbstractConcept[] concepts = conjunction.getConcepts();

    if (concepts.length > gcis.length) {
      gcis = new Inclusion[concepts.length];
    }

    for (int i = 0; i < concepts.length; i++) {
      gcis[i] = new GCI(lhs, concepts[i]);
    }

    return gcis;
  }