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

Filter or filedesc and dns records from arcs. #517

Merged
merged 1 commit into from
May 12, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/main/scala/io/archivesunleashed/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,20 @@ package object archivesunleashed {
/* Creates a column for Bytes as well in Dataframe.
Call KeepImages OR KeepValidPages on RDD depending upon the requirement before calling this method */
def all(): DataFrame = {
val records = rdd.map(r =>
Row(
r.getCrawlDate,
r.getUrl,
r.getMimeType,
DetectMimeTypeTika(r.getBinaryBytes),
r.getContentString,
r.getBinaryBytes,
r.getHttpStatus,
r.getArchiveFilename
val records = rdd
.removeFiledesc()
.map(r =>
Row(
r.getCrawlDate,
r.getUrl,
r.getMimeType,
DetectMimeTypeTika(r.getBinaryBytes),
r.getContentString,
r.getBinaryBytes,
r.getHttpStatus,
r.getArchiveFilename
)
)
)

val schema = new StructType()
.add(StructField("crawl_date", StringType, true))
Expand All @@ -192,6 +194,14 @@ package object archivesunleashed {
sqlContext.getOrCreate().createDataFrame(records, schema)
}

/** Filters out filedesc:// and dns: records. */
def removeFiledesc(): RDD[ArchiveRecord] = {
rdd.filter(r =>
!r.getUrl.toLowerCase.startsWith("filedesc:")
&& !r.getUrl.toLowerCase.startsWith("dns:")
)
}

/** Removes all non-html-based data (images, executables, etc.) from html text. */
def keepValidPages(): RDD[ArchiveRecord] = {
rdd.filter(r =>
Expand All @@ -208,6 +218,7 @@ package object archivesunleashed {
/** Extracts webpages with columns for crawl data, url, MIME type, and content. */
def webpages(): DataFrame = {
val records = rdd
.removeFiledesc()
.keepValidPages()
.map(r =>
Row(
Expand Down Expand Up @@ -235,6 +246,7 @@ package object archivesunleashed {
/** Extracts a webgraph with columns for crawl date, source url, destination url, and anchor text. */
def webgraph(): DataFrame = {
val records = rdd
.removeFiledesc()
.keepValidPages()
.flatMap(r =>
ExtractLinks(r.getUrl, r.getContentString)
Expand All @@ -256,6 +268,7 @@ package object archivesunleashed {
/* Extracts all the images links from a source page. */
def imagegraph(): DataFrame = {
val records = rdd
.removeFiledesc()
.keepValidPages()
.flatMap(r =>
ExtractImageLinks(r.getUrl, r.getContentString)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/io/archivesunleashed/RecordDFTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RecordDFTest extends FunSuite with BeforeAndAfter {
import spark.implicits._
// scalastyle:on

val expected = "000"
val expected = "200"
val base = RecordLoader
.loadArchives(arcPath, sc)
.all()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DataFrameLoaderTest extends FunSuite with BeforeAndAfter {

val r_11 = all.select(url, mime_type).take(1)(0)
assert(
r_11.getAs[String](url) == "filedesc://IAH-20080430204825-00000-blackbook.arc"
r_11.getAs[String](url) == "http://www.archive.org/robots.txt"
)
assert(r_11.getAs[String](mime_type) == "text/plain")
}
Expand Down