From 3fa996e1b8264fc296379963d119e385cc3edd4b Mon Sep 17 00:00:00 2001 From: bergkampben <benbergk@umich.edu> Date: Wed, 28 Mar 2018 18:14:12 -0400 Subject: [PATCH] made ISRWord inherit from base ISR --- CMakeLists.txt | 2 -- constraintSolver/ISR.h | 14 ++++----- constraintSolver/ISROr.cpp | 57 ++++++++++++++++++++++++------------ constraintSolver/ISROr.h | 23 ++++----------- constraintSolver/ISRWord.cpp | 32 ++++++++++++++++++-- constraintSolver/ISRWord.h | 21 +++++-------- 6 files changed, 87 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aebbb52..da93d71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,8 +140,6 @@ add_executable(ISRWord-tests util/stringProcessing.cpp util/Stemmer.cpp ) - - add_executable(ISROR-tests util/util.cpp constraintSolver/ISR.cpp diff --git a/constraintSolver/ISR.h b/constraintSolver/ISR.h index 148909d..b809687 100644 --- a/constraintSolver/ISR.h +++ b/constraintSolver/ISR.h @@ -19,29 +19,27 @@ class ISR { public: - // - ISR *DocumentEnd; - // Returns - virtual Location First ( ); + virtual Location First ( ) = 0; //Returns next post of a word given current location - virtual Location Next ( ); + virtual Location Next ( ) = 0; //Calls seek onto one past the current end doc location //Return first instance of word at new document - virtual Location NextDocument ( ); + virtual Location NextDocument ( ) = 0; //Returns first instance of word after target location - virtual Location Seek ( Location target ); + virtual Location Seek ( Location target ) = 0; //Returns the location of the end of the document - virtual Location GetEndDocument ( ); + virtual Location GetEndDocument ( ) = 0; Location currentLocation; + ISR *DocumentEnd; }; diff --git a/constraintSolver/ISROr.cpp b/constraintSolver/ISROr.cpp index 6a1aa56..e765d1e 100644 --- a/constraintSolver/ISROr.cpp +++ b/constraintSolver/ISROr.cpp @@ -21,23 +21,11 @@ Location ISROr::GetEndLocation ( ) } - - -Location ISROr::Seek ( Location target ) +Location ISROr::First() { - - // Seek all the ISRs to the first occurrence beginning at// the target location. Return null if there is no match. - // The document is the document containing the nearest term. - //seek past target locations, - //seek all terms in or past starting location, take the ones that nears - //the document that the nearest term is in is the document ur in - //updates private members - - - - - return 1; - + //Fixme + Location x; + return x; } /* @@ -48,21 +36,52 @@ Location ISROr::Next ( ) Location nearestEnd = this->nearestTerm->GetEndDocument( ); for(auto Term : Terms) - { + { Location newSeekLocation = Term->Seek( nearestEnd + 1 ); if ( newSeekLocation < nearestStartLocation ) - { + { nearestStartLocation = newSeekLocation; nearestTerm = Term; - } } + } return this->nearestTerm->currentLocation; + } +Location ISROr::NextDocument() + { + //Fixme + Location x; + return x; } +Location ISROr::Seek ( Location target ) + { + + // Seek all the ISRs to the first occurrence beginning at// the target location. Return null if there is no match. + // The document is the document containing the nearest term. + //seek past target locations, + //seek all terms in or past starting location, take the ones that nears + //the document that the nearest term is in is the document ur in + //updates private members + + + + + return 1; + + } + + +Location ISROr::GetEndDocument() + { + //Fixme + Location x; + return x; + } + /* ISR *ISROr::GetCurrentEndDoc ( ) { diff --git a/constraintSolver/ISROr.h b/constraintSolver/ISROr.h index 9486a3c..29d3b09 100644 --- a/constraintSolver/ISROr.h +++ b/constraintSolver/ISROr.h @@ -15,28 +15,17 @@ public: vector<ISR*>Terms; unsigned NumberOfTerms; + Location First ( ) override; + Location Next ( ) override; + Location NextDocument ( ) override; + Location Seek ( Location target ) override; + Location GetEndDocument ( ) override; + Location GetCurrentLocation(); Location GetStartLocation ( ); - Location GetEndLocation ( ); - Location Seek ( Location target ); - - //ISR *GetCurrentEndDoc ( ); - - - Location First ( ) ; - - Location Next ( ); - //{ Do a next on the nearest term, then return// the new nearest match.} - //next on nearest term, return nearest temr - - - Location NextDocument ( ); - // - // { Seek all the ISRs to the first occurrence just past the end of this document.returnSeek( DocumentEnd->GetEndLocation( ) + 1 );} - ISROr ( vector<ISR * > InputTerms ) : Terms( InputTerms ) { diff --git a/constraintSolver/ISRWord.cpp b/constraintSolver/ISRWord.cpp index 2c180c5..5d05848 100644 --- a/constraintSolver/ISRWord.cpp +++ b/constraintSolver/ISRWord.cpp @@ -8,8 +8,12 @@ size_t FileSize(int f) { return fileInfo.st_size; } -ISRWord::ISRWord ( char *word ) : term( word ) +ISRWord::ISRWord ( char *word ) { + + term = new char[strlen(word)]; + strcpy(term, word); + getChunks( ); currentChunk = 0; currentLocation = First( ); @@ -18,8 +22,15 @@ ISRWord::ISRWord ( char *word ) : term( word ) // put into util file vector<size_t> ISRWord::getSeekContents(string fileName) { int file = open(fileName.c_str(), O_RDONLY); - ssize_t fileSize = FileSize(file); - vector<size_t> contents; + vector<size_t> contents; + + if(file == -1) + { + cerr << "Was not able to open master index file"; + exit(1); + } + ssize_t fileSize = FileSize(file); + char* memMap = (char*) mmap(nullptr, fileSize, PROT_READ, MAP_PRIVATE, file, 0); @@ -207,3 +218,18 @@ Location ISRWord::Seek( Location target ) { } } + +Location ISRWord::NextDocument() + { + //FixMe + Location x; + return x; + } + +Location ISRWord::GetEndDocument() + { + //Fixme + Location x; + return x; + } + diff --git a/constraintSolver/ISRWord.h b/constraintSolver/ISRWord.h index b7a848d..788c911 100644 --- a/constraintSolver/ISRWord.h +++ b/constraintSolver/ISRWord.h @@ -1,6 +1,6 @@ #pragma once -//#include "ISR.h" +#include "ISR.h" #include <iostream> #include <vector> #include <fcntl.h> @@ -12,7 +12,7 @@ #include <sys/types.h> #include "WordSeek.h" #include "../util/util.h" -#include "ISR.h" + using namespace std; @@ -24,26 +24,21 @@ class ISRWord : public ISR public: ISRWord ( char *word ); + Location First ( ) override; + Location Next ( ) override; + Location NextDocument ( ) override; + Location Seek ( Location target ) override; + Location GetEndDocument ( ) override; + vector< size_t > getSeekContents ( string fileName ); unsigned GetDocumentCount ( ); unsigned GetNumberOfOccurrences ( ); - // ISR* DocumentEnd; - Location First ( ); - - Location Next ( ); - - Location nextDocument ( ); - - Location Seek ( Location target ); - // ISR *GetDocumentISR( ); - Location GetEndDocument ( ); - Location currentLocation; char *term; char *masterIndex; vector< size_t > listOfChunks; -- GitLab