Package weka.associations.tertius

Examples of weka.associations.tertius.Literal


  private Predicate buildPredicate(Instances instances,
           Attribute attr, boolean isClass)
    throws Exception {

    Predicate predicate; /* The result. */
    Literal lit;
    Literal negation;
    boolean missingValues; /* Missing values for this attribute ? */
    boolean individual = (m_parts != null); /* Individual-based learning ? */
    int type = (instances == m_parts)
      ? IndividualLiteral.PART_PROPERTY
      : IndividualLiteral.INDIVIDUAL_PROPERTY; /* Type of property. */

    if (attr.isNumeric()) {
      throw new Exception("Can't handle numeric attributes!");
    }
 
    missingValues = instances.attributeStats(attr.index()).missingCount > 0;

    /* Build predicate. */
    if (individual) {
      predicate = new Predicate(instances.relationName() + "." + attr.name(),
        attr.index(), isClass);
    } else {
      predicate = new Predicate(attr.name(), attr.index(), isClass);
    }
 
    if (attr.numValues() == 2
  && (!missingValues || m_missing == EXPLICIT)) {
      /* Case of two values.
       * If there are missing values, this case is treated like other cases.
       */
      if (individual) {
  lit = new IndividualLiteral(predicate, attr.value(0), 0,
            Literal.POS, m_missing, type);
  negation = new IndividualLiteral(predicate, attr.value(1), 1,
           Literal.POS, m_missing, type);
      } else {
  lit = new AttributeValueLiteral(predicate, attr.value(0), 0,
          Literal.POS, m_missing);
  negation = new AttributeValueLiteral(predicate, attr.value(1), 1,
               Literal.POS, m_missing);
      }
      lit.setNegation(negation);
      negation.setNegation(lit);
      predicate.addLiteral(lit);     
    } else {
      /* Case of several values. */
      for (int i = 0; i < attr.numValues(); i++) {
  if (individual) {
    lit = new IndividualLiteral(predicate, attr.value(i), i,
              Literal.POS, m_missing, type);
  } else {
    lit = new AttributeValueLiteral(predicate, attr.value(i), i,
            Literal.POS, m_missing);
  }
  if (m_negation != NONE) {
    if (individual) {
      negation = new IndividualLiteral(predicate, attr.value(i), i,
               Literal.NEG, m_missing, type);
    } else {
      negation = new AttributeValueLiteral(predicate, attr.value(i), i,
             Literal.NEG, m_missing);
    }
    lit.setNegation(negation);
    negation.setNegation(lit);
  }
  predicate.addLiteral(lit);
      }

      /* One more value if missing is significant. */
      if (missingValues && m_missing == SIGNIFICANT) {
  if (individual) {
    lit = new IndividualLiteral(predicate, "?", -1,
              Literal.POS, m_missing, type);
  } else {
    lit = new AttributeValueLiteral(predicate, "?", -1,
            Literal.POS, m_missing);
  }
  if (m_negation != NONE) {
    if (individual) {
      negation = new IndividualLiteral(predicate, "?", -1,
               Literal.NEG, m_missing, type);
    } else {
      negation = new AttributeValueLiteral(predicate, "?", -1,
             Literal.NEG, m_missing);
    }
    lit.setNegation(negation);
    negation.setNegation(lit);
  }
  predicate.addLiteral(lit);
      }
    }
    return predicate;
View Full Code Here


  private Predicate buildPredicate(Instances instances,
           Attribute attr, boolean isClass)
    throws Exception {

    Predicate predicate; /* The result. */
    Literal lit;
    Literal negation;
    boolean missingValues; /* Missing values for this attribute ? */
    boolean individual = (m_parts != null); /* Individual-based learning ? */
    int type = (instances == m_parts)
      ? IndividualLiteral.PART_PROPERTY
      : IndividualLiteral.INDIVIDUAL_PROPERTY; /* Type of property. */

    if (attr.isNumeric()) {
      throw new Exception("Can't handle numeric attributes!");
    }
 
    missingValues = instances.attributeStats(attr.index()).missingCount > 0;

    /* Build predicate. */
    if (individual) {
      predicate = new Predicate(instances.relationName() + "." + attr.name(),
        attr.index(), isClass);
    } else {
      predicate = new Predicate(attr.name(), attr.index(), isClass);
    }
 
    if (attr.numValues() == 2
  && (!missingValues || m_missing == EXPLICIT)) {
      /* Case of two values.
       * If there are missing values, this case is treated like other cases.
       */
      if (individual) {
  lit = new IndividualLiteral(predicate, attr.value(0), 0,
            Literal.POS, m_missing, type);
  negation = new IndividualLiteral(predicate, attr.value(1), 1,
           Literal.POS, m_missing, type);
      } else {
  lit = new AttributeValueLiteral(predicate, attr.value(0), 0,
          Literal.POS, m_missing);
  negation = new AttributeValueLiteral(predicate, attr.value(1), 1,
               Literal.POS, m_missing);
      }
      lit.setNegation(negation);
      negation.setNegation(lit);
      predicate.addLiteral(lit);     
    } else {
      /* Case of several values. */
      for (int i = 0; i < attr.numValues(); i++) {
  if (individual) {
    lit = new IndividualLiteral(predicate, attr.value(i), i,
              Literal.POS, m_missing, type);
  } else {
    lit = new AttributeValueLiteral(predicate, attr.value(i), i,
            Literal.POS, m_missing);
  }
  if (m_negation != NONE) {
    if (individual) {
      negation = new IndividualLiteral(predicate, attr.value(i), i,
               Literal.NEG, m_missing, type);
    } else {
      negation = new AttributeValueLiteral(predicate, attr.value(i), i,
             Literal.NEG, m_missing);
    }
    lit.setNegation(negation);
    negation.setNegation(lit);
  }
  predicate.addLiteral(lit);
      }

      /* One more value if missing is significant. */
      if (missingValues && m_missing == SIGNIFICANT) {
  if (individual) {
    lit = new IndividualLiteral(predicate, "?", -1,
              Literal.POS, m_missing, type);
  } else {
    lit = new AttributeValueLiteral(predicate, "?", -1,
            Literal.POS, m_missing);
  }
  if (m_negation != NONE) {
    if (individual) {
      negation = new IndividualLiteral(predicate, "?", -1,
               Literal.NEG, m_missing, type);
    } else {
      negation = new AttributeValueLiteral(predicate, "?", -1,
             Literal.NEG, m_missing);
    }
    lit.setNegation(negation);
    negation.setNegation(lit);
  }
  predicate.addLiteral(lit);
      }
    }
    return predicate;
View Full Code Here

TOP

Related Classes of weka.associations.tertius.Literal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.