grew-nlp / grewpy

grewpy: Python library for Grew
4 stars 2 forks source link

global in Request #2

Closed s-herrera closed 1 year ago

s-herrera commented 1 year ago

Hello, Is it possible to add the global query to the Request Class? I take this opportunity to say that the function with is repeated.

class Request():
    """
    lists of ClauseList
    """
    def __init__(self, *L):
        """
        L is either a list of
         - RequestItem or
         - (pattern) string or a
         - Request (for copies)
        """
        elts = tuple()
        for e in L:
            if isinstance(e,str):
                elts += (RequestItem("pattern", e),)
            elif isinstance(e,RequestItem):
                elts += (e,)
            elif isinstance(e,Request):
                elts += e.items
            elif isinstance(e,tuple): #supposed to be a list of ClauseList
                elts += e
            else:
                try:
                    #suppose it is a generator
                    for x in e:
                        elts += (x,)
                except:
                    raise ValueError(f"{e} cannot be used to build a Request")
        self.items = elts

    def without(self, *L):
        self.items += tuple(RequestItem("without", e) for e in L)
        return self

    def with_(self, *L):
        self.items += tuple(RequestItem("with", e) for e in L)
        return self

    def with_(self, *L):
        self.items += tuple(RequestItem("with", e) for e in L)
        return self