Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eecs398-search
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vcday
eecs398-search
Commits
93aef450
Commit
93aef450
authored
7 years ago
by
vcday
Browse files
Options
Downloads
Patches
Plain Diff
added parser.cpp
parent
5d2dea33
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
Parser.cpp
+127
-0
127 additions, 0 deletions
Parser.cpp
with
130 additions
and
0 deletions
.gitignore
0 → 100644
+
3
−
0
View file @
93aef450
.idea/
CMakeLists.txt
cmake-build-debug/
This diff is collapsed.
Click to expand it.
Parser.cpp
0 → 100644
+
127
−
0
View file @
93aef450
//
// Created by Veronica Day on 1/28/18.
//
#include
<string>
#include
<functional>
#include
<queue>
#include
<iostream>
#include
<fstream>
using
namespace
std
;
// Doc Id
std
::
priority_queue
<
int
>
DOCID_PQ
;
std
::
priority_queue
<
string
>
URL_PQ
;
string
PATH
=
"/doc"
;
//TODO
// get doc id from DocIDqueue (sent from crawler)
// go to disk and get the HTML file
// parse the html file
// if find url; send to crawler
// if find title send string to tokenizer
class
Parser
{
public:
/**
* Parser
* @return
*/
string
execute
()
{
ifstream
inFile
;
string
docid
=
to_string
(
DOCID_PQ
.
top
());
inFile
.
open
(
PATH
+
docid
);
// error checking
if
(
!
inFile
)
cerr
<<
"Unable to open file datafile.txt"
;
parse
(
inFile
);
//TODO
// close file and remove
}
private
:
/**
* Parses file
* @param inFile
* @return
*/
string
parse
(
ifstream
inFile
)
{
string
word
=
""
;
while
(
!
inFile
.
eof
())
{
inFile
>>
word
;
// checks for url
check_url
(
word
);
// checks for title tags
Tokenizer
.
execute
(
check_title
(
word
));
}
}
/**
* Checks for url in string word
* @param word
*/
void
check_url
(
string
&
word
)
{
if
(
char
*
pos
=
strstr
(
"href"
,
word
))
{
while
(
pos
!=
"
\"
"
&&
pos
!=
"
\'
"
)
++
pos
;
// take everything until next quote
string
url
=
""
;
++
pos
;
while
(
pos
!=
"
\"
"
&&
pos
!=
"
\'
"
)
{
url
+=
*
pos
;
}
// send it back to the crawler
URL_PQ
.
push
(
url
);
}
}
/**
* <title >AJF</title>
* @param word
*/
string
check_title
(
string
&
word
)
{
if
(
char
*
pos
=
strstr
(
"<title>"
,
word
))
{
pos
+=
6
;
end_pos
=
strstr
(
"</title>"
,
word
);
string
title
=
""
;
while
(
pos
!=
end_pos
)
{
++
pos
;
title
+=
*
pos
;
}
return
title
;
}
}
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment