Skip to content
Snippets Groups Projects
Commit 75780d20 authored by Nicholas Yang's avatar Nicholas Yang
Browse files

Merge remote-tracking branch 'origin/indexer' into indexer

parents 7dea3986 d45939c2
No related branches found
No related tags found
1 merge request!1Add makefile for everyone and tests for the indexer
Makefile 0 → 100644
# the compiler: gcc for C program, define as g++ for C++
CC = g++
# compiler flags:
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
CFLAGS = -std=c++11 -c
# the build target executable:
TARGET = indexer/tests/test
all: $(TARGET)
$(TARGET): $(TARGET).cpp
$(CC) $(CFLAGS) $(TARGET).cpp -o $(TARGET)
clean:
$(RM) $(TARGET)
test:
make all
chmod a+x indexer/tests/test
./indexer/tests/test indexer/tests/source/test1.txt > indexer/tests/source/test1out.txt
diff test1out.txt test1.out.correct.txt
......@@ -27,6 +27,18 @@ void Indexer::run() {
save();
}
void Indexer::verbose_run() {
while(pointerToDictionaries.Size() != 0) {
unordered_map<string, vector<int>> dictionary = *pointerToDictionaries.Pop();
for(auto word : dictionary) {
for(auto location : word.second) {
indexedCount++;
masterDictionary[word.first].push_back(location);
}
}
}
}
void Indexer::save() {
map<string, vector<size_t> > maps(masterDictionary.begin(), masterDictionary.end());
string fileName = "index" + to_string(currentFile) + ".txt";
......@@ -42,7 +54,19 @@ void Indexer::save() {
}
close(file);
currentFile++;
}
}
void Indexer::verbose_save() {
map<string, vector<size_t> > maps(masterDictionary.begin(), masterDictionary.end());
for(auto word : maps) {
cout << word.first << endl;
for(auto location : word.second) {
cout << location << " ";
}
cout << endl;
}
currentFile++;
}
void Indexer::reset() {
masterDictionary.clear();
......
#ifndef indexer_h
#define indexer_h
#include "../ProducerConsumerQueue.h"
#include "../ProducerConsumerQueue.cpp"
#include <unordered_map>
......@@ -8,6 +10,7 @@
#include <fcntl.h>
#include <unistd.h>
/*
Objective: Pulls small dictionaries from the parser and merges them into the
......@@ -20,8 +23,10 @@ using namespace std;
class Indexer {
public:
Indexer();
void run();
ProducerConsumerQueue<unordered_map<string, vector<int> >*> pointerToDictionaries;
void run();
void verbose_run();
void verbose_save();
ProducerConsumerQueue<unordered_map<string, vector<int> > * > pointerToDictionaries;
private:
void save();
void reset();
......@@ -30,4 +35,6 @@ class Indexer {
size_t currentFile;
size_t totalIndexed;
size_t currentlyIndexed;
};
\ No newline at end of file
};
#endif /*indexer_h*/
and
34 36
anticipated
13
are
15 31
back
17
been
39
better
11
companies
14
country
20
cut
41
economy
2
even
10
good
6
great
33
have
38
in
7
into
18
is
3
jobs
42 43 44
leaving
27
long
23
looking
4 32
massively
40
my
8
numbers
30
of
26
opinion
9
our
19
pouring
16
regulations
35
reversing
21
taxes
37
term
24
than
12
the
0 22 28
trend
25
unemployment
29
us
1
very
5
\ No newline at end of file
The U.S. economy is looking very good, in my opinion,
even better than anticipated. Companies are pouring back into our country,
reversing the long term trend of leaving. The unemployment numbers are looking great,
and Regulations and Taxes have been massively Cut! JOBS, JOBS, JOBS
\ No newline at end of file
File added
//
// Created by Zane Dunnings on 2/19/18.
//
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include "../Indexer.h"
using namespace std;
int main( int argc, char *argv[]) {
Indexer indexer = Indexer();
unordered_map<string, vector<int> > test1;
ifstream ifstream1(argv[ 1 ]);
string word = "";
int id = 0;
while(ifstream1 >> word) {
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
word.erase(remove_if(word.begin(), word.end(), [](char c) { return !isalpha(c); } ), word.end());
if(word != "")
test1[word].push_back(id);
id++;
}
indexer.pointerToDictionaries.Push(&test1);
indexer.verbose_run();
indexer.verbose_save();
cout << "congrats!";
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment