Exemplo n.º 1
0
            // MinRemMatchLen and MaxRemMatchLen are calculated on the fly during the matching process

            /*
             *    // For future enhancement (don't forget CopyEx())
             *    public ListPatternElem (DownRepFactor downRepFactor, DisjunctiveSearchTerm altSearchTerms, AcrossRepFactor acrossRepFactor)
             *      : base ("RANGE")  // used by CopyEx
             *    {
             *      this.downRepFactor = downRepFactor;
             *      this.altSearchTerms = altSearchTerms;
             *      this.acrossRepFactor = acrossRepFactor;
             *
             *      int n = TARGETOFFSET + (altSearchTerms == null ? 1 : altSearchTerms.Count);
             *      args = new BaseTerm [n];
             *
             *      args [0] = HasAcrossRepFactor ? acrossRepFactor.minLenTerm : DecimalTerm.ZERO;
             *      args [1] = HasAcrossRepFactor ? acrossRepFactor.maxLenTerm : DecimalTerm.ZERO;
             *      args [2] = HasAcrossRepFactor ? acrossRepFactor.bindVar : null;
             *      args [3] = HasAltSearchTerms ? altSearchTerms.bindVar : null;
             *
             *      int i = TARGETOFFSET;
             *
             *      if (altSearchTerms != null)
             *        foreach (BaseTerm t in altSearchTerms.alternatives)
             *          args [i++] = t;
             *
             *      isNegSearch = (altSearchTerms == null) ? false : altSearchTerms.isNegSearch;
             *    }
             */
            public ListPatternElem(BaseTerm[] a, DownRepFactor downRepFactor, bool isNegSearch)
                : base("RANGE", a) // used by CopyEx
            {
#if old
                this.isNegSearch = isNegSearch;
#endif
            }
Exemplo n.º 2
0
            // MinRemMatchLen and MaxRemMatchLen are calculated on the fly during the matching process

            // DEZE UITEINDELIJK GEBRUIKEN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // DENK AAN CopyEx()
            public ListPatternElem(DownRepFactor downRepFactor, DisjunctiveSearchTerm altSearchTerms, AcrossRepFactor acrossRepFactor)
                : base("RANGE") // used by CopyEx
            {
                this.downRepFactor   = downRepFactor;
                this.altSearchTerms  = altSearchTerms;
                this.acrossRepFactor = acrossRepFactor;

                int n = TARGETOFFSET + (altSearchTerms == null ? 1 : altSearchTerms.Count);

                args = new BaseTerm [n];

                args [0] = HasAcrossRepFactor ? acrossRepFactor.minLenTerm : DecimalTerm.ZERO;
                args [1] = HasAcrossRepFactor ? acrossRepFactor.maxLenTerm : DecimalTerm.ZERO;
                args [2] = HasAcrossRepFactor ? acrossRepFactor.bindVar : null;
                args [3] = HasAltSearchTerms ? altSearchTerms.bindVar : null;

                int i = TARGETOFFSET;

                if (altSearchTerms != null)
                {
                    foreach (BaseTerm t in altSearchTerms.alternatives)
                    {
                        args [i++] = t;
                    }
                }

                isNegSearch = (altSearchTerms == null) ? false : altSearchTerms.isNegSearch;
            }
Exemplo n.º 3
0
 public SearchTerm(DownRepFactor downRepFactor, BaseTerm term)
 {
     this.downRepFactor = downRepFactor;
     this.term          = term;
 }
