Package aterm

Examples of aterm.ATerm


  public ATerm getPattern() {
    return pattern;
  }

  public int getPatternType() {
    ATerm match_pattern = buildMatchPattern();

    if (match_pattern.getType() == ATerm.PLACEHOLDER) {
      ATerm ph = ((ATermPlaceholder) match_pattern).getPlaceholder();
      if (ph.match("int") != null) {
        return ATerm.INT;
      } else if (ph.match("real") != null) {
        return ATerm.REAL;
      } else if (ph.match("str") != null) {
        return ATerm.APPL;
      } else if (ph.match("list") != null) {
        return ATerm.LIST;
      } else if (ph.match("term") != null) {
        return ATerm.APPL;
      } else if (ph.match("chars") != null) {
        return ATerm.LIST;
      } else if (ph.match("char") != null) {
        return ATerm.INT;
      } else {
        throw new RuntimeException("strange root pattern: "
            + match_pattern);
      }
View Full Code Here


  }

  public boolean isMany() {
    if (getPattern().getType() == ATerm.LIST) {
      ATermList l = (ATermList) getPattern();
      ATerm headPh = l.getFirst();
      ATerm tailList = l.getNext();

      if (headPh != null && headPh.getType() == ATerm.PLACEHOLDER
          && tailList.getType() == ATerm.LIST) {
        ATerm head = ((ATermPlaceholder) headPh).getPlaceholder();
        ATerm tailPh = ((ATermList) tailList).getFirst();
        if (tailPh != null && tailPh.getType() == ATerm.PLACEHOLDER) {
          ATerm tail = ((ATermPlaceholder) tailPh).getPlaceholder();

          ATerm headPattern = getPattern().getFactory().parse(
              "head(<term>)");
          ATerm tailPattern = getPattern().getFactory().parse(
              "[tail(<term>)]");

          List<Object> subst1 = head.match(headPattern);
          List<Object> subst2 = tail.match(tailPattern);
          // System.out.println("head = " + head);
View Full Code Here

  }

  public boolean isSingle() {
    if (getPattern().getType() == ATerm.LIST) {
      ATermList l = (ATermList) getPattern();
      ATerm headPh = l.getFirst();
      ATerm tailList = l.getNext();

      if (headPh != null && headPh.getType() == ATerm.PLACEHOLDER
          && tailList.getType() == ATerm.LIST) {
        ATerm head = ((ATermPlaceholder) headPh).getPlaceholder();
        ATermList tail = ((ATermList) tailList);
        if (tail.isEmpty()) {
          ATerm headPattern = getPattern().getFactory().parse(
              "head(<term>)");
          List<Object> subst1 = head.match(headPattern);
          if (getId().equals(ListType.SINGLE_LIST_ALT_NAME)
              && (subst1 != null)) {
            return true;
View Full Code Here

    l = factory.makeModuleList_Modules(mods[3]);
    testAssert(l.isSortModuleList() == true, "is<type> test");
    testAssert(l.isModules() == true, "is<cons> test");

    String example = "[]";
    ATerm termExample;

    try {
      termExample = factory.getPureFactory().parse(example);
      testAssert(termExample != null, "need reference to prevent gc");
      mods[4] = factory.makeModules();
    }
    catch (ClassCastException ex) {
      testAssert(false, "ClassCastException occurred due to wrong equivalence implementation");
    }

    example = "\"amodule\"";
    termExample = factory.getPureFactory().parse(example);
    Module amodule = factory.makeModule_Default(example);
    testAssert(amodule != null, "test cast");

    ATerm pattern =
      factory.getPureFactory().parse(
        "[\"m1\",l(\"l1\"),\"sep\",l(\"l2\"),\"m2\",l(\"l3\"),\"sep\",l(\"l4\"),\"m3\",l(\"l5\"),\"sep\",l(\"l6\"),\"m4\"]");

    Separated sep = factory.SeparatedFromTerm(pattern);
    testAssert(sep.toTerm().isEqual(pattern), " fromTerm == toTerm separated lists");

    ATerm patternReversed =
      factory.getPureFactory().parse(
        "[\"m4\",l(\"l5\"),\"sep\",l(\"l6\"),\"m3\",l(\"l3\"),\"sep\",l(\"l4\"),\"m2\",l(\"l1\"),\"sep\",l(\"l2\"),\"m1\"]");
    Separated sepReversed = factory.SeparatedFromTerm(patternReversed);
    testAssert(sep.reverse().isEqual(sepReversed), " separated reverse test");
    testAssert(sep.reverseSeparated().toTerm().isEqual(patternReversed), "separated reverse toTerm test");

    Module head = sep.getHead();

    testAssert(head.isEqual(factory.makeModule_Default("m1")), "separator from term test, head");
    Layout l1 = sep.getWsl();
    testAssert(l1.isEqual(factory.makeLayout_Default("l1")), "getSeparator test l1");
    Layout l2 = sep.getWsr();
    testAssert(l2.isEqual(factory.makeLayout_Default("l2")), "getSeparator test l2");
    Module second = sep.getTail().getHead();
    testAssert(second.isEqual(factory.makeModule_Default("m2")), "separator from term test, second element");
    Layout l3 = sep.getTail().getWsl();

    testAssert(l3.isEqual(factory.makeLayout_Default("l3")), "getSeparator test l3");
    Layout l4 = sep.getTail().getWsr();
    testAssert(l4.isEqual(factory.makeLayout_Default("l4")), "getSeparator test l4");

    testAssert(sep.getLength() == 4, "separated list length test");

    sep = factory.makeSeparated();
    testAssert(sep.toTerm().isEqual(factory.getPureFactory().makeList()), "empty separated list");

    m = factory.makeModule_Default("m");
    sep = factory.makeSeparated(m);

    testAssert(sep.toTerm().isEqual(factory.getPureFactory().makeList(m.toTerm())), "singleton separated list");

    Module m2 = factory.makeModule_Default("m2");
    l1 = factory.makeLayout_Default("l1");
    l2 = factory.makeLayout_Default("l2");
    sep = factory.makeSeparated(m, l1, l2, factory.makeSeparated(m2));

    ATerm p = factory.getPureFactory().parse("[\"m\",l(\"l1\"),\"sep\",l(\"l2\"),\"m2\"]");
    testAssert(sep.toTerm().isEqual(p), "many separated list");

    ATerm pc =
      ((ATermList) p).concat((ATermList) factory.getPureFactory().parse("[l(\"l1\"),\"sep\",l(\"l2\")]")).concat(
        (ATermList) p);
    testAssert(factory.concat(sep, l1, l2, sep).toTerm().isEqual(pc), "concat test");

    testMakeLists();
View Full Code Here

                break;

            case ATerm.PLACEHOLDER :
                //{{{ Add a new field based on this placeholder

                ATerm ph = ((ATermPlaceholder) t).getPlaceholder();

                if (ph.getType() == ATerm.LIST) {
                    list = (ATermList) ph;
                    appl = (ATermAppl) list.elementAt(0);
                    String fieldId = appl.getAFun().getName();
                    appl = (ATermAppl) appl.getArgument(0);
                    String fieldType = appl.getAFun().getName();
                    loc.makeTail();
                    addField(fieldId, fieldType, loc);
                } else if (ph.getType() == ATerm.APPL) {
                    appl = (ATermAppl) ph;
                    String fieldId = appl.getAFun().getName();
                    appl = (ATermAppl) appl.getArgument(0);
                    String fieldType = appl.getAFun().getName();
                    addField(fieldId, fieldType, loc);
View Full Code Here

    public void applyAllValues( Individual x, ATermAppl av, DependencySet ds ) {
        // Timer timer = kb.timers.startTimer("applyAllValues");

        if( av.getArity() == 0 )
            throw new InternalReasonerException();
        ATerm p = av.getArgument( 0 );
        ATermAppl c = (ATermAppl) av.getArgument( 1 );       
       
        ATermList roleChain = ATermUtils.EMPTY_LIST;
        Role s = null;
        if( p.getType() == ATerm.LIST ) {
            roleChain = (ATermList) p;
            s = strategy.getABox().getRole( roleChain.getFirst() );
            roleChain = roleChain.getNext();
        }
        else
View Full Code Here

        int allValuesSize = allValues.size();
        Iterator<ATermAppl> i = allValues.iterator();
        while( i.hasNext() ) {
            ATermAppl av = i.next();

            ATerm p = av.getArgument( 0 );
            ATermAppl c = (ATermAppl) av.getArgument( 1 );
           
            ATermList roleChain = ATermUtils.EMPTY_LIST;
            Role s = null;
            if( p.getType() == ATerm.LIST ) {
                roleChain = (ATermList) p;
                s = strategy.getABox().getRole( roleChain.getFirst() );
                roleChain = roleChain.getNext();
            }
            else
View Full Code Here

    /*
     * Gather all data properties that appear in universal restrictions on this node.
     */
    for( ATermAppl allDesc : x.getTypes( Node.ALL ) ) {
      final ATerm rTerm = allDesc.getArgument(0);
     
      /*
       * Skip object property chains
       */
      if (rTerm instanceof ATermList)
View Full Code Here

        if(node == null)
            return "<<null>>";
//        usedStatements = new HashSet();
        sw.getBuffer().setLength(0);
       
        ATerm term = node2term(node);
       
        if(term instanceof ATermAppl)
            renderer.visit((ATermAppl) term);
        else {
            sw.write("{");
View Full Code Here

       
        return sw.toString();
    }   
   
    public ATerm node2term(RDFNode node) {
        ATerm aTerm = null;

        if(node.equals(OWL.Thing))
            return ATermUtils.TOP;
        else if(node.equals(OWL.Nothing))
            return ATermUtils.BOTTOM;
        else if (node.equals( OWL2.topDataProperty ))
          return ATermUtils.TOP_DATA_PROPERTY;
        else if (node.equals( OWL2.bottomDataProperty ))
          return ATermUtils.BOTTOM_DATA_PROPERTY;
        else if (node.equals( OWL2.topObjectProperty ))
          return ATermUtils.TOP_OBJECT_PROPERTY;
        else if (node.equals( OWL2.bottomObjectProperty ))
          return ATermUtils.BOTTOM_OBJECT_PROPERTY;
        else if(node instanceof com.hp.hpl.jena.rdf.model.Literal) {
            com.hp.hpl.jena.rdf.model.Literal l = (com.hp.hpl.jena.rdf.model.Literal) node;
            String datatypeURI = l.getDatatypeURI();
            if(datatypeURI != null)
                aTerm = ATermUtils.makeTypedLiteral(l.getString(), datatypeURI);
            else
                aTerm = ATermUtils.makePlainLiteral(l.getString(), l.getLanguage());
        }
        else if(node instanceof Resource) {
            Resource r = (Resource) node;

            if(rawModel.contains(r, OWL.onProperty, NULL)) {
                aTerm = createRestriction(r);
            }
            else if(r.isAnon()) {
                if(rawModel.contains(r, RDF.first, NULL)) {
                    aTerm = createList(r);
                }
                else if(rawModel.contains(r, OWL.intersectionOf)) {
                    ATermList list = createList(rawModel.getProperty(r, OWL.intersectionOf).getResource());
                    aTerm = ATermUtils.makeAnd(list);
                }
                else if(rawModel.contains(r, OWL.unionOf)) {
                    ATermList list = createList(rawModel.getProperty(r, OWL.unionOf).getResource());
                    aTerm = ATermUtils.makeOr(list);
                }
                else if(rawModel.contains(r, OWL.oneOf)) {
                    ATermList list = createList(rawModel.getProperty(r, OWL.oneOf).getResource());
                    ATermList result = ATermUtils.EMPTY_LIST;
                    for(ATermList l = list; !l.isEmpty(); l = l.getNext()) {
                        ATermAppl c = (ATermAppl) l.getFirst();
                        ATermAppl nominal = ATermUtils.makeValue(c);
                        result = result.insert(nominal);
                    }

                    aTerm = ATermUtils.makeOr(result);
                }
                else if(rawModel.contains(r, OWL.complementOf)) {
                    ATerm complement = node2term(rawModel.getProperty(r, OWL.complementOf).getResource());
                    aTerm = ATermUtils.makeNot(complement);
                }
                else
                    aTerm = ATermUtils.makeBnode(r.getId().toString());
            }
View Full Code Here

TOP

Related Classes of aterm.ATerm

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.