/// <summary> /// Get all operators from user input text. /// </summary> /// <param name="userInputText">User input text.</param> /// <param name="invertedIndex">The inverted index that we are going to run operators on it.</param> /// <returns>List of all operators order by priority.</returns> public static List <IOperator> GetAllOperators(string userInputText, InvertedIndex invertedIndex) { var operatorExtractor = new OperatorExtractor(userInputText); var operators = new List <IOperator>(); while (!operatorExtractor.EndOfText()) { operators.Add(operatorExtractor.GetNextOperator(invertedIndex)); } return(operators.OrderBy(op => op.Priority).ToList()); }
public List <string> Filter(List <string> inputList) { if (inputList == null || inputList.Count == 0) { return(new List <string>()); } var tokenDocumentIDs = new List <string>(); InvertedIndex.TryGetTokenDocumentIDs(Token, out tokenDocumentIDs); inputList.RemoveAll(item => tokenDocumentIDs.Contains(item)); return(inputList); }
/// <summary> /// Get next operator from user input text. /// </summary> /// <param name="invertedIndex">The inverted index that we are going to run operators on it.</param> /// <returns>Next operator from user Input text.</returns> public IOperator GetNextOperator(InvertedIndex invertedIndex) { var operatorToken = tokens[pointer++]; switch (operatorToken[0]) { case '+': return(new Or(operatorToken.Substring(1), invertedIndex)); case '-': return(new Not(operatorToken.Substring(1), invertedIndex)); default: return(new And(operatorToken, invertedIndex)); } }
public List <string> Filter(List <string> inputList) { if (inputList == null || inputList.Count == 0) { return(new List <string>()); } List <string> tokenDocumentIDs; if (InvertedIndex.TryGetTokenDocumentIDs(Token, out tokenDocumentIDs)) { return(inputList.Intersect(tokenDocumentIDs).ToList()); } return(new List <string>()); }
public List <string> Filter(List <string> inputList) { if (inputList == null) { inputList = new List <string>(); } List <string> tokenDocuments; if (InvertedIndex.TryGetTokenDocumentIDs(Token, out tokenDocuments)) { inputList = inputList.Union(tokenDocuments).ToList(); } return(inputList); }
static void Main(string[] args) { IUserInterface ui = new ConsoleUI(); var dataPath = ui.UserDataPath; var fileReader = new FileReader(dataPath); var directoryData = fileReader.GetRawData(); var invertedIndex = new InvertedIndex(); foreach (KeyValuePair <string, string> pair in directoryData) { invertedIndex.InsertDatas(Tokenizer.GetAllTokens(pair.Key, pair.Value)); } var userInputText = ui.UserInput; var operators = OperatorExtractor.GetAllOperators(userInputText, invertedIndex); var result = new Searcher().RunOperators(operators); ui.ShowOutput(result); }
public And(string token, InvertedIndex invertedIndex) { Token = token; InvertedIndex = invertedIndex; }