From 3b687fe3bdc14e14cfd104710c873226764e6773 Mon Sep 17 00:00:00 2001 From: Zane Dunnings <zldunn@umich.edu> Date: Sat, 7 Apr 2018 15:22:17 -0400 Subject: [PATCH] changes to support nested OR --- CMakeLists.txt | 5 ++++ query/queryLanguage/QueryParser.cpp | 44 ++++++++--------------------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c5a680..f2c3b5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,11 @@ add_executable(query-Ranker-tests util/stringProcessing.cpp util/Stemmer.cpp ) +add_executable(query-queryLanguage-tests + query/queryLanguage/QueryParser.cpp + query/queryLanguage/QueryParser.h + ) + #find_package(OpenSSL REQUIRED) # #target_link_libraries(ParserTest OpenSSL::SSL) diff --git a/query/queryLanguage/QueryParser.cpp b/query/queryLanguage/QueryParser.cpp index e42ee1c..a89c5fc 100644 --- a/query/queryLanguage/QueryParser.cpp +++ b/query/queryLanguage/QueryParser.cpp @@ -2,13 +2,18 @@ // Created by Zane Dunnings on 3/16/18. // -//Outline of query language from Prof. Nicole Hamilton, University of Michigan 03/15/2018 -// 72 lines #include "QueryParser.h" #include<unordered_set> #include "../../util/stringProcessing.h" #include<iostream> - +/*** + * QUERY PARSER CLASS + * + * 1. Constraint() - CAll this at the highest level, will split on ORs if there are ORs at the highest level, + * Will split on AND if theres an AND at the highest level. b + * + * + */ /*** * Returns a token of the next word in the query, past the given index * @param index @@ -171,9 +176,9 @@ bool QueryParser::MatchAND( string input ) ORMatch.insert("AND"); ORMatch.insert("&"); ORMatch.insert("&&"); -3ww ORMatch.insert("and"); + ORMatch.insert("and"); - if( 3ORMatch.count( input ) > 0 ) + if( ORMatch.count( input ) > 0 ) { return true; } @@ -195,6 +200,8 @@ Tuple* QueryParser::Constraint( string input ) t->Type = OrTupleType; else t->Type = AndTupleType; + Tuple* toBeKilled = constraintList[ 0 ]; + constraintList = breakOnAND ( input ); t->Next = constraintList; //Iterate through the subcontraints and if there are ORs, then run this again, else split on and for each @@ -255,33 +262,6 @@ vector<Tuple * > QueryParser::breakOnOR( string input ) if( query[ i ] == "(") { ++depth; -// ++depth; -// ++i; -// start = i; -// while(depth != 0 && ( i < query.size()) ) -// { -// if (query[ i ] == "(") -// ++depth; -// else if (query[ i ] == ")") -// --depth; -// if (depth == 0) -// { -// --i; -// break; -// } -// else -// ++i; -// } -// if (i == query.size()) -// i = query.size() - 1; -// string text = ""; -// for ( int j = start; j < i; ++ j) -// { -// text+= query[ j ]; -// } -// Tuple * t = new Tuple( text ); -// constraintList.push_back( t ); -// t->Type = AndTupleType; } else if( query[ i ] == ")") { -- GitLab