<commit_before>from __future__ import generators

from rdflib.constants import TYPE
from rdflib.constants import STATEMENT, SUBJECT, PREDICATE, OBJECT
from rdflib.constants import RDFS_LABEL, RDFS_COMMENT
from rdflib.constants import RDFS_DOMAIN, RDFS_SUBCLASSOF

class Schema(object):

    def label(self, subject, default=None):
        for s, p, o in self.triples((subject, RDFS_LABEL, None)):
            return o
        return default or subject

    def comment(self, subject, default=None):
        for s, p, o in self.triples((subject, RDFS_COMMENT, None)):
            return o
        return default or self.label(subject)
        
    def typeless_resources(self):
        for subject in self.subjects():
            if not (subject, TYPE, None) in self:
                yield subject

    # TODO: should we have a version of this that answers for subclasses too?
    def is_of_type(self, subject, type):
        return (subject, TYPE, type) in self

    def subjects_by_type(self, type, predicate, object):
        for subject in self.subjects(predicate, object):
            if self.is_of_type(subject, type):
                yield subject<commit_msg>label and comment methon changed to default to default value passed in<commit_after>from __future__ import generators

from rdflib.constants import TYPE
from rdflib.constants import STATEMENT, SUBJECT, PREDICATE, OBJECT
from rdflib.constants import RDFS_LABEL, RDFS_COMMENT
from rdflib.constants import RDFS_DOMAIN, RDFS_SUBCLASSOF

class Schema(object):

    def label(self, subject, default=''):
        for s, p, o in self.triples((subject, RDFS_LABEL, None)):
            return o
        return default

    def comment(self, subject, default=''):
        for s, p, o in self.triples((subject, RDFS_COMMENT, None)):
            return o
        return default
        
    def typeless_resources(self):
        for subject in self.subjects():
            if not (subject, TYPE, None) in self:
                yield subject

    # TODO: should we have a version of this that answers for subclasses too?
    def is_of_type(self, subject, type):
        return (subject, TYPE, type) in self

    def subjects_by_type(self, type, predicate, object):
        for subject in self.subjects(predicate, object):
            if self.is_of_type(subject, type):
                yield subject
{'fraction_non_alphanumeric': 0.07705406555981269, 'fraction_numerical': 0.0, 'mean_word_length': 2.858784893267652, 'pattern_counts': {'":': 0, '<': 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': '1035446', 'n_tokens_mistral': 690, 'n_tokens_neox': 663, 'n_words': 238}