stopword.c
来自「使用具有增量学习的监控式学习方法。包括几个不同的分类算法。」· C语言 代码 · 共 97 行
C
97 行
/** * @file * Handle stopword removal. * * @author Mikael Ylikoski * @date 2001-2002 */#include <glib.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "stopword.h"#include "utility.h"/** * Word stopper. */struct word_stopper_ { GHashTable *hash; /**< Hash table of stopwords */};/** * Create a new word stopper. * * @return The word stopper. */word_stopper *stopword_new (void) { word_stopper *ws; ws = my_malloc (sizeof(word_stopper)); ws->hash = g_hash_table_new (g_str_hash, g_str_equal); if (!ws->hash) { free (ws); return NULL; } return ws;}/** * Free a word stopper. * * @param ws word stopper to free */voidstopword_free (word_stopper *ws) { g_hash_table_destroy (ws->hash); free (ws);}/** * Load stopwords from a file and add to a word stopper. * * @param ws the word stopper * @param file file of stop words * @return Zero if ok, nonzero otherwise. */intstopword_load (word_stopper *ws, const char *file) { char buf[30], *s; FILE *fp; fp = fopen (file, "r"); if (!fp) return -1; while (get_line_nows (fp, buf, 30)) { s = g_hash_table_lookup (ws->hash, buf); if (!s) { s = my_strdup (buf); g_hash_table_insert (ws->hash, s, (gpointer)1); } } fclose (fp); return 0;}/** * Test whether a word is a stop word. * * @param ws word stopper * @param word word to test * @return Nonzero if the word is a stop word, zero otherwise. */intstopword_is (word_stopper *ws, const char *word) { return (int)g_hash_table_lookup (ws->hash, word);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?