2017-12-05 6 views
1

私は、研究のために特定の部分だけが興味深い新聞記事のコーパスを持っています。データにノイズが多すぎるため、さまざまなフレームに沿ってテキストを分類することで得られる結果に満足できません。したがって、私は文書から関連する部分だけを抽出したいと思っています。私は、quantedaパッケージによって生成されたいくつかのkwicオブジェクトを単一のdfに変換することによってそうすることを考えていました。kwicオブジェクトを単一のdfmに変換する

は、これまでのところ、私は、次の

exampletext <- c("The only reason for (the haste) which we can discern is the prospect of an Olympic medal, which is the raison d'etat of the banana republic,'' The Guardian said in an editorial under the headline ''Whatever Zola Wants. . .'' The Government made it clear it had acted promptly on the application to insure that the 5-foot-2-inch track star could qualify for the British Olympic team. The International Olympic Organization has a rule that says athletes who change their nationality must wait three years before competing for that country - a rule, however, that is often waived by the I.O.C. The British Olympic Association said it consulted with the I.O.C. before asserting Miss Budd's eligibility for the British team. ''Since Zola is now here and has a British passport she should be made to feel welcome and accepted by other British athletes,'' said Paul Dickenson, chairman of the International Athletes Club, an organization that raises money for amateur athletes and looks after their political interests. ''The thing we objected to was the way she got into the country by the Government and the Daily Mail and the commercialization exploitation associated with it.", "That left 14 countries that have joined the Soviet-led withdrawal. Albania and Iran had announced that they would not compete and did not send written notification. Bolivia, citing financial trouble, announced Sunday it would not participate.The 1972 Munich Games had the previous high number of competing countries, 122.No Protest Planned on Zola Budd YAOUNDE, Cameroon, June 4 (AP) - African countries do not plan to boycott the Los Angeles Olympics in protest of the inclusion of Zola Budd, the South African-born track star, on the British team, according to Lamine Ba, the secretary-general of the Supreme Council for Sport in Africa. Because South Africa is banned from participation in the Olympics, Miss Budd, whose father is of British descent, moved to Britain in March and was granted British citizenship.75 Olympians to Train in Atlanta ATLANTA, June 4 (AP) - About 75 Olympic athletes from six African countries and Pakistan will participate in a month-long training camp this summer in Atlanta under a program financed largely by a grant from the United States Information Agency, Anne Bassarab, a member of Mayor Andrew Young's staff, said today. The athletes, from Mozambique, Tanzania, Zambia, Zimbabwe, Uganda, Somalia and Pakistan, will arrive here June 24.") 
mycorpus <- corpus(exampletext) 
mycorpus.nat <- corpus(kwic(mycorpus, "nationalit*", window = 5, valuetype = "glob")) 
mycorpus.cit <- corpus(kwic(mycorpus, "citizenship", window = 5, valuetype = "glob")) 
mycorpus.kwic <- mycorpus.nat + mycorpus.cit 
mydfm <- dfm(mycorpus.kwic) 

これを試してみた、しかし、4つの文書の代わりに2が含まれているDFMを生成し、両方のキーワードはさらに、文書中に存在しているとき。私は元の数の文書にdfmを下げる方法を考えることはできません。

私を助けていただきありがとうございます。

答えて

1

我々は最近、この目的のためにtokens_select()window引数を追加しました:

require(quanteda) 
    txt <- c("The only reason for (the haste) which we can discern is the prospect of an Olympic medal, which is the raison d'etat of the banana republic,'' The Guardian said in an editorial under the headline ''Whatever Zola Wants. . .'' The Government made it clear it had acted promptly on the application to insure that the 5-foot-2-inch track star could qualify for the British Olympic team. The International Olympic Organization has a rule that says athletes who change their nationality must wait three years before competing for that country - a rule, however, that is often waived by the I.O.C. The British Olympic Association said it consulted with the I.O.C. before asserting Miss Budd's eligibility for the British team. ''Since Zola is now here and has a British passport she should be made to feel welcome and accepted by other British athletes,'' said Paul Dickenson, chairman of the International Athletes Club, an organization that raises money for amateur athletes and looks after their political interests. ''The thing we objected to was the way she got into the country by the Government and the Daily Mail and the commercialization exploitation associated with it.", "That left 14 countries that have joined the Soviet-led withdrawal. Albania and Iran had announced that they would not compete and did not send written notification. Bolivia, citing financial trouble, announced Sunday it would not participate.The 1972 Munich Games had the previous high number of competing countries, 122.No Protest Planned on Zola Budd YAOUNDE, Cameroon, June 4 (AP) - African countries do not plan to boycott the Los Angeles Olympics in protest of the inclusion of Zola Budd, the South African-born track star, on the British team, according to Lamine Ba, the secretary-general of the Supreme Council for Sport in Africa. Because South Africa is banned from participation in the Olympics, Miss Budd, whose father is of British descent, moved to Britain in March and was granted British citizenship.75 Olympians to Train in Atlanta ATLANTA, June 4 (AP) - About 75 Olympic athletes from six African countries and Pakistan will participate in a month-long training camp this summer in Atlanta under a program financed largely by a grant from the United States Information Agency, Anne Bassarab, a member of Mayor Andrew Young's staff, said today. The athletes, from Mozambique, Tanzania, Zambia, Zimbabwe, Uganda, Somalia and Pakistan, will arrive here June 24.") 
    toks <- tokens(txt) 
    mt_nat <- dfm(tokens_select(toks, "nationalit*", window = 5)) 
    mt_cit <- dfm(tokens_select(toks, "citizenship*", window = 5)) 

あなたがQuantedaの最新バージョンを使用していることを確認してください。

+0

https://github.com/kbenoit/QTAUR-halfday/blob/master/2_basic/2_basic.Rmd –

+0

のTargeted Analysisのセクションをご覧ください。ありがとうございました!私はしかし、追加の質問があります。機能の重複がなくても両方のdfmを組み合わせる方法はありますか?または、これらのキーワードを1つのキーワードに置き換えて、dfmを作成するだけですか?再び、多くのありがとう。 編集:または、このコード行はそれを行いますか? lsd_trump_dfm < - dfm(tokens_keep(comp_toks、c( 'donald_trump'、 'trump')、window = 10)) – fritsvegters

+1

quantedaパッケージが大好きです。このような機能の選択を容易にすることで、精度とf1スコアが向上しました。 – fritsvegters

関連する問題