Exemplo n.º 4
0
            // each call processes one element of pattern[]
            bool UnifyTailEx(int ip, int it, VarStack varStack)
            {
                ListPatternElem e            = (ListPatternElem)pattern[ip];
                Variable        rangeSpecVar = (Variable)e.RangeBindVar;
                NodeIterator    subtreeIterator;
                int             k;
                int             marker;
                ListTerm        RangeList = null;
                BaseTerm        tail      = null;
                int             minLen; // minimum required range length (number of range elements)
                int             maxLen; // maximum possible ...

                if (!DoLowerAndUpperboundChecks(ip, it, out minLen, out maxLen))
                {
                    return(false);
                }

                // scan the minimal number of range elements. Add them to the range list,
                // i.e. the last variable (if present) preceding the '{ , }'
                for (int i = 0; i < minLen; i++)
                {
                    if ((k = it + i) >= target.Count)
                    {
                        return(false);
                    }

                    AppendToRangeList(ref RangeList, rangeSpecVar, target[k], ref tail);
                }

                marker = varStack.Count; // register the point to which we must possibly undo unifications

                if (e.HasSearchTerm)
                {
                    // scan the elements up to the maximum range length, and the element immediately thereafter
                    for (int i = minLen; i <= maxLen; i++)
                    {
                        BaseTerm t = null;
                        k = it + i;

                        if (k == target.Count)
                        {
                            return(false);
                        }

                        bool negSearchSucceeded = true;         // iff none of the alternative term matches the target term

                        for (int j = 4; j < e.Args.Length; j++) // scan all AltSearchTerm alternatives (separated by '|')
                        {
                            BaseTerm      searchTerm    = e.AltSearchTerms[j];
                            DownRepFactor downRepFactor = null; // e.downRepFactor [j];
                            t = target[k];
                            AltLoopStatus status = AltLoopStatus.TryNextAlt;

                            if (downRepFactor == null)
                            {
                                status =
                                    TryOneAlternative(ip, varStack, e, k, marker, RangeList, i, t, ref negSearchSucceeded, searchTerm);

                                if (status == AltLoopStatus.MatchFound)
                                {
                                    return(true);
                                }
                            }
                            else // traverse the downRepFactor tree, which in principle may yield more than one match
                            {
                                subtreeIterator = new NodeIterator(t, searchTerm, downRepFactor.minLenTerm,
                                                                   downRepFactor.maxLenTerm, false, downRepFactor.bindVar, varStack);

                                foreach (BaseTerm match in subtreeIterator) // try -- if necessary -- each tree match with the current search term
                                {
                                    status =
                                        TryOneAlternative(ip, varStack, e, k, marker, RangeList, i, match, ref negSearchSucceeded, searchTerm);

                                    if (status == AltLoopStatus.MatchFound)
                                    {
                                        return(true);
                                    }

                                    if (status == AltLoopStatus.Break)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (status == AltLoopStatus.Break)
                            {
                                break;
                            }
                        }

                        // at this point sufficient alternatives have been tried
                        if (e.IsNegSearch && negSearchSucceeded)                               // none of the terms matched => ok if binding succeeds
                        {
                            if (!TryBindingAltListVarToMatch(e.AltListBindVar, t, varStack) || // bind the AltListBindVar to the match
                                !TryBindingRangeRelatedVars(e, i, RangeList, varStack))        // bind the range to the range variables
                            {
                                return(false);                                                 // binding failed
                            }
                            if (ip == pattern.Length - 1)                                      // this was the last pattern element
                            {
                                if (k == target.Count - 1)                                     // both pattern and target exhausted
                                {
                                    return(true);
                                }
                            }
                            else if (UnifyTailEx(ip + 1, k + 1, varStack)) // now deal with the rest
                            {
                                return(true);
                            }
                        }
                        else if (i < maxLen) // append the rejected term to the range list and go try the next term
                        {
                            AppendToRangeList(ref RangeList, rangeSpecVar, t, ref tail);
                        }
                    }
                }
                else // a range without a subsequent search term (so followed by another range or end of pattern)
                {
                    for (int i = minLen; i <= maxLen; i++)
                    {
                        k = it + i;

                        if (k == target.Count)                                             // ok, target[k] does not exist, end of target hit
                        {
                            return(TryBindingRangeRelatedVars(e, i, RangeList, varStack)); // i is actual range length
                        }
                        // k is ok
                        if (i < maxLen)
                        {
                            AppendToRangeList(ref RangeList, rangeSpecVar, target[k], ref tail);
                        }

                        // now deal with the rest
                        if (TryBindingRangeRelatedVars(e, i, RangeList, varStack) &&
                            UnifyTailEx(ip + 1, k, varStack))
                        {
                            return(true);
                        }
                    }
                }

                // If we arrive here, no matching term was found in or immediately after the permitted range.
                // Therefore, undo any unifications made locally in this method and return with failure.
                if (marker != 0)
                {
                    BaseTerm.UnbindToMarker(varStack, marker);
                }

                return(false);
            }
 public SearchTerm (DownRepFactor downRepFactor, BaseTerm term)
 {
   this.downRepFactor = downRepFactor;
   this.term = term;
 }
      public ListPatternElem (BaseTerm [] a, DownRepFactor downRepFactor, bool isNegSearch)
        : base ("RANGE", a)  // used by CopyEx
      {
#if old
        this.isNegSearch = isNegSearch;
#endif
      }
      // MinRemMatchLen and MaxRemMatchLen are calculated on the fly during the matching process

      // DEZE UITEINDELIJK GEBRUIKEN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      // DENK AAN CopyEx()
      public ListPatternElem (DownRepFactor downRepFactor, DisjunctiveSearchTerm altSearchTerms, AcrossRepFactor acrossRepFactor)
        : base ("RANGE")  // used by CopyEx
      {
        this.downRepFactor = downRepFactor;
        this.altSearchTerms = altSearchTerms;
        this.acrossRepFactor = acrossRepFactor;
        
        int n = TARGETOFFSET + (altSearchTerms == null ? 1 : altSearchTerms.Count);
        args = new BaseTerm [n];

        args [0] = HasAcrossRepFactor ? acrossRepFactor.minLenTerm : DecimalTerm.ZERO;
        args [1] = HasAcrossRepFactor ? acrossRepFactor.maxLenTerm : DecimalTerm.ZERO;
        args [2] = HasAcrossRepFactor ? acrossRepFactor.bindVar : null;
        args [3] = HasAltSearchTerms ? altSearchTerms.bindVar : null;

        int i = TARGETOFFSET;

        if (altSearchTerms != null)
          foreach (BaseTerm t in altSearchTerms.alternatives)
            args [i++] = t;

        isNegSearch = (altSearchTerms == null) ? false : altSearchTerms.isNegSearch;
      }