2012-11-30 11 views
47

के साथ टेक्स्ट को लोअरकेस में कनवर्ट करने में त्रुटि मैंने tm_map का उपयोग करने का प्रयास किया। यह निम्नलिखित त्रुटि दी। मैं इसके पास कैसे आ सकता हूं?tm_map (..., tolower)

require(tm) 
byword<-tm_map(byword, tolower) 

Error in UseMethod("tm_map", x) : 
    no applicable method for 'tm_map' applied to an object of class "character" 
+2

क्या पैकेज है 'tm_map' से? ऐसा लगता है कि कुछ गैर-बेस पैकेज पर निर्भर है। कृपया पूर्णता के लिए 'लाइब्रेरी' कथन सहित विचार करें। –

+1

@DanielKrizian: 'tm_map()' 'tm' पैकेज से है, और' tolower() '' base' – smci

उत्तर

101

उपयोग आधार आर समारोह tolower():

tolower(c("THE quick BROWN fox")) 
# [1] "the quick brown fox" 
+0

धन्यवाद से है। लेकिन मुझे कोई त्रुटि क्यों मिली कि मुझे यह त्रुटि क्यों मिली? मुझे अन्य tm_map अनुप्रयोगों का उपयोग करने की आवश्यकता हो सकती है! – jackStinger

+0

'tm_map' (पैकेज' tm' में) के लिए सहायता फ़ाइल उपयोग करने योग्य परिवर्तन कार्यों की एक सूची दिखाती है और 'tolower' उनमें से एक नहीं है। परिवर्तन एस 3 विधियों के रूप में दिखाई देते हैं जो कक्षा 'कॉर्पस' की वस्तुओं पर काम करते हैं। तो आप 'tm_map' के साथ किसी भी फ़ंक्शन का उपयोग नहीं कर सकते हैं। – bdemarest

3
myCorpus <- Corpus(VectorSource(byword)) 
myCorpus <- tm_map(myCorpus , tolower) 

print(myCorpus[[1]]) 
+9

आपको 'content_transformer' के अंदर 'tolower' को लपेटना चाहिए' VCorpus' ऑब्जेक्ट को खराब नहीं करना, जैसे:' tm_map (myCorpus, content_transformer (tolower)) ' – daroczig

+0

@daroczig: कृपया इसे उत्तर दें! – smci

+0

@smci इस विचार के लिए धन्यवाद, मैंने उपरोक्त टिप्पणी को नीचे एक नया उत्तर के रूप में सबमिट किया है :) – daroczig

1

tolower इस तरह से एक अवांछनीय पक्ष प्रभाव पड़ता है का उपयोग करते हुए: यदि आप बाद में कोष से बाहर एक शब्द दस्तावेज़ मैट्रिक्स बनाने का प्रयास करें, यह असफल हो जाएगा। यह टीएम में हालिया परिवर्तन की वजह से है जो रिटर्न प्रकार के टोलर को संभाल नहीं सकता है। इसके बजाय, का उपयोग करें:

myCorpus <- tm_map(myCorpus, PlainTextDocument) 
6

यहाँ मेरी comment करने के लिए एक अधिक विस्तृत जवाब विस्तार करना: आप tolowercontent_transformer के अंदर रैप करने के लिए VCorpus वस्तु ऊपर पेंच के लिए नहीं है - की तरह कुछ:

> library(tm) 
> data('crude') 
> crude[[1]]$content 
[1] "Diamond Shamrock Corp said that\neffective today it had cut its contract prices for crude oil by\n1.50 dlrs a barrel.\n The reduction brings its posted price for West Texas\nIntermediate to 16.00 dlrs a barrel, the copany said.\n \"The price reduction today was made in the light of falling\noil product prices and a weak crude oil market,\" a company\nspokeswoman said.\n Diamond is the latest in a line of U.S. oil companies that\nhave cut its contract, or posted, prices over the last two days\nciting weak oil markets.\n Reuter" 
> tm_map(crude, content_transformer(tolower))[[1]]$content 
[1] "diamond shamrock corp said that\neffective today it had cut its contract prices for crude oil by\n1.50 dlrs a barrel.\n the reduction brings its posted price for west texas\nintermediate to 16.00 dlrs a barrel, the copany said.\n \"the price reduction today was made in the light of falling\noil product prices and a weak crude oil market,\" a company\nspokeswoman said.\n diamond is the latest in a line of u.s. oil companies that\nhave cut its contract, or posted, prices over the last two days\nciting weak oil markets.\n reuter" 
संबंधित मुद्दे