Click here to Skip to main content
15,868,419 members
Articles / Programming Languages / Python

C# ConceptNetUtils (CNU) Version 2

Rate me:
Please Sign up or sign in to vote.
4.16/5 (10 votes)
24 Mar 2007CPOL6 min read 125.5K   981   33   56
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Earthbotics.com
United States United States
Born in Pennsylvania (USA), just north of Philadelphia. Joe has been programming since he was ten[now much older]. He is entirely self-taught programmer, & he is currently working as an IT Manager in Seattle WA. He was previously U.S. Navy Active Reservist for (SPAWAR)
In '98 was honorably discharged from the USN. He served onboard the USS Carl Vinson (94-98) He was lucky enough to drink President Clinton's leftover wine, promoted by his Captain, and flew in a plane off the flightdeck but not all at the same time. His interests, when time allows, are developing
misc apps and Artificial Intelligence proof-of-concept demos that specifically exhibits human behavior. He is a true sports-a-holic, needs plenty of caffeine, & a coding junkie. He also enjoys alternative music and a big Pearl Jam, Nirvana, new alternative music fan, and the Alison Wonderland.
He is currently working on earthboticsai.net<> which he says is fun and cool. Cool | :cool: :cheers:

Joe is an INTP[
^] personality type. Joe "sees everything in terms of how it could be improved, or what it could be turned into. INTP's live primarily inside their own minds." INTPs also can have the "greatest precision in thought and language. Can readily discern contradictions and inconsistencies. The world exists primarily to be understood. 1% of the total population" [

Comments and Discussions

 
GeneralRe: can't get demo to work :( :( :( Pin
JoeSox27-May-11 3:39
JoeSox27-May-11 3:39 
Generalproblem! please help :( Pin
pennyPitstop10-May-10 23:59
pennyPitstop10-May-10 23:59 
GeneralRe: problem! please help :( Pin
JoeSox11-May-10 3:39
JoeSox11-May-10 3:39 
GeneralRe: problem! please help :( Pin
pennyPitstop11-May-10 22:37
pennyPitstop11-May-10 22:37 
GeneralRe: problem! please help :( Pin
JoeSox12-May-10 6:47
JoeSox12-May-10 6:47 
GeneralRe: problem! please help :( Pin
pennyPitstop12-May-10 12:24
pennyPitstop12-May-10 12:24 
GeneralRe: problem! please help :( Pin
JoeSox12-May-10 19:27
JoeSox12-May-10 19:27 
GeneralRe: problem! please help :( Pin
pennyPitstop12-May-10 21:25
pennyPitstop12-May-10 21:25 
GeneralRe: problem! please help :( Pin
JoeSox13-May-10 3:31
JoeSox13-May-10 3:31 
GeneralRe: problem! please help :( Pin
pennyPitstop15-May-10 2:51
pennyPitstop15-May-10 2:51 
Generalcan't get demo to work :( Pin
pennyPitstop12-Apr-10 19:57
pennyPitstop12-Apr-10 19:57 
GeneralRe: can't get demo to work :( Pin
pennyPitstop12-Apr-10 20:18
pennyPitstop12-Apr-10 20:18 
QuestionSystem.ArgumentEception:Illegal charachters in path Pin
fadi_mac858-Jul-08 8:47
fadi_mac858-Jul-08 8:47 
AnswerRe: System.ArgumentEception:Illegal charachters in path Pin
JoeSox8-Jul-08 12:56
JoeSox8-Jul-08 12:56 
GeneralRe: System.ArgumentEception:Illegal charachters in path Pin
fadi_mac859-Jul-08 0:51
fadi_mac859-Jul-08 0:51 
GeneralRe: System.ArgumentEception:Illegal charachters in path Pin
JoeSox9-Jul-08 4:06
JoeSox9-Jul-08 4:06 
GeneralNo module named MontyTokenizer Pin
JoshMouch21-Feb-07 7:46
JoshMouch21-Feb-07 7:46 
GeneralRe: No module named MontyTokenizer Pin
JoshMouch21-Feb-07 7:55
JoshMouch21-Feb-07 7:55 
GeneralRe: No module named MontyTokenizer Pin
JoshMouch21-Feb-07 8:07
JoshMouch21-Feb-07 8:07 
GeneralRe: No module named MontyTokenizer Pin
JoshMouch21-Feb-07 8:40
JoshMouch21-Feb-07 8:40 
GeneralRe: No module named MontyTokenizer Pin
JoeSox21-Feb-07 12:18
JoeSox21-Feb-07 12:18 
AnswerRe: No module named MontyTokenizer Pin
evalex10-Apr-07 5:05
evalex10-Apr-07 5:05 
GeneralRe: No module named MontyTokenizer Pin
robert.tw26-Dec-07 16:12
robert.tw26-Dec-07 16:12 
GeneralDifferent Result Pin
woods771-Aug-06 10:58
woods771-Aug-06 10:58 
GeneralRe: Different Result Pin
JoeSox1-Aug-06 12:28
JoeSox1-Aug-06 12:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.