Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

C# ConceptNetUtils (CNU) Version 2

0.00/5 (No votes)
24 Mar 2007 1  
A C# dynamic link library that runs ConceptNet: A Semantic Network of Common Sense

Sample Image - cnu2.jpg

Introduction

ConceptNet¹ is a commonsense knowledgebase, composed mainly from the Open Mind Project, written and put together by Hugo Liu and Push Singh (Media Laboratory Massachusetts Institute of Technology). ConceptNet 2.1 (current version at the time of this composition) also includes MontyLingua, a natural-language-processing package. ConceptNet is written in Python but it's commonsense knowledgebase is stored in text files. To read more specific details about the complete overview of ConceptNet, read Liu and Singh's outstanding paper (pdf). Most of the projects available from MIT are not written in Microsoft Visual Studio .NET and I am attempting to make use of ConceptNet for educational, research purposes, and just to have fun with the technology involved. This version is 2.x. It is closely integrated with Microsoft's IronPython.

The Visual Studio .NET C# ConceptNetUtils (CNU) Version 2.x Class Library

ConceptNetUtils (CNU) version 2 uses IronPython and edited ConceptNet script files to achieve the same results as the Python version of ConceptNet. The only con is that there is some speed lost when loading and creating the semantic network using ConceptNetUtils. This loss is not much and probably worth the price considering the positives of having a .NET compatible ConceptNet. Below is a summary of CNU's methods and namespaces. Most of the detailed documentation and explanations are found within the code itself, as well as ConceptNet's documentation. You may also read my first article Having fun with MIT's ConceptNet 2.1 in C#.

CNU's Namespaces

CNU ConceptNet
ConceptNetUtils.CNDB ConceptNetDB.py
ConceptNetUtils.CNTools ConceptNetNLTools.py
ConceptNetUtils.Monty Misc MontyLingua module support

 

 

CNU What It Does
ConceptNetUtils.Converts Misc. conversion helper methods that are not ConceptNet related.
ConceptNetUtils.Misc A mixture of ConceptNet and non-ConceptNet related helper methods. (As of CNU v2.7.9.0b, this namespace is still being constructed by all of MontyLingua is still accessible if you load the CNU *.py script files direction thru IronPython. These script files are embedded and also found in the "...\CNU\ConceptNetUtils2\ConceptNetUtils2" path of the CNU project.
[e.g. engine1.Execute("import CNUMontylingua")])
ConceptNetUtils.Forms As of CNU v2.7.9.0b, this namespace has two classes.
FileOptionsForm is a System.Windows.Forms.Form for setting the options for loading ConceptNet's predicate files or your own predicate files.
ProgressbarForm is a System.Windows.Forms.Form for displaying a progressbar when loading the predicate files.
ConceptNetUtils.IPEWrapper PythonEngine's output is in Stream so this class helps obtain that output.
ConceptNetUtils.Paths MiscDirs: Holds misc. directory paths (ConceptNet paths located here.)
Python24Dirs: Holds your common Python 2.4 paths
IronPythonDirs: Holds your common IronPython paths.

 

 

The Demo

ConceptNet 2.1 comes with its own Python demo named "ConceptNet Mini-Browser." It explores the ConceptNet API interactively. The ConceptNetUtils demo is a .NET version of that mini-browser. It first loads MontyLingua's Natural Language Processing methods and rules, then it loads ConceptNet's default predicate files. (It is recommended that you have a 2.0 GHZ processor or higher or you may have to wait five minutes for semantic network to be created). In the textbox, enter some input text (a word, word phrase, sentence, or sentences) then either click on the green buttons ("node-level" modes: handles words and word phrases) or the yellow buttons ("document-level" modes: handles sentences and paragraphs).

  • BROWSE: Displays matching predicate nodes from node-level text input. (ConceptNetUtils.CNDB.display_node(): Returns IronPython List of the matching predicate nodes from a node-level text)
  • CONTEXT: Displays matching related topics. Returns IronPython List of related topics from node-level text input. (ConceptNetUtils.CNDB.get_context(): Returns IronPython List of related topics.)
  • PROJECTION: Computes all available contextual projections (Consequences, Details, Spatial, and Affective) from node-level text input. (ConceptNetUtils.CNDB.get_all_projections(): Returns an IronPython List of pairs.)
  • ANALOGY: Displays a list of rank-ordered concepts from node-level text input. (ConceptNetUtils.CNDB.get_analogous_concepts(): Returns an IronPython List of rank-ordered concepts if simple_results_p = 1.)
  • GUESS CONTEXT: Displays list of most likely context from document-level text input.
  • GUESS TOPIC: Displays list of most likely related topics from document-level text input.
  • GUESS MOOD: Displays percentage of most likely emotions (happy, sad, angry, fearful, disgusted, surprised) from document-level text input.
  • SUMMARIZE: Displays an interpretation in sentence form from document-level text input.

