예제 #1
0
파일: test_facet.py 프로젝트: edponce/FACET
def test_facet():
    config = {'formatter': 'csv'}
    f = facet.FacetFactory(config).create()
    f.install('data/install/american-english', nrows=50000)
    matches = f.match('beautiful window in Apollo spacecraft')
    print(matches)
    f.close()
예제 #2
0
파일: cli.py 프로젝트: edponce/FACET
def server(
    config,
    host,
    port,
    query,
    alpha,
    similarity,
    ngram,
    formatter,
    tokenizer,
    database,
    install,
    dump_config,
):
    # Resolve settings for dumping configuration
    full_config = copy.deepcopy(config)
    dump_config = config.pop('dump_config', dump_config)
    if dump_config:
        dump_output, dump_format = parse_dump_configuration(dump_config)

    # Support CLI shortcut options from configuration files
    host = config.pop('host', host)
    port = config.pop('port', port)
    query = config.pop('query', query)
    install = config.pop('install', install)
    if isinstance(install, str):
        install = {'filename': install}

    # Prepare factory options from configuration
    factory_config = copy.deepcopy(config)
    factory_config['class'] = config.get('class', 'facet')
    factory_config['tokenizer'] = config.get('tokenizer', tokenizer)
    factory_config['formatter'] = config.get('formatter', formatter)
    factory_config['matcher'] = config.get(
        'matcher', {
            'class': 'simstring',
            'db': database,
            'alpha': config.get('alpha', alpha),
            'similarity': config.get('similarity', similarity),
            'ngram': config.get('ngram', ngram),
        })

    if dump_config:
        full_config.update(factory_config)
        dump_configuration({'SERVER': full_config}, dump_output, dump_format)
        return

    f = facet.FacetFactory(factory_config).create()

    if install:
        f.install(**install)

    with facet.network.SocketServer(
        (host, port),
            facet.network.SocketServerHandler,
            served_object=f,
    ) as server:
        server.serve_forever()

    f.close()
예제 #3
0
파일: cli.py 프로젝트: edponce/FACET
def run(
    config,
    query,
    alpha,
    similarity,
    ngram,
    formatter,
    output,
    tokenizer,
    database,
    install,
    dump_config,
):
    # Resolve settings for dumping configuration
    full_config = copy.deepcopy(config)
    dump_config = config.pop('dump_config', dump_config)
    if dump_config:
        dump_output, dump_format = parse_dump_configuration(dump_config)

    # Support CLI shortcut options from configuration files
    query = config.pop('query', query)
    output = config.pop('output', output)
    install = config.pop('install', install)
    if isinstance(install, str):
        install = {'filename': install}

    # Prepare factory options from configuration
    factory_config = copy.deepcopy(config)
    factory_config['class'] = config.get('class', 'facet')
    factory_config['tokenizer'] = config.get('tokenizer', tokenizer)
    factory_config['formatter'] = config.get('formatter', formatter)
    factory_config['matcher'] = config.get(
        'matcher', {
            'class': 'simstring',
            'db': database,
            'alpha': config.get('alpha', alpha),
            'similarity': config.get('similarity', similarity),
            'ngram': config.get('ngram', ngram),
        })

    if dump_config:
        full_config.update(factory_config)
        dump_configuration({'FACET': full_config}, dump_output, dump_format)
        return

    f = facet.FacetFactory(factory_config).create()

    if install:
        f.install(**install)

    if query:
        matches = f.match(query, output=output)
        if matches is not None:
            print(matches)
    else:
        repl_loop(f)

    f.close()
예제 #4
0
파일: parallel.py 프로젝트: edponce/FACET
 def __init__(
     self,
     config: Union[str, Dict[str, Any]],
     num_procs: int = multiprocessing.cpu_count(),
 ):
     self.num_procs = num_procs
     self._factory = facet.FacetFactory(config)
     self._formatter = get_formatter(
         self._factory.get_config().pop('formatter', None)
     )
예제 #5
0
import facet


def generate_sources(n):
    source = 'acetate'
    return [source] * n


factory = facet.FacetFactory('config/umls_sqlite.yaml:Search')

host = 'localhost'
port = 4444
with facet.network.SocketClient(
    (host, port),
        target_class=factory.get_class(),
) as f:
    matches = f.match(generate_sources(8))
    print(matches)
예제 #6
0
import facet

factory = facet.FacetFactory('config/umls_sqlite.yaml:Install')

f = factory.create()

f.install('data/umls', nrows=40000)

host = 'localhost'
port = 4444
with facet.network.SocketServer(
    (host, port),
        facet.network.SocketServerHandler,
        served_object=f,
) as server:
    server.serve_forever()

f.close()
예제 #7
0
import facet


def generate_sources(n):
    source = 'acetate'
    return [source] * n


factory = facet.FacetFactory('config/umls_redis.yaml:Search')

host = 'localhost'
port = 4444
with facet.network.SocketClient(
    (host, port),
        target_class=factory.get_class(),
) as f:
    matches = f.match(generate_sources(8))
    print(matches)
예제 #8
0
import facet

# Install
factory = facet.FacetFactory('config/umls_redis.yaml:Install')

tmp_f = factory.create()
tmp_f.install('data/umls', nrows=40000)

# Parallel matcher
f = facet.ParallelFacet('config/umls_redis.yaml:Search')

host = 'localhost'
port = 4444
with facet.network.SocketServer(
    (host, port),
        facet.network.SocketServerHandler,
        served_object=f,
) as server:
    server.serve_forever()

f.close()