2010-06-04 4 views

답변

9

예를 사용하여 (이것은 x는/VBX, 하나의 문자로 태그 단어를 추출)

좋아, 내 정규 표현식 위해 몇 가지 개선이 필요한

가 마지막 줄 제거하는

library("openNLP") 

acq <- "Gulf Applied Technologies Inc said it sold its subsidiaries engaged in pipeline and terminal operations for 12.2 mln dlrs. The company said the sale is subject to certain post closing adjustments, which it did not explain. Reuter." 

acqTag <- tagPOS(acq) 

sapply(strsplit(acqTag,"[[:punct:]]*/VB.?"),function(x) sub("(^.*\\s)(\\w+$)", "\\2", x)) 

    [,1]       
[1,] "said"       
[2,] "sold"       
[3,] "engaged"      
[4,] "said"       
[5,] "is"       
[6,] "did"       
[7,] " not/RB explain./NN Reuter./." 
그 결과

편집

대안은 행이 space 문자를

sapply(strsplit(acqTag,"[[:punct:]]*/VB.?"),function(x) {res = sub("(^.*\\s)(\\w+$)", "\\2", x); res[!grepl("\\s",res)]}) 
+0

감사를 포함 무시 될 수있다! gd047 :) 작동합니다 ... 나는 추출을 위해 sapply를 거의 사용하려고했지만 어떻게 할 수 없었습니다. 감사. –

관련 문제