GithubHelp home page GithubHelp logo

weightdictr's Introduction

weightdictR

The goal of weightdictR is to facialiate the deployment of weighted dictionaries especially ones including complex multiword patterns. The package was build taking inspirations from gruendls package multidictR.

Installation

You can install the development version of weightdictR from GitHub with:

# install.packages("devtools")
devtools::install_github("TomSOWI/weightdictR")

Example

First of all clean and prepare textdata. This is only necessary if the weighted dictionary includes complex multiword-patterns.

library(weightdictR)
library(quanteda)
library(dplyr)

#Takes a long time to execute

toksBT17_20_clean <- corpus_to_compound_tokens(
  corpus = corpBT17_20,
  pattern = popdictR::gruendl_terms,
  include_totals = TRUE)

…this is already done for a sample of 100 documents to run as an example

#Clean and compound textdata sample
weightdictR::toksBT17_20_clean

#This is my dictionary
weightdictR::klotz_clara


#Deploy my weighted dictionary using the main function of this package: run_weightdict

result_klotz <- run_weightdict(
  text = weightdictR::toksBT17_20_clean,
  dict = klotz_clara,
  dict_name = "klotz"
  )

#Individual context information -----------------------------------------------

#Add party 
party <- data.frame(docname = quanteda::docnames(corpBT17_20), party = docvars(corpBT17_20)$party)
result_klotz <- merge(result_klotz, party)

#Add totals
totals <- data.frame(docname = quanteda::docnames(corpBT17_20), nsentences = nsentence(corpBT17_20), ntokens = ntoken(corpBT17_20))
result_klotz <- merge(result_klotz, totals)

#Final result
result <- result_klotz %>%
  group_by(party) %>%
  reframe(
    nsentence = sum(nsentences),
    ntokens = sum(ntokens),
    klotz_clara = sum(weight)/nsentence,
  )
result

#You may continue by comparing the results using z-transformation
result$klotz_clara_z <- scale(result$klotz_clara, center = T)

weightdictr's People

Contributors

tomsowi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.