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
a041c8ff
Commit
a041c8ff
authored
7 years ago
by
vcday
Browse files
Options
Downloads
Patches
Plain Diff
parser tests pass
parent
2ceeed1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
parser/Parser.h
+12
-6
12 additions, 6 deletions
parser/Parser.h
parser/tests/parserTest.cpp
+10
-21
10 additions, 21 deletions
parser/tests/parserTest.cpp
util/stringProcessing.h
+1
-1
1 addition, 1 deletion
util/stringProcessing.h
with
23 additions
and
28 deletions
parser/Parser.h
+
12
−
6
View file @
a041c8ff
...
...
@@ -59,12 +59,17 @@ private:
string
tokenizerInput
=
""
;
string
currentTerm
=
""
;
for
(
int
i
=
0
;
i
<
html
.
size
(
);
++
i
)
int
index
=
0
;
while
(
index
!=
html
.
size
())
{
while
(
html
.
at
(
i
)
!=
'\n'
)
currentTerm
=
""
;
while
(
html
.
at
(
index
)
!=
'\n'
)
{
currentTerm
+=
html
[
i
];
currentTerm
+=
html
[
index
];
++
index
;
}
++
index
;
string
url
=
extract_url
(
currentTerm
);
if
(
url
!=
""
)
...
...
@@ -121,14 +126,15 @@ private:
string
extract_title
(
string
&
word
)
{
string
title
=
""
;
char
end
=
'<'
;
auto
pos
=
findStr
(
"<title>"
,
word
);
if
(
*
pos
!=
'\0'
)
{
pos
+=
6
;
while
(
*
pos
!=
*
findStr
(
"</title>"
,
wor
d
)
)
pos
+=
7
;
while
(
*
pos
!=
en
d
)
{
++
pos
;
title
+=
*
pos
;
++
pos
;
}
}
return
title
;
...
...
This diff is collapsed.
Click to expand it.
parser/tests/parserTest.cpp
+
10
−
21
View file @
a041c8ff
...
...
@@ -15,30 +15,19 @@ int main ( )
{
cout
<<
"Testing Parser ... "
<<
endl
<<
endl
;
ProducerConsumerQueue
<
string
>
*
urlFrontierTest
;
Document
document
(
"<!DOCTYPE html>
\n
"
"<html>
\n
"
"<head>
\n
"
"<!-- HTML Codes by Quackit.com -->
\n
"
"<title>
\n
"
"Story of Cat</title>
\n
"
"<meta name=
\"
viewport
\"
content=
\"
width=device-width, initial-scale=1
\"
>
\n
"
"<meta name=
\"
keywords
\"
content=
\"
cat story
\"
>
\n
"
"<meta name=
\"
description
\"
content=
\"
This is the tale of a cat names joe
\"
>
\n
"
"<style>
\n
"
"body {background-color:#ffffff;background-repeat:no-repeat;background-position:top left;background-attachment:fixed;}
\n
"
"h1{font-family:Arial, sans-serif;color:#000000;background-color:#ffffff;}
\n
"
"p {font-family:Georgia, serif;font-size:14px;font-style:normal;font-weight:normal;color:#000000;background-color:#ffffff;}
\n
"
"</style>
\n
"
"</head>
\n
"
"<body>
\n
"
"<h1>Joe the cat</h1>
\n
"
"<p>On Saturday, joe the cat went to the store. He climbed up a mountain? It was weird. The store was called Food Store</p>
\n
"
"</body>
\n
"
"</html>"
);
Document
document
(
"<title>This Cat Title Cat</title>
\n
"
);
Parser
parser
(
urlFrontierTest
);
auto
dictionary
=
parser
.
execute
(
&
document
);
assert
(
dictionary
!=
nullptr
);
assert
(
dictionary
!=
nullptr
);
assert
(
dictionary
->
size
()
==
2
);
assert
(
dictionary
->
find
(
"cat"
)
!=
dictionary
->
end
()
);
assert
(
dictionary
->
find
(
"title"
)
!=
dictionary
->
end
()
);
assert
(
dictionary
->
find
(
"this"
)
==
dictionary
->
end
()
);
assert
(
dictionary
->
at
(
"cat"
)[
0
]
==
0
&&
dictionary
->
at
(
"cat"
)[
1
]
==
2
);
assert
(
dictionary
->
at
(
"title"
)[
0
]
==
1
);
cout
<<
"Parser Tests Passed! :D"
<<
endl
;
}
...
...
This diff is collapsed.
Click to expand it.
util/stringProcessing.h
+
1
−
1
View file @
a041c8ff
...
...
@@ -28,7 +28,7 @@ set< string > stopWords = { "a", "all", "an", "and", "any", "are", "as", "at", "
* @param needle
* @return
*/
string
::
iterator
findStr
(
string
haystack
,
string
needle
)
string
::
iterator
findStr
(
string
needle
,
string
haystack
)
{
auto
beginNeedle
=
needle
.
begin
(
);
...
...
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