Iam versuchen, Zeilen in auf Zeile zu kombinieren in TermDocumentMatrix
Wie Zeilen in TermDocumentMatrix zu einer Zeile kombinieren?
(weiß, dass ich jede Zeile jeweils Worte darstellt) Samething, zu kombinieren Iam versuchen
ex) cabin, staff -> crews
Weil ‚Kabine, Personal und Besatzung‘ bedeuten Zeilen, die "Kabine, Personal" in einer Zeile darstellen, die "Besatzung" darstellt.
aber es funktioniert überhaupt nicht.
R sagte argument "weighting" is missing, with no default
Die Codes Ich tippte unter
r=GET('http://www.airlinequality.com/airline-reviews/cathay-pacific-airways/')
base_url=('http://www.airlinequality.com/airline-reviews/cathay-pacific-airways/')
h<-read_html(base_url)
all.reviews = c()
for (i in 1:10){
print(i)
url = paste(base_url, 'page/', i, '/', sep="")
r = GET(url)
h = read_html(r)
comment_area = html_nodes(h, '.tc_mobile')
comments= html_nodes(comment_area, '.text_content')
reviews = html_text(comments)
all.reviews=c(all.reviews, reviews)}
cps <- Corpus(VectorSource(all.reviews))
cps <- tm_map(cps, content_transformer(tolower))
cps <- tm_map(cps, content_transformer(stripWhitespace))
cps <- tm_map(cps, content_transformer(removePunctuation))
cps <- tm_map(cps, content_transformer(removeNumbers))
cps <- tm_map(cps, removeWords, stopwords("english"))
tdm <- TermDocumentMatrix(cps, control=list(
wordLengths=c(3, 20),
weighting=weightTf))
rows.cabin = grep('cabin|staff', row.names(tdm))
rows.cabin
# [1] 235 1594
count.cabin = as.array(rollup(tdm[rows.cabin,], 1))
count.cabin
#Docs
#Terms 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#1 0 1 1 0 0 2 2 0 0 1 1 0 4 0 1 0 1 0 2 1 0 0 1 3 1 4 2 0 3 0 1 1 4 0 0 2 1 0 0 2 1 0 2 1 3 3 1
#Docs
#Terms 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#1 0 1 0 1 2 3 2 2 1 1 0 2 0 0 0 0 0 2 0 1 0 0 4 0 2 2 1 3 1 1 1 1 0 0 0 5 3 0 2 1 0 1 0 0
#Docs
#Terms 92 93 94 95 96 97 98 99 100
#1 1 5 2 1 0 0 0 1 0
row.crews = grep('crews', row.names(tdm))
row.crews
#[1] 408
tdm[row.crews,] = count.cabin
rows.cabin = setdiff(rows.cabin, row.crews) # ok
tdm = tdm[-rows.cabin,] # ok
dtm = as.DocumentTermMatrix(tdm)
# Error in .TermDocumentMatrix(t(x), weighting) :
# argument "weighting" is missing, with no default
vielleicht ist es nicht richtiger Ansatz ist, dies zu kombinieren Reihen in TermDocumentMatrix
Bitte beheben Sie diesen Codes oder schlagen besseren Ansatz zu lösen Problem.
Vielen Dank im Voraus.
Hallo
dict
angepasst! Es tut mir leid, dass ich spät danke gesagt habe. –aber es gibt immer noch das Problem, dass ich, nachdem ich Zeilen in der von Ihnen vorgeschlagenen Weise kombiniert habe, "Gewicht" ex) verloren habe, tfidf in 'TermDocumentMatrix'. Ich habe viele Dinge ausprobiert, aber ich weiß nicht warum und wie ich es lösen kann. hast du irgendeine Idee? –
In der Theorie: Add 'Attribute (tdm) <- c (Attribute (tdm), Liste (Gewichtung = unlist (Attribute (GewichtTf) [c (" Name "," Akronym ")], F, F))) und Die Standard-Häufigkeitsgewichtung ist zurück (Name & Akronym). – lukeA