Help us understand the problem. What is going on with this article?

係り受け解析

More than 1 year has passed since last update.

library(dplyr)

library(RMeCab)


sentence=c("日々の出来事を紙などに記録したものである。単なる記録として扱われるものから、文学として扱われるものまで、その内容は様々である。ある人物の生涯にわたって記されるような長期にわたるものから、ある旅、ある職務、ある事件などの間だけ記された短期のものまで、期間・分量も様々であり、西洋・東洋を問わず、世界的に存在する。")

write.table(sentence,"~/txt.txt")

p=NgramDF("txt.txt",type=1,N=2)

freq=RMeCabFreq("txt.txt")

library(stringr)

sentence_num=length(unlist(strsplit(sentence,"。")))

sentences=unlist(strsplit(sentence,"。"))

#一文をやってみる!

j=3

a_sentence=sentences[j]

write.table(sentences[j],"~/txt_sub.txt")

p_sub=NgramDF2("txt_sub.txt",type=1,N=2)

freq_sub=RMeCabFreq("txt_sub.txt")

#Lの計算

w_sub=unique(freq_sub$Term)

#C(1,length(w_sub))を計算

n=length(w_sub)

L=c();und_approx=c();upp_approx=c()

L_fun=function(j){

z<-(1/j)*prod(c(1:(2*(j-1)))/rep(c(1:(j-1)),2))

z[is.nan(z)>0]=1

return(z)

}

for(j in 1:(n-1)){

if(j==1){

approx=c(approx,(2^j)/(4*sqrt(pi)))  

und_approx=c(und_approx,(2^j)/(4*sqrt(pi)))

upp_approx=c(upp_approx,(2^(2*j))/(4*sqrt(pi)))

L=c(L,1)  

}else{  

L=c(L,L_fun(j))

approx=c(approx,(2^j)/(4*sqrt(pi)))  

und_approx=c(und_approx,(2^j)/(4*sqrt(pi)))

upp_approx=c(upp_approx,(2^(2*j))/(4*sqrt(pi)))


}

}



#Lの畳み込みを計算する

L_real=c()

for(j in 1:(n-1)){

L_real=c(L_real,L_fun(j)*L_fun(n-j))  

}

und_approx<L

L<upp_approx

#出発ワードを決める

start_word=freq_sub$Term[30]

word_vectors=c()

times=100

for(k in 1:times){

if(k==1){  

p_sub_sub = p_sub %>% filter(Ngram1==start_word)

word_vectors=c(word_vectors,p_sub_sub$Ngram2[p_sub_sub$Freq==max(p_sub_sub$Freq)])

word=p_sub_sub$Ngram2[p_sub_sub$Freq==max(p_sub_sub$Freq)]

}else{

p_sub_sub = p_sub %>% filter(Ngram1==word)

if(length(p_sub_sub)>0){

word_vectors=c(word_vectors,p_sub_sub$Ngram2[p_sub_sub$Freq==max(p_sub_sub$Freq)])

word=p_sub_sub$Ngram2[p_sub_sub$Freq==max(p_sub_sub$Freq)]

}

}

}

word_vectors=word_vectors[word_vectors!="\""]

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away