Skip to main content

Driver for LIWC2015 analysis. LIWC2015 dictionary not included.

Project description

liwc-analysis

This package serves as a driver for the LIWC2015 .txt dictionary. The dictionary is not included and can be purchased directly from LIWC.

Usage

The usage is fairly straight forward. First import the package

import liwcanalysis

Then you need to create an instance of the LIWC analysis with the path to the .txt file.

LIWCLocation = "/Users/Eric/repositories/transcript-analysis/LIWC/LIWC.2015.all.txt"
LIWC = liwcanalysis.liwc(LIWCLocation)

Then you can pass in a list of strings to analyze to receive a tuple of results dictionary and count dictionary

transcripts = {
    "Example1": "This is a single transcript. Red hat angry.",
    "Example2": "This is another single transcript. Dog boy cat.",
}

strs = []
for key in transcripts:
    strs.append(transcripts[key])

result_dics, count_dics = LIWC.analyze(strs)

result_dics is a list of dictionaries. Each dictionary corresponds to one of the strings passed into analyze. Each dictionary follows the form of "LIWC Category": [list, of, words, matched]. For instance the dictionary for one string might look something like:

{
    "FUNCTION": ["is", "a"],
    "QUANT": ["single"],
    ...
}

count_dics is very similar to result_dics, but instead of giving a list of words matched, it gives the length of each list of words matched:

{
    "FUNCTION": 2,
    "QUANT": 1,
    ...
}

Finally, you can print out the results to csv using:

LIWC.print(output_dir, titles)

You need to specify the output directory, as well as a list of titles for each string. See the full example for more details.

Full Example

import liwcanalysis

transcripts = {
    "Example1": "This is a single transcript. Red hat angry.",
    "Example2": "This is another single transcript. Dog boy cat.",
}

strs = []
for key in transcripts:
    strs.append(transcripts[key])

LIWCLocation = "/Users/Downloads/LIWC/LIWC.2015.all.txt"
output_dir = "/Path/to/my/file/"

LIWC = liwcanalysis.liwc(LIWCLocation)
result_dics, count_dics = LIWC.analyze(strs)
LIWC.print(output_dir, list(transcript.keys()))

Using print will return the following tables: /Path/to/my/file/LIWCcounts.csv:

Category Example1 Example2
ADJ 1 1
ARTICLE 1
AUXVERB 1 1
FOCUSPRESENT 1 1
FUNCTION 2 2
IPRON 1
MALE 1
NUMBER 1 1
PRONOUN 1
QUANT 1 2
SOCIAL 1
VERB 1 1
WORK 1 1
TOTAL 8 8

/Path/to/my/file/LIWCwords.csv:

Category Example1 Example2
ADJ ['single'] ['single']
ARTICLE ['a']
AUXVERB ['is'] ['is']
FOCUSPRESENT ['is'] ['is']
FUNCTION ['is', 'a'] ['is', 'another']
IPRON ['another']
MALE ['boy']
NUMBER ['single'] ['single']
PRONOUN ['another']
QUANT ['single'] ['another', 'single']
SOCIAL ['boy']
VERB ['is'] ['is']
WORK ['transcript.'] ['transcript.']

/Path/to/my/file/LIWCrelativefreq.csv

Category Example1 Example2
ADJ 0.125 0.125
ARTICLE 0.125
AUXVERB 0.125 0.125
FOCUSPRESENT 0.125 0.125
FUNCTION 0.25 0.25
IPRON 0.125
MALE 0.125
NUMBER 0.125 0.125
PRONOUN 0.125
QUANT 0.125 0.25
SOCIAL 0.125
VERB 0.125 0.125
WORK 0.125 0.125

Please let me know if you have any questions or features requests. Please feel free to open up a pull request, issue, or shoot me an email at ericwiener3@gmail.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liwc-analysis-1.2.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liwc_analysis-1.2.0-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file liwc-analysis-1.2.0.tar.gz.

File metadata

  • Download URL: liwc-analysis-1.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for liwc-analysis-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8a4a0964b4e557619f158ccfdb3eaf85317bcc6edb6ec2310526c92fbcb25667
MD5 d3240c92c61db6db1d19770ef7e0cf8b
BLAKE2b-256 5df23ff6ca092b8bee54bcd8101caf0b829ca68a683ffb4dbc3c48b0db213b84

See more details on using hashes here.

File details

Details for the file liwc_analysis-1.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: liwc_analysis-1.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for liwc_analysis-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1544012b5f0eb9a4a66f4cce26658e5ecf79db2e97eaecca55ca72c526bfceab
MD5 3b22fee6ffa47bbaa50f3b0e7d72d166
BLAKE2b-256 bf162c8839032834bedd7d36b900909ca5ff131a8a739073f664251db8dae663

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page