Example #1
0
def render_all(filepattern='*.cxt', encoding=None,
               directory=None, out_format=None):  # pragma: no cover
    import concepts

    for cxtfile in glob.iglob(filepattern):
        c = concepts.load(cxtfile, encoding=encoding)
        l = c.lattice

        filename = '%s.gv' % os.path.splitext(cxtfile)[0]
        if directory is not None:
            filename = os.path.basename(filename)

        dot = l.graphviz(filename, directory, format=out_format)
        dot.render()
Example #2
0
def render_all(filepattern='*.cxt', encoding=None,
               directory=None, out_format=None):  # pragma: no cover
    import concepts

    for cxtfile in glob.iglob(filepattern):
        c = concepts.load(cxtfile, encoding=encoding)
        l = c.lattice

        filename = f'{os.path.splitext(cxtfile)[0]}.gv'
        if directory is not None:
            filename = os.path.basename(filename)

        dot = l.graphviz(filename, directory, format=out_format)
        dot.render()
Example #3
0
def render_all(filepattern='*.cxt',
               *,
               exclude=(),
               encoding: str = None,
               directory=None,
               out_format=None) -> None:  # pragma: no cover
    import concepts

    for cxtfile in glob.iglob(filepattern):
        print(cxtfile)
        if os.path.basename(cxtfile) in exclude:
            print(f'  matches exclude, skip')
            continue
        c = concepts.load(cxtfile, encoding=encoding)
        l = c.lattice

        filename = f'{os.path.splitext(cxtfile)[0]}.gv'
        if directory is not None:
            filename = os.path.basename(filename)

        dot = l.graphviz(filename, directory, format=out_format)
        dot.render()
Example #4
0
print(f'{properties!r:}')
assert len(properties) == 128, f'{len(attributes):_d} != 128'

if not all(path.exists() for path in RESULTS):
    data = list(tools.csv_iterrows(DATA))
    assert len(data) == 8_124, f'{len(data):_d} != 8_124'

    tools.write_csv(CSV, iterrows(attributes, data), header=[MUSHROOM.stem] + properties,
                    encoding=ENCODING)
    print(CSV, f'{CSV.stat().st_size:_d} bytes')

    tools.write_lines(CXT, iter_cxt_lines(attributes, data),
                      encoding=ENCODING, newline='\n')
    print(CXT, f'{CXT.stat().st_size:_d} bytes')

    context = concepts.load(str(CXT))
    context.tofile(DAT, frmat='fimi')
    print(DAT, f'{DAT.stat().st_size:_d} bytes')

    definition = concepts.Definition.fromfile(CXT)
    removed = definition.remove_empty_properties()
    assert removed == ['gill-attachment:descending',
                       'gill-attachment:notched',
                       'gill-spacing:distant',
                       'stalk-root:cup',
                       'stalk-root:rhizomorphs',
                       'veil-type:universal',
                       'ring-type:cobwebby',
                       'ring-type:sheathing',
                       'ring-type:zone']
Example #5
0
import os
import pathlib
import sys
import time

sys.path.insert(1, os.pardir)

import concepts  # noqa: E402

SEGMENTS = pathlib.Path(os.pardir) / 'examples' / 'segments.cxt'

ENCODING = 'utf-8'

start = time.perf_counter()

context = concepts.load(SEGMENTS, encoding=ENCODING)
print(f'{context!r:}')

assert context.shape == (143, 56), f'{context.shape} != (143, 56)'

lattice = context.lattice
print(f'{lattice!r:}')

assert len(lattice) == 11_878, f'{len(lattice):_d} != 11_878'

duration = time.perf_counter() - start
print(f'{duration:.1f} seconds')

assert duration <= 40, f'{duration:.1f} > 40'

context = context.copy()
Example #6
0
import os
import sys
import time

sys.path.insert(1, os.pardir)

import concepts  # noqa: E402
from concepts import algorithms  # noqa: E402

from mushroom import CXT_MINIMAL, ENCODING  # noqa: E402

INTENTS = CXT_MINIMAL.with_name(f'{CXT_MINIMAL.stem}-intents.dat')

start = time.perf_counter()

context = concepts.load(CXT_MINIMAL, encoding=ENCODING)
print(f'{context!r}')

assert context.shape == (8_124, 119), f'{context.shape} != (8_124, 119)'

result = algorithms.get_concepts(context)
print(f'{len(result):_d} concepts')

result.tofile(INTENTS)
print(INTENTS, f'{INTENTS.stat().st_size:_d} bytes')

duration = time.perf_counter() - start
print(f'{duration:.1f} seconds')

assert len(result) == 238_710, f'{len(result):_d} != 238_710'