2014-04-13 4 views
1

나는 폴란드 언어의 코퍼스에 연결하고 목표 단어 빈도를 묻는 Rcurl으로 쓰여진 작은 스크립트가 있습니다. 그러나이 솔루션은 표준 문자로만 작동합니다. 나는 폴란드어 편지 (즉, "ę", "±")로 단어에 대해 물으면 그 일치가 없습니다. 출력 로그는 스크립트가 URL 주소의 폴란드 문자를 올바르게 전송하지 못한다는 것을 나타냅니다.getForm - 특수 문자를 보내는 방법?

내 스크립트 :

#slowo = word; 
wordCorpusChecker<- function (slowo, korpus=2) { 
#this line help me bypass the redirection page after calling for specific word 
curl = getCurlHandle(cookiefile = "", verbose = TRUE, 
         followlocation=TRUE, encoding = "utf-8") 
#standard call for submitting html form 
getForm("http://korpus.pl/poliqarp/poliqarp.php", 
      query = slowo, corpus = as.character(korpus), showMatch = "1", 
      showContext = "3",leftContext = "5", rightContext = "5", 
      wideContext = "50", hitsPerPage = "10", 
      .opts = curlOptions(
      verbose = T, 
      followlocation=TRUE, 
      encoding = "utf-8" 
     ) 
      , curl = curl) 
#In test2 there is html of page where I can find information I'm interested in 
    test1 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl) 
    test2 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl) 
#"scrapping" the frequency from html website 
a<-regexpr("Found <em>", test2)[1]+ 
     as.integer(attributes(regexpr("Found <em>", test2))) 
     b<-regexpr("</em> results<br />\n", test2)[1] - 1 
     c<-a:b 
     value<-substring(test2, c[1], c[length(c)]) 
     return(value) 

    } 

#if you try this you will get nice result about "pies" (dog) frequency in polish corpus 
    wordCorpusChecker("pies") 

#if you try this you will get no match because of the special characters 
    wordCorpusChecker("kałuża") 

#the log from `verbose`: 

    GET /poliqarp/poliqarp.php?query=ka%B3u%BFa&corpus=2&showMatch=1&showContext=3&leftContext=5&rightContext=5&wideContext=50&hitsPerPage=10 

나는 encoding 옵션을 지정하려고 노력하지만 설명서가 말한다 같은 쿼리의 결과를 의미했습니다. curlUnescape으로 실험하고 있지만 긍정적 인 결과는 없습니다. 친절하게 조언을 구합니다.

답변

0

한 가지 해결책은 내가 유니 코드에 특수 문자를 변경 iconv`to`사용 관리, 예를 들어 당신의 adivce에

> "ka\u0142u\u017Ca" 
[1] "kałuża" 
wordCorpusChecker("ka\u0142u\u017Ca") 

[1] "55" 
+0

감사를 UTF 코딩을 지정하는 것입니다. 정말 대단히 고마워! – KkK

관련 문제