Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80324877
ExtractTopLevelDomain.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 04:04
Size
1 KB
Mime Type
text/x-java
Expires
Mon, Sep 2, 04:04 (2 d)
Engine
blob
Format
Raw Data
Handle
20342829
Attached To
R1473 warcbase
ExtractTopLevelDomain.java
View Options
package
org.warcbase.pig.piggybank
;
import
java.io.IOException
;
import
java.net.URL
;
import
org.apache.pig.EvalFunc
;
import
org.apache.pig.data.Tuple
;
/**
* UDF for extracting the top-level domain from an URL. Extracts the hostname from the first
* argument; if it's <code>null</code>, extracts the hostname from the second argument. The second
* argument is typically a source page, e.g., if the first URL is a relative URL, take the host from
* the source page.
*/
public
class
ExtractTopLevelDomain
extends
EvalFunc
<
String
>
{
public
String
exec
(
Tuple
input
)
throws
IOException
{
if
(
input
==
null
||
input
.
size
()
==
0
||
input
.
get
(
0
)
==
null
)
{
return
null
;
}
String
host
=
null
;
try
{
host
=
(
new
URL
((
String
)
input
.
get
(
0
))).
getHost
();
}
catch
(
Exception
e
)
{
// It's okay, just fall through here.
}
if
(
host
!=
null
||
(
host
==
null
&&
input
.
size
()
==
0
))
{
return
host
;
}
try
{
return
(
new
URL
((
String
)
input
.
get
(
1
))).
getHost
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
}
Event Timeline
Log In to Comment