Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtractBoilerpipeText to remove headers as well. #253 #256

Merged
merged 3 commits into from Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -28,12 +28,17 @@ object ExtractBoilerpipeText {
* @param input an html string possibly containing boilerpipe text
* @return text with boilerplate removed or Nil if the text is empty.
*/

def apply(input: String): String = {
val maybeInput = Option(input)
removeBoilerplate(RemoveHttpHeader(input))
}

private def removeBoilerplate(input: String): String = {
val maybeInput = Option(DefaultExtractor.INSTANCE
.getText(input).replaceAll("[\\r\\n]+", " ").trim())
maybeInput match {
case Some(text) =>
DefaultExtractor.INSTANCE
.getText(input).replaceAll("[\\r\\n]+", " ").trim()
text
case None =>
""
}
Expand Down
Expand Up @@ -25,6 +25,9 @@ import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class ExtractBoilerPipeTextTest extends FunSuite {
val header = "HTTP/1.0 200 OK Content-Type: text/html;" +
"charset=UTF-8 Expires: Fri, 20 Jul 2018 19:09:28 GMT Date:" +
"Fri, 20 Jul 2018 19:09:28 GMT Cache-Control: private,;\r\n\r\n"
var text = """<p>Text with a boiler plate.<p>
<footer>Copyright 2017</footer>"""
var boiler = """Copyright 2017"""
Expand All @@ -36,4 +39,8 @@ class ExtractBoilerPipeTextTest extends FunSuite {
// scalastyle:on null
assert(ExtractBoilerpipeText("All Rights Reserved.") == "")
}

test("Removes Header information") {
assert(ExtractBoilerpipeText(header + text) == boiler)
}
}