-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add office document binary extraction.
- Add WordProcessor DF and binary extraction - Add Spreadsheets DF and binary extraction - Add Presentation Program DF and binary extraction - Add tests for new DF and binary extractions - Add test fixture for new DF and binary extractions - Resolves #303 - Resolves #304 - Resolves #305 - Back out 39831c2 (We _might_ not have to do this)
- Loading branch information
Showing
6 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
72 changes: 72 additions & 0 deletions
72
src/test/scala/io/archivesunleashed/df/ExtractPresentationProgramDetailsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Archives Unleashed Toolkit (AUT): | ||
* An open-source toolkit for analyzing web archives. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.archivesunleashed | ||
|
||
import com.google.common.io.Resources | ||
import org.apache.spark.sql.SparkSession | ||
// scalastyle:off underscore.import | ||
import io.archivesunleashed.df._ | ||
import org.apache.spark.sql.functions._ | ||
// scalastyle:on underscore.import | ||
import org.apache.spark.{SparkConf, SparkContext} | ||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.{BeforeAndAfter, FunSuite} | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class ExtractPresentationProgramDetailsTest extends FunSuite with BeforeAndAfter { | ||
private val warcPath = Resources.getResource("warc/example.docs.warc.gz").getPath | ||
private val master = "local[4]" | ||
private val appName = "example-df" | ||
private var sc: SparkContext = _ | ||
|
||
before { | ||
val conf = new SparkConf() | ||
.setMaster(master) | ||
.setAppName(appName) | ||
sc = new SparkContext(conf) | ||
} | ||
|
||
test("Word Processor DF extraction") { | ||
val df = RecordLoader.loadArchives(warcPath, sc) | ||
.extractPresentationProgramDetailsDF() | ||
|
||
val extracted = df.select("url", "filename", "extension", | ||
"mime_type_web_server", "mime_type_tika", "md5") | ||
.orderBy(desc("md5")).head(2).toList | ||
assert(extracted.size == 2) | ||
assert("https://ruebot.net/files/aut-test-fixtures/aut-test-fixtures.odp" == extracted(0)(0)) | ||
assert("aut-test-fixtures.odp" == extracted(0)(1)) | ||
assert("odp" == extracted(0)(2)) | ||
assert("application/vnd.oasis.opendocument.presentation" == extracted(0)(3)) | ||
assert("application/vnd.oasis.opendocument.presentation" == extracted(0)(4)) | ||
assert("f38b2679029cf3453c8151b92c615c70" == extracted(0)(5)) | ||
assert("https://ruebot.net/files/aut-test-fixtures/aut-test-fixtures.pptx" == extracted(1)(0)) | ||
assert("aut-test-fixtures.pptx" == extracted(1)(1)) | ||
assert("pptx" == extracted(1)(2)) | ||
assert("application/vnd.openxmlformats-officedocument.presentationml.presentation" == extracted(1)(3)) | ||
assert("application/vnd.openxmlformats-officedocument.presentationml.presentation" == extracted(1)(4)) | ||
assert("7a7b1fe4b6d311376eaced9de3b682ee" == extracted(1)(5)) | ||
} | ||
|
||
after { | ||
if (sc != null) { | ||
sc.stop() | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/test/scala/io/archivesunleashed/df/ExtractSpreadsheetDetailsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Archives Unleashed Toolkit (AUT): | ||
* An open-source toolkit for analyzing web archives. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.archivesunleashed | ||
|
||
import com.google.common.io.Resources | ||
import org.apache.spark.sql.SparkSession | ||
// scalastyle:off underscore.import | ||
import io.archivesunleashed.df._ | ||
import org.apache.spark.sql.functions._ | ||
// scalastyle:on underscore.import | ||
import org.apache.spark.{SparkConf, SparkContext} | ||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.{BeforeAndAfter, FunSuite} | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class ExtractSpreadsheetDetailsTest extends FunSuite with BeforeAndAfter { | ||
private val warcPath = Resources.getResource("warc/example.docs.warc.gz").getPath | ||
private val master = "local[4]" | ||
private val appName = "example-df" | ||
private var sc: SparkContext = _ | ||
|
||
before { | ||
val conf = new SparkConf() | ||
.setMaster(master) | ||
.setAppName(appName) | ||
sc = new SparkContext(conf) | ||
} | ||
|
||
test("Spreadsheet DF extraction") { | ||
val df = RecordLoader.loadArchives(warcPath, sc) | ||
.extractSpreadsheetDetailsDF() | ||
|
||
val extracted = df.select("url", "filename", "extension", | ||
"mime_type_web_server", "mime_type_tika", "md5") | ||
.orderBy(desc("md5")).head(4).toList | ||
assert(extracted.size == 4) | ||
assert("https://ruebot.net/files/aut-test-fixtures/test-aut-fixture.xlsx" == extracted(0)(0)) | ||
assert("test-aut-fixture.xlsx" == extracted(0)(1)) | ||
assert("xlsx" == extracted(0)(2)) | ||
assert("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" == extracted(0)(3)) | ||
assert("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" == extracted(0)(4)) | ||
assert("befb3304cb592e0761509bf626171071" == extracted(0)(5)) | ||
assert("https://ruebot.net/files/aut-test-fixtures/test-aut-fixture%20-%20Sheet1.tsv" == extracted(1)(0)) | ||
assert("test-aut-fixture%20-%20Sheet1.tsv" == extracted(1)(1)) | ||
assert("tsv" == extracted(1)(2)) | ||
assert("text/tab-separated-values" == extracted(1)(3)) | ||
assert("text/plain" == extracted(1)(4)) | ||
assert("8ce6e9489c1c1129cca0e3f1eb8206ce" == extracted(1)(5)) | ||
assert("https://ruebot.net/files/aut-test-fixtures/test-aut-fixture.ods" == extracted(2)(0)) | ||
assert("test-aut-fixture.ods" == extracted(2)(1)) | ||
assert("ods" == extracted(2)(2)) | ||
assert("application/vnd.oasis.opendocument.spreadsheet" == extracted(2)(3)) | ||
assert("application/vnd.oasis.opendocument.spreadsheet" == extracted(2)(4)) | ||
assert("7f70280757d8beb2d1bfd6fb1b6ae6e9" == extracted(2)(5)) | ||
assert("https://ruebot.net/files/aut-test-fixtures/test-aut-fixture%20-%20Sheet1.csv" == extracted(3)(0)) | ||
assert("test-aut-fixture%20-%20Sheet1.csv" == extracted(3)(1)) | ||
assert("csv" == extracted(3)(2)) | ||
assert("text/csv" == extracted(3)(3)) | ||
assert("text/plain" == extracted(3)(4)) | ||
assert("38c3a488b239ec7b9b8e377b78968ef5" == extracted(3)(5)) | ||
|
||
} | ||
|
||
after { | ||
if (sc != null) { | ||
sc.stop() | ||
} | ||
} | ||
} |
Oops, something went wrong.