Package: liwc-analysis
liwc-analysisThis package serves as a driver for the LIWC2015 .txt dictionary. The dictionary is not included and can be purchased directly from LIWC.UsageThe usage is fairly straight forward. First import the packageimportliwcanalysisThen 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.",}str_list=[]forkeyintranscripts:str_list.append(transcripts[key])result_dics,count_dics=LIWC.analyze(str_list)Please note thatanalyze()can take either a single string argument or a list of strings. Example:# this is validresult_dics,coutn_dics=LIWC.analyze(["this is a string","here is another","one more"])# this is also validresult_dics,coutn_dics=LIWC.analyze("this is a string")result_dicsis a list of dictionaries. Each dictionary corresponds to one of the strings passed intoanalyze. 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_dicsis very similar toresult_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.You can also retrieve an alphabetically sorted (A->Z) list of LIWC categories usingLIWC.get_categories().Full Exampleimportliwcanalysistranscripts={"Example1":"This is a single transcript. Red hat angry.","Example2":"This is another single transcript. Dog boy cat.",}str_list=[]forkeyintranscripts: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(str_list)LIWC.print(output_dir,list(transcript.keys()))Using print will return the following tables:
/Path/to/my/file/LIWCcounts.csv:CategoryExample1Example2ADJ11ARTICLE1AUXVERB11FOCUSPRESENT11FUNCTION22IPRON1MALE1NUMBER11PRONOUN1QUANT12SOCIAL1VERB11WORK11TOTAL88/Path/to/my/file/LIWCwords.csv:CategoryExample1Example2ADJ['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.csvCategoryExample1Example2ADJ0.1250.125ARTICLE0.125AUXVERB0.1250.125FOCUSPRESENT0.1250.125FUNCTION0.250.25IPRON0.125MALE0.125NUMBER0.1250.125PRONOUN0.125QUANT0.1250.25SOCIAL0.125VERB0.1250.125WORK0.1250.125Please 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 atericwiener3@gmail.com.