61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
/**
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_CORE_FILTER_H
|
|
#define OCARINA_CORE_FILTER_H
|
|
|
|
#include <set>
|
|
#include <string>
|
|
|
|
/**
|
|
* The filter layer is used to find a subset of songs based on an input
|
|
* string. Since this layer does text processing, it also provides a
|
|
* functions for converting strings to lowercase.
|
|
*
|
|
* The text processing is mostly interested in alphanumeric characters, so
|
|
* any special characters included in the input text will be stripped out.
|
|
* Tabs, spaces and the following characters are used to delimit words:
|
|
*
|
|
* \/,;()_-~+"
|
|
*/
|
|
namespace filter {
|
|
|
|
/**
|
|
* Convert the key to lowercase and break into individual words.
|
|
* Generate substrings for each word and add each (substring, index)
|
|
* pair to the Index.
|
|
*
|
|
* To generate substrings: iterate over the word starting from the
|
|
* first character, and append a character for every iteration. For
|
|
* example, the word "goron" would contain the substrings:
|
|
* { g, go, gor, goro, goron }.
|
|
*
|
|
* @param text The text to parse.
|
|
* @param index The track index to pair with the text.
|
|
* @return The lowercase form of the input text.
|
|
*/
|
|
const std::string add(const std::string &, unsigned int);
|
|
|
|
/**
|
|
* Break the input text into lowercase words and search the Index
|
|
* for matches. The results set should be filled out with the
|
|
* intersection of the IndexEntry for each word. If any word does
|
|
* not appear in the index, then the result set should be empty.
|
|
*
|
|
* @param text The text to search for.
|
|
* @param res The results set to fill in with matching indexes.
|
|
*/
|
|
void search(const std::string &, std::set<unsigned int> &);
|
|
|
|
/**
|
|
* Converts the input text to lowercase and returns the result.
|
|
*
|
|
* @param text The text to be converted.
|
|
* @return The lowercase form of the input text.
|
|
*/
|
|
std::string lowercase(const std::string &);
|
|
|
|
};
|
|
|
|
#endif /* OCARINA_CORE_FILTER_H */
|