
import eulfedora.server
import time

class Sparqler(eulfedora.server.Repository):
    def query(self, sparql, flush=None, batch_size=100, pause=0):
        page = 0
        while True:
            query = " ".join([
                sparql,
                "LIMIT",
                str(batch_size),
                "OFFSET",
                str(page * batch_size)
                ])
            results = list(super(Sparqler, self).risearch.sparql_query(query, flush=flush))
            if len(results):
                for r in results:
                    yield r
                page += 1
                time.sleep(pause)
            else:
                break
            

