-
Notifications
You must be signed in to change notification settings - Fork 33
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
PySpark support for core AUT functionality. #12, #13. #100
Closed
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4b46c1f
copy over scala code to new directory for pyspark
23129e8
Merge remote-tracking branch 'upstream/master'
2ea2d69
add pyspark files
d1b2659
add spark-sql_2.11 dependency to pom.xml
6d940ce
Merge remote-tracking branch 'upstream/master'
f871b40
delete aut/python directory
7d1be99
add python files
8e2e436
remove extraneous pyspark directory
a40d93e
add RecordLoaderPythonHelper.scala
1133c9f
Merge remote-tracking branch 'upstream/master'
e1b1ad4
remove runpyspark script
bfb2678
fix some typos and add two example scripts
c8a29f8
delete some commented out code
b8629ea
remove unneeded TODOs
1845d34
remove python scripts
a6de005
Merge remote-tracking branch 'upstream/master'
ed1bd88
remove loadArc and loadWarc
79e7475
Removes old RecordRDD call
ianmilligan1 7118169
Updated urlparse call for Python 3 support
ianmilligan1 e292af2
Merge branch 'master' into master
greebie bafa23f
- Remove errant type reference in DetectLanguage
greebie 8c5fb17
Merge branch 'master' into master
greebie 9731e25
Fix bug with keepContent using re.search instead re.match.
greebie f9fa7ab
Merge branch 'master' of https://github.com/MapleOx/aut
greebie 9e23524
Swapped match for search in DFTransformations.py
ianmilligan1 d3859c2
Include git search instead of replace on RowTransformations as well.
greebie 58fb708
removed _java2py import
ianmilligan1 c569d6a
Merge branch 'master' into master
greebie 85fade6
Merge remote-tracking branch 'upstream/master'
ianmilligan1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Archives Unleashed Toolkit (AUT): | ||
# An open-source platform 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. | ||
|
||
import RecordLoader | ||
from DFTransformations import * | ||
from ExtractDomain import ExtractDomain | ||
from ExtractLinks import ExtractLinks | ||
from pyspark.sql import SparkSession | ||
|
||
if __name__ == "__main__": | ||
# replace with your own path to archive file | ||
path = "/Users/Prince/Projects/pyaut/aut/example.arc.gz" | ||
|
||
spark = SparkSession.builder.appName("extractLinks").getOrCreate() | ||
sc = spark.sparkContext | ||
|
||
rdd = RecordLoader.loadArchivesAsRDD(path, sc, spark) | ||
rdd1 = rdd.flatMap(lambda r: ExtractLinks(r.url, r.contentString)) | ||
rdd2 = rdd1.map(lambda r: (ExtractDomain(r[0]), ExtractDomain(r[1]))) | ||
rdd3 = rdd2.filter(lambda r: r[0] is not None and r[0]!= "" and r[1] is not None and r[1] != "") | ||
rdd4 = countItems(rdd3).filter(lambda r: r[1] > 5) | ||
|
||
print(rdd4.take(10)) | ||
|
||
spark.stop() |
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,37 @@ | ||
# Archives Unleashed Toolkit (AUT): | ||
# An open-source platform 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. | ||
|
||
import RecordLoader | ||
from DFTransformations import * | ||
from ExtractDomain import ExtractDomain | ||
from ExtractLinks import ExtractLinks | ||
from ExtractDate import DateComponent | ||
from RemoveHTML import RemoveHTML | ||
from pyspark.sql import SparkSession | ||
|
||
if __name__ == "__main__": | ||
# replace with your own path to archive file | ||
path = "/Users/Prince/Projects/pyaut/aut/example.arc.gz" | ||
|
||
spark = SparkSession.builder.appName("filterByDate").getOrCreate() | ||
sc = spark.sparkContext | ||
|
||
df = RecordLoader.loadArchivesAsDF(path, sc, spark) | ||
filtered_df = keepDate(df, "2008", DateComponent.YYYY).filter(df['url'].like("%archive%")) | ||
rdd = filtered_df.rdd | ||
rdd.map(lambda r: (r.crawlDate, r.domain, r.url, RemoveHTML(r.contentString))) \ | ||
.saveAsTextFile("out/") | ||
|
||
spark.stop() |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't remember if there is an equivalent to the Resource Scala library for Python (Resource has a tool to finds paths in the package). It would be better for unit testing / coverage. If not, we could also move this script to aut-docs as we did with the Scala scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the scripts were just to give some examples of how to use AUT in PySpark, and it doesn't really matter where the scripts are located. I just put them under aut for convenience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would push this down to the loader. Add an option to keep only valid pages, which is always true by default. So
load('path')
would be the default form, which is reallyload('path', true)
- the user can suppress withload('path', false)
if they really want all the crap...