Package aterm

Examples of aterm.AFun


      assert false;
    }
  }

  private void translateSuperSome(ATermAppl anon, ATermAppl sup) {
    AFun fun = sup.getAFun();
    if (ATermUtils.isPrimitive(sup) || ATermUtils.isBottom(sup)) {
      m_Facts.add(makeSubclassFact(anon, sup));
    } else if (fun.equals(ATermUtils.ANDFUN)) {
      ATermList list = (ATermList) sup.getArgument(0);

      while (!list.isEmpty()) {
        ATermAppl conj = (ATermAppl) list.getFirst();
        translateSuperSome(anon, conj);
        list = list.getNext();
      }
    } else if (fun.equals(ATermUtils.SOMEFUN)) {
      ATermAppl prop = (ATermAppl) sup.getArgument(0);
      ATermAppl q = (ATermAppl) sup.getArgument(1);

      if (!ATermUtils.isPrimitive(q) && !ATermUtils.isBottom(q)) {
        // Normalization - breaking complex concepts within someValues
View Full Code Here


    translateSuper(head, sup, freeVar, var);
    m_Rules.add(new Rule(head, body));
  }

  private void translateSub(List<ClauseEntry> outBody, ATermAppl sub, FreeVariableStore freeVar, Node currentVar) {
    AFun fun = sub.getAFun();
    if (ATermUtils.isPrimitive(sub) || ATermUtils.isBottom(sub)) {
      outBody.add(makeSubclassTriple(currentVar, m_Names.get(sub)));
    } else if (fun.equals( ATermUtils.ANDFUN )) {
      ATermList list = (ATermList) sub.getArgument(0);
     
      while( !list.isEmpty() ) {
        ATermAppl conj = (ATermAppl) list.getFirst();
        translateSub(outBody, conj, freeVar, currentVar);
        list = list.getNext();
      }
    } else if (fun.equals( ATermUtils.SOMEFUN )) {
      ATermAppl prop = (ATermAppl) sub.getArgument(0);
      ATermAppl q = (ATermAppl) sub.getArgument(1);
      Node nextVar = freeVar.next();
      outBody.add(makeSubOfSomeTriple(currentVar, prop, nextVar));
      translateSub(outBody, q, freeVar, nextVar);
View Full Code Here

      assert false;
    }
  }
 
  private void translateSuper(List<ClauseEntry> outHead, ATermAppl sup, FreeVariableStore freeVar, Node currentVar) {
    AFun fun = sup.getAFun();
    if (ATermUtils.isPrimitive(sup) || ATermUtils.isBottom(sup)) {
      outHead.add(makeSubclassTriple(currentVar, m_Names.get(sup)));
    } else if (fun.equals( ATermUtils.ANDFUN )) {
      ATermList list = (ATermList) sup.getArgument(0);
     
      while( !list.isEmpty() ) {
        ATermAppl conj = (ATermAppl) list.getFirst();
        translateSuper(outHead, conj, freeVar, currentVar);
        list = list.getNext();
      }
    } else if (fun.equals( ATermUtils.SOMEFUN )) {
      ATermAppl prop = (ATermAppl) sup.getArgument(0);
      ATermAppl q = (ATermAppl) sup.getArgument(1);
     
      if (!ATermUtils.isPrimitive(q) && !ATermUtils.isBottom(q)) {
        //Normalization - breaking complex concepts within someValues
View Full Code Here

      assert false;
    }
  }

  private void translateSuperSome(ATermAppl anon, ATermAppl sup) {
    AFun fun = sup.getAFun();
    if( ATermUtils.isPrimitive( sup ) || ATermUtils.isBottom( sup ) ) {
      m_Facts.add( makeSubclassFact( anon, sup ) );
    }
    else if( fun.equals( ATermUtils.ANDFUN ) ) {
      ATermList list = (ATermList) sup.getArgument( 0 );

      while( !list.isEmpty() ) {
        ATermAppl conj = (ATermAppl) list.getFirst();
        translateSuperSome( anon, conj );
        list = list.getNext();
      }
    }
    else if( fun.equals( ATermUtils.SOMEFUN ) ) {
      ATermAppl prop = (ATermAppl) sup.getArgument( 0 );
      ATermAppl q = (ATermAppl) sup.getArgument( 1 );

      if( !ATermUtils.isPrimitive( q ) && !ATermUtils.isBottom( q ) ) {
        // Normalization - breaking complex concepts within someValues
View Full Code Here

    }
    else if( negated.isKnown() && ATermUtils.isNot( term ) ) {
      toString( (ATermAppl) term.getArgument( 0 ), sb, negated.not(), printLocalName );
    }
    else {   
      AFun fun = term.getAFun();
      if( negated.isTrue() ) {
        if( fun.equals( ATermUtils.ANDFUN ) ) {
                  sb.append( ATermUtils.ORFUN.getName() );
                }
                else if( fun.equals( ATermUtils.ORFUN ) ) {
                  sb.append( ATermUtils.ANDFUN.getName() );
                }
                else if( fun.equals( ATermUtils.SOMEFUN ) ) {
                  sb.append( ATermUtils.ALLFUN.getName() );
                }
                else if( fun.equals( ATermUtils.ALLFUN ) ) {
                  sb.append( ATermUtils.SOMEFUN.getName() );
                }
                else if( fun.equals( ATermUtils.MINFUN ) ) {
                  sb.append( ATermUtils.MAXFUN.getName() );
                }
                else if( fun.equals( ATermUtils.MAXFUN ) ) {
                  sb.append( ATermUtils.MINFUN.getName() );
                }
                else if( !fun.equals( ATermUtils.NOTFUN ) ) {
          if( fun.equals( ATermUtils.VALUEFUN )
            || fun.equals( ATermUtils.RESTRDATATYPEFUN )) {
                      sb.append( "not(" );
                    }
          sb.append( fun.getName() );
        }
      }
      else {
        sb.append( fun.getName() );
      }
     
      Bool negatedRecurse = negated;
      if( negated.isKnown() && fun.equals( ATermUtils.MINFUN ) || fun.equals( ATermUtils.MAXFUN ) ) {
        negatedRecurse = Bool.FALSE;
      }
      else if( fun.equals( ATermUtils.NOTFUN ) ) {
        negatedRecurse = negated.not();
      }

      sb.append( "(" );
      for( int i = 0, n = term.getArity(); i < n; i++ ) {
        if( i > 0 ) {
          sb.append ( ", " );       
        }
        ATerm arg = term.getArgument( i );
        if( arg instanceof ATermAppl ) {
          toString( (ATermAppl) arg, sb, i > 0 ? negatedRecurse : Bool.FALSE, printLocalName );         
        }
        else if( arg instanceof ATermList ) {
          sb.append( "[" );
          ATermList list = (ATermList) arg;
          while( !list.isEmpty() ) {
            toString( (ATermAppl) list.getFirst(), sb, negatedRecurse, printLocalName );
            list = list.getNext();
            if( !list.isEmpty() ) {
                          sb.append ( ", " );
                        }
          }
          sb.append( "]" );
        }
        else {
          int value = ((ATermInt) arg).getInt();
          if( negated.isTrue() ) {
            if( fun.equals( ATermUtils.MINFUN ) ) {
                          value--;
                        }
                        else if( fun.equals( ATermUtils.MAXFUN ) ) {
                          value++;
                        }
          }
          sb.append( value );
        }
      }
      sb.append( ")" );
      if( (fun.equals( ATermUtils.VALUEFUN )
        || fun.equals( ATermUtils.RESTRDATATYPEFUN )) && negated.isTrue() ) {
              sb.append( ")" );
            }
    }
  }
View Full Code Here

  }

  public static boolean isComplexClass(ATerm c) {
    if( c instanceof ATermAppl ) {
      ATermAppl a = (ATermAppl) c;
      AFun f = a.getAFun();
      return CLASS_FUN.contains( f );
    }
    return false;
  }
View Full Code Here

   * concepts
   */
  public static ATermAppl nnf(ATermAppl term) {
    ATermAppl newterm = null;

    AFun af = term.getAFun();

    if( af.equals( ATermUtils.NOTFUN ) ) { // Function is a NOT
      // Take the first argument to the NOT, then check
      // the type of that argument to determine what needs to be done.
      ATermUtils.assertTrue( af.getArity() == 1 );
      ATermAppl arg = (ATermAppl) term.getArgument( 0 );
      af = arg.getAFun();

      if( arg.getArity() == 0 ) {
        newterm = term; // Negation is in as far as it can go
      }
      else if( af.equals( ATermUtils.NOTFUN ) ) { // Double negation.
        newterm = nnf( (ATermAppl) arg.getArgument( 0 ) );
      }
      else if( af.equals( ATermUtils.VALUEFUN ) || af.equals( ATermUtils.SELFFUN || af.equals( ATermUtils.RESTRDATATYPEFUN ) ) {
        newterm = term;
      }
      else if( af.equals( ATermUtils.MAXFUN ) ) {
        ATermInt n = (ATermInt) arg.getArgument( 1 );
        newterm = ATermUtils.makeMin( arg.getArgument( 0 ), n.getInt() + 1, nnf( arg
            .getArgument( 2 ) ) );
      }
      else if( af.equals( ATermUtils.MINFUN ) ) {
        ATermInt n = (ATermInt) arg.getArgument( 1 );
        if( n.getInt() == 0 ) {
                  newterm = ATermUtils.BOTTOM;
                }
                else {
                  newterm = ATermUtils.makeMax( arg.getArgument( 0 ), n.getInt() - 1, nnf( arg
              .getArgument( 2 ) ) );
                }
      }
      else if( af.equals( ATermUtils.CARDFUN ) ) {
        newterm = nnf( makeNot( makeExactCard( arg.getArgument( 0 ), ((ATermInt) arg
            .getArgument( 1 )), arg.getArgument( 2 ) ) ) );
      }
      else if( af.equals( ATermUtils.ANDFUN ) ) {
        newterm = ATermUtils.makeOr( nnf( negate( (ATermList) arg.getArgument( 0 ) ) ) );
      }
      else if( af.equals( ATermUtils.ORFUN ) ) {
        newterm = ATermUtils.makeAnd( nnf( negate( (ATermList) arg.getArgument( 0 ) ) ) );
      }
      else if( af.equals( ATermUtils.SOMEFUN ) ) {
        ATerm p = arg.getArgument( 0 );
        ATerm c = arg.getArgument( 1 );
        newterm = ATermUtils.makeAllValues( p, nnf( makeNot( c ) ) );
      }
      else if( af.equals( ATermUtils.ALLFUN ) ) {
        ATerm p = arg.getArgument( 0 );
        ATerm c = arg.getArgument( 1 );
        newterm = ATermUtils.makeSomeValues( p, nnf( makeNot( c ) ) );
      }
      else {
        throw new InternalReasonerException( "Unknown term type: " + term );
      }
    }
    else if( af.equals( ATermUtils.MINFUN ) || af.equals( ATermUtils.MAXFUN )
        || af.equals( ATermUtils.SELFFUN ) ) {
      newterm = term;
    }
    else if( af.equals( ATermUtils.CARDFUN ) ) {
      newterm = nnf( makeExactCard( term.getArgument( 0 ),
          ((ATermInt) term.getArgument( 1 )), term.getArgument( 2 ) ) );
    }
    else {
      // Return the term with all of its arguments in nnf
View Full Code Here

   * @param term
   * @return
   */
  public static ATermAppl normalize(ATermAppl term) {
    ATermAppl norm = term;
    AFun fun = term.getAFun();
    ATerm arg1 = (term.getArity() > 0)
      ? term.getArgument( 0 )
      : null;
    ATerm arg2 = (term.getArity() > 1)
      ? term.getArgument( 1 )
      : null;
    ATerm arg3 = (term.getArity() > 2)
      ? term.getArgument( 2 )
      : null;

    if( arg1 == null || fun.equals( SELFFUN ) || fun.equals( VALUEFUN ) || fun.equals( INVFUN )
      || fun.equals( RESTRDATATYPEFUN ) ) {
      // do nothing because these terms cannot be decomposed any further
    }
    else if( fun.equals( NOTFUN ) ) {
      if( !isPrimitive( (ATermAppl) arg1 ) ) {
              norm = simplify( makeNot( normalize( (ATermAppl) arg1 ) ) );
            }
    }
    else if( fun.equals( ANDFUN ) ) {
      norm = simplify( makeAnd( normalize( (ATermList) arg1 ) ) );
    }
    else if( fun.equals( ORFUN ) ) {
      ATermList neg = negate( (ATermList) arg1 );
      ATermAppl and = makeAnd( neg );
      ATermAppl notAnd = makeNot( and );
      norm = normalize( notAnd );
    }
    else if( fun.equals( ALLFUN ) ) {
      norm = simplify( makeAllValues( arg1, normalize( (ATermAppl) arg2 ) ) );
    }
    else if( fun.equals( SOMEFUN ) ) {
      norm = normalize( makeNot( makeAllValues( arg1, makeNot( arg2 ) ) ) );
    }
    else if( fun.equals( MAXFUN ) ) {
      norm = normalize( makeNot( makeMin( arg1, ((ATermInt) arg2).getInt() + 1, arg3 ) ) );
    }
    else if( fun.equals( MINFUN ) ) {
      norm = simplify( makeMin( arg1, (ATermInt) arg2, normalize( (ATermAppl) arg3 ) ) );
    }
    else if( fun.equals( CARDFUN ) ) {
      ATermAppl normMin = simplify( makeMin( arg1, ((ATermInt) arg2).getInt(),
          normalize( (ATermAppl) arg3 ) ) );
      ATermAppl normMax = normalize( makeMax( arg1, ((ATermInt) arg2).getInt(), arg3 ) );
      norm = simplify( makeAnd( normMin, normMax ) );
    }
View Full Code Here

   * @param term
   * @return
   */
  public static ATermAppl simplify(ATermAppl term) {
    ATermAppl simp = term;
    AFun fun = term.getAFun();
    ATerm arg1 = (term.getArity() > 0)
      ? term.getArgument( 0 )
      : null;
    ATerm arg2 = (term.getArity() > 1)
      ? term.getArgument( 1 )
      : null;
    ATerm arg3 = (term.getArity() > 2)
      ? term.getArgument( 2 )
      : null;

    if( arg1 == null || fun.equals( SELFFUN ) || fun.equals( VALUEFUN ) || fun.equals( ATermUtils.RESTRDATATYPEFUN ) ) {
      // do nothing because term is primitive or self restriction
    }
    else if( fun.equals( NOTFUN ) ) {
      ATermAppl arg = (ATermAppl) arg1;
      if( isNot( arg ) ) {
              simp = simplify( (ATermAppl) arg.getArgument( 0 ) );
            }
            else if( isMin( arg ) ) {
        ATermInt n = (ATermInt) arg.getArgument( 1 );
        if( n.getInt() == 0 ) {
                  simp = BOTTOM;
                }
      }
    }
    else if( fun.equals( ANDFUN ) ) {
      ATermList conjuncts = (ATermList) arg1;
      if( conjuncts.isEmpty() ) {
              simp = TOP;
            }
            else {
        Set<ATermAppl> set = new HashSet<ATermAppl>();
        List<ATermAppl> negations = new ArrayList<ATermAppl>();
        MultiListIterator i = new MultiListIterator( conjuncts );
        while( i.hasNext() ) {
          ATermAppl c = i.next();
          if( c.equals( TOP ) ) {
                      continue;
                    }
                    else if( c.equals( BOTTOM ) ) {
                      return BOTTOM;
                    }
                    else if( isAnd( c ) ) {
                      i.append( (ATermList) c.getArgument( 0 ) );
                    }
                    else if( isNot( c ) ) {
                      negations.add( c );
                    }
                    else {
                      set.add( c );
                    }
        }

        for( ATermAppl notC : negations ) {
          ATermAppl c = (ATermAppl) notC.getArgument( 0 );
          if( set.contains( c ) ) {
                      return BOTTOM;
                    }
        }

        if( set.isEmpty() ) {
          if( negations.isEmpty() ) {
                      return TOP;
                    }
                    else if( negations.size() == 1 ) {
                      return negations.get( 0 );
                    }
        }
        else if( set.size() == 1 && negations.isEmpty() ) {
                  return set.iterator().next();
                }

        negations.addAll( set );
        int size = negations.size();
        ATermAppl[] terms = new ATermAppl[size];
        negations.toArray( terms );
        simp = makeAnd( toSet( terms, size ) );
      }
    }
    else if( fun.equals( ALLFUN ) ) {
      if( arg2.equals( TOP ) ) {
              simp = TOP;
            }
    }
    else if( fun.equals( MINFUN ) ) {
      ATermInt n = (ATermInt) arg2;
      if( n.getInt() == 0 ) {
              simp = TOP;
            }
      if( arg3.equals( ATermUtils.BOTTOM ) ) {
              simp = BOTTOM;
            }
    }
    else if( fun.equals( MAXFUN ) ) {
      ATermInt n = (ATermInt) arg2;
      if( n.getInt() > 0 && arg3.equals( ATermUtils.BOTTOM ) ) {
              simp = TOP;
            }
    }
View Full Code Here

    findPrimitives( term, primitives, false, false );
  }

  public static void findPrimitives(ATermAppl term, Set<ATermAppl> primitives,
      boolean skipRestrictions, boolean skipTopLevel) {
    AFun fun = term.getAFun();

    if( isPrimitive( term ) ) {
      primitives.add( term );
    }
    else if( fun.equals( SELFFUN ) || fun.equals( VALUEFUN ) || fun.equals( RESTRDATATYPEFUN ) ) {
      // do nothing because there is no atomic concept here
    }
    else if( fun.equals( NOTFUN ) ) {
      ATermAppl arg = (ATermAppl) term.getArgument( 0 );
      if( !isPrimitive( arg ) || !skipTopLevel ) {
              findPrimitives( arg, primitives, skipRestrictions, false );
            }
    }
    else if( fun.equals( ANDFUN ) || fun.equals( ORFUN ) ) {
      ATermList list = (ATermList) term.getArgument( 0 );
      while( !list.isEmpty() ) {
        ATermAppl arg = (ATermAppl) list.getFirst();
        if( !isNegatedPrimitive( arg ) || !skipTopLevel ) {
                  findPrimitives( arg, primitives, skipRestrictions, false );
                }
        list = list.getNext();
      }
    }
    else if( !skipRestrictions ) {
      if( fun.equals( ALLFUN ) || fun.equals( SOMEFUN ) ) {
        ATermAppl arg = (ATermAppl) term.getArgument( 1 );
        findPrimitives( arg, primitives, skipRestrictions, false );
      }
      else if( fun.equals( MAXFUN ) || fun.equals( MINFUN ) || fun.equals( CARDFUN ) ) {
        ATermAppl arg = (ATermAppl) term.getArgument( 2 );
        findPrimitives( arg, primitives, skipRestrictions, false );
      }
            else {
              throw new InternalReasonerException( "Unknown concept type: " + term );
View Full Code Here

TOP

Related Classes of aterm.AFun

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.