コード例 #1
0
    def evaluate(self, output=None, output_format=RDFFormat.TABLE):
        """
        Execute the embedded query against the RDF store.

        :param output: A file name, file descriptor or a file-like
                       object to save the results to
                       (optional). ``True`` can be used as a synonym
                       for stdout.
        :type output: str|file|int|bool
        :param output_format: Serialization format for ``output``.
                              The default is TABLE.
        :type output_format: RDFFormat
        :return: An iterator over statements or None (if ``output`` is used)..
        :rtype: GraphQueryResult
        """
        with output_to(output) as out:
            callback = None if output is None else out.write
            accept = None if output is None else RDFFormat.mime_type_for_format(
                output_format)
            response = self.evaluate_generic_query(accept=accept,
                                                   callback=callback)
            if output is None:
                return GraphQueryResult(response)
            else:
                return None
コード例 #2
0
ファイル: query.py プロジェクト: janatalab/agraph-python
 def evaluate(self, output=None, output_format=RDFFormat.NQUADS):
     """
     Execute the embedded query against the RDF store.  Return
     a graph.
     """
     with output_to(output) as out:
         callback = None if output is None else out.write
         accept = None if output is None else RDFFormat.mime_type_for_format(output_format)
         response = self.evaluate_generic_query(accept=accept, callback=callback)
         if output is None:
             return GraphQueryResult(response)
         else:
             return None
コード例 #3
0
    def evaluate(self,
                 count=False,
                 output=None,
                 output_format=TupleFormat.TABLE):
        """Execute the embedded query against the RDF store.

        Return an iterator that produces for each step a tuple of values
        (resources and literals) corresponding to the variables or
        expressions in a 'select' clause (or its equivalent).

        :param count: If ``True`` return the number of result rows
                      instead of the usual iterator.
        :type count: bool
        :param output: A file name, file descriptor or a file-like
                       object to save the results to
                       (optional). ``True`` can be used as a synonym
                       for stdout.
        :type output: str|file|int|bool
        :param output_format: Serialization format for ``output``.
                              The default is TABLE.
        :type output_format: RDFFormat
        :return: Either an iterator over results, 
                 an integer (the number of results, if ``count`` is used) 
                 or ``None`` (if ``output`` is used).
        :rtype: TupleQueryResult|int
        """

        with output_to(output) as out:
            callback = None if output is None else out.write
            accept = None if output is None else TupleFormat.mime_type_for_format(
                output_format)
            response = self.evaluate_generic_query(count=count,
                                                   accept=accept,
                                                   callback=callback)

            if count:
                return response

            if output is not None:
                return None

            return TupleQueryResult(response['names'], response['values'],
                                    response.get('queryInfo'))
コード例 #4
0
ファイル: query.py プロジェクト: janatalab/agraph-python
    def evaluate(self, count=False, output=None, output_format=TupleFormat.CSV):
        """
        Execute the embedded query against the RDF store.  Return
        an iterator that produces for each step a tuple of values
        (resources and literals) corresponding to the variables
        or expressions in a 'select' clause (or its equivalent).
        """

        with output_to(output) as out:
            callback = None if output is None else out.write
            accept = None if output is None else TupleFormat.mime_type_for_format(output_format)
            response = self.evaluate_generic_query(
                count=count, accept=accept, callback=callback)

            if count:
                return response

            if output is not None:
                return None

            return TupleQueryResult(response['names'], response['values'])
コード例 #5
0
ファイル: query.py プロジェクト: franzinc/agraph-python
    def evaluate(self, count=False, output=None,
                 output_format=TupleFormat.TABLE):
        """Execute the embedded query against the RDF store.

        Return an iterator that produces for each step a tuple of values
        (resources and literals) corresponding to the variables or
        expressions in a 'select' clause (or its equivalent).

        :param count: If ``True`` return the number of result rows
                      instead of the usual iterator.
        :type count: bool
        :param output: A file name, file descriptor or a file-like
                       object to save the results to
                       (optional). ``True`` can be used as a synonym
                       for stdout.
        :type output: str|file|int|bool
        :param output_format: Serialization format for ``output``.
                              The default is TABLE.
        :type output_format: RDFFormat
        :return: Either an iterator over results, 
                 an integer (the number of results, if ``count`` is used) 
                 or ``None`` (if ``output`` is used).
        :rtype: TupleQueryResult|int
        """

        with output_to(output) as out:
            callback = None if output is None else out.write
            accept = None if output is None else TupleFormat.mime_type_for_format(output_format)
            response = self.evaluate_generic_query(
                count=count, accept=accept, callback=callback)

            if count:
                return response

            if output is not None:
                return None

            return TupleQueryResult(response['names'], response['values'])
コード例 #6
0
ファイル: query.py プロジェクト: franzinc/agraph-python
    def evaluate(self, output=None, output_format=RDFFormat.TABLE):
        """
        Execute the embedded query against the RDF store.

        :param output: A file name, file descriptor or a file-like
                       object to save the results to
                       (optional). ``True`` can be used as a synonym
                       for stdout.
        :type output: str|file|int|bool
        :param output_format: Serialization format for ``output``.
                              The default is TABLE.
        :type output_format: RDFFormat
        :return: An iterator over statements or None (if ``output`` is used)..
        :rtype: GraphQueryResult
        """
        with output_to(output) as out:
            callback = None if output is None else out.write
            accept = None if output is None else RDFFormat.mime_type_for_format(output_format)
            response = self.evaluate_generic_query(accept=accept, callback=callback)
            if output is None:
                return GraphQueryResult(response)
            else:
                return None
コード例 #7
0
ファイル: newtests.py プロジェクト: fazleh2010/qa_generator
def test_output_to_stderr(capfd):
    with output_to(2) as f:
        f.write(b'test')
    out, err = capfd.readouterr()
    assert err == 'test'
コード例 #8
0
ファイル: newtests.py プロジェクト: fazleh2010/qa_generator
def test_output_to_true(capfd):
    with output_to(True) as f:
        f.write(b'test')
    out, err = capfd.readouterr()
    assert out == 'test'