Update index.c
Browse files
index.c
CHANGED
|
@@ -2,60 +2,371 @@
|
|
| 2 |
#include <stdlib.h>
|
| 3 |
#include <string.h>
|
| 4 |
#include <ctype.h>
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
//
|
| 7 |
typedef struct {
|
| 8 |
int token;
|
| 9 |
-
char model
|
| 10 |
char* return_value;
|
| 11 |
} ZetaResult;
|
| 12 |
|
| 13 |
-
//
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
for (int i = 0; str[i]; i++) {
|
| 16 |
-
|
| 17 |
}
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
-
//
|
| 21 |
-
|
| 22 |
-
for (int i = 0; i <
|
| 23 |
-
if (strcmp(
|
| 24 |
-
return
|
| 25 |
}
|
| 26 |
}
|
| 27 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
-
//
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
int j = 0;
|
| 33 |
for (int i = 0; str[i]; i++) {
|
| 34 |
-
if (isalpha((unsigned char)str[i]) ||
|
| 35 |
-
|
| 36 |
}
|
| 37 |
}
|
| 38 |
-
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
-
//
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
ZetaResult zeta(const char* q) {
|
| 58 |
const char* db[] = {
|
|
|
|
|
|
|
| 59 |
"Artificial intelligence, or AI, is a technology that allows computers to learn, think, and make decisions like humans. Today, AI is used in many parts of our daily lives. It helps us find information online, recommends songs we might like, and even drives cars automatically.AI can understand language, recognize faces, and solve problems faster than people in some cases. However, AI still needs humans to guide it and make sure it is used safely. Many scientists believe that AI will continue to grow and improve, making our future smarter and more efficient. The key is to use it responsibly and for the benefit of everyone.",
|
| 60 |
"Developing AI systems requires a mix of math, programming, and creativity. Engineers begin by collecting data, which helps the AI learn patterns and make predictions. They then design a model, usually using machine-learning frameworks like TensorFlow or PyTorch. After training the model, developers test it to make sure it works correctly and safely.AI development is not only about making machines smart—it also involves careful decision-making. Developers must think about privacy, fairness, and how their technology will be used. Building AI responsibly ensures that it can help people while avoiding harmful effects. As the field grows, AI developers continue to create new tools that push technology forward and open the door to future innovations.",
|
| 61 |
"Cybersecurity is the practice of protecting computers, networks, and data from unauthorized access or attacks. In today's digital world, people store a lot of personal information online, from bank accounts to social media. Hackers can try to steal this information or cause damage.To stay safe, organizations and individuals use strong passwords, firewalls, and encryption. Regular software updates and careful behavior online are also important. Cybersecurity is not just about technology—it is about awareness and responsibility. By following good practices, we can reduce risks and keep our digital world safe.",
|
|
@@ -65,109 +376,171 @@ ZetaResult zeta(const char* q) {
|
|
| 65 |
"Websites are an important part of the modern world. They can be simple pages with text and images, or dynamic websites that change content based on user input. Dynamic websites allow users to interact, shop online, or post comments. Examples include online stores, social media, and news websites.However, websites must be protected from cyber threats. Web security involves using strong passwords, secure connections (HTTPS), and regular updates to prevent hackers from stealing data or causing damage. Developers also use firewalls, encryption, and safe coding practices to keep websites safe.Dynamic websites offer many benefits, but they must be carefully maintained to ensure that users' information is secure. A well-protected website provides a safe and smooth experience for everyone online.",
|
| 66 |
"Artificial intelligence has grown rapidly, and many AI models are helping people in different ways. ChatGPT is a language model that can chat, answer questions, and even write text like essays or code. Gemini is another AI developed for understanding language and assisting with research and creative tasks.DeepSeek focuses on analyzing large amounts of data, helping users find patterns and insights quickly. Gemma3 is designed for generating content, such as text, images, or code, making it useful for creative work. Copilot, developed for programmers, helps write code faster by suggesting lines or functions in real time.These AI models show how technology can assist humans in communication, research, and productivity. They are powerful tools, but users should always consider ethics, privacy, and responsible use when using them."
|
| 67 |
};
|
| 68 |
-
int db_length = 8;
|
| 69 |
-
|
| 70 |
//Put article to db array.
|
| 71 |
-
char* raw = strdup(q);
|
| 72 |
-
toLowerCase(raw);
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
free(raw);
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
res[0] = '\0';
|
|
|
|
| 86 |
int token = 0;
|
| 87 |
|
| 88 |
-
// Check if first word is
|
| 89 |
-
if (
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
free(words[0]);
|
| 96 |
-
for (int i = 0; i < word_count - 1; i++) {
|
| 97 |
-
words[i] = words[i + 1];
|
| 98 |
}
|
| 99 |
-
|
| 100 |
token += 1;
|
| 101 |
}
|
| 102 |
}
|
| 103 |
|
| 104 |
// Filter out "is", "are", "the"
|
| 105 |
const char* filter_words[] = {"is", "are", "the"};
|
| 106 |
-
int
|
| 107 |
-
for (int i = 0; i <
|
| 108 |
-
if (!
|
| 109 |
-
|
| 110 |
} else {
|
| 111 |
-
free(
|
| 112 |
}
|
| 113 |
}
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
} else {
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
char* catc = malloc(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
catc[0] = '\0';
|
| 127 |
|
| 128 |
-
for (int i = 0; i <
|
| 129 |
-
if (
|
| 130 |
strcat(catc, db[i]);
|
| 131 |
token += strlen(db[i]);
|
| 132 |
}
|
| 133 |
}
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
sprintf(res, "%s, about %s...\n%s\n%s, a good discuss for us.", q, keyword, catc, keyword);
|
| 136 |
token += 5;
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
}
|
| 142 |
-
free(
|
| 143 |
free(keyword);
|
| 144 |
free(catc);
|
| 145 |
-
|
| 146 |
-
ZetaResult result;
|
| 147 |
-
result.token = token;
|
| 148 |
-
strcpy(result.model, "zeta-x1-lite");
|
| 149 |
-
result.return_value = res;
|
| 150 |
|
| 151 |
return result;
|
| 152 |
}
|
| 153 |
|
| 154 |
-
// Helper function to free
|
| 155 |
void freeZetaResult(ZetaResult* result) {
|
| 156 |
-
if (result
|
|
|
|
| 157 |
free(result->return_value);
|
| 158 |
-
result->return_value = NULL;
|
| 159 |
}
|
| 160 |
}
|
| 161 |
|
| 162 |
// Example usage
|
| 163 |
int main() {
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
printf("
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
return 0;
|
| 173 |
-
}
|
|
|
|
| 2 |
#include <stdlib.h>
|
| 3 |
#include <string.h>
|
| 4 |
#include <ctype.h>
|
| 5 |
+
#include <math.h>
|
| 6 |
+
#include <stdbool.h>
|
| 7 |
|
| 8 |
+
// Struct to hold the return value
|
| 9 |
typedef struct {
|
| 10 |
int token;
|
| 11 |
+
char* model;
|
| 12 |
char* return_value;
|
| 13 |
} ZetaResult;
|
| 14 |
|
| 15 |
+
// Helper function to convert string to lowercase
|
| 16 |
+
char* toLowerCase(const char* str) {
|
| 17 |
+
if (str == NULL) return NULL;
|
| 18 |
+
char* lower = (char*)malloc(strlen(str) + 1);
|
| 19 |
+
if (lower == NULL) return NULL;
|
| 20 |
for (int i = 0; str[i]; i++) {
|
| 21 |
+
lower[i] = tolower((unsigned char)str[i]);
|
| 22 |
}
|
| 23 |
+
lower[strlen(str)] = '\0';
|
| 24 |
+
return lower;
|
| 25 |
}
|
| 26 |
|
| 27 |
+
// Helper function to check if a string is in an array
|
| 28 |
+
bool isInArray(const char* str, const char** array, int size) {
|
| 29 |
+
for (int i = 0; i < size; i++) {
|
| 30 |
+
if (strcmp(str, array[i]) == 0) {
|
| 31 |
+
return true;
|
| 32 |
}
|
| 33 |
}
|
| 34 |
+
return false;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// Helper function to check if a string contains a substring (case-insensitive)
|
| 38 |
+
bool containsIgnoreCase(const char* haystack, const char* needle) {
|
| 39 |
+
if (haystack == NULL || needle == NULL) return false;
|
| 40 |
+
char* hay_lower = toLowerCase(haystack);
|
| 41 |
+
char* needle_lower = toLowerCase(needle);
|
| 42 |
+
bool result = (strstr(hay_lower, needle_lower) != NULL);
|
| 43 |
+
free(hay_lower);
|
| 44 |
+
free(needle_lower);
|
| 45 |
+
return result;
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// Helper function to remove non-alphabetic characters
|
| 49 |
+
char* removeNonAlpha(const char* str) {
|
| 50 |
+
if (str == NULL) return NULL;
|
| 51 |
+
char* result = (char*)malloc(strlen(str) + 1);
|
| 52 |
+
if (result == NULL) return NULL;
|
| 53 |
int j = 0;
|
| 54 |
for (int i = 0; str[i]; i++) {
|
| 55 |
+
if (isalpha((unsigned char)str[i]) || str[i] == ' ') {
|
| 56 |
+
result[j++] = str[i];
|
| 57 |
}
|
| 58 |
}
|
| 59 |
+
result[j] = '\0';
|
| 60 |
+
return result;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
// Helper function to split a string by spaces
|
| 64 |
+
char** splitString(const char* str, int* count) {
|
| 65 |
+
if (str == NULL) {
|
| 66 |
+
*count = 0;
|
| 67 |
+
return NULL;
|
| 68 |
+
}
|
| 69 |
|
| 70 |
+
// Count words
|
| 71 |
+
int word_count = 0;
|
| 72 |
+
bool in_word = false;
|
| 73 |
+
for (int i = 0; str[i]; i++) {
|
| 74 |
+
if (str[i] != ' ' && !in_word) {
|
| 75 |
+
word_count++;
|
| 76 |
+
in_word = true;
|
| 77 |
+
} else if (str[i] == ' ') {
|
| 78 |
+
in_word = false;
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
|
| 82 |
+
if (word_count == 0) {
|
| 83 |
+
*count = 0;
|
| 84 |
+
return NULL;
|
| 85 |
+
}
|
| 86 |
|
| 87 |
+
char** words = (char**)malloc(word_count * sizeof(char*));
|
| 88 |
+
if (words == NULL) {
|
| 89 |
+
*count = 0;
|
| 90 |
+
return NULL;
|
| 91 |
+
}
|
| 92 |
|
| 93 |
+
// Extract words
|
| 94 |
+
int word_index = 0;
|
| 95 |
+
int start = -1;
|
| 96 |
+
for (int i = 0; i <= strlen(str); i++) {
|
| 97 |
+
if (str[i] != ' ' && str[i] != '\0' && start == -1) {
|
| 98 |
+
start = i;
|
| 99 |
+
} else if ((str[i] == ' ' || str[i] == '\0') && start != -1) {
|
| 100 |
+
int len = i - start;
|
| 101 |
+
words[word_index] = (char*)malloc(len + 1);
|
| 102 |
+
if (words[word_index] == NULL) {
|
| 103 |
+
for (int j = 0; j < word_index; j++) {
|
| 104 |
+
free(words[j]);
|
| 105 |
+
}
|
| 106 |
+
free(words);
|
| 107 |
+
*count = 0;
|
| 108 |
+
return NULL;
|
| 109 |
+
}
|
| 110 |
+
strncpy(words[word_index], str + start, len);
|
| 111 |
+
words[word_index][len] = '\0';
|
| 112 |
+
word_index++;
|
| 113 |
+
start = -1;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
*count = word_count;
|
| 118 |
+
return words;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// Stack structure for expression evaluation
|
| 122 |
+
typedef struct {
|
| 123 |
+
double* data;
|
| 124 |
+
int top;
|
| 125 |
+
int capacity;
|
| 126 |
+
} DoubleStack;
|
| 127 |
+
|
| 128 |
+
typedef struct {
|
| 129 |
+
char* data;
|
| 130 |
+
int top;
|
| 131 |
+
int capacity;
|
| 132 |
+
} CharStack;
|
| 133 |
+
|
| 134 |
+
DoubleStack* createDoubleStack(int capacity) {
|
| 135 |
+
DoubleStack* stack = (DoubleStack*)malloc(sizeof(DoubleStack));
|
| 136 |
+
if (stack == NULL) return NULL;
|
| 137 |
+
stack->data = (double*)malloc(capacity * sizeof(double));
|
| 138 |
+
if (stack->data == NULL) {
|
| 139 |
+
free(stack);
|
| 140 |
+
return NULL;
|
| 141 |
+
}
|
| 142 |
+
stack->top = -1;
|
| 143 |
+
stack->capacity = capacity;
|
| 144 |
+
return stack;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
CharStack* createCharStack(int capacity) {
|
| 148 |
+
CharStack* stack = (CharStack*)malloc(sizeof(CharStack));
|
| 149 |
+
if (stack == NULL) return NULL;
|
| 150 |
+
stack->data = (char*)malloc(capacity * sizeof(char));
|
| 151 |
+
if (stack->data == NULL) {
|
| 152 |
+
free(stack);
|
| 153 |
+
return NULL;
|
| 154 |
+
}
|
| 155 |
+
stack->top = -1;
|
| 156 |
+
stack->capacity = capacity;
|
| 157 |
+
return stack;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
void pushDouble(DoubleStack* stack, double value) {
|
| 161 |
+
if (stack->top < stack->capacity - 1) {
|
| 162 |
+
stack->data[++stack->top] = value;
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
double popDouble(DoubleStack* stack) {
|
| 167 |
+
if (stack->top >= 0) {
|
| 168 |
+
return stack->data[stack->top--];
|
| 169 |
+
}
|
| 170 |
+
return 0.0;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
double peekDouble(DoubleStack* stack) {
|
| 174 |
+
if (stack->top >= 0) {
|
| 175 |
+
return stack->data[stack->top];
|
| 176 |
+
}
|
| 177 |
+
return 0.0;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
void pushChar(CharStack* stack, char value) {
|
| 181 |
+
if (stack->top < stack->capacity - 1) {
|
| 182 |
+
stack->data[++stack->top] = value;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
char popChar(CharStack* stack) {
|
| 187 |
+
if (stack->top >= 0) {
|
| 188 |
+
return stack->data[stack->top--];
|
| 189 |
+
}
|
| 190 |
+
return '\0';
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
char peekChar(CharStack* stack) {
|
| 194 |
+
if (stack->top >= 0) {
|
| 195 |
+
return stack->data[stack->top];
|
| 196 |
+
}
|
| 197 |
+
return '\0';
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
bool isEmptyChar(CharStack* stack) {
|
| 201 |
+
return stack->top == -1;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
void freeDoubleStack(DoubleStack* stack) {
|
| 205 |
+
if (stack) {
|
| 206 |
+
free(stack->data);
|
| 207 |
+
free(stack);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
void freeCharStack(CharStack* stack) {
|
| 212 |
+
if (stack) {
|
| 213 |
+
free(stack->data);
|
| 214 |
+
free(stack);
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// Get operator precedence
|
| 219 |
+
int getPrecedence(char op) {
|
| 220 |
+
if (op == '+' || op == '-') return 1;
|
| 221 |
+
if (op == '*' || op == '/') return 2;
|
| 222 |
+
if (op == '^') return 3;
|
| 223 |
+
return 0;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
// Apply operator to two operands
|
| 227 |
+
double applyOp(double a, double b, char op) {
|
| 228 |
+
switch (op) {
|
| 229 |
+
case '+': return a + b;
|
| 230 |
+
case '-': return a - b;
|
| 231 |
+
case '*': return a * b;
|
| 232 |
+
case '/': return b != 0 ? a / b : 0.0;
|
| 233 |
+
case '^': return pow(a, b);
|
| 234 |
+
}
|
| 235 |
+
return 0.0;
|
| 236 |
}
|
| 237 |
|
| 238 |
+
// Evaluate mathematical expression
|
| 239 |
+
bool evalMath(const char* input, double* result) {
|
| 240 |
+
if (input == NULL) return false;
|
| 241 |
+
|
| 242 |
+
// Extract mathematical expression (digits, operators, parentheses, decimal points)
|
| 243 |
+
char* expr = (char*)malloc(strlen(input) + 1);
|
| 244 |
+
if (expr == NULL) return false;
|
| 245 |
+
int expr_len = 0;
|
| 246 |
+
bool found_digit = false;
|
| 247 |
+
|
| 248 |
+
for (int i = 0; input[i]; i++) {
|
| 249 |
+
char c = input[i];
|
| 250 |
+
if (isdigit(c) || c == '+' || c == '-' || c == '*' || c == '/' ||
|
| 251 |
+
c == '(' || c == ')' || c == '^' || c == '.') {
|
| 252 |
+
expr[expr_len++] = c;
|
| 253 |
+
if (isdigit(c)) found_digit = true;
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
expr[expr_len] = '\0';
|
| 257 |
+
|
| 258 |
+
if (!found_digit || expr_len == 0) {
|
| 259 |
+
free(expr);
|
| 260 |
+
return false;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// Replace ^ with ** is not needed in C, we handle ^ directly
|
| 264 |
+
|
| 265 |
+
// Validate expression (only allowed characters)
|
| 266 |
+
for (int i = 0; expr[i]; i++) {
|
| 267 |
+
char c = expr[i];
|
| 268 |
+
if (!isdigit(c) && c != '+' && c != '-' && c != '*' && c != '/' &&
|
| 269 |
+
c != '(' && c != ')' && c != '.' && c != '^' && c != ' ') {
|
| 270 |
+
free(expr);
|
| 271 |
+
return false;
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
// Evaluate expression using two stacks
|
| 276 |
+
DoubleStack* values = createDoubleStack(256);
|
| 277 |
+
CharStack* ops = createCharStack(256);
|
| 278 |
+
|
| 279 |
+
if (values == NULL || ops == NULL) {
|
| 280 |
+
if (values) freeDoubleStack(values);
|
| 281 |
+
if (ops) freeCharStack(ops);
|
| 282 |
+
free(expr);
|
| 283 |
+
return false;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
int i = 0;
|
| 287 |
+
while (i < expr_len) {
|
| 288 |
+
// Skip whitespace
|
| 289 |
+
if (expr[i] == ' ') {
|
| 290 |
+
i++;
|
| 291 |
+
continue;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
// Current token is a number
|
| 295 |
+
if (isdigit(expr[i]) || expr[i] == '.') {
|
| 296 |
+
char num_str[64];
|
| 297 |
+
int num_len = 0;
|
| 298 |
+
while (i < expr_len && (isdigit(expr[i]) || expr[i] == '.')) {
|
| 299 |
+
num_str[num_len++] = expr[i++];
|
| 300 |
+
}
|
| 301 |
+
num_str[num_len] = '\0';
|
| 302 |
+
pushDouble(values, atof(num_str));
|
| 303 |
+
continue;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
// Current token is an opening parenthesis
|
| 307 |
+
if (expr[i] == '(') {
|
| 308 |
+
pushChar(ops, expr[i]);
|
| 309 |
+
i++;
|
| 310 |
+
continue;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// Current token is a closing parenthesis
|
| 314 |
+
if (expr[i] == ')') {
|
| 315 |
+
while (!isEmptyChar(ops) && peekChar(ops) != '(') {
|
| 316 |
+
double val2 = popDouble(values);
|
| 317 |
+
double val1 = popDouble(values);
|
| 318 |
+
char op = popChar(ops);
|
| 319 |
+
pushDouble(values, applyOp(val1, val2, op));
|
| 320 |
+
}
|
| 321 |
+
if (!isEmptyChar(ops)) {
|
| 322 |
+
popChar(ops); // Remove '('
|
| 323 |
+
}
|
| 324 |
+
i++;
|
| 325 |
+
continue;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// Current token is an operator
|
| 329 |
+
if (expr[i] == '+' || expr[i] == '-' || expr[i] == '*' ||
|
| 330 |
+
expr[i] == '/' || expr[i] == '^') {
|
| 331 |
+
while (!isEmptyChar(ops) && getPrecedence(peekChar(ops)) >= getPrecedence(expr[i])) {
|
| 332 |
+
double val2 = popDouble(values);
|
| 333 |
+
double val1 = popDouble(values);
|
| 334 |
+
char op = popChar(ops);
|
| 335 |
+
pushDouble(values, applyOp(val1, val2, op));
|
| 336 |
+
}
|
| 337 |
+
pushChar(ops, expr[i]);
|
| 338 |
+
i++;
|
| 339 |
+
continue;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
i++;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
// Apply remaining operators
|
| 346 |
+
while (!isEmptyChar(ops)) {
|
| 347 |
+
double val2 = popDouble(values);
|
| 348 |
+
double val1 = popDouble(values);
|
| 349 |
+
char op = popChar(ops);
|
| 350 |
+
pushDouble(values, applyOp(val1, val2, op));
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
// Result is at top of values stack
|
| 354 |
+
*result = popDouble(values);
|
| 355 |
+
|
| 356 |
+
bool is_finite = isfinite(*result);
|
| 357 |
+
|
| 358 |
+
freeDoubleStack(values);
|
| 359 |
+
freeCharStack(ops);
|
| 360 |
+
free(expr);
|
| 361 |
+
|
| 362 |
+
return is_finite;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
// Main zeta function
|
| 366 |
ZetaResult zeta(const char* q) {
|
| 367 |
const char* db[] = {
|
| 368 |
+
"Who am I? I'm a model trained by NeuralNexusLab and developed by NeuralNexusLab. I can use article to answer you or computation math.",
|
| 369 |
+
"Who are you? I don't know who are you but I know you are my best friend! I can explain what is AI to you, or computation math.",
|
| 370 |
"Artificial intelligence, or AI, is a technology that allows computers to learn, think, and make decisions like humans. Today, AI is used in many parts of our daily lives. It helps us find information online, recommends songs we might like, and even drives cars automatically.AI can understand language, recognize faces, and solve problems faster than people in some cases. However, AI still needs humans to guide it and make sure it is used safely. Many scientists believe that AI will continue to grow and improve, making our future smarter and more efficient. The key is to use it responsibly and for the benefit of everyone.",
|
| 371 |
"Developing AI systems requires a mix of math, programming, and creativity. Engineers begin by collecting data, which helps the AI learn patterns and make predictions. They then design a model, usually using machine-learning frameworks like TensorFlow or PyTorch. After training the model, developers test it to make sure it works correctly and safely.AI development is not only about making machines smart—it also involves careful decision-making. Developers must think about privacy, fairness, and how their technology will be used. Building AI responsibly ensures that it can help people while avoiding harmful effects. As the field grows, AI developers continue to create new tools that push technology forward and open the door to future innovations.",
|
| 372 |
"Cybersecurity is the practice of protecting computers, networks, and data from unauthorized access or attacks. In today's digital world, people store a lot of personal information online, from bank accounts to social media. Hackers can try to steal this information or cause damage.To stay safe, organizations and individuals use strong passwords, firewalls, and encryption. Regular software updates and careful behavior online are also important. Cybersecurity is not just about technology—it is about awareness and responsibility. By following good practices, we can reduce risks and keep our digital world safe.",
|
|
|
|
| 376 |
"Websites are an important part of the modern world. They can be simple pages with text and images, or dynamic websites that change content based on user input. Dynamic websites allow users to interact, shop online, or post comments. Examples include online stores, social media, and news websites.However, websites must be protected from cyber threats. Web security involves using strong passwords, secure connections (HTTPS), and regular updates to prevent hackers from stealing data or causing damage. Developers also use firewalls, encryption, and safe coding practices to keep websites safe.Dynamic websites offer many benefits, but they must be carefully maintained to ensure that users' information is secure. A well-protected website provides a safe and smooth experience for everyone online.",
|
| 377 |
"Artificial intelligence has grown rapidly, and many AI models are helping people in different ways. ChatGPT is a language model that can chat, answer questions, and even write text like essays or code. Gemini is another AI developed for understanding language and assisting with research and creative tasks.DeepSeek focuses on analyzing large amounts of data, helping users find patterns and insights quickly. Gemma3 is designed for generating content, such as text, images, or code, making it useful for creative work. Copilot, developed for programmers, helps write code faster by suggesting lines or functions in real time.These AI models show how technology can assist humans in communication, research, and productivity. They are powerful tools, but users should always consider ethics, privacy, and responsible use when using them."
|
| 378 |
};
|
|
|
|
|
|
|
| 379 |
//Put article to db array.
|
|
|
|
|
|
|
| 380 |
|
| 381 |
+
int db_size = 10;
|
| 382 |
+
|
| 383 |
+
ZetaResult result;
|
| 384 |
+
result.model = (char*)malloc(strlen("zeta-xf") + 1);
|
| 385 |
+
strcpy(result.model, "zeta-xf");
|
| 386 |
+
|
| 387 |
+
char* raw = toLowerCase(q);
|
| 388 |
+
int raw_count = 0;
|
| 389 |
+
char** raw_words = splitString(raw, &raw_count);
|
| 390 |
free(raw);
|
| 391 |
|
| 392 |
+
if (raw_words == NULL || raw_count == 0) {
|
| 393 |
+
result.token = 0;
|
| 394 |
+
result.return_value = (char*)malloc(1);
|
| 395 |
+
result.return_value[0] = '\0';
|
| 396 |
+
return result;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
char* res = (char*)malloc(10000);
|
| 400 |
+
if (res == NULL) {
|
| 401 |
+
for (int i = 0; i < raw_count; i++) {
|
| 402 |
+
free(raw_words[i]);
|
| 403 |
+
}
|
| 404 |
+
free(raw_words);
|
| 405 |
+
result.token = 0;
|
| 406 |
+
result.return_value = (char*)malloc(1);
|
| 407 |
+
result.return_value[0] = '\0';
|
| 408 |
+
return result;
|
| 409 |
+
}
|
| 410 |
res[0] = '\0';
|
| 411 |
+
|
| 412 |
int token = 0;
|
| 413 |
|
| 414 |
+
// Check if first word is in the list and remove it
|
| 415 |
+
if (raw_count > 0) {
|
| 416 |
+
const char* check_words[] = {"do", "what", "who", "which", "where", "when", "was", "were", "is", "are"};
|
| 417 |
+
if (isInArray(raw_words[0], check_words, 10)) {
|
| 418 |
+
free(raw_words[0]);
|
| 419 |
+
for (int i = 1; i < raw_count; i++) {
|
| 420 |
+
raw_words[i - 1] = raw_words[i];
|
|
|
|
|
|
|
|
|
|
| 421 |
}
|
| 422 |
+
raw_count--;
|
| 423 |
token += 1;
|
| 424 |
}
|
| 425 |
}
|
| 426 |
|
| 427 |
// Filter out "is", "are", "the"
|
| 428 |
const char* filter_words[] = {"is", "are", "the"};
|
| 429 |
+
int new_count = 0;
|
| 430 |
+
for (int i = 0; i < raw_count; i++) {
|
| 431 |
+
if (!isInArray(raw_words[i], filter_words, 3)) {
|
| 432 |
+
raw_words[new_count++] = raw_words[i];
|
| 433 |
} else {
|
| 434 |
+
free(raw_words[i]);
|
| 435 |
}
|
| 436 |
}
|
| 437 |
+
raw_count = new_count;
|
| 438 |
+
|
| 439 |
+
char* keyword = (char*)malloc(strlen("nothing") + 1);
|
| 440 |
+
strcpy(keyword, "nothing");
|
| 441 |
|
| 442 |
+
if (raw_count > 0 && raw_words[0] != NULL) {
|
| 443 |
+
free(keyword);
|
| 444 |
+
keyword = (char*)malloc(strlen(raw_words[0]) + 1);
|
| 445 |
+
strcpy(keyword, raw_words[0]);
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
// Transform keyword
|
| 449 |
+
if (strcmp(keyword, "you") == 0 || strcmp(keyword, "your") == 0) {
|
| 450 |
+
free(keyword);
|
| 451 |
+
keyword = (char*)malloc(2);
|
| 452 |
+
strcpy(keyword, "i");
|
| 453 |
} else {
|
| 454 |
+
if (strcmp(keyword, "i") == 0 || strcmp(keyword, "me") == 0) {
|
| 455 |
+
free(keyword);
|
| 456 |
+
keyword = (char*)malloc(4);
|
| 457 |
+
strcpy(keyword, "you");
|
| 458 |
+
}
|
| 459 |
}
|
| 460 |
|
| 461 |
+
// Remove non-alphabetic characters
|
| 462 |
+
char* cleaned_keyword = removeNonAlpha(keyword);
|
| 463 |
+
free(keyword);
|
| 464 |
+
keyword = cleaned_keyword;
|
| 465 |
|
| 466 |
+
char* catc = (char*)malloc(50000);
|
| 467 |
+
if (catc == NULL) {
|
| 468 |
+
for (int i = 0; i < raw_count; i++) {
|
| 469 |
+
free(raw_words[i]);
|
| 470 |
+
}
|
| 471 |
+
free(raw_words);
|
| 472 |
+
free(keyword);
|
| 473 |
+
free(res);
|
| 474 |
+
result.token = 0;
|
| 475 |
+
result.return_value = (char*)malloc(1);
|
| 476 |
+
result.return_value[0] = '\0';
|
| 477 |
+
return result;
|
| 478 |
+
}
|
| 479 |
catc[0] = '\0';
|
| 480 |
|
| 481 |
+
for (int i = 0; i < db_size; i++) {
|
| 482 |
+
if (containsIgnoreCase(db[i], keyword)) {
|
| 483 |
strcat(catc, db[i]);
|
| 484 |
token += strlen(db[i]);
|
| 485 |
}
|
| 486 |
}
|
| 487 |
|
| 488 |
+
double math_result;
|
| 489 |
+
if (evalMath(q, &math_result)) {
|
| 490 |
+
char math_str[256];
|
| 491 |
+
sprintf(math_str, "\"%s\", the computation's answer is %g.", q, math_result);
|
| 492 |
+
strcat(catc, math_str);
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
sprintf(res, "%s, about %s...\n%s\n%s, a good discuss for us.", q, keyword, catc, keyword);
|
| 496 |
token += 5;
|
| 497 |
|
| 498 |
+
result.token = token;
|
| 499 |
+
result.return_value = (char*)malloc(strlen(res) + 1);
|
| 500 |
+
strcpy(result.return_value, res);
|
| 501 |
+
|
| 502 |
+
// Free allocated memory
|
| 503 |
+
for (int i = 0; i < raw_count; i++) {
|
| 504 |
+
free(raw_words[i]);
|
| 505 |
}
|
| 506 |
+
free(raw_words);
|
| 507 |
free(keyword);
|
| 508 |
free(catc);
|
| 509 |
+
free(res);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 510 |
|
| 511 |
return result;
|
| 512 |
}
|
| 513 |
|
| 514 |
+
// Helper function to free ZetaResult
|
| 515 |
void freeZetaResult(ZetaResult* result) {
|
| 516 |
+
if (result) {
|
| 517 |
+
free(result->model);
|
| 518 |
free(result->return_value);
|
|
|
|
| 519 |
}
|
| 520 |
}
|
| 521 |
|
| 522 |
// Example usage
|
| 523 |
int main() {
|
| 524 |
+
// Test with a question
|
| 525 |
+
ZetaResult result1 = zeta("Who are you?");
|
| 526 |
+
printf("Model: %s\n", result1.model);
|
| 527 |
+
printf("Token: %d\n", result1.token);
|
| 528 |
+
printf("Result:\n%s\n\n", result1.return_value);
|
| 529 |
+
freeZetaResult(&result1);
|
| 530 |
|
| 531 |
+
// Test with a math expression
|
| 532 |
+
ZetaResult result2 = zeta("What is 2+2*3?");
|
| 533 |
+
printf("Model: %s\n", result2.model);
|
| 534 |
+
printf("Token: %d\n", result2.token);
|
| 535 |
+
printf("Result:\n%s\n\n", result2.return_value);
|
| 536 |
+
freeZetaResult(&result2);
|
| 537 |
|
| 538 |
+
// Test with AI keyword
|
| 539 |
+
ZetaResult result3 = zeta("Tell me about AI");
|
| 540 |
+
printf("Model: %s\n", result3.model);
|
| 541 |
+
printf("Token: %d\n", result3.token);
|
| 542 |
+
printf("Result:\n%s\n", result3.return_value);
|
| 543 |
+
freeZetaResult(&result3);
|
| 544 |
|
| 545 |
return 0;
|
| 546 |
+
}
|