def test_assoc():
    assoc = AssocSpaceWrapper(ASSOC_DIR, FINDER)
    results = assoc.associations([('/c/en/orange', 1.0)], limit=3)
    similar = [r[0] for r in results]
    eq_(similar, ['/c/en/orange', '/c/en/yellow', '/c/en/lemon'])

    results = assoc.associations([('/c/en/example', 1.0)], limit=3)
    similar = [r[0] for r in results]
    eq_(similar, ['/c/en/example', '/c/en/ideas', '/c/en/green'])

    results = assoc.associations([('/c/en/case_in_point', 1.0)], limit=3)
    similar = [r[0] for r in results]
    eq_(similar, ['/c/en/example', '/c/en/ideas', '/c/en/green'])
Ejemplo n.º 2
0
def configure_api(db_path, assertion_dir, assoc_dir=None, nshards=8):
    """
    Override the usual AssertionFinder with a new one, possibly with different
    settings. Do the same for the assoc_dir if given.

    This is useful for testing.
    """
    global FINDER, ASSOC_WRAPPER
    FINDER = AssertionFinder(db_path, assertion_dir, nshards)
    ASSOC_WRAPPER = AssocSpaceWrapper(assoc_dir, FINDER)
Ejemplo n.º 3
0
from conceptnet5.assoc_query import AssocSpaceWrapper, MissingAssocSpace
from conceptnet5.util import get_data_filename
app = flask.Flask(__name__)
limiter = Limiter(app, global_limits=["600 per minute", "6000 per hour"])
CORS(app)

if not app.debug:
    import logging
    file_handler = logging.FileHandler('logs/flask_errors.log')
    file_handler.setLevel(logging.INFO)
    app.logger.addHandler(file_handler)

### Configuration ###

FINDER = AssertionFinder()
ASSOC_WRAPPER = AssocSpaceWrapper(get_data_filename('assoc/assoc-space-5.3'),
                                  FINDER)
commonsense_assoc = None

if len(sys.argv) == 1:
    root_url = 'http://conceptnet5.media.mit.edu/data/5.3'
else:
    root_url = sys.argv[1]


def configure_api(db_path, assertion_dir, assoc_dir=None, nshards=8):
    """
    Override the usual AssertionFinder with a new one, possibly with different
    settings. Do the same for the assoc_dir if given.

    This is useful for testing.
    """
Ejemplo n.º 4
0
from conceptnet5.query import AssertionFinder, VALID_KEYS
from conceptnet5.assoc_query import AssocSpaceWrapper, MissingAssocSpace
from conceptnet5.util import get_data_filename, get_support_data_filename

### Configuration ###

VERSION = '5.3'
API_URL = '/data/5.3'
WORKING_DIR = os.getcwd()
STATIC_PATH = os.environ.get('CONCEPTNET_WEB_STATIC',
                             os.path.join(WORKING_DIR, 'static'))
TEMPLATE_PATH = os.environ.get('CONCEPTNET_WEB_TEMPLATES',
                               os.path.join(WORKING_DIR, 'templates'))

FINDER = AssertionFinder()
ASSOC_WRAPPER = AssocSpaceWrapper(
    get_data_filename('assoc/assoc-space-%s' % VERSION), FINDER)

app = flask.Flask('conceptnet5',
                  template_folder=TEMPLATE_PATH,
                  static_folder=STATIC_PATH)
app.config['JSON_AS_ASCII'] = False
limiter = Limiter(app, global_limits=["600 per minute", "6000 per hour"])
CORS(app)

if len(sys.argv) == 1:
    root_url = 'http://conceptnet5.media.mit.edu/data/%s' % VERSION
else:
    root_url = sys.argv[1]


def configure_api(db_path, assertion_dir, assoc_dir=None, nshards=8):