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

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


    Set<GdlVariable> multipleVars = new HashSet<GdlVariable>();
    //...which, of course, means we have to spot non-candidate vars
    Set<GdlVariable> nonCandidateVars = new HashSet<GdlVariable>();

    for(int i = 0; i < tuple.size(); i++) {
      GdlTerm term = tuple.get(i);
      if(term instanceof GdlVariable
          && !multipleVars.contains(term)) {
        GdlVariable var = (GdlVariable) term;
        if(candidateVars.contains(var)
            || nonCandidateVars.contains(var)) {
View Full Code Here


    {
        List<GdlTerm> body = new ArrayList<GdlTerm>();
        body.add(template.getName());
        for(int i=0; i<template.arity(); i++)
        {
            GdlTerm arg = template.get(i);
            if(arg instanceof GdlConstant)
            {
                List<GdlTerm> domBody = new ArrayList<GdlTerm>();
                domBody.add(arg);
                GdlFunction dom = GdlPool.getFunction(GdlPool.getConstant("val"), domBody);
View Full Code Here

        //If we have two constants: Either remove one or
        //maybe get rid of the ___?
        //One is a variable: Replace the variable with the other thing
        //throughout the rule
        GdlDistinct distinct = (GdlDistinct) notDistinctLiteral.getBody();
        GdlTerm arg1 = distinct.getArg1();
        GdlTerm arg2 = distinct.getArg2();
        if(arg1 == arg2) {
            //Just remove that literal
            List<GdlLiteral> newBody = new ArrayList<GdlLiteral>();
            newBody.addAll(rule.getBody());
            newBody.remove(notDistinctLiteral);
View Full Code Here

  private static GdlLiteral cleanParentheses(GdlLiteral literal) {
    if(literal instanceof GdlSentence) {
      return cleanParentheses((GdlSentence)literal);
    } else if(literal instanceof GdlDistinct) {
      GdlDistinct distinct = (GdlDistinct) literal;
      GdlTerm term1 = cleanParentheses(distinct.getArg1());
      GdlTerm term2 = cleanParentheses(distinct.getArg2());
      return GdlPool.getDistinct(term1, term2);
    } else if(literal instanceof GdlNot) {
      GdlLiteral body = ((GdlNot) literal).getBody();
      return GdlPool.getNot(cleanParentheses(body));
    } else if(literal instanceof GdlOr) {
View Full Code Here

      int querySize = terms.size();
      List<Boolean> isInputConstant = new ArrayList<Boolean>(terms.size());
      Map<Integer, GdlConstant> queryConstants = Maps.newHashMap();
      List<Integer> queryInputIndices = new ArrayList<Integer>(terms.size());
      for(int i = 0; i < terms.size(); i++) {
        GdlTerm term = terms.get(i);
        if(term instanceof GdlConstant) {
          isInputConstant.add(true);
          queryConstants.put(i, (GdlConstant) term);
          queryInputIndices.add(-1);
        } else if(term instanceof GdlVariable) {
View Full Code Here

        newBody.add(replaceVariables(term, assignment));
      }
      return GdlPool.getFunction(name, newBody);
    } else if (gdl instanceof GdlDistinct) {
      GdlDistinct distinct = (GdlDistinct) gdl;
      GdlTerm arg1 = replaceVariables(distinct.getArg1(), assignment);
      GdlTerm arg2 = replaceVariables(distinct.getArg2(), assignment);
      return GdlPool.getDistinct(arg1, arg2);
    } else if (gdl instanceof GdlNot) {
      GdlLiteral internal = ((GdlNot) gdl).getBody();
      return GdlPool.getNot(replaceVariables(internal, assignment));
    } else if (gdl instanceof GdlOr) {
View Full Code Here

            return GdlPool.getRule(head, body);
        }
        else if(gdl instanceof GdlDistinct)
        {
            GdlDistinct distinct = (GdlDistinct)gdl;
            GdlTerm arg1 = (GdlTerm)getInstantiationAux(distinct.getArg1(), varInstantiation);
            GdlTerm arg2 = (GdlTerm)getInstantiationAux(distinct.getArg2(), varInstantiation);
            return GdlPool.getDistinct(arg1, arg2);
        }
        else if(gdl instanceof GdlNot)
        {
            GdlNot not = (GdlNot)gdl;
View Full Code Here

        {
            GdlRelation relation = (GdlRelation) gdl;
            String name = relation.getName().toString();
            if(!name.equals("base"))
            {
                GdlTerm term = relation.toTerm();
                GdlTerm generified = findGenericForm(term);
                Assignment instantiation = getConstantList(term);
                if(!domains.containsKey(generified))
                    domains.put(generified, new Domain(generified, term));
                Domain dom = domains.get(generified);
                dom.assignments.add(instantiation);
            }
        }
        else if(gdl instanceof GdlRule)
        {
            GdlRule rule = (GdlRule)gdl;
            GdlSentence head = rule.getHead();
            if(head instanceof GdlRelation)
            {
                GdlRelation rel = (GdlRelation)head;
                GdlTerm term = rel.toTerm();

                GdlTerm generified = findGenericForm(term);
                if(!domains.containsKey(generified))
                    domains.put(generified, new Domain(generified, term));
                Domain dom = domains.get(generified);

                List<GdlTerm> productionTemplate = getConstantAndVariableList(term);

                List<List<GdlLiteral>> newRHSs = deOr(rule.getBody());
                for(List<GdlLiteral> RHS : newRHSs)
                {
                    RuleReference ruleRef = new RuleReference(GdlPool.getRule(head, RHS));
                    ruleRef.productionTemplate = productionTemplate;
                    for(GdlLiteral lit : RHS)
                    {
                        if(lit instanceof GdlSentence)
                        {
                            GdlTerm t = ((GdlSentence)lit).toTerm();
                            Condition cond = new Condition(t);
                            ruleRef.conditions.add(cond);
                        }
                    }
                    dom.ruleRefs.add(ruleRef);
                }

            }
            else
            {
                List<List<GdlLiteral>> newRHSs = deOr(rule.getBody());
                for(List<GdlLiteral> RHS : newRHSs)
                {
                    RuleReference ruleRef = new RuleReference(GdlPool.getRule(head, RHS));
                    for(GdlLiteral lit : RHS)
                    {
                        if(lit instanceof GdlSentence)
                        {
                            GdlTerm t = ((GdlSentence)lit).toTerm();
                            Condition cond = new Condition(t);
                            ruleRef.conditions.add(cond);
                        }
                    }
                    extraRefs.add(ruleRef);
View Full Code Here

        Condition cond = conditions.get(idx);
        Domain dom = cond.dom;
        Assignments assignments = null;
        for(int i=0; i<cond.template.size(); i++)
        {
            GdlTerm t = cond.template.get(i);
            GdlConstant c = null;
            if(t instanceof GdlVariable)
            {
                GdlVariable v = (GdlVariable)t;
                if(instantiation.containsKey(v))
                    c = instantiation.get(v);
            }
            else if(t instanceof GdlConstant)
                c = (GdlConstant)t;

            if(c != null)
            {
                if(assignments == null)
                {
                    assignments = new Assignments();
                    if(dom.indices.size() > i//if this doesn't hold it is because there are no assignments and the indices haven't been set up yet
                    {
                        Index index = dom.indices.get(i);
                        if(index.containsKey(c))  //Might be no assignment which satisfies this condition
                            assignments.addAll(index.get(c));
                    }
                }
                else
                {
                    if(dom.indices.size()>i)
                    {
                        Index index = dom.indices.get(i);
                        if(index.containsKey(c))  //Might be no assignment which satisfies this condition
                            assignments.retainAll(index.get(c));
                    }
                    else  //This is when we've tried to find an assignment for a form that doesn't have any assignments yet.  Pretend it returned an empty set
                        assignments.clear();
                }
            }
        }
        if(assignments == null) //case where there are no constants to be consistent with
        {
            assignments = dom.assignments;
        }

        for(Assignment a : assignments)
        {
            Map<GdlVariable, GdlConstant> newInstantiation = new HashMap<GdlVariable, GdlConstant>(instantiation);
            for(int i=0; i<a.size(); i++)
            {
                GdlTerm t = cond.template.get(i);
                if(t instanceof GdlVariable)
                {
                    GdlVariable var = (GdlVariable)t;
                    if(!instantiation.containsKey(var))
                        newInstantiation.put(var, a.get(i));
View Full Code Here

      if(tuple.size() != dependentSlots.size())
        throw new RuntimeException("Mismatched sentence " + functionalSentence + " and constant form " + functionInfo);

      Set<GdlVariable> candidateVars = new HashSet<GdlVariable>();
      for(int i = 0; i < tuple.size(); i++) {
        GdlTerm term = tuple.get(i);
        if(term instanceof GdlVariable && dependentSlots.get(i)
            && !varOrdering.contains(term)
            && varsToAssign.contains(term))
          candidateVars.add((GdlVariable) term);
      }
View Full Code Here

TOP

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

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.