<commit_before>from __future__ import absolute_import

import sys
from collections import defaultdict
from functools import wraps
import copy
import platform
import pkg_resources

import gringo

import equibel as eb

if platform.system() == 'Linux':
    if platform.architecture()[0] == '64bit':
        if platform.dist()[0] in ['centos', 'CentOS']:
            import equibel.includes.linux.bit64.centos.gringo as gringo
            from equibel.includes.linux.bit64.centos.gringo import Control, Model, Fun
        else:
            import equibel.includes.linux.bit64.gringo as gringo
            from equibel.includes.linux.bit64.gringo import Control, Model, Fun
    elif platform.architecture()[0] == '32bit':
        import equibel.includes.linux.bit32.gringo as gringo
        from equibel.includes.linux.bit32.gringo import Control, Model, Fun
elif platform.system() == 'Darwin':
    import equibel.includes.mac.gringo as gringo
    from equibel.includes.mac.gringo import Control, Model, Fun

import equibel.FormulaExtractor as FormulaExtractor
import equibel.formatters.ASP_Formatter as ASP_Formatter
#from equibel.simbool.simplify import simplify

EQ_SETS_FILE = pkg_resources.resource_filename('equibel', 'asp/eq_sets.lp')

CONTAINMENT = 0
CARDINALITY = 1

def completion(G, method=CONTAINMENT):
    atoms = [eb.Prop(atom) for atom in G.atoms()]
    sorted_atoms = tuple(sorted(atoms))

    ctl = gringo.Control()
    #ctl.conf.configuration = 'handy'
    ctl.conf.solver.heuristic = 'domain'
    ctl.conf.solve.enum_mode = 'domRec'
    ctl.conf.solve.models = 0
    #ctl.conf.solve.parallel_mode = 2

    ctl.load(EQ_SETS_FILE)
    ctl.add('base', [], eb.convert_to_asp(G))
    ctl.ground([('base', [])])

    node_models = defaultdict(set)
    node_tv_dict = defaultdict(int)
    
    it = ctl.solve_iter()
    for m in it:
        node_tv_dict.clear()
        terms = m.atoms(gringo.Model.SHOWN)
        for term in terms:
            if term.name() == 'tv':
                node, atom_index, truth_value = term.args()
                node_tv_dict[node] |= truth_value << atom_index
       <commit_msg>Small changes to the solver<commit_after>from __future__ import absolute_import

import sys
from collections import defaultdict
from functools import wraps
import copy
import platform
import pkg_resources

import gringo

import equibel as eb

if platform.system() == 'Linux':
    if platform.architecture()[0] == '64bit':
        if platform.dist()[0] in ['centos', 'CentOS']:
            import equibel.includes.linux.bit64.centos.gringo as gringo
            from equibel.includes.linux.bit64.centos.gringo import Control, Model, Fun
        else:
            import equibel.includes.linux.bit64.gringo as gringo
            from equibel.includes.linux.bit64.gringo import Control, Model, Fun
    elif platform.architecture()[0] == '32bit':
        import equibel.includes.linux.bit32.gringo as gringo
        from equibel.includes.linux.bit32.gringo import Control, Model, Fun
elif platform.system() == 'Darwin':
    import equibel.includes.mac.gringo as gringo
    from equibel.includes.mac.gringo import Control, Model, Fun

import equibel.FormulaExtractor as FormulaExtractor
import equibel.formatters.ASP_Formatter as ASP_Formatter
#from equibel.simbool.simplify import simplify

EQ_SETS_FILE = pkg_resources.resource_filename('equibel', 'asp/eq_sets.lp')

CONTAINMENT = 'containment'
CARDINALITY = 'cardinality'

def completion(G, method=CONTAINMENT):
    atoms = [eb.Prop(atom) for atom in G.atoms()]
    sorted_atoms = tuple(sorted(atoms))

    ctl = gringo.Control()
    #ctl.conf.configuration = 'handy'
    ctl.conf.solver.heuristic = 'domain'
    ctl.conf.solve.enum_mode = 'domRec'
    ctl.conf.solve.models = 0
    #ctl.conf.solve.parallel_mode = 2

    ctl.load(EQ_SETS_FILE)
    ctl.add('base', [], eb.convert_to_asp(G))
    ctl.ground([('base', [])])

    node_models = defaultdict(set)
    node_tv_dict = defaultdict(int)
    
    it = ctl.solve_iter()
    for m in it:
        node_tv_dict.clear()
        terms = m.atoms(gringo.Model.SHOWN)
        for term in terms:
            if term.name() == 'tv':
                node, atom_index, truth_value = term.args()
                node_tv_dict[node] |= truth_value << atom_index
       
{'fraction_non_alphanumeric': 0.10851262862488306, 'fraction_numerical': 0.01028999064546305, 'mean_word_length': 3.238850346878097, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3576964', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1360, 'n_words': 318}