Ejemplo n.º 1
0
  /**
   * Given a production or application returns the constructor name attached to the production, or
   * null if there is no constructor.
   *
   * @author Martin Bravenboer
   * @author Lennart Kats
   */
  public String getConstructor(ATerm arg) {
    ATermAppl appl = assertAppl(arg, applFun);

    ATermAppl prod;
    if (appl.getAFun() == prodFun) {
      prod = appl;
    } else if (appl.getAFun() == applFun) {
      prod = assertAppl(appl.getArgument(APPL_PROD), prodFun);
    } else {
      throw new IllegalArgumentException("Expected prod or appl: " + arg);
    }

    ATermAppl attrs = assertAppl(prod.getArgument(PROD_ATTRS));
    if (attrs.getAFun() == noattrsFun) {
      return null;
    } else {
      for (ATerm attr : (ATermList) attrs.getChildAt(ATTRS_LIST)) {
        if (attr instanceof ATermAppl) {
          ATermAppl namedAttr = (ATermAppl) attr;
          if (namedAttr.getAFun() == termFun) {
            namedAttr = (ATermAppl) namedAttr.getArgument(TERM_CONS);
            if (namedAttr.getAFun() == consFun) {
              namedAttr = (ATermAppl) namedAttr.getArgument(CONS_NAME);
              return namedAttr.getName();
            }
          }
        }
      }
    }

    return null;
  }
Ejemplo n.º 2
0
 @Override
 public OWLLiteral map(ATermAppl term) {
   String lexValue = ((ATermAppl) term.getArgument(0)).getName();
   ATermAppl lang = (ATermAppl) term.getArgument(1);
   ATermAppl dtype = (ATermAppl) term.getArgument(2);
   if (dtype.equals(ATermUtils.PLAIN_LITERAL_DATATYPE)) {
     if (lang.equals(ATermUtils.EMPTY)) return factory.getOWLLiteral(lexValue);
     else return factory.getOWLLiteral(lexValue, lang.toString());
   } else {
     OWLDatatype datatype = DT_MAPPER.map(dtype);
     return factory.getOWLLiteral(lexValue, datatype);
   }
 }
Ejemplo n.º 3
0
 /**
  * Apply a conversion on the ATerm contained in the String and returns a gram.i.types.Expressao
  * from it
  *
  * @param trm ATerm to convert into a Gom term
  * @param atConv ATerm Converter used to convert the ATerm
  * @return the Gom term
  */
 public static gram.i.types.Expressao fromTerm(
     aterm.ATerm trm, tom.library.utils.ATermConverter atConv) {
   trm = atConv.convert(trm);
   if (trm instanceof aterm.ATermAppl) {
     aterm.ATermAppl appl = (aterm.ATermAppl) trm;
     if (symbolName.equals(appl.getName()) && !appl.getAFun().isQuoted()) {
       return make(
           gram.i.types.Expressao.fromTerm(appl.getArgument(0), atConv),
           gram.i.types.LComentarios.fromTerm(appl.getArgument(1), atConv),
           gram.i.types.LComentarios.fromTerm(appl.getArgument(2), atConv),
           gram.i.types.Expressao.fromTerm(appl.getArgument(3), atConv));
     }
   }
   return null;
 }
Ejemplo n.º 4
0
  /**
   * Yields a parse tree (parsetree or appl) to a string builder.
   *
   * @author Martin Bravenboer
   */
  public void yield(ATerm parsetree, StringBuilder builder) {
    ATermAppl appl = assertAppl(parsetree);
    if (appl.getAFun() == parsetreeFun) {
      appl = assertAppl(appl.getArgument(PARSE_TREE));
    }

    yieldAppl(appl, builder);
  }
Ejemplo n.º 5
0
 /**
  * Apply a conversion on the ATerm contained in the String and returns a parser.rec.types.RelExp
  * from it
  *
  * @param trm ATerm to convert into a Gom term
  * @param atConv ATerm Converter used to convert the ATerm
  * @return the Gom term
  */
 public static parser.rec.types.RelExp fromTerm(
     aterm.ATerm trm, tom.library.utils.ATermConverter atConv) {
   trm = atConv.convert(trm);
   if (trm instanceof aterm.ATermAppl) {
     aterm.ATermAppl appl = (aterm.ATermAppl) trm;
     if (symbolName.equals(appl.getName()) && !appl.getAFun().isQuoted()) {
       return make(parser.rec.types.AritExp.fromTerm(appl.getArgument(0), atConv));
     }
   }
   return null;
 }
Ejemplo n.º 6
0
  public TermCons(ATermAppl atm, Context context) {
    super(atm);
    this.cons = atm.getName();
    this.sort = StringUtil.getSortNameFromCons(cons);
    this.production = context.conses.get(cons);
    assert this.production != null;

    contents = new ArrayList<Term>();
    if (atm.getArity() == 0) {
      contents = new ArrayList<Term>();
    } else if (atm.getArgument(0) instanceof ATermList) {
      ATermList list = (ATermList) atm.getArgument(0);
      for (; !list.isEmpty(); list = list.getNext()) {
        if (isColon(list.getFirst())) continue;
        contents.add((Term) JavaClassesFactory.getTerm(list.getFirst()));
      }
      contents.add(new ListTerminator(sort, null));
    } else {
      for (int i = 0; i < atm.getArity(); i++) {
        if (isColon(atm.getArgument(i))) continue;
        contents.add((Term) JavaClassesFactory.getTerm(atm.getArgument(i)));
      }
    }
  }
Ejemplo n.º 7
0
 /** Private helper for the yield method. */
 private void yieldAppl(ATermAppl appl, StringBuilder builder) {
   for (ATerm t : (ATermList) appl.getArgument(APPL_ARGS)) {
     if (t instanceof ATermAppl) {
       ATermAppl arg = (ATermAppl) t;
       if (arg.getAFun() == applFun) {
         yieldAppl(arg, builder);
       } else {
         throw new IllegalArgumentException("Don't know how to yield " + arg);
       }
     } else if (t instanceof ATermInt) {
       ATermInt arg = (ATermInt) t;
       builder.append((char) arg.getInt());
     } else {
       throw new IllegalArgumentException("Don't know how to yield " + t);
     }
   }
 }