/** * 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; }
/** * Apply a conversion on the ATerm contained in the String and returns a gram.i.types.DefTipo 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.DefTipo 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(); } } return null; }
/** * 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; }
@Override protected void printURI(PrintWriter out, ATermAppl c) { String str = null; if (c.equals(ATermUtils.TOP)) str = "owl:Thing"; else if (c.equals(ATermUtils.BOTTOM)) str = "owl:Nothing"; else if (ATermUtils.isPrimitive(c)) str = qnames.shortForm(c.getName()); else str = c.toString(); out.print(str); }
/** * 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; }
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))); } } }
private static IRI iri(ATermAppl term) { if (term.getArity() != 0) throw new OWLRuntimeException("Trying to convert an anonymous term " + term); return IRI.create(term.getName()); }