-
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.
Browse files
Browse the repository at this point in the history
* DataFrameLoader - provides bridge to PySpark. * Initial python classes for aut. * Better packaging of Python modules.
- Loading branch information
Showing
6 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> | ||
<id>python</id> | ||
<formats> | ||
<format>zip</format> | ||
</formats> | ||
<fileSets> | ||
<fileSet> | ||
<directory>src/main/python/aut/</directory> | ||
<outputDirectory>/</outputDirectory> | ||
</fileSet> | ||
</fileSets> | ||
</assembly> |
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,5 @@ | ||
from aut.common import WebArchive | ||
from aut.udfs import extract_domain | ||
|
||
__all__ = ['WebArchive', 'extract_domain'] | ||
|
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,15 @@ | ||
from pyspark.sql import DataFrame | ||
|
||
class WebArchive: | ||
def __init__(self, sc, sqlContext, path): | ||
self.sc = sc | ||
self.sqlContext = sqlContext | ||
self.loader = sc._jvm.io.archivesunleashed.DataFrameLoader(sc._jsc.sc()) | ||
self.path = path | ||
|
||
def pages(self): | ||
return DataFrame(self.loader.extractValidPages(self.path), self.sqlContext) | ||
|
||
def links(self): | ||
return DataFrame(self.loader.extractHyperlinks(self.path), self.sqlContext) | ||
|
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,11 @@ | ||
from pyspark.sql.functions import udf | ||
from pyspark.sql.types import StringType | ||
|
||
def extract_domain_func(url): | ||
url = url.replace('http://', '').replace('https://', '') | ||
if '/' in url: | ||
return url.split('/')[0].replace('www.', '') | ||
else: | ||
return url.replace('www.', '') | ||
|
||
extract_domain = udf(extract_domain_func, StringType()) |
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,16 @@ | ||
package io.archivesunleashed | ||
|
||
import org.apache.spark.SparkContext | ||
import org.apache.spark.sql._ | ||
|
||
class DataFrameLoader(sc: SparkContext) { | ||
def extractValidPages(path: String): DataFrame = { | ||
RecordLoader.loadArchives(path, sc) | ||
.extractValidPagesDF() | ||
} | ||
|
||
def extractHyperlinks(path: String): DataFrame = { | ||
RecordLoader.loadArchives(path, sc) | ||
.extractHyperlinksDF() | ||
} | ||
} |