How to Run the Demo

  1. Download ConceptNet 2.1 (recommended extraction to ...\My Documents\Python Projects\conceptnet2.1)
  2. Download Python 2.4 (recommended extraction to C:\Python24)
  3. Download IronPython-1.1RC1-Bin.zip (recommended extraction to ...\My Documents\Visual Studio 2005\Projects)
  4. Download and unzip this article's .NET Solution and project files. Open CNUtils2Demo.sln.
  5. Manually edit the local paths in CNUDB.py (Line 10) and CNUMontylingua.py (Line 8) [files may be found in the Solution Explorer] to point to your conceptnet2.1 and conceptnet2.1\montylingua directories.
  6. From Microsoft VC# 2005 Solution Explorer, Add a Reference by browsing to IronPython.dll and IronMath.dll located where you extracted the IronPython download.
  7. ReBuild both projects in the solution. The demo should now be able to execute.

(Please Note: I recommend running this demo if you have a 2.0 GHZ processor or above, otherwise you may be waiting more than 5 minutes for the semantic network to be created.)

Conclusion

ConceptNet 2.1 can be a tool to create personalized commonsense knowledgebase networks. Included in the ConceptNet 2.1 download is MontyLingua. It is a quick and easy implementation for Natural Language Processing once when you learn how it operates. Hopefully, this Microsoft Visual Studio .NET Class Library project can be informational, useful, and fun.

References

  • ¹ Liu, H. & Singh, P. (2004) ConceptNet: A Practical Commonsense Reasoning Toolkit. BT Technology Journal, To Appear. Volume 22, forthcoming issue. Kluwer Academic Publishers. (any modifications to ConceptNet source code have been documented in the CNU*.py files as per ConceptNet's terms of use license.) [^]
  • ConceptNet: A Practical Commonsense Reasoning Toolkit, Hugo Liu and Push Singh Media Laboratory Massachusetts Institute of Technology [^]
  • Investigating ConceptNet, Dustin Smith; Advisor: Stan Thomas, Ph.D. December 2004 [^]
  • Open Mind Common Sense Project [^]
  • IronPython: Workspace Home [^]
  • The Official Python Language Website [^]

Updates

  • 7/17/06
    • Uploaded CNUtils2Demo v1.0.0.0rc project files
    • Uploaded ConceptNetUtils2.dll v2.7.9.1b including CNU*.py scripts (Note: ConceptNetUtils2.dll has IronPython.dll and CNU*.py script dependency)
  • 7/25/06
    • Uploaded CNUtils2Demo with updated ConceptNetUtils2 project files
    • Uploaded ConceptNetUtils2.dll v2.7.9.3b
    • Changed class ConceptNetUtils.Monty.Monty to ConceptNetUtils.Monty.MontyLingua
    • Updated ConceptNetUtils.Monty.MontyLingua using dir(c.nltools.m) for fastest performance
    • Added: {jist_predicates(), jist(), split_paragraphs(), split_sentences()} methods to ConceptNetUtils.Monty.MontyLingua
  • 7/26/06
    • Updated need to support IronPython-1.0-RC1
    • Uploaded CNUtils2Demo with updated ConceptNetUtils2 project files
    • Uploaded ConceptNetUtils2.dll v2.8.0.0rc
  • 2/27/07
    • Please NOTE: IronPython 1.1 Beta 1 will not work with CNU due to the new built in array module. The IronPython Dev Team will fix this for the next release
    • Started development for a CNU XML-RPC Class that works directly with ConceptNetXMLRPCServer
  • 3/24/07
    • Uploaded ConceptNetUtils2.dll v2.8.2.0rc. Removed array.py since built-in array has been since modified to resemble CPython, so no problems now. IronPython-1.1RC1 is currently the only version of IronPython that will work with ConceptNetUtils2.dll v2.8.2.0rc
    • Successfully tested with IronPython-1.1RC1

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here