Appendix C Source Code and Documentation for Creo, Miro and Adeo A Goal-Oriented User Interface for Personalized Semantic Search by Alexander James Faaborg Submitted to the Program in Media Arts and Sciences, School of Architecture and Planning, on November 4th 2005, in partial fulfillment of the requirements for the degree of Master of Science in Media Arts and Sciences Creo File Description Pages Lines ability_commonsenseIsaNet.cs Loads all of ConceptNet’s “isa” 6 336 relationships, and TAP into memory. Contains methods for accessing the knowledge ability_webService.cs Used for dynamically invoking a web 3 179 service at runtime and inspecting it's WSDL askWindow.cs Window to receive missing input when 2 159 playing a recording confirmWindow.cs Asks the user to confirm playing a 3 280 recording, displaying all of the recording's steps CreoUI.cs Creo 51 4046 debugWindow.cs Displays a transparent black window 2 129 containing debug messages formWindow2.cs Displays options for dealing with submitted 14 2139 form information Interface.cs Class definitions 7 411 profileWindow.cs Displays an interface for modifying the 2 547 user's profile saveWindow.cs Displays a window for saving a recording 3 283 scrapeTrainWindow.cs Window for training Creo to scrape 2 160 information from a Web site submitTrainWindow.cs Debug window for submitting forms 2 126 Total 97 8,795 Total Unique 97 8,795 Miro File Description Pages Lines ability_commonsenseIsaNet.cs (From Creo) Loads all of ConceptNet’s 6 336 “isa” relationships, and TAP into memory. Contains methods for accessing the knowledge ability_nlpTools.cs Natural Language Processing tools for 5 290 learning knowledge from the Web ability_webService.cs (From Creo) Used for dynamically 3 179 invoking a web service at runtime and inspecting it's WSDL askWindow.cs (From Creo) Window to receive missing 2 159 input when playing a recording confirmWindow.cs (From Creo) Asks the user to confirm 3 280 playing a recording, displaying all of the recording's steps debugWindow.cs (From Creo) Displays a transparent black 2 129 window containing debug messages Interface.cs (From Creo) Class definitions 6 395 Interface_miro.cs Class definitions for Miro 3 195 MiroUI.cs Miro 78 6336 trainWindow.cs Displays an interface for training Miro 10 916 about new knowledge Total 118 9,215 Total Unique 96 7,737 Adeo_s (Adeo Server) File Description Pages Lines ability_commonsenseIsaNet.cs (From Creo) Loads all of ConceptNet’s 6 336 “isa” relationships, and TAP into memory. Contains methods for accessing the knowledge AdeoServer.asmx Adeo Server 6 416 Interface.cs Class definitions for Adeo 8 486 Total 20 1,238 Total Unique 14 902 Adeo_m (Adeo Mobile) File Description Pages Lines AdeoCore.cs Adeo Mobile 5 295 AdeoUI_ask.cs Window to receive missing input when 2 147 playing a recording AdeoUI_list.cs Window to list all of the available 2 173 recordings AdeoUI_result.cs Window to display the result of playing a 1 113 recording AdeoUI_search.cs Window for performing a semantic search 4 325 over recordings AdeoUI_wait.cs Window to display feedback while waiting 2 142 for a recording to finish playing AnimateCtl.cs Displays an animation in the .NET Compact 3 149 Framework PocketGuid.cs Generates a GUID in the .NET Compact 2 122 Framework Total 21 1,466 Total Unique 21 1,466 Total Pages Lines Total 256 20,714 Total Unique 228 18,900 Creo C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 1 using System; using System.Collections; using System.IO; //version 1.1 namespace Creo { /// <summary> /// Used for building up isaNet in memory /// </summary> public class Concept { public string name = ""; public Hashtable instances = new Hashtable(); public Hashtable generalizations = new Hashtable(); public Concept(){} public Concept(string _name) { name = _name; } public void addInstance(Concept concept) { if(!this.instances.ContainsKey(concept.name)) { this.instances.Add(concept.name,concept); } } public void addGeneralization(Concept concept) { if(!this.generalizations.ContainsKey(concept.name)) { this.generalizations.Add(concept.name,concept); } } } /// <summary> /// Used for returning results from queries to isaNet /// </summary> public class ConceptResult { public string name = ""; public int generalizationScore = 0; public ConceptResult(){} public ConceptResult(string _name, int _generalizationScore) { name = _name; generalizationScore = _generalizationScore; } } public enum ConceptResultSortDirection { Ascending, Descending } /// <summary> /// Used for soring ConceptResults /// </summary> public class ConceptResultComparer : IComparer C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 2 { private ConceptResultSortDirection m_direction = ConceptResultSortDirection. Descending; public ConceptResultComparer() : base() { } public ConceptResultComparer(ConceptResultSortDirection direction) { this.m_direction = direction; } int IComparer.Compare(object x, object y) { ConceptResult conceptX = (ConceptResult) x; ConceptResult conceptY = (ConceptResult) y; if (conceptX == null && conceptY == null) { return 0; } else if (conceptX == null && conceptY != null) { return (this.m_direction == ConceptResultSortDirection.Ascending) ? -1 : 1 ; } else if (conceptX != null &&conceptY == null) { return (this.m_direction == ConceptResultSortDirection.Ascending) ? 1 : -1 ; } else { return (this.m_direction == ConceptResultSortDirection.Ascending) ? conceptX.generalizationScore.CompareTo(conceptY.generalizationScore) : conceptY.generalizationScore.CompareTo(conceptX.generalizationScore); } } } /// <summary> /// Provides fast access to all of the IsA relationships in ConceptNet and Tap /// </summary> public class ability_commonsenseIsaNet { //The path to all files public static string path = System.Environment.GetFolderPath(System.Environment. SpecialFolder.ProgramFiles) + @"\FaaborgThesisMIT\"; //The location of the predicates files string isaNet_knowledgePath = path + @"Applications\Data\IsaNet\"; //The entire commonsense network Hashtable isaNet = new Hashtable(); public ability_commonsenseIsaNet() { //build the network this.isaNet_create(); } /// <summary> /// Returns the number of generalizations a concept has /// </summary> /// <param name="conceptName">The concept to look up</param> /// <returns>The number of generalizations the concept has</returns> public int isaNet_getGeneralizationScore(string conceptName) C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 3 { int score = 0; if(isaNet.Contains(conceptName)) { Concept c = (Concept)isaNet[conceptName]; score = c.generalizations.Count; } return score; } /// <summary> /// Returns the generalizations of a concept /// </summary> /// <param name="concept">The concept to look up</param> /// <returns>The instances of the concept</returns> public ArrayList isaNet_getGeneralizations(string conceptName) { ArrayList result = new ArrayList(); if(isaNet.Contains(conceptName)) { Concept c = (Concept)isaNet[conceptName]; if(c.generalizations != null) { foreach(Concept g in c.generalizations.Values) { result.Add(new ConceptResult(g.name, g.instances.Count)); } } } result.Sort(new ConceptResultComparer()); return result; } /// <summary> /// Returns the instances of a concept /// </summary> /// <param name="concept">The concept to look up</param> /// <returns>The instances of the concept</returns> public ArrayList isaNet_getInstances(string conceptName) { ArrayList result = new ArrayList(); if(isaNet.Contains(conceptName)) { Concept c = (Concept)isaNet[conceptName]; if(c.instances != null) { foreach(Concept i in c.instances.Values) { result.Add(new ConceptResult(i.name, i.instances.Count)); } } } result.Sort(new ConceptResultComparer()); return result; } /// <summary> /// Returns a list of possible word predictions, sorted /// by generalizationScore /// </summary> /// <param name="concept">The start of the concept</param> public ArrayList isaNet_getGeneralizationWordPredictions(string conceptStart) C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 4 { ArrayList conceptresults = new ArrayList(); foreach(string test in isaNet.Keys) { //check if it starts with the conceptStart if(test.StartsWith(conceptStart)) { Concept c = (Concept)isaNet[test]; if(c.instances.Count > 0) { conceptresults.Add(new ConceptResult(c.name,c.instances.Count)); } } } //sort the results by their generalization scores conceptresults.Sort(new ConceptResultComparer()); ArrayList results = new ArrayList(); foreach(ConceptResult cresult in conceptresults) { results.Add(cresult.name); } return results; } /// <summary> /// Builds the semantic network in memory for rapid access /// </summary> private void isaNet_create() { //(1) load all of the unique names StreamReader sr_concepts = File.OpenText(isaNet_knowledgePath + "allConcepts. txt"); string line_concepts = sr_concepts.ReadLine(); while(line_concepts != null) { string name = line_concepts; isaNet.Add(name,new Concept(name)); line_concepts = sr_concepts.ReadLine(); } //(2) load all of the predicates ArrayList files = new ArrayList(); files.Add(isaNet_knowledgePath + "predicates_concise_nonkline.txt"); files.Add(isaNet_knowledgePath + "predicates_nonconcise_nonkline.txt"); files.Add(isaNet_knowledgePath + "stanfordTAP2.txt"); //information learned by miro files.Add(isaNet_knowledgePath + "miro_learned.txt"); foreach(string file in files) { //load predicates file StreamReader sr_predicates = File.OpenText(file); string line_predicates = sr_predicates.ReadLine(); //iterate through each statement in the file while(line_predicates != null) { if(line_predicates.Length > 1) { string[] t = line_predicates.Split(new char[]{'\"'}); C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 5 string p = t[0].Substring(1,t[0].Length-2); string s = t[1]; string o = t[3]; if(p.Equals("IsA")) { this.isaNet_addKnowledge(s,o); } } line_predicates = sr_predicates.ReadLine(); } //close the streamReader sr_predicates.Close(); } } /// <summary> /// Adds a piece of knowledge from the hard drive to isaNet in memory /// </summary> /// <param name="s">The subject</param> /// <param name="o">The object</param> private void isaNet_addKnowledge(string s, string o) { //Add the keys if isaNet does not have them if(!isaNet.ContainsKey(s)) { this.isaNet.Add(s,new Concept(s)); } if(!isaNet.ContainsKey(o)) { this.isaNet.Add(o,new Concept(o)); } //Add the instance and the generalization for the statement ((Concept)isaNet[s]).addGeneralization((Concept)isaNet[o]); ((Concept)isaNet[o]).addInstance((Concept)isaNet[s]); } /// <summary> /// Adds a piece of knowledge to isaNet (in memory, /// and to the hard drive) /// </summary> /// <param name="s">The subject</param> /// <param name="o">The object</param> public void isaNet_addNewKnowledge(string s, string o) { //(1)Add the knowledge to isaNet in memory //Add the keys if isaNet does not have them if(!isaNet.ContainsKey(s)) { this.isaNet.Add(s,new Concept(s)); } if(!isaNet.ContainsKey(o)) { this.isaNet.Add(o,new Concept(o)); } //Add the instance and the generalization for the statement ((Concept)isaNet[s]).addGeneralization((Concept)isaNet[o]); ((Concept)isaNet[o]).addInstance((Concept)isaNet[s]); //(2)Write the knowledge to the hard drive FileStream miro_learned = new FileStream(isaNet_knowledgePath + "miro_learned. C:\0Data\My Documents\0 MIT\0 Thesis\0 Code\2 Creo\Creo\Creo\ability_commonsenseIsaNet.cs 6 txt", FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(miro_learned); sw.WriteLine("(IsA " + "\"" + s + "\" \"" + o + "\")"); sw.Close(); } } }
Description: