Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AI : MonoBehaviour
{
}

namespace Namespace
{
     using re;
     using sqlite3;
     using Counter = collections.Counter;
     using punctuation = @string.punctuation;
     using sqrt = math.sqrt;
     using System.Collections.Generic;
     using System.Linq;
    
    public static class Module
    {
        public static object connection = sqlite3.connect("chatbot.sqlite");
        public static object cursor = connection.cursor();

        public static object create_table_request_list = new List<object>
        {
            "CREATE TABLE words(word TEXT UNIQUE)",
            "CREATE TABLE sentences(sentence TEXT UNIQUE, used INT NOT NULL DEFAULT 0)",
            "CREATE TABLE associations (word_id INT NOT NULL, sentence_id INT NOT NULL, weight REAL NOT NULL)"
        };

        static Module()
        {
            cursor.execute(create_table_request);
            cursor.execute("INSERT INTO associations VALUES (?, ?, ?)", (word_id, sentence_id, weight));
            connection.commit();
            cursor.execute("CREATE TEMPORARY TABLE results(sentence_id INT, sentence TEXT, weight REAL)");
            cursor.execute("INSERT INTO results SELECT associations.sentence_id, sentences.sentence, ?*associations.weight/(4+sentences.used) FROM words INNER JOIN associations ON associations.word_id=words.rowid INNER JOIN sentences ON sentences.rowid=associations.sentence_id WHERE words.word=?", (weight, word));
            cursor.execute("SELECT sentence_id, sentence, SUM(weight) AS sum_weight FROM results GROUP BY sentence_id ORDER BY sum_weight DESC LIMIT 1");
            cursor.execute("DROP TABLE results");
            cursor.execute("SELECT rowid, sentence FROM sentences WHERE used = (SELECT MIN(used) FROM sentences) ORDER BY RANDOM() LIMIT 1");
            cursor.execute("UPDATE sentences SET used=used+1 WHERE rowid=?", ValueTuple.Create(row[0]));
        }

        public static object get_id(object entityName, object text)
        {
            var tableName = entityName + "s";
            var columnName = entityName;
            cursor.execute("SELECT rowid FROM " + tableName + " WHERE " + columnName + " = ?", ValueTuple.Create(text));
            var row = cursor.fetchone();
            if (row)
            {
                return row[0];
            }
            else
            {
                cursor.execute("INSERT INTO " + tableName + " (" + columnName + ") VALUES (?)", ValueTuple.Create(text));
                return cursor.lastrowid;
            }

            object get_words(object text)
            {
                {
                    var wordsRegexp = re.compile(wordsRegexpString);
                    var wordsList = wordsRegexp.findall(text.lower());
                    return Counter(wordsList).items();
                }
            }

            { 
            }
            
            public static object B = "Hello!";
            public static object H = raw_input("H:").strip();
            public static object words = get_words(B);
            public static object words_length = (from _tup_2 in words.Chop((word, n) => (word, n))
                let word = _tup_2.Item1
                let n = _tup_2.Item2
                select (n * word.Count)).ToList().Sum();

            public static object sentence_id = get_id("sentence", H);
            public static object word_id = get_id("word", word);
            public static object weight = sqrt(n / (words_length));
            public static object words = get_words(H);
            public static object words_length = (from _tup_5 in words.Chop((word, n) => (word, n))
                let word = _tup_5.Item1
                let n = _tup_5.Item2
                select (n * word.Count)).ToList().Sum();

            public static object weight = sqrt(n / (words_length));
            public static object row = cursor.fetchone();
            public static object row = cursor.fetchone();
            public static object B = row[1]; 
        } 
    }


What I have tried:

i've tried to add } in as many places as i could think of but to no success :(
Posted
Updated 9-Dec-20 22:25pm
v2

Your code is extremely confused, but with the correct indentation, it should be obvious where the missing } is.
C#
namespace Namespace
{
    public static class Module
    {
        // static fields
        
        public static object get_id(object entityName, object text)
        {
            // code
            
            // Unused local function:
            object get_words() 
            { 
                // Extra pair of braces, not needed:
                {
                    // code
                } 
            }
            
            // Empty extra pair of braces, not needed
            { }
            
            // Invalid attempt to declare more static fields inside a function
        }
    }
// <-- MISSING "}" HERE
 
Share this answer
 
That looks like someone found a couple of lumps of code and threw them into a single file, then hoped they would compile and work.

You've got an empty class outside all namespaces, you've got a bunch of using directives that duplicate each other, and should probably all be at eth top for clarity, you've got empty bracket blocks that aren't associated with any flow control statements:
{
}
You've got nested methods including a static class constructor declared inside a method, you've got public variables defined inside methods, the list goes goes on and on ...

Stop throwing brackets in at random, and think about what you are trying to do - because I don't think from that that you understand very much of the basics of C#. And you need those down pat or Unity is going to give you massive problems - as is grabbing code at random of hoping it will both compile and then work when stuffed into your source files.

Take all your copy'n'patse stuff out, get the basic file working, and then think about what you are trying to add before you start pasting.
You are not going to produce anything working with your current approach!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900