<commit_before>from __future__ import unicode_literals

from rdflib import BNode, URIRef, Literal
from rdflib.term import Identifier

from pprint import pprint


try:
    basestring
except NameError:
    basestring = str


def print_graph(g):
    print(g.serialize(format="turtle"))
    pprint(list(g))


def to_rdf_triples(s, p, o, datatype=None, language=None):
    if s is not None and not isinstance(s, Identifier):
        if s.startswith("_:"):
            s = BNode(s)
        else:
            s = URIRef(s)

    if p is not None and not isinstance(p, Identifier):
        p = URIRef(p)

    if isinstance(o, basestring):
        if o.startswith("_:"):
            o = BNode(o)
        elif "://" in o:
            o = URIRef(o)
        else:
            o = Literal(o, lang=language, datatype=datatype)

    if o is not None and not isinstance(o, Identifier):
        o = Literal(o, lang=language, datatype=datatype)

    return s, p, o


def get_triples(g, s, p, o, datatype=None, language=None):
    s, p, o = to_rdf_triples(s, p, o, datatype, language)
    return list(g.triples((s, p, o)))


class RdflibTestCaseMixin(object):
    def assert_uri_equal(self, uri, s):
        self.assertEqual(URIRef(uri), s)

    def assert_literal_equal(self, expected, literal, data_type=None, language=None):<commit_msg>Added "urn:" clause in `to_rdf_triples` for objects.<commit_after>from __future__ import unicode_literals

from rdflib import BNode, URIRef, Literal
from rdflib.term import Identifier

from pprint import pprint


try:
    basestring
except NameError:
    basestring = str


def print_graph(g):
    print(g.serialize(format="turtle"))
    pprint(list(g))


def to_rdf_triples(s, p, o, datatype=None, language=None):
    if s is not None and not isinstance(s, Identifier):
        if s.startswith("_:"):
            s = BNode(s)
        else:
            s = URIRef(s)

    if p is not None and not isinstance(p, Identifier):
        p = URIRef(p)

    if isinstance(o, basestring):
        if o.startswith("_:"):
            o = BNode(o)
        elif "://" in o or o.startswith("urn:"):
            o = URIRef(o)
        else:
            o = Literal(o, lang=language, datatype=datatype)

    if o is not None and not isinstance(o, Identifier):
        o = Literal(o, lang=language, datatype=datatype)

    return s, p, o


def get_triples(g, s, p, o, datatype=None, language=None):
    s, p, o = to_rdf_triples(s, p, o, datatype, language)
    return list(g.triples((s, p, o)))


class RdflibTestCaseMixin(object):
    def assert_uri_equal(self, uri, s):
        self.assertEqual(URIRef(uri), s)

    def assert_literal_equal(self, expected, literal, data_type=None, language=None):
{'fraction_non_alphanumeric': 0.11773417252869307, 'fraction_numerical': 0.0, 'mean_word_length': 2.933042212518195, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '295778', 'n_tokens_mistral': 960, 'n_tokens_neox': 941, 'n_words': 263}