2014-11-04 6 views
2

나는 내부 트윗에서 이미지 URL을 캡처하려고합니다.돼지 일치 정규식 문자열 일치

REGISTER 'hdfs:///user/cloudera/elephant-bird-pig-4.1.jar'; 
REGISTER 'hdfs:///user/cloudera/elephant-bird-core-4.1.jar'; 
REGISTER 'hdfs:///user/cloudera/elephant-bird-hadoop-compat-4.1.jar'; 

--Load Json 

loadJson = LOAD '/user/cloudera/tweetwall' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS (json:map []); 
B = FOREACH loadJson GENERATE flatten(json#'tweets') as (m:map[]); 
tweetText = FOREACH B GENERATE FLATTEN(m#'text') as (str:chararray); 

중간 날짜는 다음과 같습니다

(@somenameontwitter your nan makes me laugh with some of the things she comes out with like http://somepics.com/my.jpg) 

후 나는 다시에만 이미지 URL 얻으려면 다음을 수행하십시오 :

x = foreach tweetText generate REGEX_EXTRACT_ALL(str, '((http)(.*)(.jpg|.bmp|.png))'); 

dump x; 

을하지만이 작동하지 않는 것 . 나는 또한 아무 소용이 필터로 노력 해왔다. 로 위의 노력에도

는. *는 (빈 결과를 반환) 또는 내가 간단하게 뭔가를 누락 것을 할 수 있도록 (())는

나는 돼지에 정규식 꽤 새로운 좋은 아니에요 여기 나는 그냥 보지 않고있다.

갱신

예를 들어, 입력 데이터

{"tweets":[{"created_at":"Sat Nov 01 23:15:45 +0000 2014","id":5286804225,"id_str":"5286864225","text":"@Beace_ your nan makes me laugh with some of the things she comes out with blabla http://t.co/b7hjMWNg is an url, but not a valid one http://www.something.com/this.jpg should be a valid url","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":52812992878592,"in_reply_to_status_id_str":"522","in_reply_to_user_id":398098,"in_reply_to_user_id_str":"3","in_reply_to_screen_name":"Be_","user":{"id":425,"id_str":"42433395","name":"SAINS","screen_name":"sa3","location":"Lincoln","profile_location":null,"description":"","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":92,"friends_count":526,"listed_count":0,"created_at":"Mon May 25 16:18:05 +0000 2009","favourites_count":6,"utc_offset":0,"time_zone":"London","geo_enabled":true,"verified":false,"statuses_count":19,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"EDECE9","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/52016\/DGDCj67z_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/526\/DGDCj67z_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/424395\/13743515","profile_link_color":"088253","profile_sidebar_border_color":"D3D2CF","profile_sidebar_fill_color":"E3E2DE","profile_text_color":"634047","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":1,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"e_","name":"\u2601\ufe0f effy","id":3998,"id_str":"398","indices":[0,15]}],"urls":[]},"favorited":false,"retweeted":false,"lang":"en"}]} 
+0

각 트윗 오른쪽에서 이미지 URL을 추출 하시겠습니까? 즉, 최종 출력물은 "http://somepics.com/my.jpg"이어야합니까? –

+0

맞습니다. 그게 저에게 다소 좋은 결과를주는 – Havnar

답변

0

를 작동하는 경우에 나는 그것이 작동 얻을 관리 알려주세요 최적)

x = foreach tweetText generate REGEX_EXTRACT(str,'(http://.*(.jpg|.bmp|.png))',1) as image; 


filtered = FILTER x BY $0 is not null; 


dump filtered; 

그래서 초기 문제는 정규식 (그리고 주제에 대한 지식 부족)이었습니다.

감사합니다. sivasakthi jayaraman!

1

이 시도하고 나는 그것이 전혀 의심하지만 (이

x = foreach tweetText generate REGEX_EXTRACT(str,'.*(http://.*.[jpg|bmp|png])',1); 
DUMP x; 
+0

을 원하는 것입니다.하지만 아직 없습니다. 이것은 내가 돌아올 것을 몇 가지 예입니다 :'() (http://t.co/Vbiq6ZuvzB) RT Entran를 입력) () () (http://t.co/TQu8XGg) (http://t.co/EYp) () (http://t.co/g0p) () (http://t.co/efo13URHBg HTTP) () (HTTP ://t.co/DJU5KlsiCr HTTP) () () (http://t.co/HUVPF9j) (http://t.co/iipidujn) () () (HTTP : // t.co/Xd6NqApcnC http) () () () () () 은 (http://t.co/tXQT891XA5 HTTP) ()가 ()가 ()가 은 (http://t.co/b7hjMWNg)' – Havnar

+0

당신이 당신의 JSON을 붙여 넣을 수 있습니다 파일. 나는 이미지 URL의 모든 입력을 확인하고 싶습니까? –

+0

은 – Havnar