コード例 #1
0
def get_predictions_from_vector(lang, concepts, cat, count):
    count = 100
    tensor = get_tensor(lang)
    svd = get_svd_results(lang)
    items = svd.v_dotproducts_with(cat).top_items(count)
    print len(items)

    for feature, score in items:
        for concept in concepts:
            print concept, feature, score
            # Exclude items that are already in the database.
            # FIXME: check tensor format
            if (concept, feature) in tensor: continue
            print 'not in tensor'

            if not isinstance(feature, tuple): continue
            f = Feature.from_tuple(feature)
            if f.relation == u'InheritsFrom': continue
            print f
            
            prop = f.fill_in(concept)
            print prop

            # Exclude self-relations.
            if prop.concept1 == prop.concept2: continue

            yield prop, score
コード例 #2
0
ファイル: views.py プロジェクト: Web5design/openmind-commons
def start_lattice(request, concept_name, lr, relation_name, fconcept_name):
    from csc.conceptnet4.models import Concept, Feature
    concept = Concept.get(concept_name, 'en')

    # Build the concept tree
    edges = concept.get_tree()

    session_data = dict(
        concept=concept,
        feature=Feature.from_tuple((lr, relation_name, fconcept_name)),
        edges=edges,
        )

    # Store the new session data, overwriting anything that was there before.
    request.session['lattice_learning'] = session_data

    # Render the graphviz.
    src = as_graphviz(edges)
    
    # Go to the initial view.
    g = GVGraph(src, engine='dot')
    return HttpResponse('''
<html><head><title>Test</title></head><body>
<img src="%(src)s" usemap="#%(map_name)s">%(map)s
</body></html>''' % dict(src='/lattice/graph_images/%s/' % g.key,
                         map_name=g.map_name,
                         map=g.map))
コード例 #3
0
ファイル: json.py プロジェクト: Web5design/openmind-commons
 def feature_to_dict(feature_tup, score):
     feature = Feature.from_tuple(feature_tup)
     return dict(
         raw = feature_tup,
         logical = str(feature),
         text = feature.nl_statement('__'),
         score = score
         )
コード例 #4
0
def predictions_for_concept(lang, concept, count):
    svd = get_svd_results(lang)
    if concept not in svd.u.label_list(0): return
    tensor = get_tensor(lang)
    predictions = predict_features(svd, concept).top_items(count*5)
    for feature, score in predictions:
        if (concept, feature) in tensor: continue
        if not isinstance(feature, tuple): continue
        f = Feature.from_tuple(feature)
        if f.relation.name == u'InheritsFrom': continue
        prop = f.fill_in(concept)
        if prop.concept1 == prop.concept2: continue
        yield prop, score
コード例 #5
0
ファイル: json.py プロジェクト: kcarnold/commons
def get_predictions(lang, concepts):
    count = 100
    tensor = get_tensor(lang)
    svd = get_svd_results(lang)
    cat = make_category_failsoft(svd, concepts, [], concepts)
    items = svd.v_distances_to(cat).top_items(count)

    for feature, score in items:
        for concept in concepts:
            # Exclude items that are already in the database.
            # FIXME: check tensor format
            if (concept, feature) in tensor: continue

            f = Feature.from_tuple(feature)
            prop = f.fill_in(concept)

            # Exclude self-relations.
            if prop.concept1 == prop.concept2: continue

            yield prop, score