Package org.ggp.base.util.gdl.grammar

Examples of org.ggp.base.util.gdl.grammar.GdlFunction


        {
            doms.values.add((GdlConstant)term);
        }
        else if(term instanceof GdlFunction)
        {
            GdlFunction func = (GdlFunction)term;
            int j=0;
            for(GdlTerm newTerm : func.getBody())
            {
                Location loc2 = new Location();
                loc2.idx = j;
                loc2.name = func.getName();
                addDomain(newTerm, loc2);
                j++;
            }
        }
        else if(term instanceof GdlVariable)
View Full Code Here


            } else if (replacementTerm instanceof GdlFunction) {
                if (originalTerm instanceof GdlVariable) {
                    int varIndex = Integer.valueOf(originalTerm.toString().replace("?v", ""));
                    replacementsByOriginalTupleIndex.put(varIndex, (GdlFunction) replacementTerm);
                } else if (originalTerm instanceof GdlFunction) {
                    GdlFunction originalFunction = (GdlFunction) originalTerm;
                    GdlFunction replacementFunction = (GdlFunction) replacementTerm;
                    if (originalFunction.getName() != replacementFunction.getName()) {
                        return false;
                    }

                    boolean successSoFar = findAmbiguity(originalFunction.getBody(),
                            replacementFunction.getBody(),
                            replacementsByOriginalTupleIndex);
                    if (!successSoFar) {
                        return false;
                    }
                } else {
View Full Code Here

        String rval = "";
        if(gdl instanceof GdlConstant) {
            GdlConstant c = (GdlConstant)gdl;
            return c.getValue();
        } else if(gdl instanceof GdlFunction) {
            GdlFunction f = (GdlFunction)gdl;
            if(f.getName().toString().equals("true"))
            {
                return "<fact>"+renderGdlToXML(f.get(0))+"</fact>";
            }
            else
            {
                rval += "<relation>"+f.getName()+"</relation>";
                for(int i=0; i<f.arity(); i++)
                    rval += "<argument>"+renderGdlToXML(f.get(i))+"</argument>";
                return rval;
            }
        } else if (gdl instanceof GdlRelation) {
            GdlRelation relation = (GdlRelation) gdl;
            if(relation.getName().toString().equals("true"))
View Full Code Here

            Preconditions.checkArgument(applies(sentence));

            Map<GdlVariable, GdlTerm> assignment = Maps.newHashMap();
            List<GdlTerm> tuple = GdlUtils.getTupleFromSentence(sentence);
            for (int varIndex : replacementsByOriginalTupleIndex.keySet()) {
                GdlFunction function = replacementsByOriginalTupleIndex.get(varIndex);

                GdlFunction replacementFunction = varGen.replaceVariablesAndConstants(function);
                assignment.put((GdlVariable) tuple.get(varIndex), replacementFunction);
            }
            return assignment;
        }
View Full Code Here

  private static GdlTerm cleanParentheses(GdlTerm term) {
    if(term instanceof GdlConstant || term instanceof GdlVariable)
      return term;
    if(term instanceof GdlFunction) {
      GdlFunction function = (GdlFunction) term;
      //The whole point of the function
      if(function.arity() == 0)
        return function.getName();
      List<GdlTerm> cleanedBody = new ArrayList<GdlTerm>();
      for(GdlTerm functionTerm : function.getBody())
        cleanedBody.add(cleanParentheses(functionTerm));
      return GdlPool.getFunction(function.getName(), cleanedBody);
    }
    throw new RuntimeException("Unexpected term type in GdlCleaner");
  }
View Full Code Here

            }
            return GdlPool.getRule((GdlSentence) replaceVariableInternal(rule.getHead(), toSubstitute, theReplacement), rval);
        } else if(gdl instanceof GdlConstant) {
            return gdl;
        } else if(gdl instanceof GdlFunction) {
            GdlFunction func = (GdlFunction)gdl;
            List<GdlTerm> rval = new ArrayList<GdlTerm>();
            for(int i=0; i<func.arity(); i++)
            {
                rval.add((GdlTerm) replaceVariableInternal(func.get(i), toSubstitute, theReplacement));
            }
            return GdlPool.getFunction(func.getName(), rval);
        } else if(gdl instanceof GdlVariable) {
            if(gdl == toSubstitute) {
                return theReplacement;
            } else {
                return gdl;
View Full Code Here

      if(assignment.containsKey(gdl))
        return assignment.get(gdl);
      else
        return gdl;
    } else if (gdl instanceof GdlFunction) {
      GdlFunction function = (GdlFunction) gdl;
      GdlConstant name = function.getName();
      List<GdlTerm> newBody = new ArrayList<GdlTerm>(function.arity());
      for (GdlTerm term : function.getBody()) {
        newBody.add(replaceVariables(term, assignment));
      }
      return GdlPool.getFunction(name, newBody);
    } else if (gdl instanceof GdlDistinct) {
      GdlDistinct distinct = (GdlDistinct) gdl;
View Full Code Here

            if (!unifyVariable((GdlVariable) y, x, theta))
                return false;
        }
        else if ((x instanceof GdlFunction) && (y instanceof GdlFunction))
        {
            GdlFunction xFunction = (GdlFunction) x;
            GdlFunction yFunction = (GdlFunction) y;

            if (! unifyTerm(xFunction.getName(), yFunction.getName(), theta))
                return false;

            for (int i = 0; i < xFunction.arity(); i++)
            {
                if (! unifyTerm(xFunction.get(i), yFunction.get(i), theta))
                    return false;
            }
        }
        else
        {
View Full Code Here

      GdlTerm term = body.get(i);
      TermModel termModel = bodyModel.get(i);
      if (term instanceof GdlConstant) {
        domainContents.add(termModel.getPossibleConstants());
      } else if (term instanceof GdlFunction) {
        GdlFunction function = (GdlFunction) term;
        List<TermModel> functionBodyModel = termModel.getFunctionBodyModel(function);
        getDomainInternal(function.getBody(), functionBodyModel, domainContents);
      } else {
        throw new IllegalStateException();
      }
    }
  }
View Full Code Here

    for (NameAndArity nameAndArity : termModel.getPossibleFunctions().keySet()) {
      List<TermModel> bodyModel = termModel.getPossibleFunctions().get(nameAndArity);
      List<Set<GdlTerm>> functionSampleTerms = toSampleTerms(bodyModel);
      Set<List<GdlTerm>> functionBodies = Sets.cartesianProduct(functionSampleTerms);
      for (List<GdlTerm> functionBody : functionBodies) {
        GdlFunction function = GdlPool.getFunction(nameAndArity.getName(), functionBody);
        results.add(function);
      }
    }
    return results;
  }
View Full Code Here

TOP

Related Classes of org.ggp.base.util.gdl.grammar.GdlFunction

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.