<commit_before>from collections import defaultdict

from connectedafrica.core import schemata
from connectedafrica.util.properties import Properties


def load_entity_relations(entity, filters={}):
    """ Get all relations associated with this entity. """
    relations = []
    for collection in (entity.inbound, entity.outbound):
        params = {'limit': 1000}
        collection = collection.query(params=params)
        for key, value in filters.items():
            collection = collection.filter(key, value)
        for relation in collection.results:
            relation.props = Properties(relation)
            relations.append(relation)
    return relations


def load_entity_relations_schemata(entity, filters={}):
    """ Get the facet counts for schemata associated with
    the relations of the given entity. """
    schemata_counts = defaultdict(int)
    for collection in (entity.inbound, entity.outbound):
        params = {'limit': 0, 'facet': 'schema'}
        collection = collection.query(params=params)
        facets = collection.data.get('facets', {}).get('schema', {})
        for schema, count in facets.get('results'):
            schemata_counts[schema['name']] += count
    return schemata_counts


def sort_key(relation):
    """ Sort relations by date by default. """
    if 'date_start' in relation.props:
        return relation.props.date_start.value
    if 'date_end' in relation.props:
        return relation.props.date_end.value
    return '3000-' + relation.id
<commit_msg>Convert to string when comparing to strings. <commit_after>from collections import defaultdict

from connectedafrica.core import schemata
from connectedafrica.util.properties import Properties


def load_entity_relations(entity, filters={}):
    """ Get all relations associated with this entity. """
    relations = []
    for collection in (entity.inbound, entity.outbound):
        params = {'limit': 1000}
        collection = collection.query(params=params)
        for key, value in filters.items():
            collection = collection.filter(key, value)
        for relation in collection.results:
            relation.props = Properties(relation)
            relations.append(relation)
    return relations


def load_entity_relations_schemata(entity, filters={}):
    """ Get the facet counts for schemata associated with
    the relations of the given entity. """
    schemata_counts = defaultdict(int)
    for collection in (entity.inbound, entity.outbound):
        params = {'limit': 0, 'facet': 'schema'}
        collection = collection.query(params=params)
        facets = collection.data.get('facets', {}).get('schema', {})
        for schema, count in facets.get('results'):
            schemata_counts[schema['name']] += count
    return schemata_counts


def sort_key(relation):
    """ Sort relations by date by default. """
    if 'date_start' in relation.props:
        return unicode(relation.props.date_start.value)
    if 'date_end' in relation.props:
        return unicode(relation.props.date_end.value)
    return '3000-' + relation.id

{'fraction_non_alphanumeric': 0.10616883116883116, 'fraction_numerical': 0.005844155844155844, 'mean_word_length': 3.309090909090909, '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': '3931259', 'n_tokens_mistral': 846, 'n_tokens_neox': 801, 'n_words': 239}