Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Memboric implements Serializable{
- /**
- *
- * The Memboric Core stores the various databases the AI needs to function.
- *
- * Essentially acting as a subconcious.
- *
- * @author Brayden McKinney
- * @date 5/14/2013
- */
- private static final long serialVersionUID = 4477889114653605232L;
- ArrayList<String> knownWords = new ArrayList<String>();
- HashMap<String, Word> thesaurus = new HashMap<String, Word>();
- ArrayList<ConversationLog> conversations = new ArrayList<ConversationLog>();
- File location = null;
- public void addWord(Word word){
- if (!knownWords.contains(word.getName())){
- knownWords.add(word.getName());
- thesaurus.put(word.getName(), word);
- }
- }
- public Word getWord(String name){
- return getWord(name, Brain.get().tagWord(name));
- }
- public Word getWord(String name, String tag){
- Word word = thesaurus.get(name.toLowerCase());
- WikiParser parser = Brain.get().getParser();
- if (word == null){
- word = new Word(name);
- addWord(word);
- word.addTag(tag);
- if (word.tagsConsistOf("N") || word.tagsConsistOf("J") || word.tagsConsistOf("V")){
- ArrayList<String> synonyms = parser.getSynonyms(word.getName());
- if (synonyms != null){
- for (int a = 0; a < synonyms.size(); a++){
- Word get = getWord(synonyms.get(a));
- get.addSynonym(word);
- word.addSynonym(get);
- }
- }
- }
- }
- word.addTag(tag);
- return word;
- }
- public void addConversation(ConversationLog log){
- conversations.add(log);
- }
- public ArrayList<String> getKnownWords(){
- return knownWords;
- }
- public boolean save(){
- if (location == null){
- location = new File("memboric.core");
- }
- return save(location);
- }
- public static Memboric load(File location){
- Memboric memboric;
- try{
- FileInputStream file = new FileInputStream(location);
- ObjectInputStream oo = new ObjectInputStream(file);
- memboric = (Memboric) oo.readObject();
- oo.close();
- System.out.println("Memboric Core loaded and mounted successfully.");
- return memboric;
- }catch(FileNotFoundException fn){
- System.err.println("Failed to load Memboric Core.");
- }catch(InvalidClassException ic){
- System.err.println("Memboric Core is incompatible.");
- }catch(Exception e){
- e.printStackTrace();
- }
- System.err.println("Creating new Memboric Core.");
- return new Memboric();
- }
- public boolean save(File location){
- this.location = location;
- try{
- FileOutputStream file = new FileOutputStream(location);
- ObjectOutputStream oo = new ObjectOutputStream(file);
- oo.writeObject(this);
- oo.close();
- System.out.println("Memboric Core saved successfully.");
- return true;
- }catch(FileNotFoundException ex){
- try{
- if (location.createNewFile()) save(location);
- }catch(IOException exx){
- exx.printStackTrace();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment