00001 /*========================================================================== 00002 * Copyright (c) 2001 Carnegie Mellon University. All Rights Reserved. 00003 * 00004 * Use of the Lemur Toolkit for Language Modeling and Information Retrieval 00005 * is subject to the terms of the software license set forth in the LICENSE 00006 * file included with this software, and also available at 00007 * http://www.cs.cmu.edu/~lemur/license.html 00008 * 00009 *========================================================================== 00010 */ 00011 00012 00013 #ifndef _STRINGQUERY_HPP 00014 #define _STRINGQUERY_HPP 00015 00016 00017 #include "Document.hpp" 00018 #include "RetrievalMethod.hpp" 00019 00021 class StringTokenTerm : public TokenTerm { 00022 public: 00023 StringTokenTerm(char * tokterm) { term = strdup(tokterm); } 00024 ~StringTokenTerm() { free(term); } 00025 virtual const char * spelling() { return term; } 00026 private: 00027 char * term; 00028 }; 00029 00031 class StringQuery : public Query { 00032 public: 00033 StringQuery(char * qid, char * qry) { 00034 if (qid != NULL) { 00035 tid = strdup(qid); 00036 } else { 00037 tid = NULL; 00038 } 00039 if (qry != NULL) { 00040 query = strdup(qry); 00041 } else { 00042 query = NULL; 00043 } 00044 } 00045 virtual ~StringQuery() { 00046 free(tid); 00047 free(query); 00048 } 00049 virtual char * id() { return tid; } 00050 virtual void startTermIteration() { 00051 current = strtok(query, " "); 00052 } 00053 virtual bool hasMore() { 00054 if (current == NULL) { 00055 return false; 00056 } 00057 return true; 00058 } 00059 virtual TokenTerm * nextTerm() { 00060 if (!hasMore()) { 00061 return NULL; 00062 } 00063 TokenTerm * term = new StringTokenTerm(current); 00064 current = strtok(NULL, " "); 00065 return term; 00066 } 00067 protected: 00068 char * tid; 00069 char * query; 00070 char * current; 00071 }; 00072 00073 00074 00075 #endif