<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from org.wikiup.database.orm import WikiupEntityManager
from org.wikiup.modules.jython.orm import PythonEntity


def getEntity(name, ctx=None, **selection):
    return PythonEntity(_getEntity(name, selection, ctx))


def query(name, relation, ctx=None, **selection):
    entity = _getEntity(name, selection, ctx, autoselect=False)
    relatives = entity.getRelatives(relation, None)
    props = [str(i.getName()) for i in relatives.getAttributes()]
    r = [dict([(j, str(i.getAttribute(j))) for j in props]) for i in relatives.getChildren()]
    if len(r) == 0:
        r = dict([(str(i.getName()), i.getObject()) for i in relatives.getAttributes()])
    entity.release()
    return r


def _getEntity(name, selection=None, ctx=None, autoselect=True):
    entity = None
    if ctx is not None:
        entity = ctx.get(name)
    if entity is None:
        entity = (ctx or WikiupEntityManager.getInstance()).getEntity(name)
    if selection:
        for k in selection:<commit_msg>change private getEntity function signature<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from org.wikiup.database.orm import WikiupEntityManager
from org.wikiup.modules.jython.orm import PythonEntity


def getEntity(name, ctx=None, **selection):
    return PythonEntity(_getEntity(name, ctx, selection))


def query(name, relation, ctx=None, **selection):
    entity = _getEntity(name, ctx, selection, False)
    relatives = entity.getRelatives(relation, None)
    props = [str(i.getName()) for i in relatives.getAttributes()]
    r = [dict([(j, str(i.getAttribute(j))) for j in props]) for i in relatives.getChildren()]
    if len(r) == 0:
        r = dict([(str(i.getName()), i.getObject()) for i in relatives.getAttributes()])
    entity.release()
    return r


def _getEntity(name, ctx=None, selection=None, autoselect=True):
    entity = None
    if ctx is not None:
        entity = ctx.get(name)
    if entity is None:
        entity = (ctx or WikiupEntityManager.getInstance()).getEntity(name)
    if selection:
        for k in selection:
{'fraction_non_alphanumeric': 0.1343141907925961, 'fraction_numerical': 0.0018984337921214998, 'mean_word_length': 3.8237986270022883, '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': '1791065', 'n_tokens_mistral': 654, 'n_tokens_neox': 647, 'n_words': 185}