LIWC2015分析的驱动因素。不包括LIWC2015字典。

liwc-analysis的Python项目详细描述


LIWC分析

此包用作liwc2015.txt字典的驱动程序。字典不包括在内,可以直接从LIWC购买。

用法

用法相当直截了当。首先导入包

importliwcanalysis

然后需要创建一个liwc分析的实例,该实例的路径是.txt文件。

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

然后,您可以传入要分析的字符串列表,以接收结果字典和计数字典的元组。

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)

请注意,analyze()可以接受单个字符串参数或字符串列表。示例:

# 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_dics是字典列表。每个字典对应于传入analyze的一个字符串。每本词典都遵循"LIWC Category": [list, of, words, matched]的形式。例如,一个字符串的字典可能类似于:

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

count_dicsresult_dics非常相似,但它不是给出匹配的单词列表,而是给出每个匹配单词列表的长度:

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

最后,您可以使用:

LIWC.print(output_dir,titles)

您需要指定输出目录,以及每个字符串的标题列表。有关更多详细信息,请参见完整示例。

还可以使用LIWC.get_categories()检索按字母顺序排序的LIWC类别列表(a->;z)。

完整示例

importliwcanalysistranscripts={"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()))

使用print将返回以下表格: /路径/to/my/file/liwccounts.csv:

CategoryExample1Example2
ADJ11
ARTICLE1
AUXVERB11
FOCUSPRESENT11
FUNCTION22
IPRON1
MALE1
NUMBER11
PRONOUN1
QUANT12
SOCIAL1
VERB11
WORK11
TOTAL88

/路径/to/my/file/liwcwords.csv:

CategoryExample1Example2
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.']

/路径/to/my/file/liwcrelativerefreq.csv

CategoryExample1Example2
ADJ0.1250.125
ARTICLE0.125
AUXVERB0.1250.125
FOCUSPRESENT0.1250.125
FUNCTION0.250.25
IPRON0.125
MALE0.125
NUMBER0.1250.125
PRONOUN0.125
QUANT0.1250.25
SOCIAL0.125
VERB0.1250.125
WORK0.1250.125

如果您有任何问题或功能要求,请告诉我。请随时打开一个请求,发布,或向我发送一封电子邮件到ericwiener3@gmail.com

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
jsoup有效文件路径抛出java。木卫一。FileNotFoundException   java如何在不删除和添加Mapbox中的层的情况下更改SymbolLayer的Z值?   java计算用户定义年数内四个季度的降雨量   如何在Java中轻松地将格式为“20 0F 01”的字符串更改为十六进制值?   java在JPA或Hibernate中“持久类”和“实体”之间有什么区别?   java Android:AlarmManager“缺少对unregisterReceiver()的调用?”当按下后退按钮时   logcat中的java错误“isDataSchedulerEnabled():false”   java i/p col特性必须是字符串或数字类型,但不能是org。阿帕奇。火花利纳格小姐。向量   java如何从Post请求url和浏览器转储中隐藏密码   多线程javamail中的java问题   java我的用户应该直接连接到数据库吗?如何将用户连接到数据库;   java如何获得Spring数据JPA存储库工厂?   windows java字节数组转换为字符串,但不同的操作系统会产生不同的结果   java代码在eclipse中编译,但不在命令行上编译