ConceptNetDB (version 2.0)
index
c:\work\conceptnet\python\conceptnetdb.py

Module ConceptNetDB - ConceptNet's main API file
(for ConceptNet's NL-enabled API, see ConceptNetNLTools module)
 
CONCEPTNET - A Very-Large Semantic Network of Common Sense Knowledge
             and Practical Textual Reasoning Toolkit
 
Author: Hugo Liu & Push Singh <{hugo,push}@media.mit.edu>
Project Page: <www.conceptnet.org>
 
Copyright (c) 2002-2004 by authors and the MIT Media Lab
 All rights reserved.
 
Non-commercial use is free, as provided in the GNU GPL
By downloading and using ConceptNet, you agree to abide
by the additional copyright and licensing information in
 "license.txt", included in this distribution
 
If you use this software in your research, please 
acknowledge ConceptNet and its authors, and link back
to the project page www.conceptnet.org.
Please cite ConceptNet in academic publications as: 
 
Liu, H. & Singh, P. (2004) ConceptNet: A Practical
Commonsense Reasoning Toolkit. BT Technology Journal,
To Appear. Volume 22, forthcoming issue. Kluwer
Academic Publishers.

 
Modules
       
ConceptNetNLTools
math
sys

 
Classes
       
ConceptNetDB

 
class ConceptNetDB
     Methods defined here:
__init__(self, ConceptNetNLTools_handle=None, pred_filename='./generalised_predicates.txt')
decode_node(self, node_tuple)
decode_word(self, word_uid)
display_node(self, textnode)
returns the pretty print of a node's contents
edgeuid2zipped(self, uid)
encode_node(self, textnode)
encode_word(self, word)
get_all_projections(self, textnode_list)
inputs a list of concepts
computes all available contextual projections
and returns a list of pairs, each of the form:
     ('ProjectionName',
        (('concept1',score1), ('concept2,score2), ...)
     )
get_analogous_concepts(self, textnode, simple_results_p=0)
-inputs a node
-uses structure-mapping to generate a list of
analogous concepts
-each analogous concept shares some structural features
with the input node
-the strength of an analogy is determined by the number
and weights of each feature. a weighting scheme is used
to disproportionately weight different relation types
and also weights a structural feature by the equation:
math.log(f+f2+0.5*(i+i2)+2,4), where f= # of utterances,
i = # of times inferred
- outputs a list of RESULTs rank-ordered by relevance
- each RESULT is a triple of the form:
             ('analogous concept', SHARED_STRUCTURES, SCORE)
- SCORE is a scalar valuation of quality of a result
  (for now, this number does not have much external meaning)
- SHARED_STRUCTURES is a list of triples, each of the form:
             ('RelationType', 'target node', SCORE2)
- SCORE2 is a scalar valuation of the strength of a
particular shared structure
 
- if simple_results_p = 1, then output object is simply
a list of rank-ordered concepts
get_context(self, textnode_list, max_node_visits=500, max_results=200, flow_pinch=300, linktype_weights_dict=None, textnode_list_weighted_p=0)
the max_node_visits determines how far context will spread
increasing it adversely affects runtime
 
max_results limits the number of results returned
but changing it does not affect runtime
 
flow_pinch limits the number of edges considered
at each step of the context flow
 
the linktype_weights_dict is a python dictionary
whose keys are the conceptnet relationtypes and whose
values are a weight assigned to each, in the range [0.0,1.0]
- to blacklist a linktype, set its weight to 0.0
- context flow along backedges are regulated by entries in the
linktype_weights_dict whose key names are "relationtype"+"Inverse"
- considering inverse flows slow the runtime of this function a bit
- omitting a relationtype will default to it being blacklisted
- for reference, the default_linktype_weights_dict is:
    default_linktype_weights_dict = {
        'ConceptuallyRelatedTo':0.1,
        'IsA':0.9,
        'FirstSubeventOf':1.0,
        'DesirousEffectOf':1.0,
        'ThematicKLine':0.8,
        'MadeOf':0.7,
        'SubeventOf':0.9,
        'UsedFor':1.0,
        'SuperThematicKLine':1.0,
        'DefinedAs':1.0,
        'LastSubeventOf':1.0,
        'LocationOf':0.9,
        'CapableOfReceivingAction':0.6,
        'CapableOf':0.8,
        'PrerequisiteEventOf':1.0,
        'MotivationOf':1.0,
        'PropertyOf':1.0,
        'PartOf':1.0,
        'EffectOf':1.0,
        'DesireOf':1.0,
        'ConceptuallyRelatedToInverse':0.0,
        'IsAInverse':0.0,
        'FirstSubeventOfInverse':0.0,
        'DesirousEffectOfInverse':0.0,
        'ThematicKLineInverse':0.0,
        'MadeOfInverse':0.0,
        'SubeventOfInverse':0.0,
        'UsedForInverse':0.0,
        'SuperThematicKLineInverse':0.0,
        'DefinedAsInverse':0.0,
        'LastSubeventOfInverse':0.0,
        'LocationOfInverse':0.0,
        'CapableOfReceivingActionInverse':0.0,
        'CapableOfInverse':0.0,
        'PrerequisiteEventOfInverse':0.0,
        'MotivationOfInverse':0.0,
        'PropertyOfInverse':0.0,
        'PartOfInverse':0.0,
        'EffectOfInverse':0.0,
        'DesireOfInverse':0.0,
        }
 
if textnode_list_weighted_p, then each element of textnode_list
is not a string, but instead, of the form: ('dog',0.5)
where the cdr is the relative origin weight of that concept.
getuid(self)
load_predicates(self)
nodeuid2zipped(self, uid)
optimize_order(self)
pp_predicate(self, pred)
project_affective(self, textnode_list)
-inputs a list of concepts
-computes the affective projection, which is
the emotional context and consequences underlying these concepts
-returns a rank-ordered list of concepts and their scores
e.g.: (('concept1',score1), ('concept2,score2), ...)
project_consequences(self, textnode_list)
-inputs a list of concepts
-computes the causal projection, which consists of
possible consequences of an event or possible actions
resulting from the presence of a thing
-returns a rank-ordered list of concepts and their scores
e.g.: (('concept1',score1), ('concept2,score2), ...)
project_details(self, textnode_list)
-inputs a list of concepts
-computes the detail projection, which consists of
a thing's parts, materials, properties, and instances
and an event's subevents
-returns a rank-ordered list of concepts and their scores
e.g.: (('concept1',score1), ('concept2,score2), ...)
project_spatial(self, textnode_list)
-inputs a list of concepts
-computes the spatial projection, which consists of
relevant locations, relevant objects in the same scene.
-returns a rank-ordered list of concepts and their scores
e.g.: (('concept1',score1), ('concept2,score2), ...)
unpp(self, pp)
zipped2edgeuid(self, edge)
zipped2nodeuid(self, zipped)

 
Data
        __author__ = 'hugo@media.mit.edu'
__url__ = 'www.conceptnet.org'
__version__ = '2.0'

 
Author
        hugo@media.mit.edu