Fizzarolli commited on
Commit
89f0644
·
verified ·
1 Parent(s): 3231be8

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. discobase3-29-2021-9-32-09-PM.db +3 -0
  3. output.json +0 -0
  4. output.py +163 -0
.gitattributes CHANGED
@@ -57,3 +57,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
+ discobase3-29-2021-9-32-09-PM.db filter=lfs diff=lfs merge=lfs -text
discobase3-29-2021-9-32-09-PM.db ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f15a2ef698594362d55a83aa7a5e3725384803aedab966e79a509d13daccdac
3
+ size 23461888
output.json ADDED
The diff for this file is too large to render. See raw diff
 
output.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+ import random
3
+ import json
4
+ import hashlib
5
+ from pybloom_live import ScalableBloomFilter
6
+
7
+ from tqdm import tqdm
8
+
9
+ DATABASE_FILE = "discobase3-29-2021-9-32-09-PM.db" # Replace with your database file
10
+
11
+ def get_actor_name(cursor, actor_id):
12
+ """Fetches the name of an actor from the actors table."""
13
+ cursor.execute("SELECT name FROM actors WHERE id=?", (actor_id,))
14
+ result = cursor.fetchone()
15
+ return result[0] if result else f"Unknown Actor ({actor_id})"
16
+
17
+ def get_dialogue_children(cursor, convo_id, dialogue_id):
18
+ """Fetches the child dialogue entries of a given dialogue entry."""
19
+ cursor.execute(
20
+ "SELECT destinationconversationid, destinationdialogueid FROM dlinks WHERE originconversationid=? AND origindialogueid=?",
21
+ (convo_id, dialogue_id),
22
+ )
23
+ return cursor.fetchall()
24
+
25
+ def get_dialogue_entry(cursor, convo_id, dialogue_id):
26
+ """Fetches a specific dialogue entry from the dentries table."""
27
+ cursor.execute(
28
+ "SELECT dialoguetext, actor, conversant, conditionstring, userscript FROM dentries WHERE conversationid=? AND id=?",
29
+ (convo_id, dialogue_id),
30
+ )
31
+ return cursor.fetchone()
32
+
33
+ def is_hub(entry):
34
+ """Checks if a dialogue entry is a HUB (actor is 'HUB' and dialoguetext is '0')."""
35
+ if entry is None:
36
+ return False
37
+ dialogue_text, actor_id, conversant_id, _, _ = entry # unpack all
38
+ return dialogue_text == "0" and actor_id == 0
39
+
40
+ def generate_conversation_path(cursor, start_convo_id, start_dialogue_id, max_length=20):
41
+ """Generates a single conversation path, treating '0' entries as placeholders."""
42
+ path = []
43
+ current_convo_id = start_convo_id
44
+ current_dialogue_id = start_dialogue_id
45
+
46
+ for _ in range(max_length):
47
+ entry = get_dialogue_entry(cursor, current_convo_id, current_dialogue_id)
48
+ if not entry:
49
+ print(f"Warning: Could not find dialogue entry for convo_id={current_convo_id}, dialogue_id={current_dialogue_id}. Path may be incomplete.")
50
+ break
51
+
52
+ dialogue_text, actor_id, conversant_id, conditionstring, userscript = entry
53
+
54
+ if is_hub(entry):
55
+ # Skip HUB entries
56
+ children = get_dialogue_children(cursor, current_convo_id, current_dialogue_id)
57
+ if not children:
58
+ break
59
+ current_convo_id, current_dialogue_id = random.choice(children)
60
+ continue
61
+
62
+ actor_name = get_actor_name(cursor, actor_id)
63
+
64
+ if dialogue_text == "0":
65
+ # Treat '0' entry as a placeholder with context
66
+ placeholder_text = "[Action/Check: "
67
+ if conditionstring:
68
+ placeholder_text += f"Condition: {conditionstring}; "
69
+ if userscript:
70
+ placeholder_text += f"Script: {userscript}; "
71
+ placeholder_text = placeholder_text.rstrip("; ") + "]"
72
+ path.append({"actor": actor_name, "dialogue": placeholder_text})
73
+ else:
74
+ path.append({"actor": actor_name, "dialogue": dialogue_text})
75
+
76
+ children = get_dialogue_children(cursor, current_convo_id, current_dialogue_id)
77
+ if not children:
78
+ break
79
+
80
+ current_convo_id, current_dialogue_id = random.choice(children)
81
+
82
+ return path
83
+
84
+ def get_starting_dialogues(cursor):
85
+ """Get a list of potential starting dialogues (those with no parents)."""
86
+ cursor.execute("""
87
+ SELECT dentries.conversationid, dentries.id
88
+ FROM dentries
89
+ LEFT JOIN dlinks ON dentries.conversationid = dlinks.destinationconversationid AND dentries.id = dlinks.destinationdialogueid
90
+ WHERE dlinks.originconversationid IS NULL
91
+ """)
92
+ return cursor.fetchall()
93
+
94
+ def format_conversation_output(conversation):
95
+ """
96
+ Formats a conversation list into a string that resembles the game's output.
97
+
98
+ Args:
99
+ conversation: A list of dictionaries, where each dictionary represents a
100
+ dialogue entry with "actor" and "dialogue" keys.
101
+ """
102
+
103
+ output = ""
104
+ for entry in conversation:
105
+ actor = entry["actor"]
106
+ dialogue = entry["dialogue"]
107
+
108
+ if dialogue.startswith("["): # Placeholder for action/check
109
+ output += f"{dialogue}\n"
110
+ elif actor.upper() == actor: # If the actor is all uppercase, it's like a skill or internal thought
111
+ output += f"\n{actor} - {dialogue}\n"
112
+ else:
113
+ output += f"{actor} - {dialogue}\n"
114
+
115
+ return output.strip()
116
+
117
+ def main():
118
+ """Main function to generate and output conversation paths."""
119
+ conn = sqlite3.connect(DATABASE_FILE)
120
+ cursor = conn.cursor()
121
+
122
+ conversations = []
123
+ num_paths_to_generate = 1000
124
+ paths_generated = 0
125
+
126
+ # Initialize Bloom filter
127
+ bloom = ScalableBloomFilter(initial_capacity=100000, error_rate=0.001)
128
+
129
+ # Either pick a random starting point:
130
+ starting_dialogues = get_starting_dialogues(cursor)
131
+ if not starting_dialogues:
132
+ print("Error: No starting dialogues found in the database.")
133
+ conn.close()
134
+ return
135
+
136
+ with tqdm(total=num_paths_to_generate, desc="Generating paths") as pbar:
137
+ while paths_generated < num_paths_to_generate:
138
+ start_convo_id, start_dialogue_id = random.choice(starting_dialogues)
139
+ path = generate_conversation_path(cursor, start_convo_id, start_dialogue_id)
140
+
141
+ # Create unique key for conversation
142
+ path_text = "".join(entry["dialogue"] for entry in path)
143
+ path_hash = hashlib.sha256(path_text.encode()).hexdigest()
144
+
145
+ # Check for duplicates using Bloom filter
146
+ try:
147
+ if path_hash not in bloom and any(entry["dialogue"][0] != "[" for entry in path):
148
+ bloom.add(path_hash)
149
+ conversations.append(path)
150
+ paths_generated += 1
151
+ pbar.update(1)
152
+ except Exception as e:
153
+ print(f"Error: {e}")
154
+ continue
155
+
156
+ output = {"conversations": conversations}
157
+ with open("output.json", "w") as f:
158
+ json.dump(output, f, indent=4)
159
+
160
+ conn.close()
161
+
162
+ if __name__ == "__main__":
163
+ main()